-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add blas/ext/join
#9009
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?
feat: add blas/ext/join
#9009
Conversation
---
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
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
Signed-off-by: Muhammad Haris <[email protected]>
Signed-off-by: Muhammad Haris <[email protected]>
Signed-off-by: Muhammad Haris <[email protected]>
lib/node_modules/@stdlib/blas/ext/join/benchmark/benchmark.assign.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <[email protected]>
Signed-off-by: Athan <[email protected]>
Signed-off-by: Athan <[email protected]>
Signed-off-by: Athan <[email protected]>
| var odtypes = dtypes( 'all' ); | ||
| var policies = { | ||
| 'output': 'same', | ||
| 'casting': 'promoted' | ||
| }; |
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.
@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?
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.
Also, this is a unary API. What exactly is supposed to be promoted? Between what arrays?
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.
@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.
| 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 ) ); | ||
| } | ||
|
|
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.
| 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 |
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.
| * @throws {TypeError} third argument must be an ndarray-like object having the generic data type |
| if ( nargs < 3 ) { | ||
| throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) ); | ||
| } |
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 are you validating this way? Why not !isndarrayLike( out )? Given that >=3 args must always be provided, you can validate out explicitly.
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.
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.
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.
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.
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.
@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.
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.
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] ) |
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.
@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 |
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 regarding whether this should be a required argument.
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 initial comments.
| var idtypes0 = dtypes( 'all' ); // input ndarray | ||
| var idtypes1 = dtypes( 'all' ); // separator ndarray | ||
| var odtypes = dtypes( 'all' ); | ||
| var policies = { | ||
| 'output': 'same', | ||
| 'casting': 'promoted' | ||
| }; |
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.
| 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' | |
| }; |
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.
@kgryte I think we'll get an error if x = float64ndarray
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.
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.
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves stdlib-js/metr-issue-tracker#124.
Description
This pull request:
blas/ext/joinRelated Issues
This pull request has the following related issues:
blas/ext/joinmetr-issue-tracker#124Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers