numojo.core.indexing.index_buffer¶
IndexBuffer (numojo.core.indexing.index_buffer)
Shared integer buffer backend for shape/strides/item.
This type owns a contiguous heap buffer of Ints and provides small helpers for pointer access and SIMD load/store.
Structs¶
IndexBuffer¶
Memory convention: register_passable
Implements: AnyType, Copyable, Equatable, ImplicitlyCopyable, ImplicitlyDestructible, Movable, RegisterPassable, Sized, Stringable, Writable
Shared integer buffer backend for shape/strides/item.
Fields¶
ptr(UnsafePointer[Scalar[DType.int], MutExternalOrigin]): Pointer to the buffer.ndim(Int): Number of elements in the buffer.
Aliases¶
element_type¶
Value: DType.int
Element type of the buffer.
simd_width¶
Value: simd_width_of[DType.int]()
SIMD width for the element type.
__del__is_trivial¶
Value: False
__move_ctor_is_trivial¶
Value: True
__copy_ctor_is_trivial¶
Value: False
Methods¶
__init__¶
Overload 1¶
static
Initialize an IndexBuffer of given size.
Args:
size(Int): Number of elements in the buffer.
Returns:
Self
Overload 2¶
static
Initialize an IndexBuffer with an existing pointer and size.
Args:
ptr(UnsafePointer): UnsafePointer to the buffer.size(Int): Number of elements in the buffer.
Returns:
Self
Overload 3¶
static
Initialize an empty IndexBuffer.
Returns:
Self
Overload 4¶
static
Initialize an IndexBuffer with given Int values.
Args:
*values(Int): Variadic list of integer values.
Returns:
Self
Overload 5¶
static
Initialize an IndexBuffer with given values.
Args:
*values(Scalar): Variadic list of integer values.
Returns:
Self
Overload 6¶
static
Initialize an IndexBuffer with a list of values.
Args:
values(List): List of integer values.
Returns:
Self
Overload 7¶
static
Initialize an IndexBuffer with a list of Int values.
Args:
values(List): List of integer values.
Returns:
Self
Overload 8¶
static
Initialize an IndexBuffer with a range of values.
Args:
values(VariadicList): Range of integer values.
Returns:
Self
Overload 9¶
static
Initialize an IndexBuffer with a range of values.
Args:
values(VariadicList): Range of integer values.
Returns:
Self
Overload 10¶
static
Copy-initialize an IndexBuffer from ancopy IndexBuffer.
Args:
copy(Self): The copy IndexBuffer to copy from.
Returns:
Self
__getitem__¶
Overload 1¶
Get the element at the given index.
Args:
self(Self)idx(Int): Index of the element.
Returns:
Int
Raises
Overload 2¶
Get the element at the given index.
Args:
self(Self)idx(Scalar): Index of the element.
Returns:
Scalar
Raises
Overload 3¶
Get a sub-buffer using a slice.
Args:
self(Self)slice(Slice): Slice object defining the sub-buffer.
Returns:
Self
Raises
__setitem__¶
Overload 1¶
Set the element at the given index.
Args:
self(Self)[mut]idx(Int): Index of the element.value(Int): Value to set.
Raises
Overload 2¶
Set the element at the given index.
Args:
self(Self)[mut]idx(Scalar): Index of the element.value(Scalar): Value to set.
Raises
Overload 3¶
Set a sub-buffer using a slice.
Args:
self(Self)[mut]slice(Slice): Slice object defining the sub-buffer.value(Self): Buffer to set.
Raises
__eq__¶
Check if two IndexBuffers are equal.
Args:
self(Self)other(Self): The other IndexBuffer to compare with.
Returns:
Bool
__ne__¶
Check if two IndexBuffers are not equal.
Args:
self(Self)other(Self): The other IndexBuffer to compare with.
Returns:
Bool
__contains__¶
Overload 1¶
Check if the IndexBuffer contains the given value.
Args:
self(Self)value(Scalar): Value to check for.
Returns:
Bool
Overload 2¶
Check if the IndexBuffer contains the given value.
Args:
self(Self)value(Int): Value to check for.
Returns:
Bool
get_ptr¶
Get the underlying pointer of the buffer.
Notes: The returned pointer is a reference to the internal pointer.
Args:
self(Self)[ref]
Returns:
ref
offset¶
Get a pointer offset by the given amount.
Args:
self(Self)[ref]offset(Int): Offset amount.
Returns:
UnsafePointer
unsafe_load¶
Overload 1¶
Unsafely load a SIMD vector from the buffer at the given index.
Parameters:
width(Int): Width of the SIMD vector.
Args:
self(Self)idx(Int): Index to load from.
Returns:
SIMD
Overload 2¶
Unsafely load a SIMD vector from the buffer at the given index.
Parameters:
width(Int): Width of the SIMD vector.
Args:
self(Self)idx(Scalar): Index to load from.
Returns:
SIMD
unsafe_store¶
Overload 1¶
Unsafely store a SIMD vector to the buffer at the given index.
Parameters:
width(Int): Width of the SIMD vector.
Args:
self(Self)idx(Int): Index to store to.value(SIMD): SIMD vector to store.
Overload 2¶
Unsafely store a SIMD vector to the buffer at the given index.
Parameters:
width(Int): Width of the SIMD vector.
Args:
self(Self)idx(Scalar): Index to store to.value(SIMD): SIMD vector to store.
extend¶
Overload 1¶
Extend the buffer by appending additional integer values.
Args:
self(Self)*values(Int): Variadic list of sizes of extended dimensions.
Returns:
Self
Overload 2¶
Extend the buffer by appending additional integer values from a List.
Args:
self(Self)values(List): List of sizes of extended dimensions.
Returns:
Self
move_axis_to_end¶
Returns a new IndexBuffer by moving the value at axis to the end.
Args:
self(Self)axis(Int): The axis (index) to move. It should be in [-ndim, ndim).
Returns:
Self
pop¶
Drops the item at the given axis (index).
Args:
self(Self)axis(Int): The axis (index) to drop. It should be in [0, ndim).
Returns:
Self
Raises
insert¶
Inserts a value at the given axis (index).
Args:
self(Self)axis(Int): The axis (index) to insert at. It should be in [0, ndim].value(Int): The value to insert.
Returns:
Self
Raises
join¶
Overload 1¶
Join multiple IndexBuffers into a single IndexBuffer.
Args:
self(Self)*others(Self): Variable number of IndexBuffer objects.
Returns:
Self
Overload 2¶
Join multiple IndexBuffers into a single IndexBuffer from a List.
Args:
self(Self)others(List): List of IndexBuffer objects.
Returns:
Self
sort¶
Sort the IndexBuffer in-place.
Args:
self(Self)[mut]order(Bool): If True, sort in ascending order; if False, sort in descending order.
sorted¶
Returns a new IndexBuffer that is sorted.
Args:
self(Self)order(Bool): If True, sort in ascending order; if False, sort in descending order.
Returns:
Self
arange¶
static
Create a IndexBuffer with a range of values.
Args:
start(Int): Start of the range.end(Int): End of the range.step(Int): Step size of the range.
Returns:
Self
Raises
fill¶
static
Create a IndexBuffer filled with the given value.
Args:
size(Int): Number of elements in the buffer.value(Int): Value to fill the buffer with.
Returns:
Self
zeros¶
static
Create a IndexBuffer filled with zeros.
Args:
size(Int): Number of elements in the buffer.
Returns:
Self
ones¶
static
Create a IndexBuffer filled with ones.
Args:
size(Int): Number of elements in the buffer.
Returns:
Self
linspace¶
static
Create a IndexBuffer with linearly spaced values.
Args:
start(Int): Start of the range.end(Int): End of the range.num(Int): Number of elements in the buffer.
Returns:
Self
Raises
invert_permutation¶
static
Invert a permutation.
Args:
perm(Self): IndexBuffer representing a permutation.
Returns:
Self
__repr__¶
Get the official string representation of the IndexBuffer.
Args:
self(Self)
Returns:
String
write_to¶
Write the IndexBuffer to a writer.
Parameters:
W(Writer)
Args:
self(Self)writer(W)[mut]
init_value¶
Initialize the element at the given index. No bounds checking.
Args:
self(Self)[mut]idx(Int): Index of the element.value(Scalar): Value to set.
__iter__¶
Get a forward iterator for the IndexBuffer.
Args:
self(Self)[ref]
Returns:
_IndexBufferIter
__reversed__¶
Get a backward iterator for the IndexBuffer.
Args:
self(Self)[ref]
Returns:
_IndexBufferIter