Skip to main content

Crate rapl

Crate rapl 

Source
Expand description

Enjoyable, composable, hackable N-dimensional arrays for Rust.

rapl combines the familiar parts of NumPy with array programming languages like APL and BQN. Ranks are part of the type, so rank mistakes are compile errors, and every operation is built from a small set of composable primitives.

use rapl::*;

let x = Ndarr::from([3, 1, 4, 1, 5, 9, 2, 6]);
let windows = x.slice(s![Win(3)])?;            // a [6, 3] view, no copy
let peaks = windows.reduce(1, i32::max)?;
assert_eq!(peaks, Ndarr::from([4, 4, 5, 9, 9, 9]));

let a = Ndarr::from([1, 2, 3]);
let b = Ndarr::from([[1, 2, 3], [4, 5, 6]]);
assert_eq!(a + b - 1, Ndarr::from([[1, 3, 5], [4, 6, 8]]));  // broadcasting

println!("{peaks}");
// ┌→──────────┐
// │4 4 5 9 9 9│
// └~──────────┘

rapl is in early development: the API is still settling and speed is not yet a priority. See the README for a tour of the API.

Re-exports§

pub use complex::*;

Modules§

complex
ops
utils

Macros§

s
Build a basic-indexing selection: every input axis is named by exactly one non-NewAxis selector. An integer removes its axis, NewAxis inserts a length-one axis, ranges and Slice keep theirs, and Win turns its axis into two: positions then window. range;step takes every step-th element of a range (..;-1 reverses). Indices, bounds, and steps may be any primitive integer type.

Structs§

B0
The type-level bit 0.
B1
The type-level bit 1.
Dim
DimError
Dyn
A rank whose number of axes is known only at runtime.
ElemIter
Borrowed elements of an array in logical C-order.
Keep
A reduction axis that stays in the result with extent 1, so the result broadcasts back against its input: NumPy’s keepdims=True. A bare usize axis is removed instead. The axis is named once, so the reduction and the re-inserted axis cannot disagree.
Ndarr
N-dimensional array of T with rank R. Values live in buffer; the offset, shape, and strides describe the view onto it.
NewAxis
Inserts a length-one axis in Ndarr::slice; consumes no input axis.
Slice
One rank-preserving axis selection: start..end taken every step elements, normalized like NumPy (negative values count from the end, and out-of-range bounds clamp). In s! it is written lo..hi;step, ..;-1, and so on; ranges convert with Slice::from.
Win
Sliding windows of extent w in Ndarr::slice: one input axis (extent n, stride s) becomes a position axis (n - w + 1, stride s) then a window axis (w, stride s), so windows[p, k] == input[p + k] — an O(1) affine view, no copy. Windows alias one element into many windows, so Ndarr::slice_mut rejects Win.

Enums§

ScanDirection
Order in which Ndarr::scan_axis visits each lane.
SliceSpec
One runtime selector of the basic-indexing grammar.

Traits§

BroadcastRank
Buffer
Read-only access to a contiguous buffer of T. Sealed: the only buffers are Vec<T> (owned), &[T], and &mut [T].
BufferMut
Mutable access to a contiguous buffer of T.
BumpRank
Fold step for the output rank of a selection: U0 leaves the rank alone, U1 applies InsertAxisRank once, U2 twice (a Win selector contributes two output axes).
CellAxes
A cell count for Ndarr::map_cells: typenum counts keep the cell rank and a fixed frame rank; usize counts select Dyn for both. Sealed; generic callers may use this bound.
ContractAxes
A contraction count: k pairs trailing self axes with leading other axes; (s, k) first shares s leading axes (a batch both operands walk together), then contracts k. Typenum values preserve fixed output ranks; usize counts select Dyn. Sealed; generic callers may use this bound.
ContractRank
Rank resulting from contracting K axis pairs while sharing S leading axes (L + R - S - 2K). Fixed operands retain compile-time count guards; a dynamic operand makes the output dynamic.
FrameRank
Rank of the frame left after taking K trailing axes as cells. Fixed ranks check K at compile time; Dyn stays Dyn.
IndexInt
A primitive integer usable as an index, bound, or step in s!. Every type is accepted, so integer literals still infer (they fall back to i32) and usize extents need no casts. Values beyond isize saturate, which selects exactly what the out-of-range value would.
InsertAxisRank
Rank
Selects storage for per-axis metadata. Every typenum rank uses an exact inline GenericArray; only Dyn uses a Vec, so fixed rank and metadata length cannot disagree.
RankStore
Storage used for the shape or strides selected by a Rank.
ReduceAxis
The axis argument of Ndarr::reduce and Ndarr::fold_axis: a usize removes the axis (output rank Removed<R>); Keep keeps it with extent 1 (rank R). Sealed; generic callers may use this bound.
RemoveAxisRank
Scalar
Marker for element-like types, keeping blanket scalar operator impls coherent next to the array impls.
Selector
One typed selector of the basic-indexing grammar. Out is the number of output axes it produces: U0 for a scalar index, U2 for Win, U1 otherwise.
SliceArgs
A full selection for Ndarr::slice / Ndarr::slice_mut: computes the output rank and lowers to runtime SliceSpecs. Implemented for tuples of Selectors (built by s!) with compile-time output rank, and for &[SliceSpec] as the runtime escape hatch (output rank Dyn).
StaticRank
A fixed typenum rank. Algorithms using typenum arithmetic may require this stronger bound; ordinary structural APIs should prefer Rank.

Type Aliases§

Broadcasted
Contracted
Output rank selected by the operand ranks and contraction count type.
Inserted
NdView
Borrowed, read-only view: an Ndarr over &[T].
NdViewMut
Borrowed, mutable view: an Ndarr over &mut [T].
Removed
U0
U1
U2
U3
U4
U5
U6
U7
U8