Skip to content

Commit 1260637

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 1260637

5 files changed

Lines changed: 535 additions & 0 deletions

File tree

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
24+
var zfill = require( '@stdlib/blas/ext/base/zfill' ).ndarray;
25+
var zscal = require( '@stdlib/blas/base/zscal' ).ndarray;
26+
var realf = require( '@stdlib/complex/float64/real' );
27+
var imagf = require( '@stdlib/complex/float64/imag' );
28+
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
29+
var muladd = require( '@stdlib/complex/float64/base/mul-add' ).assign;
30+
31+
32+
// MAIN //
33+
34+
/**
35+
* Performs the matrix-vector operation `y = α*A*x + β*y`, where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` Hermitian matrix.
36+
*
37+
* @private
38+
* @param {string} uplo - specifies whether `A` is an upper or lower triangular part of matrix is supplied.
39+
* @param {NonNegativeInteger} N - number of elements along each dimension of `A`
40+
* @param {Complex128} alpha - scalar constant
41+
* @param {Complex128Array} A - input matrix
42+
* @param {integer} strideA1 - stride of the first dimension of `A`
43+
* @param {integer} strideA2 - stride of the second dimension of `A`
44+
* @param {NonNegativeInteger} offsetA - starting index for `A`
45+
* @param {Complex128Array} x - first input vector
46+
* @param {integer} strideX - `x` stride length
47+
* @param {NonNegativeInteger} offsetX - starting index for `x`
48+
* @param {Complex128} beta - scalar constant
49+
* @param {Complex128Array} y - second input vector
50+
* @param {integer} strideY - `y` stride length
51+
* @param {NonNegativeInteger} offsetY - starting index for `y`
52+
* @returns {Complex128Array} `y`
53+
*
54+
* @example
55+
* var Complex128Array = require( '@stdlib/array/complex128' );
56+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
57+
*
58+
* var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, -2.0, 4.0, 0.0, 0.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
59+
* var x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
60+
* var y = new Complex128Array( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] );
61+
* var alpha = new Complex128( 0.5, 0.5 );
62+
* var beta = new Complex128( 0.5, -0.5 );
63+
*
64+
* zhemv( 'lower', 3, alpha, A, 3, 1, 0, x, 1, 0, beta, y, 1, 0 );
65+
* // y => <Complex128Array>[ -10.0, 14.0, -11.0, 25.0, 14.0, 31.0 ]
66+
*/
67+
function zhemv( uplo, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
68+
var realpha;
69+
var imalpha;
70+
var rebeta;
71+
var imbeta;
72+
var retmp1;
73+
var imtmp1;
74+
var retmp2;
75+
var imtmp2;
76+
var viewA;
77+
var viewX;
78+
var viewY;
79+
var isrm;
80+
var cima;
81+
var sign;
82+
var sa0;
83+
var sa1;
84+
var oa2;
85+
var rea;
86+
var ima;
87+
var rex;
88+
var imx;
89+
var ix1;
90+
var ix0;
91+
var iy0;
92+
var iy1;
93+
var oa;
94+
var ox;
95+
var oy;
96+
var sx;
97+
var sy;
98+
var i0;
99+
var i1;
100+
var ia;
101+
102+
// Note on variable naming convention: sa#, ix#, i# where # corresponds to the loop number, with `0` being the innermost loop...
103+
104+
isrm = isRowMajor( [ strideA1, strideA2 ] );
105+
if ( isrm ) {
106+
// For row-major matrices, the last dimension has the fastest changing index...
107+
sa0 = strideA2 * 2; // stride for innermost loop
108+
sa1 = strideA1 * 2; // stride for outermost loop
109+
} else { // isColMajor
110+
// For column-major matrices, the first dimension has the fastest changing index...
111+
sa0 = strideA1 * 2; // stride for innermost loop
112+
sa1 = strideA2 * 2; // stride for outermost loop
113+
}
114+
// Decompose scalars into real and imaginary components:
115+
rebeta = realf( beta );
116+
imbeta = imagf( beta );
117+
realpha = realf( alpha );
118+
imalpha = imagf( alpha );
119+
120+
// y = beta*y
121+
if ( rebeta === 0.0 && imbeta === 0.0 ) {
122+
zfill( N, alpha, y, strideY, offsetY );
123+
} else if ( rebeta !== 1.0 || imbeta !== 0.0 ) {
124+
zscal( N, beta, y, strideY, offsetY );
125+
}
126+
if ( realpha === 0.0 && imalpha === 0.0 ) {
127+
return y;
128+
}
129+
// Reinterpret arrays as real-valued views of interleaved real and imaginary components:
130+
viewA = reinterpret( A, 0 );
131+
viewX = reinterpret( x, 0 );
132+
viewY = reinterpret( y, 0 );
133+
if ( isrm ) {
134+
sign = -1;
135+
} else {
136+
sign = 1;
137+
}
138+
oa = offsetA * 2;
139+
ox = offsetX * 2;
140+
oy = offsetY * 2;
141+
sx = strideX * 2;
142+
sy = strideY * 2;
143+
ix1 = ox;
144+
iy1 = oy;
145+
oa2 = oa;
146+
147+
// Form: y = alpha*A*x + y
148+
if ( ( isrm && uplo === 'upper' ) || ( !isrm && uplo === 'lower' ) ) {
149+
for ( i1 = 0; i1 < N; i1++ ) {
150+
rex = viewX[ ix1 ];
151+
imx = viewX[ ix1+1 ];
152+
retmp1 = (realpha*rex) - (imalpha*imx);
153+
imtmp1 = (realpha*imx) + (imalpha*rex);
154+
retmp2 = 0.0;
155+
imtmp2 = 0.0;
156+
ia = oa2 + ((i1+1)*sa0);
157+
ix0 = ix1 + sx;
158+
iy0 = iy1 + sy;
159+
for ( i0 = i1 + 1; i0 < N; i0++ ) {
160+
rea = viewA[ ia ];
161+
ima = viewA[ ia+1 ];
162+
cima = sign * ima;
163+
muladd( retmp1, imtmp1, rea, cima, viewY[ iy0 ], viewY[ iy0+1 ], viewY, 1, iy0 ); // eslint-disable-line max-len
164+
rex = viewX[ ix0 ];
165+
imx = viewX[ ix0+1 ];
166+
retmp2 += (rea*rex) + (cima*imx);
167+
imtmp2 += (rea*imx) - (cima*rex);
168+
ia += sa0;
169+
ix0 += sx;
170+
iy0 += sy;
171+
}
172+
ia = oa2 + (i1*sa0);
173+
rea = viewA[ ia ];
174+
viewY[ iy1 ] += retmp1 * rea;
175+
viewY[ iy1+1 ] += imtmp1 * rea;
176+
muladd( realpha, imalpha, retmp2, imtmp2, viewY[ iy1 ], viewY[ iy1+1 ], viewY, 1, iy1 ); // eslint-disable-line max-len
177+
ix1 += sx;
178+
iy1 += sy;
179+
oa2 += sa1;
180+
}
181+
return y;
182+
}
183+
// ( isrm && uplo === 'lower' ) || ( !isrm && uplo === 'upper' )
184+
for ( i1 = 0; i1 < N; i1++ ) {
185+
rex = viewX[ ix1 ];
186+
imx = viewX[ ix1+1 ];
187+
retmp1 = (realpha*rex) - (imalpha*imx);
188+
imtmp1 = (realpha*imx) + (imalpha*rex);
189+
retmp2 = 0.0;
190+
imtmp2 = 0.0;
191+
ia = oa2;
192+
ix0 = ox;
193+
iy0 = oy;
194+
for ( i0 = 0; i0 < i1; i0++ ) {
195+
rea = viewA[ ia ];
196+
ima = viewA[ ia+1 ];
197+
cima = sign * ima;
198+
muladd( retmp1, imtmp1, rea, cima, viewY[ iy0 ], viewY[ iy0+1 ], viewY, 1, iy0 ); // eslint-disable-line max-len
199+
rex = viewX[ ix0 ];
200+
imx = viewX[ ix0+1 ];
201+
retmp2 += (rea*rex) + (cima*imx);
202+
imtmp2 += (rea*imx) - (cima*rex);
203+
ia += sa0;
204+
ix0 += sx;
205+
iy0 += sy;
206+
}
207+
rea = viewA[ ia ];
208+
viewY[ iy1 ] += retmp1 * rea;
209+
viewY[ iy1+1 ] += imtmp1 * rea;
210+
muladd( realpha, imalpha, retmp2, imtmp2, viewY[ iy1 ], viewY[ iy1+1 ], viewY, 1, iy1 ); // eslint-disable-line max-len
211+
ix1 += sx;
212+
iy1 += sy;
213+
oa2 += sa1;
214+
}
215+
return y;
216+
}
217+
218+
219+
// EXPORTS //
220+
221+
module.exports = zhemv;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 performs the matrix-vector operation `y = α*A*x + β*y`, where `α` and `β` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` Hermitian matrix.
23+
*
24+
* @module @stdlib/blas/base/zhemv
25+
*
26+
* @example
27+
* var Complex128Array = require( '@stdlib/array/complex128' );
28+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
29+
* var zhemv = require( '@stdlib/blas/base/zhemv' );
30+
*
31+
* var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, -2.0, 4.0, 0.0, 0.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
32+
* var x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
33+
* var y = new Complex128Array( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] );
34+
* var alpha = new Complex128( 0.5, 0.5 );
35+
* var beta = new Complex128( 0.5, -0.5 );
36+
*
37+
* zhemv( 'row-major', 'lower', 3, alpha, A, 3, x, 1, beta, y, 1 );
38+
* // y => <Complex128Array>[ -10.0, 14.0, -11.0, 25.0, 14.0, 31.0 ]
39+
*
40+
* @example
41+
* var Complex128Array = require( '@stdlib/array/complex128' );
42+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
43+
* var zhemv = require( '@stdlib/blas/base/zhemv' );
44+
*
45+
* var A = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, -2.0, 4.0, 0.0, 0.0, 0.0, 3.0, -3.0, 5.0, -5.0, 6.0, 0.0 ] );
46+
* var x = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] );
47+
* var y = new Complex128Array( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] );
48+
* var alpha = new Complex128( 0.5, 0.5 );
49+
* var beta = new Complex128( 0.5, -0.5 );
50+
*
51+
* zhemv.ndarray( 'lower', 3, alpha, A, 3, 1, 0, x, 1, 0, beta, y, 1, 0 );
52+
* // y => <Complex128Array>[ -10.0, 14.0, -11.0, 25.0, 14.0, 31.0 ]
53+
*/
54+
55+
// MODULES //
56+
57+
var join = require( 'path' ).join;
58+
var tryRequire = require( '@stdlib/utils/try-require' );
59+
var isError = require( '@stdlib/assert/is-error' );
60+
var main = require( './main.js' );
61+
62+
63+
// MAIN //
64+
65+
var zhemv;
66+
var tmp = tryRequire( join( __dirname, './native.js' ) );
67+
if ( isError( tmp ) ) {
68+
zhemv = main;
69+
} else {
70+
zhemv = tmp;
71+
}
72+
73+
74+
// EXPORTS //
75+
76+
module.exports = zhemv;
77+
78+
// exports: { "ndarray": "zhemv.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 zhemv = require( './zhemv.js' );
25+
var ndarray = require( './ndarray.js' );
26+
27+
28+
// MAIN //
29+
30+
setReadOnly( zhemv, 'ndarray', ndarray );
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = zhemv;

0 commit comments

Comments
 (0)