Skip to content

Commit f540b09

Browse files
selection: reify_view -> reify_slice (#743)
Summary: Pull Request resolved: #743 with type `View` now in the code base, i figure `ReifyView` and `reify_view` should be renamed `ReifySlice` and `reify_slice` to get out in front of the inevitable confusion. Reviewed By: mariusae Differential Revision: D79555875 fbshipit-source-id: 5f92d4eb2eed0b2fe6c905675b2eb03ada239b97
1 parent 66da757 commit f540b09

File tree

3 files changed

+66
-66
lines changed

3 files changed

+66
-66
lines changed

hyperactor_mesh/src/actor_mesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use ndslice::ShapeError;
4141
use ndslice::SliceError;
4242
use ndslice::selection;
4343
use ndslice::selection::EvalOpts;
44-
use ndslice::selection::ReifyView;
44+
use ndslice::selection::ReifySlice;
4545
use ndslice::selection::normal;
4646
use serde::Deserialize;
4747
use serde::Serialize;
@@ -130,7 +130,7 @@ where
130130
// Casting to `*`?
131131
let sel_of_root = if selection::normalize(sel_of_sliced) == normal::NormalizedSelection::True {
132132
// Reify this view into base.
133-
root_slice.reify_view(sliced_shape.slice())?
133+
root_slice.reify_slice(sliced_shape.slice())?
134134
} else {
135135
// No, fall back on `of_ranks`.
136136
let ranks = sel_of_sliced

monarch_extension/src/mesh_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use monarch_tensor_worker::AssignRankMessage;
5858
use monarch_tensor_worker::WorkerActor;
5959
use ndslice::Slice;
6060
use ndslice::selection;
61-
use ndslice::selection::ReifyView;
61+
use ndslice::selection::ReifySlice;
6262
use pyo3::exceptions::PyValueError;
6363
use pyo3::prelude::*;
6464
use tokio::sync::Mutex;
@@ -827,7 +827,7 @@ impl Handler<ClientToControllerMessage> for MeshControllerActor {
827827
) -> anyhow::Result<()> {
828828
match message {
829829
ClientToControllerMessage::Send { slices, message } => {
830-
let sel = self.workers().shape().slice().reify_views(slices)?;
830+
let sel = self.workers().shape().slice().reify_slices(slices)?;
831831
self.workers().cast(sel, message)?;
832832
}
833833
ClientToControllerMessage::Node {

ndslice/src/selection.rs

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,81 +1076,81 @@ mod sealed {
10761076
}
10771077

10781078
/// Connects the `select!` API to the `Selection` algebra by enabling
1079-
/// `base.reify_view(view)` syntax, where `base: Slice`.
1079+
/// `base.reify_slice(slice)` syntax, where `base: Slice`.
10801080
///
1081-
/// The base slice defines the coordinate system in which the view is
1082-
/// interpreted. Views are themselves `Slice` values, typically
1081+
/// The base slice defines the coordinate system in which the slice is
1082+
/// interpreted. Slices are themselves `Slice` values, typically
10831083
/// produced by `select!`, and are reified as `Selection` expressions
10841084
/// over the base.
1085-
pub trait ReifyView: sealed::Sealed {
1086-
/// Reify a view as a `Selection` in the coordinate system of
1085+
pub trait ReifySlice: sealed::Sealed {
1086+
/// Reify a slice as a `Selection` in the coordinate system of
10871087
/// `self`.
1088-
fn reify_view(&self, view: &Slice) -> Result<Selection, SliceError>;
1088+
fn reify_slice(&self, slice: &Slice) -> Result<Selection, SliceError>;
10891089

1090-
/// Reify multiple views as a union of selections in the
1090+
/// Reify multiple slices as a union of selections in the
10911091
/// coordinate system of `self`.
1092-
fn reify_views<V: AsRef<[Slice]>>(&self, views: V) -> Result<Selection, SliceError>;
1092+
fn reify_slices<V: AsRef<[Slice]>>(&self, slices: V) -> Result<Selection, SliceError>;
10931093
}
10941094

1095-
impl ReifyView for Slice {
1095+
impl ReifySlice for Slice {
10961096
/// Constructs a [`Selection`] expression that symbolically
1097-
/// matches all coordinates in the given `view`, expressed in the
1097+
/// matches all coordinates in the given `slice`, expressed in the
10981098
/// coordinate system of the provided `base` slice (`self`).
10991099
///
11001100
/// The result is a nested sequence of `range(start..end, step)`
1101-
/// combinators that match the rectangular region covered by `view`
1101+
/// combinators that match the rectangular region covered by `slice`
11021102
/// in base coordinates. This preserves geometry and layout when
1103-
/// `view` is *layout-aligned* — that is, each of its strides is
1103+
/// `slice` is *layout-aligned* — that is, each of its strides is
11041104
/// a multiple of the corresponding base stride.
11051105
///
1106-
/// If any dimension is not layout-aligned, the view is reified
1106+
/// If any dimension is not layout-aligned, the slice is reified
11071107
/// by explicitly enumerating its coordinates.
11081108
///
1109-
/// Returns [`dsl::false_()`] if the view is empty.
1109+
/// Returns [`dsl::false_()`] if the slice is empty.
11101110
///
11111111
/// # Errors
11121112
///
11131113
/// Returns an error if:
11141114
/// - The base is not contiguous and row-major
1115-
/// - The view lies outside the bounds of the base
1115+
/// - The slice lies outside the bounds of the base
11161116
///
11171117
/// # Example
11181118
///
11191119
/// ```rust
1120-
/// use ndslice::selection::ReifyView;
1120+
/// use ndslice::selection::ReifySlice;
11211121
/// let shape = ndslice::shape!(x = 4, y = 4);
11221122
/// let base = shape.slice();
11231123
/// let selected = ndslice::select!(shape, x = 1..3, y = 2..4).unwrap();
1124-
/// let view = selected.slice();
1125-
/// let selection = base.reify_view(view).unwrap();
1124+
/// let slice = selected.slice();
1125+
/// let selection = base.reify_slice(slice).unwrap();
11261126
/// ```
1127-
fn reify_view(&self, view: &Slice) -> Result<Selection, SliceError> {
1127+
fn reify_slice(&self, slice: &Slice) -> Result<Selection, SliceError> {
11281128
// Precondition: the base is contiguous and row major.
11291129
if !self.is_contiguous() {
11301130
return Err(SliceError::NonContiguous);
11311131
}
11321132

1133-
if view.is_empty() {
1133+
if slice.is_empty() {
11341134
return Ok(dsl::false_());
11351135
}
11361136

1137-
if view.num_dim() != self.num_dim()
1138-
|| view.sizes().iter().zip(self.sizes()).any(|(&v, &s)| v > s)
1137+
if slice.num_dim() != self.num_dim()
1138+
|| slice.sizes().iter().zip(self.sizes()).any(|(&v, &s)| v > s)
11391139
{
1140-
return Selection::of_ranks(self, &view.iter().collect::<BTreeSet<usize>>());
1140+
return Selection::of_ranks(self, &slice.iter().collect::<BTreeSet<usize>>());
11411141
}
11421142

1143-
let origin = self.coordinates(view.offset())?;
1143+
let origin = self.coordinates(slice.offset())?;
11441144
let mut acc = dsl::true_();
11451145
for dim in (0..self.num_dim()).rev() {
11461146
let start = origin[dim];
1147-
let len = view.sizes()[dim];
1148-
let view_stride = view.strides()[dim];
1147+
let len = slice.sizes()[dim];
1148+
let slice_stride = slice.strides()[dim];
11491149
let base_stride = self.strides()[dim];
11501150

1151-
if view_stride % base_stride == 0 {
1151+
if slice_stride % base_stride == 0 {
11521152
// Layout-aligned with base.
1153-
let step = view_stride / base_stride;
1153+
let step = slice_stride / base_stride;
11541154
let end = start + step * len;
11551155
// Check that `end` is within bounds.
11561156
if end - 1 > self.sizes()[dim] {
@@ -1166,32 +1166,32 @@ impl ReifyView for Slice {
11661166
acc = dsl::range(crate::shape::Range(start, Some(end), step), acc);
11671167
} else {
11681168
// Irregular layout; fallback to explicit enumeration.
1169-
return Selection::of_ranks(self, &view.iter().collect::<BTreeSet<_>>());
1169+
return Selection::of_ranks(self, &slice.iter().collect::<BTreeSet<_>>());
11701170
}
11711171
}
11721172

11731173
Ok(acc)
11741174
}
11751175

1176-
/// Converts a list of `views` into a symbolic [`Selection`]
1176+
/// Converts a list of `slices` into a symbolic [`Selection`]
11771177
/// expression over a common `base` [`Slice`].
11781178
///
1179-
/// Each view describes a rectangular subregion of the base. This
1180-
/// function reifies each view into a nested `range(.., ..)`
1179+
/// Each slice describes a rectangular subregion of the base. This
1180+
/// function reifies each slice into a nested `range(.., ..)`
11811181
/// expression in the base coordinate system and returns the union
11821182
/// of all such selections.
11831183
///
1184-
/// Empty views are ignored.
1184+
/// Empty slices are ignored.
11851185
///
11861186
/// # Errors
11871187
///
1188-
/// Returns an error if any view:
1188+
/// Returns an error if any slice:
11891189
/// - Refers to coordinates not contained within the base
11901190
///
11911191
/// # Example
11921192
///
11931193
/// ```rust
1194-
/// use ndslice::selection::ReifyView;
1194+
/// use ndslice::selection::ReifySlice;
11951195
///
11961196
/// let shape = ndslice::shape!(x = 4, y = 4);
11971197
/// let base = shape.slice();
@@ -1205,17 +1205,17 @@ impl ReifyView for Slice {
12051205
/// .slice()
12061206
/// .clone();
12071207
///
1208-
/// let sel = base.reify_views(&[a, b]).unwrap();
1208+
/// let sel = base.reify_slices(&[a, b]).unwrap();
12091209
/// ```
1210-
fn reify_views<V: AsRef<[Slice]>>(&self, views: V) -> Result<Selection, SliceError> {
1211-
let views = views.as_ref();
1212-
let mut selections = Vec::with_capacity(views.len());
1210+
fn reify_slices<V: AsRef<[Slice]>>(&self, slices: V) -> Result<Selection, SliceError> {
1211+
let slices = slices.as_ref();
1212+
let mut selections = Vec::with_capacity(slices.len());
12131213

1214-
for view in views {
1215-
if view.is_empty() {
1214+
for slice in slices {
1215+
if slice.is_empty() {
12161216
continue;
12171217
}
1218-
selections.push(self.reify_view(view)?);
1218+
selections.push(self.reify_slice(slice)?);
12191219
}
12201220

12211221
let mut iter = selections.into_iter();
@@ -1445,7 +1445,7 @@ mod tests {
14451445
use std::collections::BTreeSet;
14461446

14471447
use super::EvalOpts;
1448-
use super::ReifyView;
1448+
use super::ReifySlice;
14491449
use super::Selection;
14501450
use super::dsl::*;
14511451
use super::is_equivalent_true;
@@ -2205,9 +2205,9 @@ mod tests {
22052205
}
22062206

22072207
#[test]
2208-
fn test_reify_view_empty() {
2208+
fn test_reify_slice_empty() {
22092209
let slice = Slice::new_row_major([0]);
2210-
let selection = slice.reify_view(&slice).unwrap();
2210+
let selection = slice.reify_slice(&slice).unwrap();
22112211
let expected = false_();
22122212
assert_structurally_eq!(&selection, expected);
22132213
assert_eq!(
@@ -2220,14 +2220,14 @@ mod tests {
22202220
}
22212221

22222222
#[test]
2223-
fn test_reify_view_1d() {
2223+
fn test_reify_slice_1d() {
22242224
let shape = shape!(x = 6); // 1D shape with 6 elements
22252225
let base = shape.slice();
22262226

22272227
let selected = select!(shape, x = 2..5).unwrap();
22282228
let view = selected.slice();
22292229

2230-
let selection = base.reify_view(view).unwrap();
2230+
let selection = base.reify_slice(view).unwrap();
22312231
let expected = range(2..5, true_());
22322232
assert_structurally_eq!(&selection, expected);
22332233

@@ -2236,14 +2236,14 @@ mod tests {
22362236
}
22372237

22382238
#[test]
2239-
fn test_reify_view_2d() {
2239+
fn test_reify_slice_2d() {
22402240
let shape = shape!(x = 4, y = 5); // 2D shape: 4 rows, 5 columns
22412241
let base = shape.slice();
22422242

22432243
// Select the middle 2x3 block: rows 1..3 and columns 2..5
22442244
let selected = select!(shape, x = 1..3, y = 2..5).unwrap();
22452245
let view = selected.slice();
2246-
let selection = base.reify_view(view).unwrap();
2246+
let selection = base.reify_slice(view).unwrap();
22472247
let expected = range(1..3, range(2..5, true_()));
22482248
assert_structurally_eq!(&selection, expected);
22492249

@@ -2263,17 +2263,17 @@ mod tests {
22632263

22642264
#[test]
22652265
#[allow(clippy::identity_op)]
2266-
fn test_reify_view_1d_with_stride() {
2266+
fn test_reify_slice_1d_with_stride() {
22672267
let shape = shape!(x = 7); // 1D shape with 7 elements
22682268
let selected = shape.select("x", Range(0, None, 2)).unwrap();
22692269
let view = selected.slice();
22702270
assert_eq!(view, &Slice::new(0, vec![4], vec![1 * 2]).unwrap());
22712271

22722272
let base = shape.slice();
2273-
let selection = base.reify_view(view).unwrap();
2273+
let selection = base.reify_slice(view).unwrap();
22742274
// Note: ceil(7 / 2) = 4, hence end = 0 + 2 × 4 = 8. See the
22752275
// more detailed explanation in
2276-
// `test_reify_view_2d_with_stride`.
2276+
// `test_reify_slice_2d_with_stride`.
22772277
let expected = range(Range(0, Some(8), 2), true_());
22782278
assert_structurally_eq!(&selection, expected);
22792279

@@ -2283,7 +2283,7 @@ mod tests {
22832283

22842284
#[test]
22852285
#[allow(clippy::identity_op)]
2286-
fn test_reify_view_2d_with_stride() {
2286+
fn test_reify_slice_2d_with_stride() {
22872287
// 4 x 4: x = 4, y = 4.
22882288
let base = shape!(x = 4, y = 4);
22892289
// Step 1: select odd rows (x = 1..4 step 2)
@@ -2297,7 +2297,7 @@ mod tests {
22972297
);
22982298

22992299
let base = base.slice();
2300-
let selection = base.reify_view(view).unwrap();
2300+
let selection = base.reify_slice(view).unwrap();
23012301
// We use `end = start + step * len` to reify the selection.
23022302
// Note: This may yield `end > original_end` (e.g., 5 instead of 4)
23032303
// when the selection length was computed via ceiling division.
@@ -2311,7 +2311,7 @@ mod tests {
23112311
}
23122312

23132313
#[test]
2314-
fn test_reify_view_selects_column_across_rows() {
2314+
fn test_reify_slice_selects_column_across_rows() {
23152315
let shape = shape!(host = 2, gpu = 4); // shape [2, 4]
23162316
let base = shape.slice();
23172317

@@ -2321,7 +2321,7 @@ mod tests {
23212321
let coordinates: Vec<_> = view.iter().map(|i| view.coordinates(i).unwrap()).collect();
23222322
assert_eq!(coordinates, [[0, 0], [1, 0]]);
23232323

2324-
let selection = base.reify_view(view).unwrap();
2324+
let selection = base.reify_slice(view).unwrap();
23252325
let expected = range(0..2, range(2..3, true_()));
23262326
assert_structurally_eq!(&selection, expected);
23272327

@@ -2339,7 +2339,7 @@ mod tests {
23392339
}
23402340

23412341
#[test]
2342-
fn test_reify_view_dimension_mismatch() {
2342+
fn test_reify_slice_dimension_mismatch() {
23432343
let shape = shape!(host = 2, gpu = 4);
23442344
let base = shape.slice();
23452345

@@ -2351,7 +2351,7 @@ mod tests {
23512351
];
23522352

23532353
let view = Slice::new(indices[0], vec![indices.len()], vec![4]).unwrap();
2354-
let selection = base.reify_view(&view).unwrap();
2354+
let selection = base.reify_slice(&view).unwrap();
23552355

23562356
let expected = Selection::of_ranks(base, &indices.iter().cloned().collect()).unwrap();
23572357
assert_structurally_eq!(&selection, expected);
@@ -2363,7 +2363,7 @@ mod tests {
23632363
#[test]
23642364
fn test_union_of_slices_empty() {
23652365
let base = Slice::new_row_major([2]);
2366-
let sel = base.reify_views(&[]).unwrap();
2366+
let sel = base.reify_slices(&[]).unwrap();
23672367
assert_structurally_eq!(&sel, &false_());
23682368
assert_eq!(
23692369
sel.eval(&EvalOpts::strict(), &base)
@@ -2380,7 +2380,7 @@ mod tests {
23802380
let selected = select!(shape, x = 1).unwrap();
23812381
let view = selected.slice().clone();
23822382

2383-
let selection = base.reify_views(&[view]).unwrap();
2383+
let selection = base.reify_slices(&[view]).unwrap();
23842384
let expected = range(1..=1, true_());
23852385
assert_structurally_eq!(&selection, &expected);
23862386

@@ -2406,7 +2406,7 @@ mod tests {
24062406
let b = select!(shape, x = 1).unwrap();
24072407
let view_b = b.slice().clone();
24082408

2409-
let selection = base.reify_views(&[view_a, view_b]).unwrap();
2409+
let selection = base.reify_slices(&[view_a, view_b]).unwrap();
24102410
let expected = union(
24112411
range(0..1, range(0..2, true_())),
24122412
range(1..2, range(0..2, true_())),
@@ -2432,7 +2432,7 @@ mod tests {
24322432
let selected2 = select!(shape, y = 1..4).unwrap();
24332433
let view2 = selected2.slice().clone();
24342434

2435-
let selection = base.reify_views(&[view1, view2]).unwrap();
2435+
let selection = base.reify_slices(&[view1, view2]).unwrap();
24362436
let expected = union(
24372437
range(0..1, range(0..2, true_())),
24382438
range(0..1, range(1..4, true_())),

0 commit comments

Comments
 (0)