docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

core::index

On this page

Indexing + slicing traits.

arr[i], arr[i,j], arr[1:3] all desugar through these traits. xs[i] / xs[i] = v on a struct or enum call index / index_set; fixed arrays and GcBuf<T> index directly (no call). a[i:j:k] calls a.slice(i..j) (then .step(k)), see collections::slice. Slices follow Python: bounds clamp to the length (never panic), a negative step reads them from the end.

Structs

SliceArgSource

pub struct SliceArg

a:b:k as an axis argument of a multi-axis index: a[1:, ::2] is a[(SliceArg::new(1, none, none), SliceArg::new(none, none, 2))]. A part left out is none. indices applies the rules of a 1-D slice: negative bounds count from the end, bounds clamp, a negative step walks backwards, a zero step panics.

  • pub start: isize | none§

    Source
  • pub stop: isize | none§

    Source
  • pub step: isize | none§

    Source
  • pub const FULL: SliceArg = SliceArg { start: none, stop: none, step: none }§

    Source

    :, the whole axis.

  • pub const fn new(start: isize | none, stop: isize | none, step: isize | none) -> SliceArg§

    Source

    start:stop:step; a part left out is none.

  • pub const fn indices(self, len: usize) -> (usize, usize, isize)§

    Source

    (first, count, step): the positions first, first + step, .. (count of them) this slice picks from an axis of length len.

RestSource

pub struct Rest

.. among other axis arguments (a[.., 0]): every axis the others leave, taken whole. At most one per index.

NewAxisSource

pub struct NewAxis

none as an axis argument (a[:, none]): a new axis of length 1.

Traits

IndexSource

pub trait Index<I>

a[i] and a[i, j] as a read: index(i).

IndexSetSource

pub trait IndexSet<I, V>

a[i] = v: index_set(i, v). V is a parameter, so one index may take several kinds of value (a[:, 0] = 0.0 stores a scalar, a[:, 0] = col a column); the value's type picks the impl.

  • fn index_set(self, idx: I, value: V)§

    Source

    self[idx] = value.

SliceableSource

pub trait Sliceable<R>

a[i:j] (not Slice: that is the view type, and one glob-imported name cannot be both).

AxisIndexedSource

pub trait AxisIndexed

A type indexed by axes. In x[..] on such a type every integer part is an isize position (other integer types convert, a literal is one), none is NewAxis and .. beside other parts is Rest, so one set of Index / IndexSet impls over isize serves every call.