-
-
Notifications
You must be signed in to change notification settings - Fork 993
feat: add blas/ext/base/gjoin
#8742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Coverage Report
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>
| view = []; | ||
| ix = offsetX; | ||
| for ( i = 0; i < N; i++ ) { | ||
| view.push( get( xbuf, ix ) ); | ||
| ix += strideX; | ||
| } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 = []; |
There was a problem hiding this comment.
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 calljoin( x, separator ) - otherwise, perform manual concatenation (i.e., effectively copy the manual loop implementation from
array/base/joinand tweak to support strides)
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
There was a problem hiding this 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
left a comment
There was a problem hiding this 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.
Resolves stdlib-js/metr-issue-tracker#123.
Description
This pull request:
blas/ext/base/gjoinRelated Issues
This pull request has the following related issues:
blas/ext/base/joinmetr-issue-tracker#123Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
Utilized AI to the fullest. Code generation, documentation, tests, benchmarks etc.
@stdlib-js/reviewers