Skip to content

feat: add blas/ext/join-between#11287

Open
headlessNode wants to merge 2 commits intostdlib-js:developfrom
headlessNode:blas/nd-joinbetween
Open

feat: add blas/ext/join-between#11287
headlessNode wants to merge 2 commits intostdlib-js:developfrom
headlessNode:blas/nd-joinbetween

Conversation

@headlessNode
Copy link
Copy Markdown
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#238.

Description

What is the purpose of this pull request?

This pull request:

  • add blas/ext/join-between

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 but with heavy back-and-forth fixing.


@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
---
@headlessNode headlessNode added Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. labels Apr 3, 2026
@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Needs Review A pull request which needs code review. labels Apr 3, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Apr 3, 2026

Coverage Report

No coverage information available.

@headlessNode headlessNode requested a review from kgryte April 3, 2026 20:29
@github-actions github-actions bot mentioned this pull request Apr 4, 2026
Comment on lines +47 to +48
* @param {string} [options.prefix=''] - prefix to prepend to each joined string
* @param {string} [options.suffix=''] - suffix to append to each joined string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should both be allowed to be ndarrays. What if I want to prefix each joined string with different prefixes? Ditto for suffix.

Comment on lines +125 to +129
if ( opts.separators.length === 1 ) {
separators = broadcastScalar( opts.separators[ 0 ], 'generic', [ 1 ], order );
} else {
separators = new ndarray( 'generic', opts.separators, [ opts.separators.length ], [ 1 ], 0, order );
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's going on here? Why isn't separators being broadcast against the entire input array x? What if I want different separators for each row in a matrix?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The broadcasting logic may be a bit nuanced here. Namely because the separators array needs to broadcast to a shape which accounts for the number of separators needing to be one less than the number of elements to be joined.

Copy link
Copy Markdown
Member

@kgryte kgryte Apr 8, 2026

Choose a reason for hiding this comment

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

...this will mean computing the number of elements along the reduced dimensions of the input ndarray and then broadcasting the separators array against [ ..., M-1 ], where ... corresponds to the non-reduced dimensions and M corresponds to the number of elements along the reduced dimensions.

separators = new ndarray( 'generic', opts.separators, [ opts.separators.length ], [ 1 ], 0, order );
}
// Perform the reduction:
unaryReduceStrided1d( dispatch, [ x, y ], opts.dims );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is odd. Why are you doing it this way? A closure should not be necessary if you have done broadcasting correctly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using unaryReduceStrided1d and not *-dispatch and not -factory skips a bunch of validation logic that would have to be reimplemented here. That is not desirable. Ideally, we'd figure out a way to use the *-factory package.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Validation including acceptable dtypes. TL;DR: there is a lot currently incorrect with this implementation.

* @param {Array<Object>} arrays - ndarrays
* @returns {string} joined string
*/
function dispatch( arrays ) {
Copy link
Copy Markdown
Member

@kgryte kgryte Apr 4, 2026

Choose a reason for hiding this comment

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

This function should not be necessary. prefix, suffix, and separators should all be passed down as auxiliary arrays via unaryReduceStrided1d, not via a closure like this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm...but I see that separators will be problematic here, as unaryReduceStrided1d assumes all ancillary arrays are 0D, while separators will always be 1D.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's possible that we need only tweak unary-reduce-strided1d slightly here.

Copy link
Copy Markdown
Member Author

@headlessNode headlessNode Apr 4, 2026

Choose a reason for hiding this comment

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

@kgryte I think two changes in unary-reduce-strided1d would unlock the factory approach:

  1. Allow arrays with extra trailing dimensions here: https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-strided1d/lib/main.js#L380
  2. Pass K here: https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-strided1d/lib/main.js#L428, and for array with more than K dimensions, preserved trailing dimensions instead of collapsing to 0d.

I believe the iteration code would work as is. Should I go ahead with these changes in unary-reduce-strided1d? and the binary-* counterpart as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Those changes are not sufficient. It is not just main.js which needs to be updated. I'll try and take a look.

Copy link
Copy Markdown
Member

@kgryte kgryte Apr 8, 2026

Choose a reason for hiding this comment

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

@headlessNode The following commit c8df03c should now allow passing the separators ndarray as a 1D array to the lower-level strided reduction interface.

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.

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 Apr 4, 2026
@kgryte
Copy link
Copy Markdown
Member

kgryte commented Apr 8, 2026

/stdlib merge

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Apr 8, 2026
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Apr 8, 2026
* @param {Options} [options] - function options
* @param {string} [options.prefix=''] - prefix to prepend to each joined string
* @param {string} [options.suffix=''] - suffix to append to each joined string
* @param {ArrayLikeObject} [options.separators=[',']] - separators
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Separators should be an ndarray. But also, why is separators optional here? Shouldn't it be mandatory? If users just want to join elements with a single separator, they can use blas/ext/join. I think it is fine to leave prefix and suffix as optional, but we should make provided separators be a mandatory positional argument.

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

Labels

BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). 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 blas/ext/join-between

3 participants