Skip to content

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#124.

Description

What is the purpose of this pull request?

This pull request:

  • add blas/ext/join

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.".

{{TODO: add disclosure if applicable}}


@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 BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). Needs Review A pull request which needs code review. labels Dec 12, 2025
@headlessNode headlessNode added the Feature Issue or pull request for adding a new feature. label Dec 12, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 12, 2025

Coverage Report

Package Statements Branches Functions Lines
blas/ext/join $\color{red}453/459$
$\color{green}+0.00%$
$\color{red}35/38$
$\color{green}+0.00%$
$\color{green}2/2$
$\color{green}+0.00%$
$\color{red}453/459$
$\color{green}+0.00%$

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

Signed-off-by: Muhammad Haris <[email protected]>
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Dec 16, 2025
Comment on lines +32 to +36
var odtypes = dtypes( 'all' );
var policies = {
'output': 'same',
'casting': 'promoted'
};
Copy link
Member

Choose a reason for hiding this comment

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

@headlessNode What is the rationale behind this configuration? Why is "promotion" being used here? Why is the output policy to return an ndarray having the "same" dtype?

Copy link
Member

Choose a reason for hiding this comment

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

Also, this is a unary API. What exactly is supposed to be promoted? Between what arrays?

Copy link
Member Author

Choose a reason for hiding this comment

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

@kgryte I was trying to create a 'default' output policy here i.e. If input dtype is generic. promotion to "promote" say float64 to generic if input is float64 but that doesn't work.

Comment on lines +110 to +113
if ( getDType( out ) !== 'generic' ) {
throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object having the generic data type. Value: `%s`.', out ) );
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( getDType( out ) !== 'generic' ) {
throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object having the generic data type. Value: `%s`.', out ) );
}

This check is not necessary. It should be delegated to the dispatcher.

* @throws {TypeError} first argument must be an ndarray-like object
* @throws {TypeError} second argument must be either an ndarray-like object or a scalar value
* @throws {TypeError} third argument must be an ndarray-like object
* @throws {TypeError} third argument must be an ndarray-like object having the generic data type
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @throws {TypeError} third argument must be an ndarray-like object having the generic data type

Comment on lines +104 to +106
if ( nargs < 3 ) {
throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );
}
Copy link
Member

Choose a reason for hiding this comment

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

Why are you validating this way? Why not !isndarrayLike( out )? Given that >=3 args must always be provided, you can validate out explicitly.

Copy link
Member

Choose a reason for hiding this comment

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

However, as commented in the README, I am not sure I agree with the requirement that a separator argument always be provided. Not clear why we are not defaulting to ',' for the separator, similar to Array.prototype.join.

Copy link
Member

Choose a reason for hiding this comment

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

For an API which also has an optional second positional argument, see https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/cusum.

Copy link
Member Author

Choose a reason for hiding this comment

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

@kgryte Yes, also in the sentinelValue in ndarray/find. Whose initial implementation(sentinel not optional) was stuck in my mind but I should've checked.

Copy link
Member

Choose a reason for hiding this comment

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

The argument juggling done there should be informative.

I suppose, in principle, one could have a custom separator "object" with a custom toPrimitive method, which might be confusing when trying to distinguish from an options object during argument juggling, but this seems like a niche use case that we shouldn't bend over backward to accommodate. In this scenario, a user could always do join( x, String( sep ) ) to force string serialization.

var join = require( '@stdlib/blas/ext/join' );
```

#### join( x, separator\[, options] )
Copy link
Member

Choose a reason for hiding this comment

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

@headlessNode Why is a separator argument required for the top-level API? Why aren't we defaulting to the most common scenario of , and having separator be an optional positional argument?

* Returns an ndarray created by joining elements using a specified separator along an ndarray dimension.
*
* @param {ndarrayLike} x - input ndarray
* @param {(ndarrayLike|*)} separator - separator
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 regarding whether this should be a required argument.

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 the Needs Changes Pull request which needs changes before being merged. label Dec 16, 2025
Comment on lines +30 to +36
var idtypes0 = dtypes( 'all' ); // input ndarray
var idtypes1 = dtypes( 'all' ); // separator ndarray
var odtypes = dtypes( 'all' );
var policies = {
'output': 'same',
'casting': 'promoted'
};
Copy link
Member

@kgryte kgryte Dec 16, 2025

Choose a reason for hiding this comment

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

Suggested change
var idtypes0 = dtypes( 'all' ); // input ndarray
var idtypes1 = dtypes( 'all' ); // separator ndarray
var odtypes = dtypes( 'all' );
var policies = {
'output': 'same',
'casting': 'promoted'
};
var idtypes0 = dtypes( 'all' ); // input ndarray
var idtypes1 = [ 'generic' ]; // separator ndarray
var odtypes = [ 'generic' ];
var policies = {
'output': 'same', // note: because we always return a "generic" ndarray, this policy is effectively ignored
'casting': 'none'
};

Copy link
Member Author

@headlessNode headlessNode Dec 16, 2025

Choose a reason for hiding this comment

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

@kgryte I think we'll get an error if x = float64ndarray

Copy link
Member

Choose a reason for hiding this comment

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

The solution here is not to explicitly cast the input array, thus copying the input array to a temporary buffer, as that is definitely not necessary.

Instead, in main.js, you just need to explicitly pass down a dtype option equal to generic, which you already do.

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

3 participants