Skip to content
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
245 changes: 245 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaqsp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# dlaqsp

> Equilibrate a real symmetric matrix stored in packed format.

<section class="intro">

Given a vector of scaling factors `S`, the routine equilibrates a real symmetric matrix `A` stored in packed format such that

<!-- <equation class="equation" label="eq:equilibration" align="center" raw="A = \text{diag}(S) \times A \times \text{diag}(S)" alt="Equilibration of a symmetric matrix."> -->

```math
A = \text{diag}(S) \times A \times \text{diag}(S)
```

<!-- </equation> -->

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dlaqsp( order, uplo, N, AP, S, scond, amax )

Equilibrates a real symmetric matrix `A` stored in packed format using scaling factors `S`.

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

var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var S = new Float64Array( [ 0.05, 2.0, 4.0 ] );

var out = dlaqsp( 'column-major', 'upper', 3, AP, S, 0.0125, 6.0 );
// AP => <Float64Array>[ ~0.0025, 0.2, 12.0, 0.8, 40.0, 96.0 ]
// out => 'Y'
```

The function has the following parameters:

- **order**: storage layout (either `'row-major'` or `'column-major'`).
- **uplo**: specifies whether the upper or lower triangular part of the symmetric matrix `A` is supplied (either `'upper'` or `'lower'`).
- **N**: order of matrix `A`.
- **AP**: packed form of symmetric matrix `A` as a [`Float64Array`][mdn-float64array].
- **S**: scale factors vector for `A` as a [`Float64Array`][mdn-float64array].
- **scond**: ratio of the smallest `S[i]` to the largest `S[i]`.
- **amax**: absolute value of the largest matrix entry.

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 AP0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var S0 = new Float64Array( [ 0.0, 0.05, 2.0, 4.0 ] );

// Create offset views:
var AP1 = new Float64Array( AP0.buffer, AP0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var S1 = new Float64Array( S0.buffer, S0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var out = dlaqsp( 'column-major', 'upper', 3, AP1, S1, 0.0125, 6.0 );
// AP1 => <Float64Array>[ ~0.0025, 0.2, 12.0, 0.8, 40.0, 96.0 ]
// out => 'Y'
```

<!-- lint disable maximum-heading-length -->

#### dlaqsp.ndarray( order, uplo, N, AP, strideAP, offsetAP, S, strideS, offsetS, scond, amax )

<!-- lint enable maximum-heading-length -->

Equilibrates a real symmetric matrix `A` stored in packed format using scaling factors `S` and alternative indexing semantics.

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

var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var S = new Float64Array( [ 0.05, 2.0, 4.0 ] );

var out = dlaqsp.ndarray( 'column-major', 'upper', 3, AP, 1, 0, S, 1, 0, 0.0125, 6.0 );
// AP => <Float64Array>[ ~0.0025, 0.2, 12.0, 0.8, 40.0, 96.0 ]
// out => 'Y'
```

The function has the following additional parameters:

- **strideAP**: stride length for `AP`.
- **offsetAP**: starting index for `AP`.
- **strideS**: stride length for `S`.
- **offsetS**: starting index for `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 AP = new Float64Array( [ 9999.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var S = new Float64Array( [ 9999.0, 0.05, 2.0, 4.0 ] );

var out = dlaqsp.ndarray( 'column-major', 'upper', 3, AP, 1, 1, S, 1, 1, 0.0125, 6.0 );
// AP => <Float64Array>[ 9999.0, ~0.0025, 0.2, 12.0, 0.8, 40.0, 96.0 ]
// out => 'Y'
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `AP` should contain `N*(N+1)/2` elements.
- If `scond` is greater than or equal to `0.1` and `amax` is neither too small nor too large (i.e., the matrix is close to neither underflow nor overflow), the matrix is considered to be sufficiently well-scaled, `AP` is left unchanged, and the function returns `'N'`. Otherwise, the function mutates `AP` in-place, replacing `A` by `diag(S)*A*diag(S)`, and returns `'Y'`.
- `dlaqsp()` corresponds to the [LAPACK][LAPACK] routine [`dlaqsp`][lapack-dlaqsp].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

// Define a symmetric matrix in packed format and a vector of scale factors:
var AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var S = new Float64Array( [ 0.05, 2.0, 4.0 ] );

// Equilibrate the matrix, whose upper triangle is stored:
var out = dlaqsp( 'column-major', 'upper', 3, AP, S, 0.0125, 6.0 );
console.log( out );
console.log( AP );

AP = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
S = new Float64Array( [ 0.05, 2.0, 4.0 ] );

// Equilibrate the matrix, whose lower triangle is stored:
out = dlaqsp.ndarray( 'column-major', 'lower', 3, AP, 1, 0, S, 1, 0, 0.0125, 6.0 );
console.log( out );
console.log( AP );
```

</section>

<!-- /.examples -->

* * *

<section class="c">

## C APIs

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

### Usage

```c
// TODO
```

</section>

<!-- /.usage -->

<section class="notes">

</section>

<!-- /.notes -->

<section class="examples">

### Examples

```c
// TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<section class="related">

</section>

<!-- /.related -->

<section class="links">

[lapack]: https://www.netlib.org/lapack/explore-html/

[lapack-dlaqsp]: https://www.netlib.org/lapack/explore-html/d1/d63/group__laqhp_ga60516a6dc31da01e46cfad594b906b40.html#ga60516a6dc31da01e46cfad594b906b40

[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 -->
108 changes: 108 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlaqsp/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 isString = require( '@stdlib/assert/is-string' );
var floor = require( '@stdlib/math/base/special/floor' );
var pow = require( '@stdlib/math/base/special/pow' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlaqsp = require( './../lib/dlaqsp.js' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - matrix order
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var AP;
var S;

AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options );
S = uniform( N, 0.5, 2.0, options );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var equed;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
equed = dlaqsp( 'column-major', 'upper', N, AP, S, 0.01, 10.0 );
if ( !isString( equed ) ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( !isString( equed ) ) {
b.fail( 'should return a string' );
}
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 = floor( pow( pow( 10, i ), 1.0/2.0 ) );
f = createBenchmark( len );
bench( format( '%s:size=%d', pkg, len * ( len + 1 ) / 2 ), f );
}
}

main();
Loading