Skip to content

feat: add lapack/base/dlatrs #7275

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
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1f6e76b
feat: add lapack/base/dlatrs
aayush0325 Jun 8, 2025
12bc140
Merge remote-tracking branch 'upstream/develop' into lapack-dlatrs
stdlib-bot Jun 8, 2025
7870b48
feat: add main export
aayush0325 Jun 9, 2025
51984dc
test: initial tests
aayush0325 Jun 9, 2025
ee429f0
test: add lower triangular cases
aayush0325 Jun 10, 2025
1184745
test: cleaning up
aayush0325 Jun 10, 2025
025d5f8
test: add transpose cases
aayush0325 Jun 10, 2025
d90cd03
test: add more cases for unit diagonal
aayush0325 Jun 10, 2025
2fc31d0
test: mmore tests
aayush0325 Jun 11, 2025
826c766
test: add scaled tests
aayush0325 Jun 11, 2025
b72dd17
chore: remove tape.only
aayush0325 Jun 11, 2025
1959bfe
test: more tests
aayush0325 Jun 11, 2025
68e1c03
fix: fix implementation and add tests
aayush0325 Jun 11, 2025
19f2ae1
Merge remote-tracking branch 'upstream/develop' into lapack-dlatrs
stdlib-bot Jun 11, 2025
cd7ce0d
test: add tests
aayush0325 Jun 11, 2025
9e42ef5
test: add tests
aayush0325 Jun 11, 2025
82bab69
test: add tests
aayush0325 Jun 11, 2025
7dc23e4
test: add large values tests
aayush0325 Jun 12, 2025
f60f4c4
test: add ndarray tests
aayush0325 Jun 13, 2025
12322bb
docs: fix typo
kgryte Jun 13, 2025
c7f21b8
test: add offset tests
aayush0325 Jun 13, 2025
475a274
test: add negative stride test
aayush0325 Jun 13, 2025
d159785
test: add large stride tests
aayush0325 Jun 13, 2025
6dbee4c
test: add mixed strides test
aayush0325 Jun 13, 2025
8147ab4
feat: add examples and benchmarks
aayush0325 Jun 15, 2025
cc6b47a
docs: add index.d.ts file
aayush0325 Jun 15, 2025
c8e2e0b
docs: add ts test file
aayush0325 Jun 15, 2025
4af0a15
docs: add README
aayush0325 Jun 16, 2025
1f97555
docs: add README
aayush0325 Jun 16, 2025
6f9c1d8
chore: cleanup
aayush0325 Jun 16, 2025
162195b
docs: add repl.txt
aayush0325 Jun 16, 2025
940a493
docs: add comments
aayush0325 Jun 16, 2025
f526e9c
chore: copyright years
aayush0325 Jun 16, 2025
53c5b8f
test: add tests
aayush0325 Jun 16, 2025
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
522 changes: 522 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlatrs/lib/base.js

Large diffs are not rendered by default.

