-
-
Notifications
You must be signed in to change notification settings - Fork 814
feat: add lapack/base/dlacn2
#2790
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
Pranavchiku
wants to merge
14
commits into
stdlib-js:develop
Choose a base branch
from
Pranavchiku:dlacn2
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.
+2,431
−0
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
21572eb
feat: init lapack/base/dlacn2
Pranavchiku 04ec3a9
test: fix spelling mistake
Pranavchiku 4aea9fa
docs: add repl and readme
Pranavchiku e4f6172
chore: suppress lint error in README
Pranavchiku 4a67f01
docs: suppress lint error in repl
Pranavchiku e790306
fix: lint error in readme
Pranavchiku 4280cbf
fix: lint error in readme
Pranavchiku 2f4d35a
chore: apply suggestions from code review
Pranavchiku c71adae
refactor: ndarray implementation
Pranavchiku 0e59a43
test: add more ndarray tests
Pranavchiku 9297bd2
Merge branch 'develop' into dlacn2
Pranavchiku 59bdc92
test: add more ndarray tests
Pranavchiku e0cd46e
chore: remove console statements
Pranavchiku 8230c1a
chore: apply suggestion from code review
Pranavchiku 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,275 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2024 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. | ||
|
||
--> | ||
|
||
# dlacn2 | ||
|
||
> Estimate the 1-norm of a square, real matrix `A`, reverse communication is used for evaluating matrix-vector products. | ||
|
||
<section class = "usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var dlacn2 = require( '@stdlib/lapack/base/dlacn2' ); | ||
``` | ||
|
||
#### dlacn2( N, V, X, ISGN, EST, KASE, ISAVE ) | ||
|
||
Estimates the 1-norm of a square, real matrix `A`, reverse communication is used for evaluating matrix-vector products. | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var Int32Array = require( '@stdlib/array/int32' ); | ||
|
||
var V = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var ISGN = new Int32Array( [ 1, 1, 1, 1 ] ); | ||
var EST = new Float64Array( [ 0.0 ] ); | ||
var KASE = new Int32Array( [ 0 ] ); | ||
var ISAVE = new Int32Array( [ 0, 0, 0, 0, 0] ); | ||
|
||
ISGN = dlacn2( 4, V, X, ISGN, EST, KASE, ISAVE ); | ||
// ISGN => <Int32Array>[ 1, 1, 1, 1 ] | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **N**: order of matrix `A`. | ||
- **V** [`Float64Array`][mdn-float64array], on final return `V=A*W`, where `W` is not returned. | ||
- **X** input [`Float64Array`][mdn-float64array]. | ||
- **ISGN** [`Int32Array`][mdn-int32array] of signs. | ||
- **EST** [`Float64Array`][mdn-float64array] containing estimate of lower bound of 1-norm of `A`. | ||
- **KASE** [`Int32Array`][mdn-int32array] containing value KASE to control overwritting of `X`. | ||
- **ISAVE** [`Int32Array`][mdn-int32array] for internal storage. | ||
Comment on lines
+54
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about these descriptions. |
||
|
||
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | ||
|
||
<!-- eslint-disable stdlib/capitalized-comments --> | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var Int32Array = require( '@stdlib/array/int32' ); | ||
|
||
// Initial arrays... | ||
var V0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); | ||
var X0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0 ] ); | ||
var ISGN0 = new Int32Array( [ 1, 1, 1, 1, 1 ] ); | ||
var EST0 = new Float64Array( [ 0.0, 0.0 ] ); | ||
var KASE0 = new Int32Array( [ 0, 0 ] ); | ||
var ISAVE0 = new Int32Array( [ 0, 0, 0, 0, 0 ] ); | ||
|
||
// Create offset views... | ||
var V1 = new Float64Array( V0.buffer, V0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var X1 = new Float64Array( X0.buffer, X0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var ISGN1 = new Int32Array( ISGN0.buffer, ISGN0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var EST1 = new Float64Array( EST0.buffer, EST0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var KASE1 = new Int32Array( KASE0.buffer, KASE0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
var ISAVE1 = new Int32Array( ISAVE0.buffer, ISAVE0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
|
||
ISGN1 = dlacn2( 4, V1, X1, ISGN1, EST1, KASE1, ISAVE1 ); | ||
// ISGN0 => <Int32Array>[ 1, 1, 1, 1, 1 ] | ||
``` | ||
|
||
<!-- lint disable maximum-heading-length --> | ||
|
||
#### dlacn2.ndarray( N, V, sv, ov, X, sx, ox, I, si, oi, E, oe, K, ok, S, ss, os ) | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Estimates the 1-norm of a square, real matrix `A`, reverse communication is used for evaluating matrix-vector products using alternative indexing semantics. | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var Int32Array = require( '@stdlib/array/int32' ); | ||
|
||
var V = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var I = new Int32Array( [ 1, 1, 1, 1 ] ); | ||
var E = new Float64Array( [ 0.0 ] ); | ||
var K = new Int32Array( [ 0 ] ); | ||
var S = new Int32Array( [ 0, 0, 0 ] ); | ||
|
||
I = dlacn2.ndarray( 4, V, 1, 0, X, 1, 0, I, 1, 0, E, 0, K, 0, S, 1, 0 ); | ||
// I => <Int32Array>[ 1, 1, 1, 1 ] | ||
``` | ||
|
||
The function has the following additional parameters: | ||
|
||
- **sv**: stride length for `V`. | ||
- **ov**: starting index of `V`. | ||
- **sx**: stride length for `X`. | ||
- **ox**: starting index of `X`. | ||
- **si**: stride length for `I`. | ||
- **oi**: starting index of `I`. | ||
- **oe**: starting index of `E`. | ||
- **ok**: starting index of `K`. | ||
- **ss**: stride length for `S`. | ||
- **os**: starting index of `S`. | ||
|
||
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var Int32Array = require( '@stdlib/array/int32' ); | ||
|
||
var V = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var I = new Int32Array( [ 0, 1, 1, 1, 1 ] ); | ||
var E = new Float64Array( [ 0.0, 0.0 ] ); | ||
var K = new Int32Array( [ 0, 0 ] ); | ||
var S = new Int32Array( [ 0, 0, 0 ] ); | ||
|
||
I = dlacn2.ndarray( 4, V, 1, 0, X, 1, 0, I, 1, 1, E, 1, K, 1, S, 1, 1 ); | ||
// I => <Int32Array>[ 0, 1, 1, 1, 1 ] | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- `dlacn2()` corresponds to the [LAPACK][lapack] routine [`dlacn2`][lapack-dlacn2]. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var Int32Array = require( '@stdlib/array/int32' ); | ||
var dlacn2 = require( '@stdlib/lapack/base/dlacn2' ); | ||
|
||
var V = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var X = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var ISGN = new Int32Array( [ 1, 1, 1, 1 ] ); | ||
var EST = new Float64Array( [ 0.0 ] ); | ||
var KASE = new Int32Array( [ 1.0 ] ); | ||
var ISAVE = new Int32Array( [ 1, 0, 0 ] ); | ||
|
||
ISGN = dlacn2( 4, V, X, ISGN, EST, KASE, ISAVE ); | ||
console.log( ISGN ); | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- C interface documentation. --> | ||
|
||
* * * | ||
|
||
<section class="c"> | ||
|
||
## C APIs | ||
|
||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- C usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
### Usage | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
#### TODO | ||
|
||
TODO. | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
TODO | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- C API usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
### Examples | ||
|
||
```c | ||
TODO | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
</section> | ||
|
||
<!-- /.c --> | ||
|
||
<!-- 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"> | ||
|
||
[lapack]: https://www.netlib.org/lapack/explore-html/ | ||
|
||
[lapack-dlacn2]: https://www.netlib.org/lapack/explore-html/d6/d2d/group__lacn2_gabc1e7463e250c9e43596bfcbfa83c1de.html#gabc1e7463e250c9e43596bfcbfa83c1de | ||
|
||
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array | ||
|
||
[mdn-int32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array | ||
|
||
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
104 changes: 104 additions & 0 deletions
104
lib/node_modules/@stdlib/lapack/base/dlacn2/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,104 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); | ||
var Int32Array = require( '@stdlib/array/int32' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var pkg = require( './../package.json' ).name; | ||
var dlacn2 = require( './../lib/dlacn2.js' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var options = { | ||
'dtype': 'float64' | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - array length | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len ) { | ||
var ISAVE = new Int32Array( [ 1, 0, 0, 0, 0 ] ); | ||
var ISGN = new Int32Array( [ 1, 1, 1, 1 ] ); | ||
var KASE = new Int32Array( [ 0 ] ); | ||
var EST = new Float64Array( [ 0.0 ] ); | ||
var V = uniform( len, 1.0, 100.0, options ); | ||
var X = uniform( len, 1.0, 100.0, options ); | ||
|
||
return benchmark; | ||
|
||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = dlacn2( len, V, X, ISGN, EST, KASE, ISAVE ); | ||
if ( isnan( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( z[ i%z.length ] ) ) { | ||
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+':isave=1,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.
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 description is hard to read, as "reverse communication..." is a separate clause. This should be improved.