Skip to content

Implement advanced indexing (boolean mask, integer array) in mohu-index #149

Description

@Bbn08

Summary

mohu-index handles indexing strategies beyond basic slicing. Implement boolean mask indexing and integer array (fancy) indexing -- the two most common advanced indexing patterns.

API surface

// crates/mohu-index/src/lib.rs
pub fn index_bool(src: &Buffer, mask: &Buffer) -> MohuResult<Buffer>;
pub fn index_take(src: &Buffer, indices: &Buffer, axis: usize) -> MohuResult<Buffer>;

Behavior

index_bool (boolean mask):

  • mask dtype must be DType::Bool; otherwise DomainError
  • mask must have same shape as src; otherwise ShapeMismatch
  • Returns 1D buffer of elements where mask is true

index_take (integer array indexing):

  • indices dtype must be DType::I64; otherwise DomainError
  • Selects elements along axis at positions given by indices
  • Out-of-bounds index returns MohuError::IndexOutOfBounds
  • Negative indices not supported in v1 (return IndexOutOfBounds)

Acceptance criteria

  • index_bool extracts correct elements for 1D and 2D mask
  • index_take gathers correct rows/cols for 1D and 2D src
  • All error cases tested
  • Output is always a new owning buffer (no view aliasing)
  • No .unwrap() in library code

Signed-off-by: Bbn08 atrancendentbeing@gmail.com

Metadata

Metadata

Labels

GSSoCReserved for GSSoC contributorsenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions