Skip to content

Commit f8f676a

Browse files
committed
feat: add lib
--- 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: passed - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 6ad37f9 commit f8f676a

6 files changed

Lines changed: 646 additions & 0 deletions

File tree

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
24+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Solves one of the systems of equations `A*x = b` or `A^T*x = b` or `A^H*x = b` where `b` and `x` are `N` element vectors and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
31+
*
32+
* @private
33+
* @param {string} uplo - specifies whether `A` is an upper or lower triangular matrix
34+
* @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed
35+
* @param {string} diag - specifies whether `A` has a unit diagonal
36+
* @param {NonNegativeInteger} N - number of elements along each dimension of `A`
37+
* @param {Complex128Array} A - input matrix
38+
* @param {integer} strideA1 - stride of the first dimension of `A`
39+
* @param {integer} strideA2 - stride of the second dimension of `A`
40+
* @param {NonNegativeInteger} offsetA - starting index for `A`
41+
* @param {Complex128Array} x - input vector
42+
* @param {integer} strideX - `x` stride length
43+
* @param {NonNegativeInteger} offsetX - starting index for `x`
44+
* @returns {Complex128Array} `x`
45+
*
46+
* @example
47+
* var Complex128Array = require( '@stdlib/array/complex128' );
48+
*
49+
* var A = new Complex128Array( [ 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0, 3.0, 3.0, 5.0, 5.0, 6.0, 6.0 ] );
50+
* var x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
51+
*
52+
* ztrsv( 'lower', 'no-transpose', 'non-unit', 3, A, 3, 1, 0, x, 1, 0 );
53+
* // x => <Complex128Array>[ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
54+
*/
55+
function ztrsv( uplo, trans, diag, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX ) { // eslint-disable-line max-params, max-len
56+
var nonunit;
57+
var viewA;
58+
var viewX;
59+
var retmp;
60+
var imtmp;
61+
var magsq;
62+
var remul;
63+
var immul;
64+
var ixend;
65+
var isrm;
66+
var sign;
67+
var doa2;
68+
var rex;
69+
var imx;
70+
var rea;
71+
var ima;
72+
var ix0;
73+
var ix1;
74+
var sa0;
75+
var sa1;
76+
var oa2;
77+
var ox;
78+
var sx;
79+
var oa;
80+
var i0;
81+
var i1;
82+
var ia;
83+
84+
// Note on variable naming convention: sa#, ix#, i# where # corresponds to the loop number, with `0` being the innermost loop...
85+
86+
isrm = isRowMajor( [ strideA1, strideA2 ] );
87+
nonunit = ( diag === 'non-unit' );
88+
89+
if ( isrm ) {
90+
// For row-major matrices, the last dimension has the fastest changing index...
91+
sa0 = strideA2 * 2; // stride increment for innermost loop
92+
sa1 = strideA1 * 2; // stride increment for outermost loop
93+
} else { // isColMajor
94+
// For column-major matrices, the first dimension has the fastest changing index...
95+
sa0 = strideA1 * 2; // stride increment for innermost loop
96+
sa1 = strideA2 * 2; // stride increment for outermost loop
97+
}
98+
// Reinterpret arrays as real-valued views of interleaved real and imaginary components:
99+
viewA = reinterpret( A, 0 );
100+
viewX = reinterpret( x, 0 );
101+
if ( trans === 'conjugate-transpose' ) {
102+
sign = -1;
103+
} else {
104+
sign = 1;
105+
}
106+
oa = offsetA * 2;
107+
ox = offsetX * 2;
108+
sx = strideX * 2;
109+
doa2 = sa1 + sa0;
110+
111+
if (
112+
( !isrm && uplo === 'upper' && trans === 'no-transpose' ) ||
113+
( isrm && uplo === 'lower' && trans !== 'no-transpose' )
114+
) {
115+
ix1 = ox + ((N-1)*sx);
116+
oa2 = oa + (doa2*(N-1));
117+
for ( i1 = N - 1; i1 >= 0; i1-- ) {
118+
rex = viewX[ ix1 ];
119+
imx = viewX[ ix1+1 ];
120+
if ( rex !== 0.0 || imx !== 0.0 ) {
121+
if ( nonunit ) {
122+
ia = oa2;
123+
rea = viewA[ ia ];
124+
ima = sign * viewA[ ia+1 ];
125+
magsq = (rea*rea) + (ima*ima);
126+
retmp = ((rex*rea) + (imx*ima)) / magsq;
127+
imtmp = ((imx*rea) - (rex*ima)) / magsq;
128+
viewX[ ix1 ] = retmp;
129+
viewX[ ix1+1 ] = imtmp;
130+
} else {
131+
retmp = rex;
132+
imtmp = imx;
133+
}
134+
ia = oa2 - sa0;
135+
ix0 = ix1 - sx;
136+
for ( i0 = i1 - 1; i0 >= 0; i0-- ) {
137+
rea = viewA[ ia ];
138+
ima = sign * viewA[ ia+1 ];
139+
rex = viewX[ ix0 ];
140+
imx = viewX[ ix0+1 ];
141+
remul = (retmp*rea) - (imtmp*ima);
142+
immul = (retmp*ima) + (imtmp*rea);
143+
viewX[ ix0 ] = rex - remul;
144+
viewX[ ix0+1 ] = imx - immul;
145+
ix0 -= sx;
146+
ia -= sa0;
147+
}
148+
}
149+
oa2 -= doa2;
150+
ix1 -= sx;
151+
}
152+
return x;
153+
}
154+
if (
155+
( !isrm && uplo === 'lower' && trans === 'no-transpose' ) ||
156+
( isrm && uplo === 'upper' && trans !== 'no-transpose' )
157+
) {
158+
ix1 = ox;
159+
oa2 = oa;
160+
for ( i1 = 0; i1 < N; i1++ ) {
161+
rex = viewX[ ix1 ];
162+
imx = viewX[ ix1+1 ];
163+
if ( rex !== 0.0 || imx !== 0.0 ) {
164+
if ( nonunit ) {
165+
ia = oa2;
166+
rea = viewA[ ia ];
167+
ima = sign * viewA[ ia+1 ];
168+
magsq = (rea*rea) + (ima*ima);
169+
retmp = ((rex*rea) + (imx*ima)) / magsq;
170+
imtmp = ((imx*rea) - (rex*ima)) / magsq;
171+
viewX[ ix1 ] = retmp;
172+
viewX[ ix1+1 ] = imtmp;
173+
} else {
174+
retmp = rex;
175+
imtmp = imx;
176+
}
177+
ia = oa2 + sa0;
178+
ix0 = ix1 + sx;
179+
for ( i0 = i1 + 1; i0 < N; i0++ ) {
180+
rea = viewA[ ia ];
181+
ima = sign * viewA[ ia+1 ];
182+
rex = viewX[ ix0 ];
183+
imx = viewX[ ix0+1 ];
184+
remul = (retmp*rea) - (imtmp*ima);
185+
immul = (retmp*ima) + (imtmp*rea);
186+
viewX[ ix0 ] = rex - remul;
187+
viewX[ ix0+1 ] = imx - immul;
188+
ia += sa0;
189+
ix0 += sx;
190+
}
191+
}
192+
oa2 += doa2;
193+
ix1 += sx;
194+
}
195+
return x;
196+
}
197+
if (
198+
( !isrm && uplo === 'upper' && trans !== 'no-transpose' ) ||
199+
( isrm && uplo === 'lower' && trans === 'no-transpose' )
200+
) {
201+
ix1 = ox;
202+
oa2 = oa;
203+
for ( i1 = 0; i1 < N; i1++ ) {
204+
rex = viewX[ ix1 ];
205+
imx = viewX[ ix1+1 ];
206+
retmp = rex;
207+
imtmp = imx;
208+
ix0 = ox;
209+
ia = oa2;
210+
for ( i0 = 0; i0 < i1; i0++ ) {
211+
rea = viewA[ ia ];
212+
ima = sign * viewA[ ia+1 ];
213+
rex = viewX[ ix0 ];
214+
imx = viewX[ ix0+1 ];
215+
retmp -= (rex*rea) - (imx*ima);
216+
imtmp -= (rex*ima) + (imx*rea);
217+
ix0 += sx;
218+
ia += sa0;
219+
}
220+
if ( nonunit ) {
221+
rea = viewA[ ia ];
222+
ima = sign * viewA[ ia+1 ];
223+
magsq = (rea*rea) + (ima*ima);
224+
remul = (retmp*rea) + (imtmp*ima);
225+
immul = (imtmp*rea) - (retmp*ima);
226+
retmp = remul / magsq;
227+
imtmp = immul / magsq;
228+
}
229+
viewX[ ix1 ] = retmp;
230+
viewX[ ix1+1 ] = imtmp;
231+
ix1 += sx;
232+
oa2 += sa1;
233+
}
234+
return x;
235+
}
236+
// ( !isrm && uplo === 'lower' && trans !== 'no-transpose' ) || ( isrm && uplo === 'upper' && trans === 'no-transpose' )
237+
ix1 = ox + ((N-1)*sx);
238+
ixend = ix1;
239+
oa2 = oa + (doa2*(N-1));
240+
for ( i1 = N - 1; i1 >= 0; i1-- ) {
241+
rex = viewX[ ix1 ];
242+
imx = viewX[ ix1+1 ];
243+
retmp = rex;
244+
imtmp = imx;
245+
ix0 = ixend;
246+
ia = oa2;
247+
for ( i0 = N - 1; i0 > i1; i0-- ) {
248+
rea = viewA[ ia ];
249+
ima = sign * viewA[ ia+1 ];
250+
rex = viewX[ ix0 ];
251+
imx = viewX[ ix0+1 ];
252+
retmp -= (rex*rea) - (imx*ima);
253+
imtmp -= (rex*ima) + (imx*rea);
254+
ia -= sa0;
255+
ix0 -= sx;
256+
}
257+
if ( nonunit ) {
258+
rea = viewA[ ia ];
259+
ima = sign * viewA[ ia+1 ];
260+
magsq = (rea*rea) + (ima*ima);
261+
remul = (retmp*rea) + (imtmp*ima);
262+
immul = (imtmp*rea) - (retmp*ima);
263+
retmp = remul / magsq;
264+
imtmp = immul / magsq;
265+
}
266+
viewX[ ix1 ] = retmp;
267+
viewX[ ix1+1 ] = imtmp;
268+
ix1 -= sx;
269+
oa2 -= sa1;
270+
}
271+
return x;
272+
}
273+
274+
275+
// EXPORTS //
276+
277+
module.exports = ztrsv;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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+
* BLAS level 2 routine to solve one of the systems of equations `A*x = b` or `A^T*x = b` or `A^H*x = b` where `b` and `x` are `N` element vectors and `A` is an `N` by `N` unit, or non-unit, upper or lower triangular matrix.
23+
* @module @stdlib/blas/base/ztrsv
24+
*
25+
* @example
26+
* var Complex128Array = require( '@stdlib/array/complex128' );
27+
* var ztrsv = require( '@stdlib/blas/base/ztrsv' );
28+
*
29+
* var A = new Complex128Array( [ 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0, 3.0, 3.0, 5.0, 5.0, 6.0, 6.0 ] );
30+
* var x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
31+
*
32+
* ztrsv( 'row-major', 'lower', 'no-transpose', 'non-unit', 3, A, 3, x, 1 );
33+
* // x => <Complex128Array>[ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
34+
*
35+
* @example
36+
* var Complex128Array = require( '@stdlib/array/complex128' );
37+
* var ztrsv = require( '@stdlib/blas/base/ztrsv' );
38+
*
39+
* var A = new Complex128Array( [ 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 4.0, 4.0, 0.0, 0.0, 3.0, 3.0, 5.0, 5.0, 6.0, 6.0 ] );
40+
* var x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
41+
*
42+
* ztrsv.ndarray( 'lower', 'no-transpose', 'non-unit', 3, A, 3, 1, 0, x, 1, 0 );
43+
* // x => <Complex128Array>[ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]
44+
*/
45+
46+
// MODULES //
47+
48+
var join = require( 'path' ).join;
49+
var tryRequire = require( '@stdlib/utils/try-require' );
50+
var isError = require( '@stdlib/assert/is-error' );
51+
var main = require( './main.js' );
52+
53+
54+
// MAIN //
55+
56+
var ztrsv;
57+
var tmp = tryRequire( join( __dirname, './native.js' ) );
58+
if ( isError( tmp ) ) {
59+
ztrsv = main;
60+
} else {
61+
ztrsv = tmp;
62+
}
63+
64+
65+
// EXPORTS //
66+
67+
module.exports = ztrsv;
68+
69+
// exports: { "ndarray": "ztrsv.ndarray" }
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) 2026 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 ztrsv = require( './ztrsv.js' );
25+
var ndarray = require( './ndarray.js' );
26+
27+
28+
// MAIN //
29+
30+
setReadOnly( ztrsv, 'ndarray', ndarray );
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = ztrsv;

0 commit comments

Comments
 (0)