362 changes: 362 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dlatrs/lib/dlange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,362 @@
/**
* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var dlassq = require( '@stdlib/lapack/base/dlassq' ).ndarray;
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' );
var dasum = require( '@stdlib/blas/base/dasum' ).ndarray;
var Float64Array = require( '@stdlib/array/float64' );
var min = require( '@stdlib/math/base/special/min' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var abs = require( '@stdlib/math/base/special/abs' );


// FUNCTIONS //

/**
* Returns the value of the one norm of a real matrix `A`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in `A`
* @param {NonNegativeInteger} N - number of columns in `A`
* @param {Float64Array} A - input array
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index of `A`
* @param {Float64Array} work - work array, should have `N` indexed elements if row-major layout is used
* @param {integer} strideWork - stride length of `work`
* @param {NonNegativeInteger} offsetWork - starting index of `work`
* @returns {number} required norm value
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] );
* var work = new Float64Array( 4 );
*
* var out = oneNorm( 3, 4, A, 4, 1, 0, work, 1, 0 );
* // returns 33.0
*/
function oneNorm( M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ) { // eslint-disable-line max-len
var value;
var temp;
var ia1;
var ia2;
var sum;
var iw;
var i;
var j;

if ( isRowMajor( [ strideA1, strideA2 ] ) ) {
iw = offsetWork;
for ( i = 0; i < N; i++ ) {
work[ iw ] = 0.0;
iw += strideWork;
}

ia1 = offsetA;
for ( j = 0; j < M; j++ ) {
ia2 = 0;
iw = offsetWork;
for ( i = 0; i < N; i++ ) {
work[ iw ] += abs( A[ ia1 + ia2 ] );
iw += strideWork;
ia2 += strideA2;
}
ia1 += strideA1;
}

value = 0.0;

iw = offsetWork;
for ( i = 0; i < N; i++ ) {
temp = work[ iw ];
if ( value < temp || isnan( temp ) ) {
value = temp;
}
iw += strideWork;
}
} else {
value = 0.0;
ia1 = offsetA;
for ( j = 0; j < N; j++ ) {
sum = dasum( M, A, strideA1, ia1 );
if ( value < sum || isnan( sum ) ) {
value = sum;
}
ia1 += strideA2;
}
}

return value;
}

/**
* Returns the absolute value of the maximum element of a real matrix `A`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in `A`
* @param {NonNegativeInteger} N - number of columns in `A`
* @param {Float64Array} A - input array
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index of `A`
* @returns {number} required norm value
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] );
*
* var out = maxAbs( 3, 4, A, 4, 1, 0 );
* // returns 12.0
*/
function maxAbs( M, N, A, strideA1, strideA2, offsetA ) {
var value;
var temp;
var da0;
var da1;
var ia;
var sa;
var sh;
var S0;
var S1;
var o;
var i;
var j;

value = 0.0;

// Resolve the loop interchange order:
o = loopOrder( [ M, N ], [ strideA1, strideA2 ] );
sh = o.sh;
sa = o.sx;
S0 = sh[ 0 ];
S1 = sh[ 1 ];
da0 = sa[ 0 ];
da1 = sa[ 1 ] - ( S0*sa[0] );
ia = offsetA;

for ( i = 0; i < S1; i++ ) {
for ( j = 0; j < S0; j++ ) {
temp = A[ ia ];
if ( value < temp || isnan( temp ) ) {
value = temp;
}
ia += da0;
}
ia += da1;
}
return value;
}

/**
* Returns the value of the infinity norm of a real matrix `A`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in `A`
* @param {NonNegativeInteger} N - number of columns in `A`
* @param {Float64Array} A - input array
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index of `A`
* @param {Float64Array} work - work array, should have `M` indexed elements if column-major layout is used
* @param {integer} strideWork - stride length of `work`
* @param {NonNegativeInteger} offsetWork - starting index of `work`
* @returns {number} required norm value
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] );
* var work = new Float64Array( 3 );
*
* var out = infinityNorm( 3, 4, A, 4, 1, 0, work, 1, 0 );
* // returns 30.0
*/
function infinityNorm( M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ) { // eslint-disable-line max-len
var value;
var temp;
var sum;
var ia1;
var ia2;
var iw;
var i;
var j;

if ( isRowMajor( [ strideA1, strideA2 ] ) ) {
value = 0.0;
ia1 = offsetA;
for ( j = 0; j < M; j++ ) {
sum = dasum( N, A, strideA2, ia1 );
if ( value < sum || isnan( sum ) ) {
value = sum;
}
ia1 += strideA1;
}
} else {
iw = offsetWork;
for ( i = 0; i < M; i++ ) {
work[ iw ] = 0.0;
iw += strideWork;
}

ia1 = offsetA;
for ( j = 0; j < N; j++ ) {
ia2 = 0;
iw = offsetWork;
for ( i = 0; i < M; i++ ) {
work[ iw ] += abs( A[ ia1 + ia2 ] );
iw += strideWork;
ia2 += strideA1;
}
ia1 += strideA2;
}

value = 0.0;

iw = offsetWork;
for ( i = 0; i < M; i++ ) {
temp = work[ iw ];
if ( value < temp || isnan( temp ) ) {
value = temp;
}
iw += strideWork;
}
}
return value;
}

