Skip to content

feat: add @stdlib/ndarray/to-locale-string#10898

Open
headlessNode wants to merge 7 commits intostdlib-js:developfrom
headlessNode:ndarray-toLocaleString
Open

feat: add @stdlib/ndarray/to-locale-string#10898
headlessNode wants to merge 7 commits intostdlib-js:developfrom
headlessNode:ndarray-toLocaleString

Conversation

@headlessNode
Copy link
Member


type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:

  • task: lint_filenames status: passed
  • task: lint_editorconfig status: passed
  • task: lint_markdown status: passed
  • task: lint_package_json status: passed
  • task: lint_repl_help status: passed
  • task: lint_javascript_src status: passed
  • task: lint_javascript_cli status: na
  • task: lint_javascript_examples status: passed
  • task: lint_javascript_tests status: passed
  • task: lint_javascript_benchmarks status: passed
  • task: lint_python status: na
  • task: lint_r status: na
  • task: lint_c_src status: na
  • task: lint_c_examples status: na
  • task: lint_c_benchmarks status: na
  • task: lint_c_tests_fixtures status: na
  • task: lint_shell status: na
  • task: lint_typescript_declarations status: passed
  • task: lint_typescript_tests status: passed
  • task: lint_license_headers status: passed ---

Resolves stdlib-js/metr-issue-tracker#189.

Description

What is the purpose of this pull request?

This pull request:

  • add @stdlib/ndarray/to-locale-string

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

Primarily written by Claude Code.


@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 12, 2026
@headlessNode headlessNode added Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. labels Mar 12, 2026
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Mar 12, 2026

Coverage Report

Package Statements Branches Functions Lines
ndarray/to-locale-string $\color{red}327/334$
$\color{green}+97.90%$
$\color{red}49/54$
$\color{green}+90.74%$
$\color{green}2/2$
$\color{green}+100.00%$
$\color{red}327/334$
$\color{green}+97.90%$

The above coverage report was generated for the changes in this PR.

@headlessNode headlessNode requested a review from kgryte March 12, 2026 12:02
@headlessNode headlessNode mentioned this pull request Mar 12, 2026
7 tasks
kgryte added 2 commits March 19, 2026 17:24
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
'set': noop
};

expected = 'ndarray( \'float64\', new Float64Array( [ 3, 5, 4, 6 ] ), [ 2, 2 ], [ 1, 2 ], 0, \'column-major\' )';
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect.

t.end();

function getter( i, j ) {
return arr.data[ arr.offset+sub2ind( [ 2, 2 ], i, j ) ];
Copy link
Member

@kgryte kgryte Mar 20, 2026

Choose a reason for hiding this comment

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

I am not sure why this is the approach was used for resolving a linear index because it is wrong. sub2ind resolves a view index, not a buffer index. For that you need to use vind2bind. But even then, just compute the index manually using strides. I believe you did this elsewhere.

t.end();

function getter( i, j ) {
return arr.data.get( arr.offset+sub2ind( [ 2, 2 ], i, j ) );
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above and throughout this file.

Comment on lines +846 to +849
t.strictEqual( typeof actual, 'string', 'returns expected value' );
t.notEqual( actual.indexOf( '...' ), -1, 'contains ellipsis' );
t.notEqual( actual.indexOf( '0, 1, 2' ), -1, 'contains first three values' );
t.notEqual( actual.indexOf( '98, 99, 100' ), -1, 'contains last three values' );
Copy link
Member

Choose a reason for hiding this comment

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

What is this?

Copy link
Member

Choose a reason for hiding this comment

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

All these tests are wrong.


actual = ndarray2localeString( arr );
t.strictEqual( typeof actual, 'string', 'returns expected value' );
t.notEqual( actual.indexOf( '...' ), -1, 'contains ellipsis' );
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. Did you review these tests to ensure they made sense?

t.end();

function getter( i, j ) {
return arr.data[ arr.offset+sub2ind( [ 2, 2 ], i, j ) ];
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above regarding sub2ind.

Signed-off-by: Athan <kgryte@gmail.com>
<!-- eslint no-undef: "error" -->

```javascript
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
Copy link
Member

Choose a reason for hiding this comment

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

For a top-level package, I don't find this example particularly compelling. Instead, I suggest simplifying and simply (1) using, say, random/uniform to generate an ndarray of random values and (2) serializing that ndarray to a string using different locale identifiers (e.g., for English, German, etc) and potentially different configuration options (e.g., maximum number of digits, etc).

Copy link
Member

Choose a reason for hiding this comment

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

And I think it would be useful to use doctest return annotations for console.log statements to show the expected output. This would allow readers to develop a visual intuition regarding expected output.

Copy link
Member

Choose a reason for hiding this comment

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

This comment also applies to the corresponding example file.

Copy link
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.

Left initial comments.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Mar 20, 2026
@kgryte
Copy link
Member

kgryte commented Mar 20, 2026

For METR,

review_time: 50 mins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. Needs Changes Pull request which needs changes before being merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add ndarray/to-locale-string

3 participants