Expand description
Selection algebra for describing multidimensional mesh regions. This module defines a recursive algebra for selecting coordinates in a multidimensional space.
A Selection
describes constraints across dimensions of an
ndslice::Slice
. Variants like [All
], [First
], and Range
operate dimensionally, while [Intersection
] and [Union
] allow
for logical composition of selections.
§Example
Suppose a 3-dimensional mesh system of:
- 2 zones
- 4 hosts per zone
- 8 GPUs per host
The corresponding Slice
will have shape [2, 4, 8]
. An
expression to denote the first 4 GPUs of host 0 together with the
last 4 GPUs on host 1 across all regions can be written as:
use ndslice::selection::dsl::all;
use ndslice::selection::dsl::range;
use ndslice::selection::dsl::true_;
use ndslice::selection::dsl::union;
let s = all(range(0, range(0..4, true_())));
let t = all(range(1, range(4.., true_())));
let selection = union(s, t);
Assuming a row-major layout, that is the set of 4 x 2 x 2 = 16 coordinates {(0, 0, 0), … (0, 0, 3), (0, 1, 5), …, (0, 1, 7), (1, 0, 0), …, (1, 0, 3), (1, 1, 4), …, (1, 1, 7)} where code to print that set might read as follows.
use ndslice::Slice;
use ndslice::selection::EvalOpts;
use ndslice::selection::dsl::all;
use ndslice::selection::dsl::range;
use ndslice::selection::dsl::true_;
use ndslice::selection::dsl::union;
let slice = Slice::new(0usize, vec![2, 4, 8], vec![32, 8, 1]).unwrap();
let s = all(range(0, range(0..4, true_())));
let t = all(range(1, range(4.., true_())));
for r in union(s, t).eval(&EvalOpts::lenient(), &slice).unwrap() {
println!("{:?}", slice.coordinates(r).unwrap());
}
which is using the eval
function described next.
§Evaluation
Selections are evaluated against an ndslice::Slice
using the
Selection::eval
method, which returns a lazy iterator over the
flat (linearized) indices of elements that match.
Evaluation proceeds recursively, dimension by dimension, with each
variant of Selection
contributing logic at a particular level of
the slice.
If a Selection
is shorter than the number of dimensions, it is
implicitly extended with true_()
at the remaining levels. This
means Selection::True
acts as the identity element, matching all
remaining indices by default.
Modules§
- dsl
SelectionSYM
-based constructors specialized to theSelection
AST.- normal
- Normalization logic for
Selection
. - parse
- A parser for selection expressions in a compact textual syntax.
- pretty
- Formatting utilities for
Selection
expressions. - routing
- Shape navigation guided by
Selection
expressions. - test_
utils - token_
parser - A
TokenStream
toSelection
parser. Used at compile time in [sel!]
. See [selection::parse
] for syntax details and examples. ATokenStream
toSelection
parser used by thesel!
procedural macro.
Structs§
- Eval
Opts EvalOpts
controls runtime behavior ofSelection::eval
by enforcing stricter validation rules.- Normalized
Selection Key - Wraps a normalized selection and derives
Eq
andHash
, relying on the canonical structure of the normalized form.
Enums§
- Label
Key - A metadata label used to constrain values at a given coordinate dimension.
- Selection
- An algebra for expressing node selection.
Traits§
- Reify
Slice - Connects the
select!
API to theSelection
algebra by enablingbase.reify_slice(slice)
syntax, wherebase: Slice
. - SelectionSYM
- This trait defines an abstract syntax without committing to a
specific representation. It follow the
tagless-final
style where
Selection
is a default AST representation.
Functions§
- is_
equivalent_ true - Trivial all(true) equivalence.
- normalize
- Normalizes a
Selection
toward a canonical form for structural comparison. - selection_
from - Construct a
Selection
from aShape
and multiple labeled range constraints. - selection_
from_ one - Construct a
Selection
from aShape
and a single labeled constraint. - structurally_
equal - Compares two
Selection
values for structural equality.