Skip to content

Commit 2a2dfbf

Browse files
committed
refactor(pr-x1): array_window → array_windows (plural, std convention)
Renames the module + functions to match std's plural iterator-type convention (slice::ArrayWindows / slice::ArrayChunks). Singular `array_window` returning multiple windows was confusing. src/hpc/array_window.rs → src/hpc/array_windows.rs pub fn array_window → pub fn array_windows pub fn array_window_checked → pub fn array_windows_checked Module doc now explicitly calls out the semantic difference from std::slice::ArrayWindows: ours is **non-overlapping** (matches slice::as_chunks / ArrayChunks), std's is overlapping. The plural name follows std's iterator convention; the non-overlapping semantics is what SIMD-staged inner loops actually need (each lane register load advances by N, not by 1). src/hpc/mod.rs and src/simd.rs re-exports updated.
1 parent fa0ebae commit 2a2dfbf

3 files changed

Lines changed: 35 additions & 35 deletions

File tree

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
//!
99
//! # Layering
1010
//!
11-
//! Lives in `hpc::array_window`; the `crate::simd::*` re-export lands in the
11+
//! Lives in `hpc::array_windows`; the `crate::simd::*` re-export lands in the
1212
//! PR-X1 re-export sweep (see `.claude/knowledge/pr-x1-design.md` § 4).
13-
//! Doctests therefore use the canonical `ndarray::hpc::array_window` path
13+
//! Doctests therefore use the canonical `ndarray::hpc::array_windows` path
1414
//! until the sweep ships.
1515
//!
1616
//! # Design reference
1717
//!
18-
//! `.claude/knowledge/pr-x1-design.md` § "3. `array_window`". This module
18+
//! `.claude/knowledge/pr-x1-design.md` § "3. `array_windows`". This module
1919
//! ships the **iterator-shape** variant (whole-buffer walk yielding all
2020
//! const-size windows). The design doc sketches a singular-window form
21-
//! (`array_window(slice, offset) -> &[T; N]`); the maintainer-blessed final
21+
//! (`array_windows(slice, offset) -> &[T; N]`); the maintainer-blessed final
2222
//! shape is the iterator form here, which composes directly with SIMD-staged
2323
//! consumer loops and avoids per-call panic surface in tight inner loops.
2424
2525
/// Walk `data` as a sequence of non-overlapping const-size windows.
2626
///
2727
/// Returns an iterator over `&[T; N]` references into `data`. The tail
28-
/// (`data.len() % N` items) is discarded; use [`array_window_checked`] to
28+
/// (`data.len() % N` items) is discarded; use [`array_windows_checked`] to
2929
/// fail-fast when the length is not a multiple of `N`.
3030
///
3131
/// Zero-cost: this is a thin wrapper around [`slice::as_chunks`] that pins
@@ -34,9 +34,9 @@
3434
/// # Examples
3535
///
3636
/// ```
37-
/// use ndarray::hpc::array_window::array_window;
37+
/// use ndarray::hpc::array_windows::array_windows;
3838
/// let data: Vec<u8> = (0..16).collect();
39-
/// let windows: Vec<&[u8; 4]> = array_window::<u8, 4>(&data).collect();
39+
/// let windows: Vec<&[u8; 4]> = array_windows::<u8, 4>(&data).collect();
4040
/// assert_eq!(windows.len(), 4);
4141
/// assert_eq!(windows[0], &[0, 1, 2, 3]);
4242
/// assert_eq!(windows[3], &[12, 13, 14, 15]);
@@ -45,43 +45,43 @@
4545
/// # Examples — tail discarded
4646
///
4747
/// ```
48-
/// use ndarray::hpc::array_window::array_window;
48+
/// use ndarray::hpc::array_windows::array_windows;
4949
/// let data: Vec<u8> = (0..7).collect();
50-
/// let windows: Vec<&[u8; 4]> = array_window::<u8, 4>(&data).collect();
50+
/// let windows: Vec<&[u8; 4]> = array_windows::<u8, 4>(&data).collect();
5151
/// // 7 / 4 = 1 window; the trailing 3 items are dropped.
5252
/// assert_eq!(windows.len(), 1);
5353
/// ```
5454
#[inline]
55-
pub fn array_window<T, const N: usize>(data: &[T]) -> impl Iterator<Item = &[T; N]> + '_ {
55+
pub fn array_windows<T, const N: usize>(data: &[T]) -> impl Iterator<Item = &[T; N]> + '_ {
5656
data.as_chunks::<N>().0.iter()
5757
}
5858

