Skip to content

Commit 7870b48

Browse files
committed
feat: add main export
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 12bc140 commit 7870b48

File tree

4 files changed

+286
-0
lines changed

4 files changed

+286
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
24+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
25+
var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
26+
var isDiagonalType = require( '@stdlib/blas/base/assert/is-diagonal-type' );
27+
var isTransposeOperation = require( '@stdlib/blas/base/assert/is-transpose-operation' );
28+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
29+
var max = require( '@stdlib/math/base/special/max' );
30+
var format = require( '@stdlib/string/format' );
31+
var base = require( './base.js' );
32+
33+
34+
// MAIN //
35+
36+
/**
37+
* Solves a triangular system of equations with the scale factor set to prevent overflow.
38+
*
39+
* @param {string} order - storage layout
40+
* @param {string} uplo - specifies whether `A` is an upper or lower triangular matrix
41+
* @param {string} trans - specifies whether `A` should be transposed or not transposed
42+
* @param {string} diag - specifies whether `A` has a unit diagonal
43+
* @param {string} normin - specifies whether `CNORM` has been set or not
44+
* @param {NonNegativeInteger} N - number of rows/columns in `A`
45+
* @param {Float64Array} A - input matrix
46+
* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
47+
* @param {Float64Array} X - input vector, specifies the right hand side vector of the equation
48+
* @param {Float64Array} CNORM - used to store the column norms
49+
* @throws {TypeError} first argument must be a valid order
50+
* @throws {TypeError} second argument must be a valid matrix triangle
51+
* @throws {TypeError} third argument must be a valid transpose opeartion
52+
* @throws {TypeError} fourth argument must be a valid diagonal type
53+
* @throws {TypeError} fifth argument must be either yes or no
54+
* @throws {RangeError} eighth argument must be greater than or equal to max(1,N)
55+
* @returns {number} scaling factor
56+
*
57+
* @example
58+
* var Float64Array = require( '@stdlib/array/float64' );
59+
*
60+
* var A = new Float64Array( [ 2.0, 1.0, -1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 4.0 ] ); // => [ [ 2.0, 1.0, -1.0 ], [ 0.0, 3.0, 2.0 ], [ 0.0, 0.0, 4.0 ] ]
61+
* var X = new Float64Array( [ 5.0, 10.0, 20,0 ] );
62+
* var CNORM = new Float64Array( 3 );
63+
*
64+
* var scale = dlatrs( 'row-major', 'upper', 'no-transpose', 'non-unit', 'no', 3, A, 3, X, CNORM );
65+
* // returns 1.0
66+
* // X => <Float64Array>[ 5.0, 0.0, 5.0 ]
67+
*/
68+
function dlatrs( order, uplo, trans, diag, normin, N, A, LDA, X, CNORM ) {
69+
var sa1;
70+
var sa2;
71+
72+
if ( !isLayout( order ) ) {
73+
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
74+
}
75+
if ( !isMatrixTriangle( uplo ) ) {
76+
throw new TypeError( format( 'invalid argument. Second argument must be a valid side. Value: `%s`.', uplo ) );
77+
}
78+
if ( !isTransposeOperation( trans ) ) {
79+
throw new TypeError( format( 'invalid argument. Third argument must be a valid transpose operation. Value: `%s`.', trans ) );
80+
}
81+
if ( !isDiagonalType( diag ) ) {
82+
throw new TypeError( format( 'invalid argument. Second argument must be a valid diagonal type. Value: `%s`.', diag ) );
83+
}
84+
if ( isRowMajor( order ) && LDA < max( 1, N ) ) {
85+
throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDA ) );
86+
}
87+
if ( normin !== 'yes' && normin !== 'no' ) {
88+
throw new TypeError( format( 'invalid argument. Fifth argument must be either yes or no. Value: `%d`.', normin ) );
89+
}
90+
if ( isColumnMajor( order ) ) {
91+
sa1 = 1;
92+
sa2 = LDA;
93+
} else { // order === 'row-major'
94+
sa1 = LDA;
95+
sa2 = 1;
96+
}
97+
return base( uplo, trans, diag, normin, N, A, sa1, sa2, 0, X, 1, 0, CNORM, 1, 0 ); // eslint-disable-line max-len
98+
}
99+
100+
101+
// EXPORTS //
102+
103+
module.exports = dlatrs;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* LAPACK routine to solve a triangular system of equations with the scale factor set to prevent overflow.
23+
*
24+
* @module @stdlib/lapack/base/dlatrs
25+
*
26+
* @example
27+
* var Float64Array = require( '@stdlib/array/float64' );
28+
* var dlatrs = require( '@stdlib/lapack/base/dlatrs' );
29+
*
30+
* var A = new Float64Array( [ 2.0, 1.0, -1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 4.0 ] ); // => [ [ 2.0, 1.0, -1.0 ], [ 0.0, 3.0, 2.0 ], [ 0.0, 0.0, 4.0 ] ]
31+
* var X = new Float64Array( [ 5.0, 10.0, 20,0 ] );
32+
* var CNORM = new Float64Array( 3 );
33+
*
34+
* var scale = dlatrs( 'row-major', 'upper', 'no-transpose', 'non-unit', 'no', 3, A, 3, X, CNORM );
35+
* // returns 1.0
36+
* // X => <Float64Array>[ 5.0, 0.0, 5.0 ]
37+
*/
38+
39+
// MODULES //
40+
41+
var join = require( 'path' ).join;
42+
var tryRequire = require( '@stdlib/utils/try-require' );
43+
var isError = require( '@stdlib/assert/is-error' );
44+
var main = require( './main.js' );
45+
46+
47+
// MAIN //
48+
49+
var dlatrs;
50+
var tmp = tryRequire( join( __dirname, './native.js' ) );
51+
if ( isError( tmp ) ) {
52+
dlatrs = main;
53+
} else {
54+
dlatrs = tmp;
55+
}
56+
57+
58+
// EXPORTS //
59+
60+
module.exports = dlatrs;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24+
var dlatrs = require( './dlatrs.js' );
25+
var ndarray = require( './ndarray.js' );
26+
27+
28+
// MAIN //
29+
30+
setReadOnly( dlatrs, 'ndarray', ndarray );
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = dlatrs;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/* eslint-disable max-len, max-params */
22+
23+
// MODULES //
24+
25+
var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
26+
var isDiagonalType = require( '@stdlib/blas/base/assert/is-diagonal-type' );
27+
var isTransposeOperation = require( '@stdlib/blas/base/assert/is-transpose-operation' );
28+
var format = require( '@stdlib/string/format' );
29+
var base = require( './base.js' );
30+
31+
32+
// MAIN //
33+
34+
/**
35+
* Solves a triangular system of equations with the scale factor set to prevent overflow.
36+
*
37+
* @param {string} uplo - specifies whether `A` is an upper or lower triangular matrix
38+
* @param {string} trans - specifies whether `A` should be transposed or not transposed
39+
* @param {string} diag - specifies whether `A` has a unit diagonal
40+
* @param {string} normin - specifies whether `CNORM` has been set or not
41+
* @param {NonNegativeInteger} N - number of rows/columns in `A`
42+
* @param {Float64Array} A - input matrix
43+
* @param {integer} strideA1 - stride of the first dimension of `A`
44+
* @param {integer} strideA2 - stride of the second dimension of `A`
45+
* @param {NonNegativeInteger} offsetA - starting index for `A`
46+
* @param {Float64Array} X - input vector, specifies the right hand side vector of the equation
47+
* @param {integer} strideX - stride length for `X`
48+
* @param {NonNegativeInteger} offsetX - starting index for `X`
49+
* @param {Float64Array} CNORM - used to store the column norms
50+
* @param {integer} strideCNORM - stride length for `CNORM`
51+
* @param {NonNegativeInteger} offsetCNORM - starting index for `CNORM`
52+
* @throws {TypeError} first argument must be a valid matrix triangle
53+
* @throws {TypeError} second argument must be a valid transpose opeartion
54+
* @throws {TypeError} third argument must be a valid diagonal type
55+
* @throws {TypeError} fourth argument must be either yes or no
56+
* @returns {number} scaling factor
57+
*
58+
* @example
59+
* var Float64Array = require( '@stdlib/array/float64' );
60+
*
61+
* var A = new Float64Array( [ 2.0, 1.0, -1.0, 0.0, 3.0, 2.0, 0.0, 0.0, 4.0 ] ); // => [ [ 2.0, 1.0, -1.0 ], [ 0.0, 3.0, 2.0 ], [ 0.0, 0.0, 4.0 ] ]
62+
* var X = new Float64Array( [ 5.0, 10.0, 20,0 ] );
63+
* var CNORM = new Float64Array( 3 );
64+
*
65+
* var scale = dlatrs( 'upper', 'no-transpose', 'non-unit', 'no', 3, A, 3, 1, 0, X, 1, 0, CNORM, 1, 0 );
66+
* // returns 1.0
67+
* // X => <Float64Array>[ 5.0, 0.0, 5.0 ]
68+
*/
69+
function dlatrs( uplo, trans, diag, normin, N, A, strideA1, strideA2, offsetA, X, strideX, offsetX, CNORM, strideCNORM, offsetCNORM ) {
70+
if ( !isMatrixTriangle( uplo ) ) {
71+
throw new TypeError( format( 'invalid argument. Second argument must be a valid side. Value: `%s`.', uplo ) );
72+
}
73+
if ( !isTransposeOperation( trans ) ) {
74+
throw new TypeError( format( 'invalid argument. Third argument must be a valid transpose operation. Value: `%s`.', trans ) );
75+
}
76+
if ( !isDiagonalType( diag ) ) {
77+
throw new TypeError( format( 'invalid argument. Second argument must be a valid diagonal type. Value: `%s`.', diag ) );
78+
}
79+
if ( normin !== 'yes' && normin !== 'no' ) {
80+
throw new TypeError( format( 'invalid argument. Fifth argument must be either yes or no. Value: `%d`.', normin ) );
81+
}
82+
return base( uplo, trans, diag, normin, N, A, strideA1, strideA2, offsetA, X, strideX, offsetX, CNORM, strideCNORM, offsetCNORM );
83+
}
84+
85+
86+
// EXPORTS //
87+
88+
module.exports = dlatrs;

0 commit comments

Comments
 (0)