feat: add @stdlib/ndarray/base/nans-like#12114
Conversation
Adds `@stdlib/ndarray/base/nans-like`, which creates a NaN-filled ndarray having the same shape and data type as a provided ndarray. Uses complex NaN (`CNAN`) for complex floating-point dtypes. Also wires the new package into the `@stdlib/ndarray/base` namespace index and TypeScript declarations. https://claude.ai/code/session_015jQ1FqbZbBX2N2ZXE73Azf
- Remove inaccurate @throws annotation from JSDoc (follow ones-like convention) - Use non-NaN inputs in tests so NaN filling is visible (prevents aliasing bugs) - Add buffer identity checks (output does not alias input) - Add buffer length assertions for all dtypes - Add integer dtype tests (int32/uint32/int16/uint16/int8/uint8/uint8c all throw) - Add 0-dimensional array tests for float64/float32/complex128/complex64 - Add empty array test for float64 base ndarray - Guard allNaN helper against vacuous empty-array case https://claude.ai/code/session_015jQ1FqbZbBX2N2ZXE73Azf
Ralph Loop — Implementation NotesThis PR was produced by an automated Ralph Loop (iterative implementation + adversarial review). Here is the full context for reviewers. What was doneCreated Files created:
Files modified:
Design decisions
Review summary (5 adversarial agents)
B-blockers fixed:
B-majors fixed:
C-major disputed:
Open questions for human reviewers
Generated by Claude Code |
|
It did a decent job. I actually just implemented this as a METR task about 30 minutes before this PR was opened. There were some differences, namely because I did a bit of clean-up relative to the other packages (e.g., TS, etc). And furthermore, how it did the tests is not what we'd look for. Better to use our |
Resolves #2772 (in stdlib-js/todo).
Description
This pull request:
@stdlib/ndarray/base/nans-like, a new package that creates a NaN-filled ndarray having the same shape and data type as a provided ndarray.float64,float32,complex128,complex64,generic). Complex types are filled usingCNANfrom@stdlib/constants/complex128/nan; all others useNaN.int32,uint32,int16,uint16,int8,uint8,uint8c) are not supported and throw aTypeError(via@stdlib/ndarray/base/fill).@stdlib/ndarray/basenamespace index (lib/index.js) and TypeScript declarations (docs/types/index.d.ts).Implementation notes
emptyLike+fillpattern (consistent with@stdlib/ndarray/base/ones-like).<T extends typedndarray<...>>pattern used byones-like/zeros-like) becausenans-likeis restricted to NaN-capable types. This correctly prevents integer-typed ndarrays from being passed at compile time.Related Issues
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code.
@stdlib-js/reviewers
Generated by Claude Code