Skip to content

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

Open
headlessNode wants to merge 1 commit intostdlib-js:developfrom
headlessNode:blas/nd-joinbetween
Open

feat: add blas/ext/join-between#11287
headlessNode wants to merge 1 commit 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

Coverage Report

Package Statements Branches Functions Lines
blas/ext/join-between $\color{red}453/459$
$\color{green}+98.69%$
$\color{red}44/47$
$\color{green}+93.62%$
$\color{green}5/5$
$\color{green}+100.00%$
$\color{red}453/459$
$\color{green}+98.69%$

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

@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?

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

@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
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