pub fn selection_from<'a, R>(
shape: &Shape,
constraints: &[(&'a str, R)],
) -> Result<Selection, ShapeError>
Expand description
Construct a Selection
from a Shape
and multiple labeled
range constraints.
This function produces a multidimensional selection aligned with
the shape, applying the specified constraints to their
corresponding dimensions. All unconstrained dimensions are filled
with all
to preserve structural alignment.
§Arguments
shape
: The labeled shape defining the full coordinate space.constraints
: A slice of(label, range)
pairs specifying dimension constraints.
§Errors
Returns ShapeError::InvalidLabels
if any label in
constraints
is not present in the shape.
§Example
use ndslice::selection::selection_from;
use ndslice::shape;
let shape = shape!(zone = 2, host = 4, gpu = 8);
let sel = selection_from(&shape, &[("host", 1..3), ("gpu", 0..4)]).unwrap();
assert_eq!(
format!("{sel:?}"),
"All(Range(Range(1, Some(3), 1), Range(Range(0, Some(4), 1), True)))"
);