[Misc] Reject ndarray struct passed to template-annotated kernel param#608
Draft
hughperkins wants to merge 4 commits into
Draft
[Misc] Reject ndarray struct passed to template-annotated kernel param#608hughperkins wants to merge 4 commits into
hughperkins wants to merge 4 commits into
GitHub Actions / Coverage Report
succeeded
Jun 29, 2026 in 0s
Diff Coverage Report
See details below for per-line coverage annotations.
Details
Coverage Report (6dddeccf6)
| Metric | Value |
|---|---|
| Diff coverage (changed lines only) | 3% |
| Overall project coverage | 10% |
Total: 31 lines, 30 missing, 3% covered
🔴 python/quadrants/lang/ast/ast_transformers/function_def_transformer.py (0%)
35 QuadrantsCompilationError,
🔴 267 param_name = ctx.func.arg_metas[arg_idx].name
🔴 268 attr_path = ".".join(attr_chain)
🔴 269 raise QuadrantsCompilationError(
270 f"Kernel parameter '{param_name}' is annotated as qd.template(), but "
271 f"'{param_name}.{attr_path}' is a qd.ndarray. Passing ndarrays through "
272 f"template structs is not supported because it bypasses argument pruning "
273 f"and degrades launch performance. Use a concrete struct annotation "
274 f"(e.g. a @dataclass type hint) instead of qd.template() for struct "
275 f"parameters that contain ndarrays."
🔴 tests/python/test_tensor_annotation_in_func.py (4%)
🟢 16 from quadrants.lang.exception import QuadrantsCompilationError
🔴 84 if backend == qd.Backend.NDARRAY:
🔴 85 with pytest.raises(QuadrantsCompilationError, match="qd.template.*qd.ndarray"):
🔴 86 fill(s)
87 else:
🔴 88 fill(s)
🔴 89 np.testing.assert_array_equal(t.to_numpy(), np.arange(N) * 3)
🔴 122 if backend == qd.Backend.NDARRAY:
🔴 123 with pytest.raises(QuadrantsCompilationError, match="qd.template.*qd.ndarray"):
🔴 124 run(s)
125 else:
🔴 126 run(s)
🔴 127 np.testing.assert_array_equal(t.to_numpy(), np.arange(N) + 10)
🔴 160 if backend == qd.Backend.NDARRAY:
🔴 161 with pytest.raises(QuadrantsCompilationError, match="qd.template.*qd.ndarray"):
🔴 162 run(s)
163 else:
🔴 164 run(s)
🔴 165 np.testing.assert_array_equal(t.to_numpy(), np.arange(N) * 7)
🔴 197 if backend == qd.Backend.NDARRAY:
🔴 198 with pytest.raises(QuadrantsCompilationError, match="qd.template.*qd.ndarray"):
🔴 199 run(s)
200 else:
🔴 201 run(s)
🔴 202 np.testing.assert_array_equal(t.to_numpy(), np.arange(N) * 5)
🔴 274 if backend == qd.Backend.NDARRAY:
🔴 275 with pytest.raises(QuadrantsCompilationError, match="qd.template.*qd.ndarray"):
🔴 276 fill(s)
277 else:
🔴 278 fill(s)
🔴 279 arr = t.to_numpy()
🔴 280 assert arr.shape == (N, 3)
🔴 281 assert arr[2, 1] == pytest.approx(21.0)
Loading