Skip to content

Conversation

@headlessNode
Copy link
Member

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

Description

What is the purpose of this pull request?

This pull request:

  • add blas/ext/base/gjoin

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

Utilized AI to the fullest. Code generation, documentation, tests, benchmarks etc.


@stdlib-js/reviewers

@headlessNode headlessNode requested a review from kgryte December 3, 2025 12:55
@headlessNode headlessNode added the Feature Issue or pull request for adding a new feature. label Dec 3, 2025
@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 3, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 3, 2025

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/gjoin $\color{green}259/259$
$\color{green}+0.00%$
$\color{green}14/14$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}259/259$
$\color{green}+0.00%$

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

Signed-off-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>
Comment on lines +64 to +69
view = [];
ix = offsetX;
for ( i = 0; i < N; i++ ) {
view.push( get( xbuf, ix ) );
ix += strideX;
}
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 only something we want to do as a last resort, and I am not convinced that we should be making a data copy regardless.

* var str = gjoin( x.length, ',', x, 1 );
* // returns '1,2,3,4'
*/
( N: number, separator: unknown, x: InputArray, strideX: number ): string;
Copy link
Member

Choose a reason for hiding this comment

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

Why does the separator have an "unknown" type? Why are we not following array/base/join and typing this as string?

* Returns a string created by joining strided array elements using a specified separator.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {*} 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.

Why is the type "any" here?

* Returns a string created by joining strided array elements using a specified separator and alternative indexing semantics.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {*} 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 question.

}

// Create a view of the strided elements
view = [];
Copy link
Member

@kgryte kgryte Dec 4, 2025

Choose a reason for hiding this comment

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

Same concern as in the accessors implementation. My sense is that

  • if strideX == 1 && offsetX == 0 && N == x.length, then call join( x, separator )
  • otherwise, perform manual concatenation (i.e., effectively copy the manual loop implementation from array/base/join and tweak to support strides)

Copy link
Member

@kgryte kgryte Dec 4, 2025

Choose a reason for hiding this comment

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

And realistically speaking, what we could do is effectively move the implementation from array/base/join to this package and then have array/base/join be a thin wrapper over this package. E.g.,

var strided = require( '@stdlib/blas/ext/base/gjoin' ).ndarray;

function join( x, separator ) {
    return strided( x.length, separator, x, 1, 0 );
}

t.end();
});

tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero', function test( t ) {
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
tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero', function test( t ) {
tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero', function test( t ) {

t.end();
});

tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero (accessors)', function test( t ) {
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
tape( 'the function returns an empty string if provided `N` parameter is less than or equal to zero (accessors)', function test( t ) {
tape( 'the function returns an empty string if provided an `N` parameter is less than or equal to zero (accessors)', function test( t ) {

actual = gjoin( x.length, ' - ', x, 1 );
t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' );

actual = gjoin( x.length, 0, x, 1 );
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure how worthwhile it is to support non-string types (at least explicitly/formally).

actual = gjoin( x.length, ' - ', x, 1, 0 );
t.strictEqual( actual, '1 - 2 - 3', 'returns expected value' );

actual = gjoin( x.length, 0, x, 1, 0 );
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.

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 an initial review. Main concern is avoiding unnecessary copies. We should only call array/base/join if certain conditions are met.

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 an initial review. Main concern is avoiding unnecessary copies. We should only call array/base/join if certain conditions are met.

@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 Dec 4, 2025
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/base/join

3 participants