Skip to content

feat: add blas/ext/base/gconjoin#11142

Open
headlessNode wants to merge 3 commits intostdlib-js:developfrom
headlessNode:blas/gconjoin
Open

feat: add blas/ext/base/gconjoin#11142
headlessNode wants to merge 3 commits intostdlib-js:developfrom
headlessNode:blas/gconjoin

Conversation

@headlessNode
Copy link
Member

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

Description

What is the purpose of this pull request?

This pull request:

  • add blas/ext/base/gconjoin

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

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

stdlib-bot commented Mar 25, 2026

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/gconjoin $\color{red}337/341$
$\color{green}+98.83%$
$\color{red}30/32$
$\color{green}+93.75%$
$\color{green}5/5$
$\color{green}+100.00%$
$\color{red}337/341$
$\color{green}+98.83%$

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

@headlessNode headlessNode requested a review from kgryte March 25, 2026 19:49
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 25, 2026
@github-actions github-actions bot mentioned this pull request Mar 26, 2026
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Mar 26, 2026
if ( N <= 0 ) {
return '';
}
o = arraylike2object( x );
Copy link
Member

Choose a reason for hiding this comment

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

When conjunction is the empty string, we should delegate to blas/ext/base/gjoin which has a fast path and method delegation.

if ( conjunction === '' ) {
    return prefix + gjoin( N, SEP, x, strideX, offsetX ) + suffix;
}

Copy link
Member

Choose a reason for hiding this comment

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

Actually, you could more generally do a fast path when the stride is 1. When no conjunction, delegate fully to gjoin. When there is a conjunction, use gjoin for the first N-1 elements and then handle the last element as you do below.

This should impact your last element handling logic below as the no-conjunction case can be handled via gjoin with final concat with prefix and suffix.

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 Mar 26, 2026
@kgryte
Copy link
Member

kgryte commented Mar 26, 2026

For METR,

review_time: 25 mins

@headlessNode headlessNode removed the Needs Changes Pull request which needs changes before being merged. label Mar 26, 2026
@headlessNode headlessNode added the Needs Review A pull request which needs code review. label Mar 26, 2026
@headlessNode headlessNode requested a review from kgryte March 26, 2026 05:29
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment on lines +92 to +102
if ( strideX === 1 ) {
out = prefix + gjoin( N-1, SEP, x, strideX, offsetX );
} else {
ix = offsetX;
out = prefix + str( x, ix );
ix += strideX;
for ( i = 1; i < N - 1; i++ ) {
out += SEP + str( x, 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.

Looking at this, do we actually need to have a special path for strideX == 1?

Suggested change
if ( strideX === 1 ) {
out = prefix + gjoin( N-1, SEP, x, strideX, offsetX );
} else {
ix = offsetX;
out = prefix + str( x, ix );
ix += strideX;
for ( i = 1; i < N - 1; i++ ) {
out += SEP + str( x, ix );
ix += strideX;
}
}
out = prefix + gjoin( N-1, SEP, x, strideX, offsetX );

Comment on lines +85 to +88
o = arraylike2object( x );
if ( o.accessorProtocol ) {
return accessors( N, prefix, suffix, conjunction, oxfordComma, o, strideX, offsetX ); // eslint-disable-line max-len
}
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 no longer sure it is actually necessary anymore to have a dedicated accessors.js file.

If conjunction is '' or N == 1, we can delegate fully to gjoin.

For the first N-1 elements, we can delegate to gjoin.

It is only for the last element that we need specialized behavior. At which point, I think it is fine if instead of arraylike2object, we use array/base/resolve-getter on the input array x and use the str function from the accessors.js file to resolve the last element.

So I think we can streamline the implementation a bit further.

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.

Apart from refactoring the implementation, this is coming along.

@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 26, 2026
@kgryte
Copy link
Member

kgryte commented Mar 26, 2026

For METR,

review_time: 15 mins

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/base/gconjoin

3 participants