-
-
Notifications
You must be signed in to change notification settings - Fork 837
feat: add blas/ext/base/sindex-of
#7318
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. |
--- 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: 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 ---
blas/ext/base/sindexof
blas/ext/base/sindex-of
lib/node_modules/@stdlib/blas/ext/base/sindex-of/docs/types/index.d.ts
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/blas/ext/base/sindex-of/docs/types/index.d.ts
Outdated
Show resolved
Hide resolved
--- 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: 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 ---
lib/node_modules/@stdlib/blas/ext/base/sindex-of/lib/ndarray.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Muhammad Haris <[email protected]>
@headlessNode Would you mind going ahead and adding the C implementation and associated benchmarks, examples, docs, and tests? |
The function has the following parameters: | ||
|
||
- **N**: number of indexed elements. | ||
- **searchElement**: element to search the index of. |
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.
- **searchElement**: element to search the index of. | |
- **searchElement**: search element. |
- **N**: number of indexed elements. | ||
- **searchElement**: element to search the index of. | ||
- **x**: input [`Float32Array`][@stdlib/array/float32]. | ||
- **strideX**: index increment. |
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.
- **strideX**: index increment. | |
- **strideX**: stride length. |
- **x**: input [`Float32Array`][@stdlib/array/float32]. | ||
- **strideX**: index increment. | ||
|
||
If the function is unable to find an element which equals a provided search element, the function returns `-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.
If the function is unable to find an element which equals a provided search element, the function returns `-1`. | |
If the function is unable to find a search element, the function returns `-1`. |
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] ); | ||
|
||
var idx = sindexOf( 4, -1.0, x, 2 ); | ||
// returns 6 |
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 incorrect. N
specifies the view length. Here, that "view" is four elements. 6
is the index in the underlying buffer. That is not what we care about in this case.
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.
See also blas/base/isamax
.
|
||
// Find index... | ||
var idx = sindexOf( 3, -6.0, x1, 2 ); | ||
// returns 4 |
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 thing. This return value is incorrect.
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] ); | ||
|
||
var idx = sindexOf.ndarray( 3, 3.0, x, 1, x.length-3 ); | ||
// returns 7 |
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 incorrect.
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = sindexOf( x.length, 2.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.
out = sindexOf( x.length, 2.0, x, 1 ); | |
out = sindexOf( x.length, len+1, x, 1 ); |
2.0
obviously does not make sense here, as then the benchmarks are effectively constant time. You should be benchmarking the worst case scenario (i.e., when you need to search an entire array).
len = pow( 10, i ); | ||
|
||
f = createBenchmark( len ); | ||
bench( pkg+':dtype=float32,len='+len, f ); |
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 we including dtype
here? Only one dtype is allowed/expected.
bench( pkg+':dtype=float32,len='+len, f ); | |
bench( pkg+':len='+len, f ); |
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = sindexOf( x.length, 2.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.
out = sindexOf( x.length, 2.0, x, 1, 0 ); | |
out = sindexOf( x.length, len+1, x, 1, 0 ); |
len = pow( 10, i ); | ||
|
||
f = createBenchmark( len ); | ||
bench( pkg+':dtype=float32,len='+len, f ); |
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.
bench( pkg+':dtype=float32,len='+len, f ); | |
bench( pkg+':len='+len, f ); |
* Returns the index of a specified search element in a single-precision floating-point strided array. | ||
* | ||
* @param {PositiveInteger} N - number of indexed elements | ||
* @param {Number} searchElement - number to search index of |
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.
* @param {Number} searchElement - number to search index of | |
* @param {number} searchElement - search element |
* @param {PositiveInteger} N - number of indexed elements | ||
* @param {Number} searchElement - number to search index of | ||
* @param {Float32Array} x - input array | ||
* @param {integer} strideX - index increment |
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.
* @param {integer} strideX - index increment | |
* @param {integer} strideX - stride length |
* Returns the index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics. | ||
* | ||
* @param {PositiveInteger} N - number of indexed elements | ||
* @param {Number} searchElement - number to search index of |
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.
* @param {Number} searchElement - number to search index of | |
* @param {number} searchElement - search element |
* @param {PositiveInteger} N - number of indexed elements | ||
* @param {Number} searchElement - number to search index of | ||
* @param {Float32Array} x - input array | ||
* @param {integer} strideX - index increment |
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.
* @param {integer} strideX - index increment | |
* @param {integer} strideX - stride length |
ix = offsetX; | ||
for ( i = 0; i < N; i++ ) { | ||
if ( x[ ix ] === searchElement ) { | ||
return ix; |
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.
return ix; | |
return i; |
t.strictEqual( actual, 3, 'returns expected value' ); | ||
|
||
actual = sindexOf( x.length, 3.0, x, -1 ); | ||
t.strictEqual( actual, 5, '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.
This is incorrect.
t.strictEqual( actual, 1, 'returns expected value' ); | ||
|
||
actual = sindexOf( x.length, 2.0, x, -1 ); | ||
t.strictEqual( actual, 3, '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.
This is incorrect.
|
||
// Negative stride... | ||
actual = sindexOf( x.length, 1.0, x, -1 ); | ||
t.strictEqual( actual, 1, '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.
This is incorrect.
actual = sindexOf( x.length, 1.0, x, -1, x.length-1 ); | ||
t.strictEqual( actual, 1, 'returns expected value' ); | ||
|
||
actual = sindexOf( x.length, 2.0, x, -2, x.length-1 ); | ||
t.strictEqual( actual, 3, 'returns expected value' ); | ||
|
||
actual = sindexOf( x.length, 1.0, x, -2, x.length-2 ); | ||
t.strictEqual( actual, 0, '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.
These are all incorrect.
t.strictEqual( actual, 0, 'returns expected value' ); | ||
|
||
actual = sindexOf( x.length, 2.0, x, 1, 1 ); | ||
t.strictEqual( actual, 2, '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.
Incorrect.
t.strictEqual( actual, 2, 'returns expected value' ); | ||
|
||
actual = sindexOf( x.length, 3.0, x, 1, 2 ); | ||
t.strictEqual( actual, 4, '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.
Incorrect.
var ix; | ||
var i; | ||
|
||
if ( N <= 0 || x.length === 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.
if ( N <= 0 || x.length === 0 ) { | |
if ( N <= 0 ) { |
tape( 'the function returns `-1` if provided an offset which exceeds the maximum array index', function test( t ) { | ||
var actual; | ||
|
||
actual = sindexOf( 3, 2.0, new Float32Array( [ 1.0, 2.0, 3.0 ] ), 1, 20 ); | ||
t.strictEqual( actual, -1, 'returns expected value' ); | ||
|
||
t.end(); | ||
}); |
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 test should be removed. In strided array implementations, we don't perform buffer bounds checking.
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.
Again, it would be useful to refer to https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/blas/base/isamax/lib/ndarray.js.
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Progresses #2656 .
Description
This pull request:
blas/ext/base/sindexof
Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers