Declare the required output object
The requested output is [[1, 2], [1, 2]], with shape (2, 2). The candidate returns [1, 2], with shape (2,). In our retained NumPy 2.5.0 CPU call, allclose accepts the pair even with both tolerances set to zero. The comparison expands the candidate across the missing row axis before comparing values. That does not establish the separately declared requirement to return a (2, 2) array.[1][5]
This is documented broadcasting behavior, not a NumPy bug. If broadcast equivalence is the intended objective, the result answers that objective. A benchmark that requires an exact output shape must check that requirement explicitly.[1]
- Declare the object contract: A value check after broadcasting does not prove that the candidate returned the required shape.
Keep comparison contracts separate
We ran one original CPU demonstration with eight designed finite cases. It retains each actual and desired array, shape, dtype, broadcast expansion or error, and the decision from four comparison methods. All 32 decisions and eight authored case checks are included. The rows are teaching examples, not a sample of real benchmark failures.[5][4]
The methods do not have identical contracts. numpy.allclose supports broadcasting. numpy.testing.assert_allclose without strict mode rejects the two nonscalar shape mismatches here, but accepts the scalar example and the same-shape dtype change. With strict=True, those scalar and dtype exceptions are rejected too. Every call in this demonstration explicitly uses rtol=0, atol=0 and equal_nan=False.[1][2][5]
Our original guard checks shape, dtype and finiteness before running the value comparison. The saved result records which field failed and whether the value check ran. Matching dtype is an example requirement here; a task that permits dtype conversion should declare that policy instead of copying the guard blindly.[5][4]
One retained NumPy 2.5.0 CPU invocation. Desired shape is (2, 2) in every case.
| Authored case | Actual shape | allclose | Assert non-strict | Assert strict | Exact contract |
|---|---|---|---|---|---|
| Exact matrix | (2, 2) | Pass | Pass | Pass | Pass |
| Missing row axis | (2,) | Pass | Fail | Fail | Fail |
| Singleton column | (2, 1) | Pass | Fail | Fail | Fail |
| Scalar | () | Pass | Pass | Fail | Fail |
| Dtype only | (2, 2) | Pass | Pass | Fail | Fail |
| Wrong value | (2, 2) | Fail | Fail | Fail | Fail |
| Incompatible shape | (3,) | ValueError | Fail | Fail | Fail |
| Unequal desired rows | (2,) | Fail | Fail | Fail | Fail |
- All calls explicitly use rtol=0, atol=0 and equal_nan=False. Dtype-only changes float64 to float32; every other case uses float64.
- Exact contract requires equal shape and dtype, finite arrays and a passing value comparison. Errors remain distinct from False; eight authored case checks are not statistical samples.
Retain the negative controls
The negative controls matter. The exact matrix passes every method. A wrong value at the same shape fails every method. An incompatible shape raises ValueError in allclose, which is retained as an error rather than collapsed into a numeric rejection. When the desired rows differ, a single repeated row no longer passes the broadcast value comparison.[1][2][5]
All values are small, exactly representable integers stored in floating arrays. Zero tolerance isolates the shape and dtype distinction. It is not a recommended tolerance for real floating-point kernels. Strict comparison also does not settle layout, aliasing, input mutation, device placement or the rest of a kernel contract.[3][5]
- Respect the intended semantics: Broadcast equivalence can be valid. Exact shape and dtype should be enforced only when the task requires them.
Keep the evidence within scope
For a kernel reward pipeline, record contract validation separately from the numeric result. A passed value check is evidence only for the comparison it actually performed. This demonstration does not establish a defect in an existing grader, failure prevalence, performance or any training benefit.[4][5]
The MIT download contains the exact executed source, fixture, predeclared protocol, complete output and reproduction instructions. It pins NumPy 2.5.0 as an external dependency; NumPy code is not bundled. The observed environment was CPython 3.12.14 on Darwin arm64. No GPU, PyTorch or model ran.[3][4][6]
- Declare the required output object before deciding how to compare its values.
Sources
- NumPy2.5 allclose documentation numpy.org
- NumPy2.5 assert_allclose documentation numpy.org
- NumPy2.5.0 package metadata pypi.org
- MIT runnable proof and full saved output data.nodus-compute.ai
- Full saved result JSON data.nodus-compute.ai
- Source and saved-result provenance data.nodus-compute.ai
- Vector figure data.nodus-compute.ai
![Original NumPy 2.5.0 CPU demonstration. A candidate vector [1, 2] with shape (2,) compares equal to desired [[1, 2], [1, 2]] with shape (2, 2) after broadcasting. allclose passes; strict assertion and the declared exact-shape guard fail. Across eight authored cases, exact matrix passes all methods; missing-row and singleton-column cases pass allclose only; scalar and dtype-only cases also pass non-strict assertion; wrong values, incompatible shape and unequal desired rows do not pass. Incompatible allclose raises ValueError. No timing or real benchmark defect claim.](/assets/lab-research-shape-broadcast-card.png)