5959
/// Walk `data` as `&[T; N]` windows, returning `Err(())` if `data.len()`
6060
/// is not a multiple of `N`.
6161
///
62-
/// This is the strict variant of [`array_window`]: the consumer asserts up
62+
/// This is the strict variant of [`array_windows`]: the consumer asserts up
6363
/// front that the buffer is lane-aligned and the caller wants the error
6464
/// surfaced rather than silently truncating.
6565
///
6666
/// # Examples
6767
///
6868
/// ```
69-
/// use ndarray::hpc::array_window::array_window_checked;
69+
/// use ndarray::hpc::array_windows::array_windows_checked;
7070
/// let data: Vec<u8> = (0..16).collect();
71-
/// let it = array_window_checked::<u8, 4>(&data).expect("16 is a multiple of 4");
71+
/// let it = array_windows_checked::<u8, 4>(&data).expect("16 is a multiple of 4");
7272
/// assert_eq!(it.count(), 4);
7373
///
7474
/// let bad: Vec<u8> = (0..7).collect();
75-
/// assert!(array_window_checked::<u8, 4>(&bad).is_err());
75+
/// assert!(array_windows_checked::<u8, 4>(&bad).is_err());
7676
/// ```
7777
#[inline]
78-
pub fn array_window_checked<T, const N: usize>(
78+
pub fn array_windows_checked<T, const N: usize>(
7979
data: &[T],
8080
) -> Result<impl Iterator<Item = &[T; N]> + '_, ()> {
8181
if data.len() % N != 0 {
8282
return Err(());
8383
}
84-
Ok(array_window::<T, N>(data))
84+
Ok(array_windows::<T, N>(data))
8585
}
8686

