feat: add @stdlib/ndarray/nans-like#12113
Conversation
This commit adds the `@stdlib/ndarray/nans-like` package, which creates an ndarray filled with NaN values having the same shape and data type as a provided ndarray. The function supports floating-point and generic data types (float32, float64, complex64, complex128, generic) and accepts options to override dtype, shape, order, mode, submode, and readonly. Integer data types are not supported, as NaN is not representable in integer types. The package is wired into the `@stdlib/ndarray` namespace. https://claude.ai/code/session_01THn379nEWg1u7YggFFBuFQ
- Fix complex dtype tests to assert both real (NaN) and imaginary (0.0) parts - Use FloatingPointAndGenericDataType in OptionsWithDType TypeScript interface - Remove "numpy.full_like" keyword (no direct numpy equivalent) - Add bool/binary to dtype rejection test cases - Add buffer non-sharing test - Add column-major order inference test - Add isolated option override tests (dtype, order, shape separately) - 316 tests, all passing https://claude.ai/code/session_01THn379nEWg1u7YggFFBuFQ
|
Hello! Thank you for your contribution to stdlib. We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
This acknowledgment confirms that you've read the guidelines, which include:
We can't review or accept contributions without this acknowledgment. Thank you for your understanding and cooperation. We look forward to reviewing your contribution! |
kgryte
left a comment
There was a problem hiding this comment.
This was also completed earlier this evening, but the diff between what I pushed and this PR is instructive. The tests were not quite right. The use of a real-valued NaN was incorrect and inconsistent with ndarray/base/nans. And some spurious notes.
I'll go ahead and close.
Description
This PR adds the
@stdlib/ndarray/nans-likepackage, which creates an ndarray filled with NaN values having the same shape and data type as a provided input ndarray.Key design decisions
"generic"data types are supported (viadtypes('floating_point_and_generic')), as NaN is not defined for integer types. Attempting to use an integer dtype throws aTypeError.complex128andcomplex64,fill(out, NaN)producesreal=NaN, imag=0.0— consistent with NumPy's behavior fornp.full(..., np.nan, dtype=complex128).@stdlib/ndarray/ones-likeexactly, substitutingNaNas the fill value and restricting the dtype set accordingly.@stdlib/ndarrayalphabetically betweenmostlySafeCastsandndarraylike2ndarray.Files added/modified
lib/node_modules/@stdlib/ndarray/nans-like/— new packagelib/main.js— core implementationlib/index.js— module entry pointpackage.jsontest/test.js— 316 tests covering all dtypes, all option overrides, edge casesexamples/index.jsbenchmark/benchmark.jsand per-dtype size benchmarksdocs/repl.txtdocs/types/index.d.ts— TypeScript declarations usingFloatingPointAndGenericDataTypedocs/types/test.tsREADME.mdlib/node_modules/@stdlib/ndarray/lib/index.js— addnansLiketo namespacelib/node_modules/@stdlib/ndarray/docs/types/index.d.ts— addnansLiketype to namespace interfaceRelated Issues
Closes stdlib-js/todo#2771
Questions
None.
Other
Checklist
@stdlib/ndarray/ones-like).https://claude.ai/code/session_01THn379nEWg1u7YggFFBuFQ
Generated by Claude Code