Tensorism
A Rust library built on top of ndarray that provides a domain-specific language (DSL) for expressing tensor computations using named indexes.
Goals
- Make multi-index array expressions explicit, readable, and compositional
- Remain compatible with the
ndarrayecosystem - Provide compile-time index checking via Ricci indexes
Quick example
use Array2;
use new_ndarray;
// Generate a 2D array from indexed expressions
let x: = new_ndarray! ;
Index i ranges over the first dimension of a, while j ranges over the second dimension of a and the only dimension of b (which must be compatible).
Features
Array generation
A top-level for ⟨indexes⟩ => ⟨body⟩ inside new_ndarray! generates a new ndarray::Array whose number of dimensions matches the number of indexes:
let y = new_ndarray! ;
Iterators and aggregation
When used as a sub-expression, for ⟨indexes⟩ => ⟨body⟩ evaluates to a Rust iterator, enabling aggregations:
let x: i64 = new_ndarray! ;
Indexers
Tensorism supports special indexers inside bracket syntax:
rev: i— iterates over the axis in reverse orderplain: ⟨expr⟩— uses a fixedusizeexpression independent of iteration- User-defined indexers via
Reindexing1,Reindexing2, etc.
let array = new_ndarray! ;
Aliases
Fresh index names can be bound using let inside for constructs:
let array = new_ndarray! ;
Conditionals
Nested for constructs support conditional guards with if:
let conditional_sum = new_ndarray! ;
Status
Tensorism is currently experimental. The evaluation strategy is primarily iterator-based, and the DSL may evolve in non-backward-compatible ways in future versions.
License
MIT