Skip to content

numojo.core.indexing.validation

Validation (numojo.core.indexing.validation)

Contains utilities for validating indices, shapes, and axes for various indexing and reduction operations.

Structs

Validator

struct Validator

Memory convention: memory_only
Implements: AnyType, ImplicitlyDestructible

Aliases

__del__is_trivial
comptime __del__is_trivial

Value: True

Methods

normalize
normalize(index: Int, dim: Int) -> Int

static

Normalize a possibly negative index.

Args:

  • index (Int): The index to normalize.
  • dim (Int): The size of the dimension.

Returns:

  • Int
check_bounds
check_bounds(index: Int, dim: Int, axis: Int = 0)

static

Check if an index is within bounds for a dimension.

Args:

  • index (Int): The index to check.
  • dim (Int): The size of the dimension.
  • axis (Int): The axis index (for error reporting).

Raises

Error: If the index is out of bounds.

validate_reshape
validate_reshape(current_size: Int, new_shape: NDArrayShape)

static

Validate if a reshape operation is valid.

Args:

  • current_size (Int): Current total number of elements.
  • new_shape (NDArrayShape): The target shape.

Raises

Error: If the reshape is invalid.

validate_and_normalize_axes
validate_and_normalize_axes(rank: Int, axes: List[Int]) -> List[Int]

static

Validate and normalize axes for reduction operations.

Args:

  • rank (Int): The rank of the array.
  • axes (List): The input axes.

Returns:

  • List

Raises

Error: If any axis is invalid or duplicated.