numojo.core.layout.ndstrides¶
NDArrayStrides (numojo.core.layout.ndstrides)
Implements NDArrayStrides type. NDArrayStrides represents the strides of an NDArray, which is used to calculate the memory offset for each dimension when indexing into the array.
Structs¶
NDArrayStrides¶
Memory convention: register_passable
Implements: AnyType, Copyable, Equatable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, Representable, Sized, Stringable, Writable
Presents the strides of NDArray type.
The data buffer of the NDArrayStrides is a series of Int on memory.
The number of elements in the strides must be positive.
The number of dimension is checked upon creation of the strides.
Fields¶
ndim(Int): Number of dimensions of array. It must be larger than 0.
Aliases¶
element_type¶
Value: DType.int
The data type of the NDArrayStrides elements.
__del__is_trivial¶
Value: False
__move_ctor_is_trivial¶
Value: True
__copy_ctor_is_trivial¶
Value: False
Methods¶
__init__¶
Overload 1¶
static
Initializes an empty NDArrayStrides.
Returns:
Self
Overload 2¶
static
Initializes the NDArrayStrides from an IndexBuffer.
Args:
buf(IndexBuffer): The IndexBuffer to initialize from.
Returns:
Self
Overload 3¶
static
Initializes the NDArrayStrides from strides.
Args:
*strides(Int): Strides of the array.self(Self)[out]
Returns:
Self
Raises
Error: If the number of dimensions is not positive.
Overload 4¶
static
Initializes the NDArrayStrides from a list of strides.
Args:
strides(List): Strides of the array.self(Self)[out]
Returns:
Self
Raises
Error: If the number of dimensions is not positive.
Overload 5¶
static
Initializes the NDArrayStrides from a variadic list of strides.
Args:
strides(VariadicList): Strides of the array.self(Self)[out]
Returns:
Self
Raises
Error: If the number of dimensions is not positive.
Overload 6¶
static
Initializes the NDArrayStrides from another strides. A deep-copy of the elements is conducted.
Args:
strides(Self): Strides of the array.
Returns:
Self
Overload 7¶
static
Initializes the NDArrayStrides from a shape and an order.
Args:
shape(NDArrayShape): Shape of the array.order(String): Order of the memory layout (row-major "C" or column-major "F"). Default is "C".self(Self)[out]
Returns:
Self
Raises
ValueError: If the order argument is not C or F.
Overload 8¶
static
Overloads the function __init__(shape: NDArrayStrides, order: String). Initializes the NDArrayStrides from a given shapes and an order.
Args:
*shape(Int): Shape of the array.order(String): Order of the memory layout (row-major "C" or column-major "F").self(Self)[out]
Returns:
Self
Raises
ValueError: If the order argument is not C or F.
Overload 9¶
static
Overloads the function __init__(shape: NDArrayStrides, order: String). Initializes the NDArrayStrides from a given shapes and an order.
Args:
shape(List): Shape of the array.order(String): Order of the memory layout (row-major "C" or column-major "F").self(Self)[out]
Returns:
Self
Raises
ValueError: If the order argument is not C or F.
Overload 10¶
static
Overloads the function __init__(shape: NDArrayStrides, order: String). Initializes the NDArrayStrides from a given shapes and an order.
Args:
shape(VariadicList): Shape of the array.order(String): Order of the memory layout (row-major "C" or column-major "F").self(Self)[out]
Returns:
Self
Raises
ValueError: If the order argument is not C or F.
Overload 11¶
static
Construct NDArrayStrides with number of dimensions. This method is useful when you want to create a strides with given ndim without knowing the strides values. ndim == 0 is allowed in this method for 0darray (numojo scalar).
Args:
ndim(Int): Number of dimensions.initialized(Bool): Whether the strides is initialized. If yes, the values will be set to 0. If no, the values will be uninitialized.self(Self)[out]
Returns:
Self
Raises
Error: If the number of dimensions is negative.
Overload 12¶
static
Initializes the NDArrayStrides from ancopy strides. A deep-copy of the elements is conducted.
Args:
copy(Self): Strides of the array.
Returns:
Self
__getitem__¶
Overload 1¶
Gets stride at specified index.
Args:
self(Self)index(Int): Index to get the stride.
Returns:
Int
Raises
Overload 2¶
Gets stride at specified index.
Args:
self(Self)index(Scalar): Index to get the shape.
Returns:
Scalar
Raises
Overload 3¶
Return a sliced view of the strides as a new NDArrayStrides.
Args:
self(Self)slice_index(Slice): Slice object defining the sub-buffer.
Returns:
Self
Raises
__setitem__¶
Overload 1¶
Sets stride at specified index.
Args:
self(Self)[mut]index(Scalar): Index to set the stride.val(Scalar): Value to set at the given index.
Raises
Error: Index out of bound.
Overload 2¶
Sets stride at specified index.
Args:
self(Self)[mut]index(Int): Index to set the shape.val(Int): Value to set at the given index.
Raises
Error: Index out of bound.
__eq__¶
Checks if two strides have identical dimensions and values.
Args:
self(Self)other(Self): The strides to compare with.
Returns:
Bool
__ne__¶
Checks if two strides have identical dimensions and values.
Args:
self(Self)other(Self): The strides to compare with.
Returns:
Bool
__contains__¶
Overload 1¶
Checks if the given value is present in the strides.
Args:
self(Self)val(Int): The value to search for.
Returns:
Bool
Overload 2¶
Check if the NDArrayStrides contains the given value.
Args:
self(Self)val(Scalar): Value to check for.
Returns:
Bool
load¶
Load a SIMD vector from the Strides at the specified index.
Parameters:
width(Int): The width of the SIMD vector.
Args:
self(Self)idx(Int): The starting index to load from.
Returns:
SIMD
Raises
Error: If the load exceeds the bounds of the Strides.
store¶
Store a SIMD vector into the Strides at the specified index.
Parameters:
width(Int): The width of the SIMD vector.
Args:
self(Self)idx(Int): The starting index to store to.value(SIMD): The SIMD vector to store.
Raises
Error: If the store exceeds the bounds of the Strides.
unsafe_load¶
Unsafely load a SIMD vector from the Strides at the specified index.
Parameters:
width(Int): The width of the SIMD vector.
Args:
self(Self)idx(Int): The starting index to load from.
Returns:
SIMD
unsafe_store¶
Unsafely store a SIMD vector into the Strides at the specified index.
Parameters:
width(Int): The width of the SIMD vector.
Args:
self(Self)idx(Int): The starting index to store to.value(SIMD): The SIMD vector to store.
permute¶
Return new strides with axes reordered.
Args:
self(Self)axes(List): New axis order. Must contain each axis exactly once.
Returns:
Self
Raises
Error: If axes length doesn't match ndim or contains invalid/duplicate axes.
swapaxes¶
Returns a new strides with the given axes swapped.
Args:
self(Self)axis1(Int): The first axis to swap.axis2(Int): The second axis to swap.
Returns:
Self
Raises
join¶
Join multiple strides into a single strides.
Args:
self(Self)*strides(Self): Variable number of NDArrayStrides objects.
Returns:
Self
extend¶
Extend the shape by sizes of extended dimensions.
Args:
self(Self)*values(Int): Sizes of extended dimensions.
Returns:
Self
move_axis_to_end¶
Returns a new strides by moving the value of axis to the end.
Args:
self(Self)axis(Int): The axis (index) to move.
Returns:
Self
pop¶
Drops information of certain axis.
Args:
self(Self)axis(Int): The axis (index) to drop.
Returns:
Self
Raises
is_contiguous¶
Check if strides represent a contiguous layout for the shape.
Args:
self(Self)shape(NDArrayShape): The shape of the array.
Returns:
Bool
Raises
__len__¶
Gets number of elements in the strides. It equals to the number of dimensions of the array.
Args:
self(Self)
Returns:
Int
write_to¶
Writes the strides representation to a writer.
Parameters:
W(Writer)
Args:
self(Self)writer(W)[mut]
row_major¶
static
Create row-major (C-style) strides from a shape.
Args:
shape(NDArrayShape): The shape of the array.
Returns:
Self
Raises
col_major¶
static
Create column-major (Fortran-style) strides from a shape.
Args:
shape(NDArrayShape): The shape of the array.
Returns:
Self
Raises
default¶
static
Create default (row-major) strides from a shape.
Args:
shape(NDArrayShape): The shape of the array.
Returns:
Self
Raises
normalize_index¶
Normalizes the given index to be within the valid range [0, ndim).
Args:
self(Self)index(Int): The index to normalize.
Returns:
Int
__iter__¶
Iterate over elements of the NDArrayStrides, returning copied values.
Args:
self(Self)[ref]
Returns:
_StrideIter
__reversed__¶
Iterate over elements of the NDArrayStrides, returning copied values.
Args:
self(Self)[ref]
Returns:
_StrideIter