-
-
Notifications
You must be signed in to change notification settings - Fork 848
feat: add blas/base/icamax
#5068
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
Open
ShabiShett07
wants to merge
34
commits into
stdlib-js:develop
Choose a base branch
from
ShabiShett07:feature/icamax
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
79a0bcf
feat: add blas/base/icamax
ShabiShett07 5cbf955
docs: files completed
ShabiShett07 f1afdc1
fix: resolve lint errors
stdlib-bot 0b7117d
chore: update copyright years
stdlib-bot aefb83a
Update package.json
aman-095 ea43236
Update README.md
aman-095 ec7efeb
fix: resolved errors
ShabiShett07 61c28cf
fix: resolved errors
ShabiShett07 229f39c
Merge remote-tracking branch 'upstream/develop' into feature/icamax
stdlib-bot a6b105b
chore: update implementation
ShabiShett07 eb6d0b0
chore: update variable name
ShabiShett07 117f26e
chore: update implementation
ShabiShett07 a0e1f2e
chore: update implementation
ShabiShett07 ff25470
chore: add ndarray example
ShabiShett07 2486f5f
chore: minor clean-up
ShabiShett07 aad7629
Merge remote-tracking branch 'upstream/develop' into feature/icamax
stdlib-bot c218d94
chore: minor clean-up
ShabiShett07 cfa22e8
chore: minor clean-up
ShabiShett07 4e71757
chore: minor clean-up
ShabiShett07 66ef6c5
chore: clean-up
ShabiShett07 939fff6
chore: clean-up
ShabiShett07 aed923a
chore: clean-up
ShabiShett07 9ec9c5c
chore: minor clean-up
ShabiShett07 54132e0
chore: minor clean-up
ShabiShett07 9d0ba9e
chore: change y to idx
ShabiShett07 2e8d355
chore: add appropriate statements
ShabiShett07 c2fa56c
test: add negative stride
ShabiShett07 d793db6
docs: update jsdoc
ShabiShett07 e4f78af
chore: update comment
ShabiShett07 ce66993
chore: reducing variable
ShabiShett07 d7fb24e
chore: add appropriate keyword
ShabiShett07 99d56c1
test: remove duplicate
ShabiShett07 9f4ecb6
refactor: reduce variable
ShabiShett07 dcd48eb
chore: add appropriate parameter value
ShabiShett07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2025 The Stdlib Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
--> | ||
|
||
# icamax | ||
|
||
> Finds the index of the first element having maximum |Re(.)| + |Im(.)|. | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var icamax = require( '@stdlib/blas/base/icamax' ); | ||
``` | ||
|
||
#### icamax( N, cx, strideX ) | ||
|
||
Finds the index of the first element having maximum |Re(.)| + |Im(.)|. | ||
|
||
```javascript | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
|
||
var cx = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); | ||
|
||
var icx = icamax( cx.length, cx, 1 ); | ||
// returns 1 | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **N**: number of indexed elements. | ||
- **cx**: input [`Complex64Array`][@stdlib/array/complex64]. | ||
- **strideX**: index increment for `cx`. | ||
|
||
The `N` and `strideX` parameters determine which elements in `cx` are accessed at runtime. For example, to traverse every other value, | ||
|
||
```javascript | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
|
||
var cx = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); | ||
|
||
var icx = icamax( 2, cx, 2 ); | ||
// returns 1 | ||
``` | ||
|
||
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | ||
|
||
```javascript | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
|
||
// Initial array: | ||
var cx0 = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); | ||
|
||
// Create an offset view: | ||
var cx1 = new Complex64Array( cx0.buffer, cx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
|
||
// Find index of element having the maximum absolute value: | ||
var icx = icamax( 2, cx1, 1 ); | ||
// returns 1 | ||
``` | ||
|
||
#### icamax.ndarray( N, cx, strideX, offset ) | ||
|
||
Finds the index of the first element having maximum |Re(.)| + |Im(.)| using alternative indexing semantics. | ||
|
||
```javascript | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
|
||
var cx = new Complex64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); | ||
|
||
var icx = icamax.ndarray( cx.length, cx, 1, 0 ); | ||
// returns 1 | ||
``` | ||
|
||
The function has the following additional parameters: | ||
|
||
- **offsetX**: starting index. | ||
|
||
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a starting index. For example, to start from the second index, | ||
ShabiShett07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
|
||
var cx = new Complex64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] ); | ||
|
||
var icx = icamax.ndarray( 3, cx, 1, 1 ); | ||
// returns 2 | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- If `N < 1`, both functions return `-1`. | ||
- `icamax()` corresponds to the [BLAS][blas] level 1 function [`icamax`][icamax]. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); | ||
var filledarrayBy = require( '@stdlib/array/filled-by' ); | ||
var complex64 = require( '@stdlib/complex/float32/ctor' ); | ||
var icamax = require( '@stdlib/blas/base/icamax' ); | ||
|
||
function rand() { | ||
return new complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); | ||
} | ||
|
||
// Generate random input arrays: | ||
var cx = filledarrayBy( 10, 'complex64', rand ); | ||
console.log( cx.toString() ); | ||
|
||
var icx = icamax( cx.length, cx, 1 ); | ||
console.log( icx ); | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[blas]: http://www.netlib.org/blas | ||
|
||
[icamax]: https://netlib.org/lapack/explore-html/d0/da5/izamax_8f.html | ||
ShabiShett07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64 | ||
|
||
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
105 changes: 105 additions & 0 deletions
105
lib/node_modules/@stdlib/blas/base/icamax/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
var pkg = require( './../package.json' ).name; | ||
var icamax = require( './../lib/icamax.js' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var options = { | ||
'dtype': 'float32' | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Create a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - array length | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len ) { | ||
var cx; | ||
|
||
cx = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); | ||
ShabiShett07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var icx; | ||
ShabiShett07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
icx = icamax( cx.length, cx, 1 ); | ||
if ( isnan( icx ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( icx ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
len = pow( 10, i ); | ||
f = createBenchmark( len ); | ||
bench( pkg+':len='+len, f ); | ||
} | ||
} | ||
|
||
main(); |
105 changes: 105 additions & 0 deletions
105
lib/node_modules/@stdlib/blas/base/icamax/benchmark/benchmark.ndarray.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
var pkg = require( './../package.json' ).name; | ||
var icamax = require( './../lib/ndarray.js' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var options = { | ||
'dtype': 'float32' | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Create a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - array length | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len ) { | ||
var cx; | ||
|
||
cx = new Complex64Array( uniform( len*2, -100.0, 100.0, options ) ); | ||
ShabiShett07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var icx; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
icx = icamax( cx.length, cx, 1, 0 ); | ||
ShabiShett07 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ( isnan( icx ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( icx ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
len = pow( 10, i ); | ||
f = createBenchmark( len ); | ||
bench( pkg+':ndarray:len='+len, f ); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.