Skip to content

feat: add @stdlib/ndarray/nans-like#12113

Closed
Planeshifter wants to merge 2 commits into
developfrom
claude/vibrant-brahmagupta-9A236
Closed

feat: add @stdlib/ndarray/nans-like#12113
Planeshifter wants to merge 2 commits into
developfrom
claude/vibrant-brahmagupta-9A236

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

This PR 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 input ndarray.

Key design decisions

  • Restricted dtype support: Only floating-point and "generic" data types are supported (via dtypes('floating_point_and_generic')), as NaN is not defined for integer types. Attempting to use an integer dtype throws a TypeError.
  • Complex NaN fill: For complex128 and complex64, fill(out, NaN) produces real=NaN, imag=0.0 — consistent with NumPy's behavior for np.full(..., np.nan, dtype=complex128).
  • Pattern: Follows @stdlib/ndarray/ones-like exactly, substituting NaN as the fill value and restricting the dtype set accordingly.
  • Namespace: Wired into @stdlib/ndarray alphabetically between mostlySafeCasts and ndarraylike2ndarray.

Files added/modified

  • lib/node_modules/@stdlib/ndarray/nans-like/ — new package
    • lib/main.js — core implementation
    • lib/index.js — module entry point
    • package.json
    • test/test.js — 316 tests covering all dtypes, all option overrides, edge cases
    • examples/index.js
    • benchmark/benchmark.js and per-dtype size benchmarks
    • docs/repl.txt
    • docs/types/index.d.ts — TypeScript declarations using FloatingPointAndGenericDataType
    • docs/types/test.ts
    • README.md
  • lib/node_modules/@stdlib/ndarray/lib/index.js — add nansLike to namespace
  • lib/node_modules/@stdlib/ndarray/docs/types/index.d.ts — add nansLike type to namespace interface

Related Issues

Closes stdlib-js/todo#2771

Questions

None.

Other

  • All 316 tests pass.
  • This implementation was developed with AI assistance (Claude Code / claude-sonnet-4-6).

Checklist

  • I have read the contributing guidelines.
  • I have followed the code style guidelines.
  • The implementation is based on an existing analogous package (@stdlib/ndarray/ones-like).
  • Tests cover all supported dtypes, all option overrides, error cases, and edge cases (zero-dim, empty arrays).
  • AI assistance disclosure: this PR was generated with Claude Code (claude-sonnet-4-6).

https://claude.ai/code/session_01THn379nEWg1u7YggFFBuFQ


Generated by Claude Code

claude added 2 commits May 13, 2026 06:29
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
@stdlib-bot
Copy link
Copy Markdown
Contributor

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:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kgryte kgryte closed this May 13, 2026
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.

4 participants