Skip to content

Commit 32eaf11

Browse files
committed
test(hpc/blocked_grid): integration tests + module-level doctest (PR-X3 A6)
Adds the final test-density layer after A1-A5 shipped their inline #[cfg(test)] coverage: - src/hpc/blocked_grid/tests.rs (new) — integration tests that span multiple submodules: W4 bulk_apply composition, L1→L2 cascade, all seven type aliases instantiate, half-square AMX INT8 pattern, as_padded_slice footgun verification, const-generic compile-fail - src/hpc/blocked_grid/mod.rs — module-level doctest demonstrating the canonical compose pattern (ShaderMantissaGrid → map_l1 → verify input unchanged + output as expected) and #[cfg(test)] mod tests registration Test count: +17 lib tests + 2 doctests above the A5 baseline (74 + 74). All 5 gates green. https://claude.ai/code/session_01UwJuKqP828qyX1VkLgGJFS
1 parent fbbbb35 commit 32eaf11

2 files changed

Lines changed: 463 additions & 0 deletions

File tree

src/hpc/blocked_grid/mod.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,62 @@
1616
//! - `compute` (worker A4) — `map_base`, `map_tier`, `bulk_apply_base`, `bulk_apply_tier`
1717
//! - `aliases` (worker A5) — `ShaderMantissaGrid`, `AmxBf16Grid`, … and L1-L4 alias impls
1818
//! - `grid_struct_macro` (worker B) — `blocked_grid_struct!` SoA-of-grids macro
19+
//!
20+
//! # Zero-dimension compile-fail guard
21+
//!
22+
//! Instantiating `BlockedGrid` with a zero block dimension is a **compile-time
23+
//! error** (the `const { assert!(BR > 0 && BC > 0, …) }` in `new_with_pad` fires
24+
//! before any code is generated).
25+
//!
26+
//! ```compile_fail
27+
//! use ndarray::hpc::blocked_grid::BlockedGrid;
28+
//! // BR = 0 is rejected at compile time — this must not compile.
29+
//! let _ = BlockedGrid::<u64, 0, 64>::new_with_pad(10, 10, 0);
30+
//! ```
31+
//!
32+
//! # Canonical compose pattern
33+
//!
34+
//! The idiomatic way to derive a new grid from an existing one:
35+
//!
36+
//! ```
37+
//! use ndarray::hpc::blocked_grid::{BlockedGrid, ShaderMantissaGrid};
38+
//!
39+
//! // Build a 128×128 ShaderMantissaGrid (= BlockedGrid<u64, 64, 64>).
40+
//! // padded_rows() == padded_cols() == 128, so blocks_l1() yields 4 blocks (2×2).
41+
//! let input: ShaderMantissaGrid = BlockedGrid::new(128, 128);
42+
//! assert_eq!(input.blocks_l1().count(), 4); // 2 block-rows × 2 block-cols
43+
//!
44+
//! // map_l1: derive a transformed grid without mutating input (data-flow Rule #3).
45+
//! let output = input.map_l1::<u64, _>(|inp, outp| {
46+
//! for r in 0..64 {
47+
//! let in_row = inp.row(r);
48+
//! let out_row = outp.row_mut(r);
49+
//! for (dst, &src) in out_row.iter_mut().zip(in_row.iter()) {
50+
//! *dst = src.wrapping_add(1);
51+
//! }
52+
//! }
53+
//! });
54+
//!
55+
//! // Rule #3 demo: input is unchanged — all cells remain u64::default() == 0.
56+
//! assert!(input.as_padded_slice().iter().all(|&v| v == 0u64));
57+
//!
58+
//! // Output: every cell is input (0) + 1 = 1.
59+
//! assert!(output.as_padded_slice().iter().all(|&v| v == 1u64));
60+
//!
61+
//! // blocks_l1 iterates the 4 base blocks; blocks_l2 requires ≥256×256.
62+
//! let coords: Vec<_> = output.blocks_l1()
63+
//! .map(|b| (b.block_row(), b.block_col()))
64+
//! .collect();
65+
//! assert_eq!(coords, vec![(0, 0), (0, 1), (1, 0), (1, 1)]);
66+
//! ```
1967
2068
mod base;
2169
mod iter;
2270
mod super_block;
2371
mod compute;
2472
mod aliases;
73+
#[cfg(test)]
74+
mod tests;
2575

2676
pub use aliases::{
2777
AmxBf16Grid, AmxInt8Grid, HalfSquareU64, ShaderMantissaGrid, SquareF64Stack8, StripF32Stack2, StripF32Stack4,

0 commit comments

Comments
 (0)