Skip to content

test: FuzzMixedDTypes, the values of mixed-dtype operations - #50

Merged
tannevaled merged 1 commit into
mainfrom
fuzz-mixed-dtypes
Oct 18, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fuzz-mixed-dtypes

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

values.json checks every operation on operands of one dtype, and FuzzOps builds only float64 arrays. So the values of a mixed-dtype operation (int8 + uint64, bool * float32, …) were checked by nothing.

FuzzMixedDTypes (dtype_fuzz_test.go) covers:

  • Operations: Add, Sub, Mul, Maximum, Minimum and Equal, over every pair of the 13 dtypes.
  • Shapes: up to 3 axes, broadcastable or not, with transposed (strided) views.
  • Values: integer extremes, -0, NaN, ±Inf and complex combinations.

The oracle is written in the test, independently of the library:

  • the result dtype comes from NumPy's own testdata/promotion.json (numpy 2.5.3);
  • the shape follows NumPy's broadcasting rule;
  • each element is recomputed by casting both operands to the result dtype and applying Go's arithmetic of that type, which wraps integers as C and NumPy do. Bool + is or, * is and, and bool - bool must be refused, as NumPy refuses it.

There must be no panic, an error exactly where the oracle refuses, and NumPy's dtype, shape and every element. Complex Maximum/Minimum are checked for dtype and shape only, because NumPy orders complex numbers lexicographically with its own NaN rules.

Measured:

  • 35 million inputs (3 min + 5 min) with no failure: the library agrees.
  • Negative control: I changed the bool→int16 conversion to turn true into 2. The fuzzer failed in under a second with Add(bool [2], int16 []) at [1] = 2, oracle 1, so it can see what it guards against.
  • The test package compiles for linux/386 and arm.

SECURITY.md gains the guarantee and an audit entry. There are no library changes.

🤖 Generated with Claude Code

values.json checks every operation on operands of one dtype and FuzzOps
builds only float64 arrays, so nothing checked the values of int8 +
uint64, bool * float32, ... The new fuzzer drives Add, Sub, Mul,
Maximum, Minimum and Equal over every dtype pair, broadcastable or not,
with transposed views and edge values. Oracle: NumPy's promotion table
(testdata/promotion.json) for the dtype, the broadcasting rule for the
shape, and each element recomputed by casting both operands to the
result dtype and using Go's arithmetic of that type; bool - bool must be
refused, as NumPy refuses it.

35 million inputs, no failure. Turning true into 2 in the bool->int16
conversion failed it in under a second. SECURITY.md: the guarantee and
an audit entry. Compiles for 386 and arm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit a1f82eb into main Oct 18, 2026
12 checks passed
@tannevaled
tannevaled deleted the fuzz-mixed-dtypes branch October 18, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant