Dolphin dtype
- class dolphin.dtype(value)[source]
Bases:
Enum
Dolphin data types In order to manage the data types in Dolphin, bind dolphin types the numpy data types as well as the CUDA data types. To do so, each element from the Enum class is a tuple containing the numpy data type (numpy.dtype) and the CUDA data type (str).
- uint8 = (<class 'numpy.uint8'>, 'uint8_t')
- uint16 = (<class 'numpy.uint16'>, 'uint16_t')
- uint32 = (<class 'numpy.uint32'>, 'uint32_t')
- int8 = (<class 'numpy.int8'>, 'int8_t')
- int16 = (<class 'numpy.int16'>, 'int16_t')
- int32 = (<class 'numpy.int32'>, 'int32_t')
- float32 = (<class 'numpy.float32'>, 'float')
- float64 = (<class 'numpy.float64'>, 'double')
- __call__(value: Union[int, float, number]) dtype [source]
In order to use the data type as a function to cast a value into a particular type, we need to implement the __call__ method.
Example:
a = dtype.uint8 a(4) -> numpy.uint8(4)
- Parameters:
value (Union[int, float, numpy.number]) – The value to cast to the data type
- Returns:
The numpy casted number passed as value
- Return type:
numpy.dtype
- property numpy_dtype: dtype
Since Dolphin data types are tuples, we need to access the first element which is the numpy data type.
- Returns:
The equivalent numpy data type of Dolphin data type
- Return type:
numpy.dtype
- property cuda_dtype: str
Since Dolphin data types are tuples, we need to access the second element which is the CUDA data type. Which as well are standard C types.
- Returns:
The equivalent CUDA data type of Dolphin data type
- Return type:
str
- property itemsize: int
Returns the size of the data type in bytes. Uses the numpy data type to get the size :
>>> @property >>> def itemsize(self) -> int: >>> return self.numpy_dtype.itemsize
- static from_numpy_dtype(numpy_dtype: dtype) dtype [source]
Returns the equivalent Dolphin data type from the numpy data type.
- Parameters:
numpy_dtype (numpy.dtype) – The numpy data type
- Returns:
The equivalent Dolphin data type
- Return type:
- __getitem__(key: Union[str, int]) Union[dtype, str] [source]
In order to dynamically access the numpy and CUDA data types, we also need to implement the __getitem__ method. if key is an integer, it will return one of the tuple element as long as the key is either 0 or 1. if key is a string, it will return the numpy or CUDA data type as long as the key is either ‘numpy_dtype’ or ‘cuda_dtype’.
Usage:
a = dtype.uint8 a[0] # numpy.uint8 a[1] # 'uint8_t' a["numpy_dtype"] # numpy.uint8 a["cuda_dtype"] # 'uint8_t'
- Parameters:
key (Union[str, int]) – ‘numpy_dtype’ or ‘cuda_dtype’ or a int 0 or 1
- Raises:
KeyError – If the key is not valid as described above
- Returns:
The numpy or CUDA data type
- Return type:
Union[numpy.dtype, str]
- __module__ = 'dolphin.core.dtype'