gt4py.storage.cartesian package¶
Submodules¶
gt4py.storage.cartesian.interface module¶
- gt4py.storage.cartesian.interface.empty(shape: Sequence[int], dtype: DTypeLike = <class 'numpy.float64'>, *, backend: str, aligned_index: Optional[Sequence[int]] = None, dimensions: Optional[Sequence[str]] = None) np.ndarray | 'cp.ndarray'[source]¶
Allocate an array of uninitialized (undefined) values with performance-optimal strides and alignment.
- Parameters:
shape (Sequence of int) – The shape of the resulting ndarray
dtype (DTypeLike, optional) – The dtype of the resulting ndarray
- Keyword Arguments:
backend (str) – The target backend for which the allocation is optimized.
aligned_index (Sequence of int, optional) – Indicate the index of the resulting array that most commonly corresponds to the origin of the compute domain. If not passed, it is aligned at the data origin.
dimensions (Sequence of str, optional) – Indicate the semantic meaning of the dimensions in the provided array. Only used for determining optimal strides, the information is not stored.
- Returns:
With uninitialized values, padded and aligned to provide optimal performance for the given backend and aligned_index
- Return type:
NumPy or CuPy ndarray
- Raises:
TypeError – If arguments of an unexpected type are specified.
ValueError – If illegal or inconsistent arguments are specified.
- gt4py.storage.cartesian.interface.from_array(data: ArrayLike, dtype: DTypeLike = <class 'numpy.float64'>, *, backend: str, aligned_index: Sequence[int] | None = None, dimensions: Sequence[str] | None = None) np.ndarray | 'cp.ndarray'[source]¶
Allocate an array with values initialized to those of data with performance-optimal strides and alignment.
This copies the values from data to the resulting buffer.
- Parameters:
data (ArrayLike) – Source data to be copied, from which also the shape of the result is derived.
dtype (DTypeLike, optional) – The dtype of the resulting ndarray
- Keyword Arguments:
backend (str) – The target backend for which the allocation is optimized.
aligned_index (Sequence of int, optional) – Indicate the index of the resulting array that most commonly corresponds to the origin of the compute domain. If not passed, it is aligned at the data origin.
dimensions (Sequence of str, optional) – Indicate the semantic meaning of the dimensions in the provided array. Only used for determining optimal strides, the information is not stored.
- Returns:
Copy of data, padded and aligned to provide optimal performance for the given backend and aligned_index
- Return type:
NumPy or CuPy ndarray
- Raises:
TypeError – If arguments of an unexpected type are specified.
ValueError – If illegal or inconsistent arguments are specified.
- gt4py.storage.cartesian.interface.full(shape: Sequence[int], fill_value: numbers.Number, dtype: DTypeLike = <class 'numpy.float64'>, *, backend: str, aligned_index: Optional[Sequence[int]] = None, dimensions: Optional[Sequence[str]] = None) np.ndarray | 'cp.ndarray'[source]¶
Allocate an array with values initialized to fill_value with performance-optimal strides and alignment.
- Parameters:
shape (Sequence of int) – The shape of the resulting ndarray
fill_value (numbers.Number) – The value to which the array elements are initialized.
dtype (DTypeLike, optional) – The dtype of the resulting ndarray
- Keyword Arguments:
backend (str) – The target backend for which the allocation is optimized.
aligned_index (Sequence of int, optional) – Indicate the index of the resulting array that most commonly corresponds to the origin of the compute domain. If not passed, it is aligned at the data origin.
dimensions (Sequence of str, optional) – Indicate the semantic meaning of the dimensions in the provided array. Only used for determining optimal strides, the information is not stored.
- Returns:
Initialized to fill_value, padded and aligned to provide optimal performance for the given backend and aligned_index
- Return type:
NumPy or CuPy ndarray
- Raises:
TypeError – If arguments of an unexpected type are specified.
ValueError – If illegal or inconsistent arguments are specified.
- gt4py.storage.cartesian.interface.ones(shape: Sequence[int], dtype: DTypeLike = <class 'numpy.float64'>, *, backend: str, aligned_index: Optional[Sequence[int]] = None, dimensions: Optional[Sequence[str]] = None) np.ndarray | 'cp.ndarray'[source]¶
Allocate an array with values initialized to 1.0 with performance-optimal strides and alignment.
- Parameters:
shape (Sequence of int) – The shape of the resulting ndarray
dtype (DTypeLike, optional) – The dtype of the resulting ndarray
- Keyword Arguments:
backend (str) – The target backend for which the allocation is optimized.
aligned_index (Sequence of int, optional) – Indicate the index of the resulting array that most commonly corresponds to the origin of the compute domain. If not passed, it is aligned at the data origin.
dimensions (Sequence of str, optional) – Indicate the semantic meaning of the dimensions in the provided array. Only used for determining optimal strides, the information is not stored.
- Returns:
Initialized to 1.0, padded and aligned to provide optimal performance for the given backend and aligned_index
- Return type:
NumPy or CuPy ndarray
- Raises:
TypeError – If arguments of an unexpected type are specified.
ValueError – If illegal or inconsistent arguments are specified.
- gt4py.storage.cartesian.interface.zeros(shape: Sequence[int], dtype: DTypeLike = <class 'numpy.float64'>, *, backend: str, aligned_index: Optional[Sequence[int]] = None, dimensions: Optional[Sequence[str]] = None) np.ndarray | 'cp.ndarray'[source]¶
Allocate an array with values initialized to 0.0 with performance-optimal strides and alignment.
- Parameters:
shape (Sequence of int) – The shape of the resulting ndarray
dtype (DTypeLike, optional) – The dtype of the resulting ndarray
- Keyword Arguments:
backend (str) – The target backend for which the allocation is optimized.
aligned_index (Sequence of int, optional) – Indicate the index of the resulting array that most commonly corresponds to the origin of the compute domain. If not passed, it is aligned at the data origin.
dimensions (Sequence of str, optional) – Indicate the semantic meaning of the dimensions in the provided array. Only used for determining optimal strides, the information is not stored.
- Returns:
Initialized to 0.0, padded and aligned to provide optimal performance for the given backend and aligned_index
- Return type:
NumPy or CuPy ndarray
- Raises:
TypeError – If arguments of an unexpected type are specified.
ValueError – If illegal or inconsistent arguments are specified.
gt4py.storage.cartesian.layout module¶
gt4py.storage.cartesian.layout_registry module¶
- gt4py.storage.cartesian.layout_registry.from_name(name: str) LayoutInfo[source]¶
- gt4py.storage.cartesian.layout_registry.register(name: str, info: LayoutInfo) None[source]¶
gt4py.storage.cartesian.utils module¶
- gt4py.storage.cartesian.utils._allocate_gpu(shape: Sequence[int], layout_map: allocators.BufferLayoutMap, dtype: DTypeLike, alignment_bytes: int, aligned_index: Sequence[int] | None) Tuple['cp.ndarray', 'cp.ndarray'][source]¶
- gt4py.storage.cartesian.utils.allocate_cpu(shape: Sequence[int], layout_map: BufferLayoutMap, dtype: DTypeLike, alignment_bytes: int, aligned_index: Sequence[int] | None) Tuple[Buffer | ArrayInterface | CUDAArrayInterface | MultiStreamDLPackBuffer | SingleStreamDLPackBuffer, ndarray][source]¶
- gt4py.storage.cartesian.utils.allocate_gpu(shape: Sequence[int], layout_map: allocators.BufferLayoutMap, dtype: DTypeLike, alignment_bytes: int, aligned_index: Sequence[int] | None) Tuple['cp.ndarray', 'cp.ndarray']¶
- gt4py.storage.cartesian.utils.asarray(array: FieldLike, *, device: Literal['cpu', 'gpu', None] = None) np.ndarray | cp.ndarray[source]¶
- gt4py.storage.cartesian.utils.dimensions_to_mask(dimensions: Tuple[str, ...]) Tuple[bool, ...][source]¶
- gt4py.storage.cartesian.utils.get_dims(obj: GTDimsInterface | NDArray) Tuple[str, ...] | None[source]¶
- gt4py.storage.cartesian.utils.get_origin(obj: GTDimsInterface | NDArray) Tuple[int, ...] | None[source]¶
- gt4py.storage.cartesian.utils.normalize_storage_spec(aligned_index: Sequence[int] | None, shape: Sequence[int], dtype: DTypeLike, dimensions: Sequence[str] | None) Tuple[Sequence[int], Sequence[int], dtype, Tuple[str, ...]][source]¶
Normalize the fields of the storage spec in a homogeneous representation.
- Returns:
- The output tuple fields verify the following semantics:
aligned_index: tuple of ints with default origin values for the non-masked dimensions
shape: tuple of ints with shape values for the non-masked dimensions
dtype: scalar numpy.dtype (non-structured and without subarrays)
backend: backend identifier string (numpy, gt:cpu_kfirst, gt:gpu, …)
dimensions: a tuple of dimension identifier strings
- Return type:
tuple(aligned_index, shape, dtype, mask)