Skip to content
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

feat: add lapack/base/dlacn2 #2790

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
273 changes: 273 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlacn2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
<!--

@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.
Copy link
Member

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.


<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
Copy link
Member Author

Choose a reason for hiding this comment

The 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 ]
```

#### 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 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 ] );

ISGN = dlacn2.ndarray( 4, V, 1, 0, X, 1, 0, ISGN, 1, 0, EST, 0, KASE, 0, ISAVE, 1, 0 );
// ISGN => <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 ISGN = new Int32Array( [ 0, 1, 1, 1, 1 ] );
var EST = new Float64Array( [ 0.0, 0.0 ] );
var KASE = new Int32Array( [ 0, 0 ] );
var ISAVE = new Int32Array( [ 0, 0, 0, 0, 0, 0 ] );

ISGN = dlacn2.ndarray( 4, V, 1, 0, X, 1, 0, ISGN, 1, 1, EST, 1, KASE, 1, ISAVE, 1, 1 );
// ISGN => <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 lib/node_modules/@stdlib/lapack/base/dlacn2/benchmark/benchmark.js
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();
Loading
Loading