Docs/Guarantees and recipes
Common Pitfalls
Things that look broken but aren't, plus things that look fine but bite you later.
| Pattern | What happens | What to do |
|---|---|---|
Generator::from_pcg64_dxsm(seed).standard_normal(5), calling it twice and expecting the same result |
Second call gives the next 5 samples, not the first 5 again. The generator is stateful. | Build the generator inside the test/function; or to_pickle_payload() + from_pickle_payload() to rewind. |
default_rng() without a seed and expecting reproducible output |
The result is intentionally non-deterministic, matching NumPy's OS-entropy default | Pass an explicit seed for a reproducible stream. |
UFuncArray::empty(vec![1_000_000], DType::F64) expecting uninitialized memory for benchmark realism |
The Rust result is zero-filled (it is zeros; safe Rust has no uninitialized allocation). Python fnp_python.empty is NumPy's and uninitialized |
Benchmark realistically by writing into the buffer before timing reads. |
reduce_mean(None, false) on a float array, then asserting shape [1] |
Result shape is [] (0-D scalar), not [1]. keepdims=true gives [1, ...] of all-ones. |
Use keepdims=true if you want a shape-preserving reduction. |
| Sorting an array containing NaN and expecting NaN in the middle | NaN sorts to end (NumPy convention). | Use nansort_index style explicit ordering if you need to filter out NaN first. |
Comparing two NaN values with == and getting true |
== returns false for NaN (IEEE 754). |
Use f64::is_nan() or equal_nan=True parameter in helpers like allclose. |
Passing a Vec<f32> where the API expects a &[f64] |
Compile error. The API is strongly typed; there is no auto-coercion. | Use as_slice() and convert dtypes explicitly via cast / astype. |
Calling binomial(10, 0.5, 100) and forgetting ? |
Compile error: returns Result<Vec<u64>, RandomError>. |
Add ? or .unwrap() (test code) / explicit match (production). |
Building a view with as_strided(shape, strides, offset) that exceeds the backing allocation |
Returns Err(ShapeError::OutOfBoundsView { required_nbytes, available_nbytes }), not UB. |
Use the error to debug your stride math; the byte-span check is the safety net. |
Calling f64 arithmetic on integer arrays > 2^53 and expecting exact results |
f64 arithmetic loses precision above 2^53; IntegerSidecar preserves the original bits through storage round-trips but not through arithmetic. |
Cast to a wider integer type at the right moment; see Limitations. |
Assuming fnp_python.linalg.solve(A, b) runs fnp's Rust solver |
A 2-D call goes to numpy.linalg.solve (NumPy's LAPACK). The pure-Rust LU / QR in fnp-linalg serves the Rust API (UFuncArray::solve, batch_solve) and some stacked Python calls. |
From Rust, batch via batch_solve where the broadcast is natural; from Python, expect NumPy's speed and bits for 2-D solves. |
These cover most "wait, why does this behave that way?" questions in the first week of using FrankenNumPy.