-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import ctypes | ||
import typing | ||
|
||
|
||
class Ngh_idx(ctypes.Structure): | ||
_fields_ = [("x", ctypes.c_int8), | ||
("y", ctypes.c_int8), | ||
("z", ctypes.c_int8)] | ||
|
||
def __init__(self, | ||
x: int, | ||
y: int, | ||
z: int): | ||
self.x = x | ||
self.y = y | ||
self.z = z | ||
|
||
def __len__(self): | ||
return 3 | ||
|
||
def __getitem__(self, index): | ||
if index == 0: | ||
return self.x | ||
if index == 1: | ||
return self.y | ||
if index == 2: | ||
return self.z | ||
raise IndexError("Index out of range") | ||
|
||
def to_wp_kernel_dim(self) -> typing.Tuple[int, int, int]: | ||
return (self.x, self.y, self.z) | ||
|
||
def __str__(self): | ||
str = "<Index_3d: addr=%ld>" % (ctypes.addressof(self)) | ||
str += f"\n\tx: {self.x}" | ||
str += f"\n\ty: {self.y}" | ||
str += f"\n\tz: {self.z}" | ||
return str | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, Index_3d): | ||
return NotImplemented | ||
return (self.x == other.x and self.y == other.y and self.z == other.z) |