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
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]);
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}
0 commit comments