8787
// ============================================================================
@@ -94,46 +94,46 @@ mod tests {
9494

9595
/// 16-element buffer yields four 4-wide windows.
9696
#[test]
97-
fn array_window_4_over_16() {
97+
fn array_windows_4_over_16() {
9898
let data: Vec<u8> = (0u8..16).collect();
99-
let windows: Vec<&[u8; 4]> = array_window::<u8, 4>(&data).collect();
99+
let windows: Vec<&[u8; 4]> = array_windows::<u8, 4>(&data).collect();
100100
assert_eq!(windows.len(), 4);
101101
assert_eq!(windows[0], &[0, 1, 2, 3]);
102102
assert_eq!(windows[1], &[4, 5, 6, 7]);
103103
assert_eq!(windows[2], &[8, 9, 10, 11]);
104104
assert_eq!(windows[3], &[12, 13, 14, 15]);
105105
}
106106

107-
/// Tail items are silently discarded by `array_window`.
107+
/// Tail items are silently discarded by `array_windows`.
108108
#[test]
109-
fn array_window_drops_tail() {
109+
fn array_windows_drops_tail() {
110110
let data: Vec<u8> = (0u8..7).collect();
111-
let windows: Vec<&[u8; 4]> = array_window::<u8, 4>(&data).collect();
111+
let windows: Vec<&[u8; 4]> = array_windows::<u8, 4>(&data).collect();
112112
assert_eq!(windows.len(), 1);
113113
assert_eq!(windows[0], &[0, 1, 2, 3]);
114114
}
115115

116116
/// Mismatched length surfaces as Err in the checked variant.
117117
#[test]
118-
fn array_window_checked_rejects_mismatch() {
119-
assert!(array_window_checked::<u8, 4>(&[0u8; 7]).is_err());
120-
assert!(array_window_checked::<u8, 4>(&[0u8; 5]).is_err());
121-
assert!(array_window_checked::<u8, 4>(&[0u8; 1]).is_err());
118+
fn array_windows_checked_rejects_mismatch() {
119+
assert!(array_windows_checked::<u8, 4>(&[0u8; 7]).is_err());
120+
assert!(array_windows_checked::<u8, 4>(&[0u8; 5]).is_err());
121+
assert!(array_windows_checked::<u8, 4>(&[0u8; 1]).is_err());
122122
}
123123

124124
/// Aligned length succeeds in the checked variant.
125125
#[test]
126-
fn array_window_checked_accepts_aligned() {
126+
fn array_windows_checked_accepts_aligned() {
127127
let data = [0u8; 16];
128-
let it = array_window_checked::<u8, 4>(&data).expect("16 is a multiple of 4");
128+
let it = array_windows_checked::<u8, 4>(&data).expect("16 is a multiple of 4");
129129
assert_eq!(it.count(), 4);
130130
}
131131

132132
/// Empty buffer yields zero windows (not an error in either variant).
133133
#[test]
134-
fn array_window_empty_buffer() {
135-
assert_eq!(array_window::<u8, 4>(&[]).count(), 0);
136-
let it = array_window_checked::<u8, 4>(&[]).expect("0 % 4 == 0, should be Ok");
134+
fn array_windows_empty_buffer() {
135+
assert_eq!(array_windows::<u8, 4>(&[]).count(), 0);
136+
let it = array_windows_checked::<u8, 4>(&[]).expect("0 % 4 == 0, should be Ok");
137137
assert_eq!(it.count(), 0);
138138
}
139139
}

src/hpc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub mod fingerprint;
4242
// PR-X1 — multi-lane typed column substrate + const-size array windows.
4343
// Re-exported from crate::simd::* per the W1a consumer contract.
4444
pub mod column;
45-
pub mod array_window;
45+
pub mod array_windows;
4646
#[allow(missing_docs)]
4747
pub mod plane;
4848
#[allow(missing_docs)]

src/simd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ fn tier() -> Tier {
134134
// function uses as_chunks::<16>() + as_chunks::<8>() for SIMD widths.
135135

136136
// ============================================================================
137-
// Preferred SIMD lane widths — compile-time constants for array_windows
137+
// Preferred SIMD lane widths — compile-time constants for array_windowss
138138
// ============================================================================
139139
//
140-
// Consumer code uses these to select array_windows size at compile time:
140+
// Consumer code uses these to select array_windowss size at compile time:
141141
//
142-
// for window in data.array_windows::<{crate::simd::PREFERRED_F64_LANES}>() {
142+
// for window in data.array_windowss::<{crate::simd::PREFERRED_F64_LANES}>() {
143143
// let v = F64x8::from_array(*window); // AVX-512: native 8-wide
144144
// // or
145145
// let v = F64x4::from_array(*window); // AVX2: native 4-wide
@@ -1723,7 +1723,7 @@ pub use crate::hpc::fingerprint::{
17231723
// through `crate::simd::*`; without these re-exports the cognitive-shader
17241724
// stack reaches for `crate::hpc::column::*` directly, breaking the contract.
17251725
pub use crate::hpc::column::MultiLaneColumn;
1726-
pub use crate::hpc::array_window::{array_window, array_window_checked};
1726+
pub use crate::hpc::array_windows::{array_windows, array_windows_checked};
17271727

17281728
pub use crate::hpc::quantized::{
17291729
dequantize_i2_to_f32, dequantize_i4_to_f32, dequantize_i8_to_f32, quantize_f32_to_i2, quantize_f32_to_i4,

0 commit comments

Comments
 (0)