Skip to content

Commit 3504424

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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 6ad37f9 commit 3504424

5 files changed

Lines changed: 576 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)