/**
* Returns the absolute value of the frobenius norm of a real matrix `A`.

Check warning on line 251 in lib/node_modules/@stdlib/lapack/base/dlatrs/lib/dlange.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "frobenius"
*
* @private
* @param {NonNegativeInteger} M - number of rows in `A`
* @param {NonNegativeInteger} N - number of columns in `A`
* @param {Float64Array} A - input array
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index of `A`
* @returns {number} required norm value
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] );
*
* var out = frobeniusNorm( 3, 4, A, 4, 1, 0 );
* // returns ~25.5
*/
function frobeniusNorm( M, N, A, strideA1, strideA2, offsetA ) {
var out;
var da0;
var da1;
var S1;
var S2;
var ia;
var i;

out = new Float64Array( [ 0.0, 1.0 ] );

if ( isRowMajor( [ strideA1, strideA2 ] ) ) {
S1 = M;
S2 = N;
da0 = strideA2;
da1 = strideA1;
} else {
S1 = N;
S2 = M;
da0 = strideA1;
da1 = strideA2;
}

ia = offsetA;
for ( i = 0; i < S1; i++ ) {
dlassq( S2, A, da0, ia, out[ 0 ], out[ 1 ], out, 1, 0 );
ia += da1;
}

return out[ 0 ] * sqrt( out[ 1 ] );
}


// MAIN //

/**
* Returns the value of the one norm, or the frobenius norm, or the infinity norm, or the element with the largest absolute value of a real matrix `A`.

Check warning on line 306 in lib/node_modules/@stdlib/lapack/base/dlatrs/lib/dlange.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "frobenius"
*
* ## Notes
*
* - use `norm` = `max` to calculate the element with the largest absolute value
* - use `norm` = `one` to calculate the one norm, work should have `N` indexed elements if row-major layout is used
* - use `norm` = `infinity` to calculate the infinity norm, work should have `M` indexed elements if column-major layout is used
* - use `norm` = `frobenius` to calculate the frobenius norm

Check warning on line 313 in lib/node_modules/@stdlib/lapack/base/dlatrs/lib/dlange.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "frobenius"
*
* @private
* @param {string} norm - specifies the type of norm to be calculated
* @param {NonNegativeInteger} M - number of rows in `A`
* @param {NonNegativeInteger} N - number of columns in `A`
* @param {Float64Array} A - input array
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index of `A`
* @param {Float64Array} work - temporary workspace array
* @param {integer} strideWork - stride length of `work`
* @param {NonNegativeInteger} offsetWork - starting index of `work`
* @returns {number} required norm value
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] );
* var work = new Float64Array( 3 );
*
* var out = dlange( 'frobenius', 3, 4, A, 4, 1, 0, work, 1, 0 );
* // returns ~25.5
*/
function dlange( norm, M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ) { // eslint-disable-line max-len
if ( min( M, N ) === 0 ) {
return 0.0;
}

if ( norm === 'max' ) {
return maxAbs( M, N, A, strideA1, strideA2, offsetA );
}

if ( norm === 'one' ) {
return oneNorm( M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ); // eslint-disable-line max-len
}

if ( norm === 'infinity' ) {
return infinityNorm( M, N, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ); // eslint-disable-line max-len
}

if ( norm === 'frobenius' ) {
return frobeniusNorm( M, N, A, strideA1, strideA2, offsetA );
}
}


// EXPORTS //

module.exports = dlange;
Loading