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/dptcon #2772

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 262 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dptcon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
<!--

@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.

-->

# dptcon

> Compute the reciprocal of the condition number of a real symmetric positive definite tridiagonal matrix using the factorization `A = L*D*L^T`.

<section class = "usage">

## Usage

```javascript
var dptcon = require( '@stdlib/lapack/base/dptcon' );
```

#### dptcon( N, D, E, anorm, rcond, work )

Computes the reciprocal of the condition number of a real symmetric positive definite tridiagonal matrix using the factorization `A = L*D*L^T`.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var D = new Float64Array( [ 3.0, 2.0, 1.0 ] );
var E = new Float64Array( [ 1.0, 1.0 ] );
var rcond = new Float64Array( 1 );
var work = new Float64Array( 3 );

var out = dptcon( 3, D, E, 3.0, rcond, work );
// returns 0
```

The function has the following parameters:

- **N**: order of matrix `A`.
- **D**: the `N` diagonal elements of `A` as a [`Float64Array`][mdn-float64array].
- **E**: the N-1 off-diagonal elements of `U` or `L` from the factorization `A`.
- **anorm**: the 1-norm of `A`.
- **rcond**: an output [`Float64Array`][mdn-float64array] containing the reciprocal of the condition number of `A`
- **work**: a workspace array.

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' );

// Initial arrays...
var D0 = new Float64Array( [ 0.0, 3.0, 2.0, 1.0 ] );
var E0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var RCOND0 = new Float64Array( [ 0.0, 0.0 ] );
var WORK0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0] );

// Create offset views...
var D1 = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var E1 = new Float64Array( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var RCOND1 = new Float64Array( RCOND0.buffer, RCOND0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var WORK1 = new Float64Array( WORK0.buffer, WORK0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dptcon( 3, D1, E1, 3.0, RCOND1, WORK1 );
// RCOND0 => <Float64Array>[ 0.0, 0.07692307692307693 ]
// WORK0 => <Float64Array>[ 0.0, 4.333333333333333, 4.0, 3.0 ]
```

#### dptcon.ndarray( N, D, sd, od, E, se, oe, anorm, rc, or, work, sw, ow )

Computes the reciprocal of the condition number of a real symmetric positive definite tridiagonal matrix using the factorization `A = L*D*L^T` and alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var D = new Float64Array( [ 3.0, 2.0, 1.0 ] );
var E = new Float64Array( [ 1.0, 1.0 ] );
var rcond = new Float64Array( 1 );
var work = new Float64Array( 3 );

var out = dptcon.ndarray( 3, D, 1, 0, E, 1, 0, 3.0, rcond, 0, work, 1, 0 );
// returns 0
```

The function has the following additional parameters:

- **sd**: stride length for `D`.
- **od**: starting index for `D`.
- **se**: stride length for `E`.
- **oe**: starting index for `E`.
- **or**: starting index for `rcond`.
- **sw**: stride length for `work`.
- **ow**: starting index for `work`.

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,

<!-- eslint-disable max-len -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var D = new Float64Array( [ 0.0, 3.0, 2.0, 1.0 ] );
var E = new Float64Array( [ 0.0, 1.0, 1.0 ] );
var rcond = new Float64Array( 1 );
var work = new Float64Array( 3 );

var out = dptcon.ndarray( 3, D, 1, 1, E, 1, 1, 3.0, rcond, 0, work, 1, 0 );
// returns 0
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input arrays `D` and `E`.

- Both functions return a status code indicating success or failure. A status code indicates the following conditions:

- `0`: the execution was successful.
- `<0`: the k-th argument had an illegal value, where `-k` equals the status code value.

- `dptcon()` corresponds to the [LAPACK][LAPACK] routine [`dptcon`][lapack-dptcon].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var dptcon = require( '@stdlib/lapack/base/dptcon' );

var D = new Float64Array( [ 3.0, 2.0, 1.0 ] );
var E = new Float64Array( [ 1.0, 1.0 ] );
var rcond = new Float64Array( 1 );
var work = new Float64Array( 3 );

var out = dptcon( 3, D, E, 3.0, rcond, work );
console.log( out );
console.log( rcond );
console.log( work );
```

</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-dptcon]: https://www.netlib.org/lapack/explore-html/d1/d85/group__ptcon_gafc28b3de543d210d9dd7ad6dd9373071.html#gafc28b3de543d210d9dd7ad6dd9373071

[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
100 changes: 100 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dptcon/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var dptcon = require( './../lib/dptcon.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 rcond = new Float64Array( 1 );
var work = new Float64Array( len );
var D = uniform( len, 0.0, 100.0, options );
var E = uniform( len - 1, 0.0, 100.0, options );
return benchmark;

function benchmark( b ) {
var d;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
d = dptcon( len, D, E, 3.0, rcond, work );
if ( isnan( d ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( d ) ) {
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();
Loading
Loading