numojo.core.indexing.item¶
Item (numojo.core.indexing.item)
Implements Item type.
Item is a series of Int on the heap used to index into N-dimensional arrays.
It is used for multi-dimensional indexing, such as arr[Item(1, 2, 3)] to access arr[1, 2, 3].
Structs¶
Item¶
Memory convention: register_passable
Implements: AnyType, Copyable, Equatable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, Representable, Sized, Stringable, Writable
Represents a multi-dimensional index for array access.
The Item struct is used to specify the coordinates of an element within an N-dimensional array.
For example, arr[Item(1, 2, 3)] retrieves the element at position (1, 2, 3) in a 3D array.
Each Item instance holds a sequence of integer indices, one for each dimension of the array.
This allows for precise and flexible indexing into arrays of arbitrary dimensionality.
Example:
from numojo.prelude import *
import numojo as nm
var arr = nm.arange[f32](0, 27).reshape(Shape(3, 3, 3))
var value = arr[Item(1, 2, 3)] # Accesses arr[1, 2, 3]
Fields¶
ndim(Int): Number of dimensions (length of the index tuple).
Aliases¶
element_type¶
Value: DType.int
The data type of the Item 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 Item.
Returns:
Self
Overload 2¶
static
Initializes the Item from an IndexBuffer.
Args:
buf(IndexBuffer): The IndexBuffer to initialize from.
Returns:
Self
Overload 3¶
static
Construct the Item with variable arguments.
Parameters:
T(Indexer): Type of values. It can be converted toIntwithInt().
Args:
*args(T): Initial values.
Returns:
Self
Overload 4¶
static
Construct the Item from a list.
Parameters:
T(IndexerCollectionElement): Type of values. It can be converted toIntwithInt().
Args:
args(List): Initial values.
Returns:
Self
Overload 5¶
static
Construct the Item from a list.
Args:
args(List): Initial values.
Returns:
Self
Overload 6¶
static
Construct the Item from a variadic list.
Args:
args(VariadicList): Initial values.
Returns:
Self
Overload 7¶
static
Construct the Item with given length and initialize to zero.
Args:
ndim(Int): The length of the Item.
Returns:
Self
Overload 8¶
static
Copy construct the Item.
Args:
copy(Self): The Item to copy.
Returns:
Self
__getitem__¶
Overload 1¶
Gets the value at the specified index.
Args:
self(Self)idx(Int): The index of the value to get.
Returns:
Int
Raises
Error: If index is out of range.
Overload 2¶
Return a sliced view of the item as a new Item.
Args:
self(Self)slice_index(Slice): Slice object defining the sub-buffer.
Returns:
Self
Raises
__setitem__¶
Set the value at the specified index.
Args:
self(Self)[mut]idx(Int): The index of the value to set.val(Int): The value to set.
Raises
Error: If index is out of range.
__eq__¶
Checks if two items have identical dimensions and values.
Args:
self(Self)other(Self): The item to compare with.
Returns:
Bool
__ne__¶
Checks if two items have different dimensions or values.
Args:
self(Self)other(Self): The item to compare with.
Returns:
Bool
__contains__¶
Overload 1¶
Check if the Item contains the given value.
Args:
self(Self)val(Scalar): Value to check for.
Returns:
Bool
Overload 2¶
Checks if the given value is present in the item.
Args:
self(Self)val(Int): The value to search for.
Returns:
Bool
load¶
Load a SIMD vector from the Item 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 Item.
store¶
Store a SIMD vector into the Item 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 Item.
unsafe_load¶
Unsafely load a SIMD vector from the Item 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 Item 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.
swapaxes¶
Returns a new item 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 items into a single item.
Args:
self(Self)*others(Self): Variable number of Item 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 item 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
write_to¶
Writes the Item representation to a writer.
Parameters:
W(Writer)
Args:
self(Self)writer(W)[mut]
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
__reversed__¶
Iterate over elements of the Item in reverse.
Args:
self(Self)[ref]
Returns:
_ItemIter