cythonarrays.array_descriptors module¶
- class cythonarrays.array_descriptors.ArrayDescriptor(name, dtype, ndim, shape=None, dtype_numpy=None, default=None)¶
Bases:
object
describes an array used as an instance attribute of a cython class
- Parameters:
name (str)
dtype (str)
ndim (int)
shape (Tuple[int | str])
dtype_numpy (str)
- __init__(name, dtype, ndim, shape=None, dtype_numpy=None, default=None)¶
- Parameters:
name (
str
) – the name of the arraydtype (str) – the numpy-dtype of the array for internal storage
ndim (int) – the number of dimensions of the array
shape (
Tuple
[Union
[int
,str
]]) – the shape of the arraydtype_numpy (
str
) – the numpy-dtype of the array that should be returneddefault (number) – the default value
- get_shape(instance=None)¶
get the shape of the array defined by the ArrayDescriptor using the information from the ArrayShape-instance
- Parameters:
instance (ArrayShapes) – the CDefClass-instance holding the information on the allowed shapes
- Return type:
Tuple
[int
]- Returns:
a tuple with the shape
- static to_dim(arr, ndim)¶
Casts the array to ndim dimensions
- Parameters:
ndim (
int
) – if self.ndim > ndim and the shape of the first axis <> 0: raise ValueError- Return type:
ndarray
- Returns:
array of ndim dimensions
- validate_array(arr, instance=None)¶
checks if the ndim (and the shape, if specified) match and casts the array to the dtype specified
- Parameters:
arr (
ndarray
) – the array to testinstance (ArrayShapes) – the CDefClass-instance holding the information on the allowed shapes
- Return type:
ndarray
- Returns:
the validated array casted to the target dimension and dtype
- property dtype_numpy: str¶
return the numpy dtype
- property shape: Tuple[int | str]¶
the shape of the array described, with numbers or strings
- Parameters:
value (Union[int, str, bytes, Tuple[Union[int, str]]]) – the setter can receive the shape provided as a number, a string (comma separated for several dimensions) or a tuple/list of strings or ints