-
-
Notifications
You must be signed in to change notification settings - Fork 867
feat: add blas/base/zdotu
#6613
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
--- 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. |
/stdlib merge |
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 ---
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
Signed-off-by: Athan <kgryte@gmail.com>
/stdlib merge |
Signed-off-by: Athan <kgryte@gmail.com>
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
d = zdotu( x.length, x, 1, y, 1 ); | ||
if ( isnan( d ) ) { |
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 isn't a valid check. You need to check, e.g., the real component.
} | ||
} | ||
b.toc(); | ||
if ( isnan( d ) ) { |
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.
Here, you can check the imaginary component (e.g., isnan( imag( d ) )
).
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
d = zdotu( x.length, x, 1, 0, y, 1, 0 ); | ||
if ( isnan( d ) ) { |
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 comments.
Returns | ||
------- | ||
out: Complex128 | ||
Scalar constant. |
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.
Scalar constant. | |
Dot product. |
vectors using alternative indexing semantics. | ||
|
||
While typed array views mandate a view offset based on the underlying | ||
buffer, the offset parameters support indexing based on a starting index. |
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.
buffer, the offset parameters support indexing based on a starting index. | |
buffer, offset parameters support indexing based on starting indices. |
Returns | ||
------- | ||
out: Complex128 | ||
Second input array. |
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.
Second input array. | |
Dot product. |
*/ | ||
interface Routine { | ||
/** | ||
* Calculates the dot product of vectors `x` and `y`. |
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.
Would you mind updating all the descriptions to use consistent language? s/Calculates/Computes/ here and everywhere else.
|
||
// TESTS // | ||
|
||
// The function returns Complex128... |
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 function returns Complex128... | |
// The function returns a complex number... |
zdotu( x.length, x, 1, y, 1, 10 ); // $ExpectError | ||
} | ||
|
||
// Attached to main export is an `ndarray` method which returns a Complex128... |
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.
// Attached to main export is an `ndarray` method which returns a Complex128... | |
// Attached to main export is an `ndarray` method which returns a complex number... |
ix = offsetX; | ||
iy = offsetY; | ||
for ( i = 0; i < N; i++ ) { | ||
dot = muladd( x.get( ix ), y.get( iy ), dot ); |
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 isn't correct. We should not be using the accessors. We should reinterpret the complex input arrays as Float64Arrays
of interleaved real and imaginary components. And then we should use muladd.strided
. For reference, see
muladd( re, im, viewX[ ix ], viewX[ ix+1 ], viewY[ iy ], viewY[ iy+1 ], viewY, 1, iy ); // eslint-disable-line max-len |
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.
Instead of muladd.assign
, you want to use muladd.strided
: https://github.com/stdlib-js/stdlib/tree/02838049b98a8ae3c595714e397364aace06f7b9/lib/node_modules/%40stdlib/complex/float64/base/mul-add#muladdstrided-alpha-sa-oa-x-sx-ox-y-sy-oy-out-so-oo-
This allows you to have the output real and imaginary components stored in a Float64Array
. To return a complex number, you then do new Complex128( out[ 0 ], out[ 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.
The reason we shouldn't be using accessors and constantly materializing Complex128
instances is that all of this is happening in a hot loop. Instead, prefer to operate on the individual components directly.
y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); | ||
|
||
dot = zdotu( x.length, x, 1, 0, y, 1, 0 ); | ||
t.strictEqual(isSameComplex128( dot, new Complex128( 3, 70 ) ), true, 'returns expected value' ); |
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.
t.strictEqual(isSameComplex128( dot, new Complex128( 3, 70 ) ), true, 'returns expected value' ); | |
t.strictEqual(isSameComplex128( dot, new Complex128( 3.0, 70.0 ) ), true, 'returns expected value' ); |
To indicate that the input values are double, we should add decimals here and everywhere else in these test files when creating Complex128
instances.
7.0, // 0 | ||
8.0, // 0 | ||
9.0, // 1 | ||
10.0, // 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.
These annotations are not correct. The 0
and 1
comments should be reversed, as the strided for y
is -1
at L236.
y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); | ||
|
||
dot = zdotu( 4, x, 1, y, 1 ); | ||
t.strictEqual( isSameComplex128( dot, new Complex128( 3, 70 ) ), true, 'returns expected value' ); |
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 comments.
t.end(); | ||
}); | ||
|
||
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0 + 0i`', 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( 'if provided an `N` parameter less than or equal to `0`, the function returns `0 + 0i`', function test( t ) { | |
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) { |
Consistency with other test file.
6.0 // 1 | ||
]); | ||
y = new Complex128Array([ | ||
7.0, // 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 regarding the comments.
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 PR needs a bit of clean-up still.
@ShabiShett07 Also, in addition to the main export and the ndarray
method, we should add an assign
method with the following signature:
zdotu.assign( N, x, strideX, offsetX, y, strideY, offsetY, out, offsetOut );
In this case, the real and imaginary components of the complex number output will be written to out
which should be a Complex128Array
at the index offsetOut
.
The ndarray
method can then wrap the assign
API and you can use a preallocated Complex128Array
workspace array which you then pass as input to assign
. When returning from ndarray
, you then do workspace.get( 0 )
, which will materialize a new Complex128
value.
Similarly, the main export can also wrap the assign
API.
Why are we doing this? Because in zgemm
, you will want to use the assign
API of zdotu
, not the ndarray
API. The assign API will allow you to avoid materializing complex number instances in hot loops.
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Resolves a part of #2039.
Description
This pull request:
blas/base/zdotu
Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers