Skip to content

Commit d811c8c

Browse files
committed
feat: add blas/base/dsbmv
--- 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 630ddb7 commit d811c8c

File tree

1 file changed

+174
-0
lines changed
  • lib/node_modules/@stdlib/blas/base/dsbmv/lib

1 file changed

+174
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 dfill = require( '@stdlib/blas/ext/base/dfill' ).ndarray;
24+
var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
25+
var max = require( '@stdlib/math/base/special/max' );
26+
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
27+
var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Performs the matrix-vector operation `y = alpha*A*x + beta*y` where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric band matrix, with `K` super-diagonals.
34+
*
35+
* @param {string} order - storage layout
36+
* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced
37+
* @param {NonNegativeInteger} N - number of elements along each dimension of `A`
38+
* @param {NonNegativeInteger} K - number of super-diagonals of the matrix `A`
39+
* @param {number} alpha - scalar constant
40+
* @param {Float64Array} A - matrix
41+
* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
42+
* @param {Float64Array} x - first input array
43+
* @param {integer} strideX - `x` stride length
44+
* @param {NonNegativeInteger} offsetX - starting `x` index
45+
* @param {number} beta - scalar constant
46+
* @param {Float64Array} y - second input array
47+
* @param {integer} strideY - `y` stride length
48+
* @param {NonNegativeInteger} offsetY - starting `y` index
49+
* @throws {TypeError} first argument must be a valid order
50+
* @throws {TypeError} second argument must specify whether to reference the lower or upper triangular matrix
51+
* @throws {RangeError} third argument must be a nonnegative integer
52+
* @throws {RangeError} sixth argument must be greater than or equal to max(1,N)
53+
* @throws {RangeError} eighth argument must be non-zero
54+
* @throws {RangeError} twelfth argument must be non-zero
55+
* @returns {Float64Array} `y`
56+
*
57+
* @example
58+
* var Float64Array = require( '@stdlib/array/float64' );
59+
*
60+
* var A = new Float64Array( [ 1.0, 2.0, 0.0, 4.0, 3.0, 5.0 ] );
61+
* var x = new Float64Array( [ 1.0, 2.0, 3.0 ] );
62+
* var y = new Float64Array( [ 0.0, 0.0, 0.0 ] );
63+
*
64+
* dsbmv( 'row-major', 'lower', 3, 1, 1.0, A, 2, x, 1, 0, 0.0, y, 1, 0 );
65+
* // y => <Float64Array>[ 2.0, 17.0, 21.0 ]
66+
*/
67+
function dsbmv( order, uplo, N, K, alpha, A, LDA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
68+
var temp1;
69+
var temp2;
70+
var jmin;
71+
var ix;
72+
var iy;
73+
var jx;
74+
var jy;
75+
var ox;
76+
var oy;
77+
var i;
78+
var j;
79+
80+
if ( !isLayout( order ) ) {
81+
throw new TypeError( 'invalid argument. First argument must be a valid order. Value: `%s`.', order );
82+
}
83+
if ( !isMatrixTriangle( uplo ) ) {
84+
throw new TypeError( 'invalid argument. Second argument must specify whether to reference the lower or upper triangular matrix. Value: `%s`.', uplo );
85+
}
86+
if ( N < 0 ) {
87+
throw new RangeError( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N );
88+
}
89+
if ( K < 0 ) {
90+
throw new RangeError( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', K );
91+
}
92+
if ( LDA < max( K + 1 ) ) {
93+
throw new RangeError( 'invalid argument. Seventh argument must be greater than or equal to ( K + 1 ). Value: `%d`.', N, LDA );
94+
}
95+
if ( strideX === 0 ) {
96+
throw new RangeError( 'invalid argument. Ninth argument must be non-zero. Value: `%d`.', strideX );
97+
}
98+
if ( strideY === 0 ) {
99+
throw new RangeError( 'invalid argument. Therteenth argument must be non-zero. Value: `%d`.', strideY );
100+
}
101+
if ( N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) {
102+
return y;
103+
}
104+
// Form: y = beta*y
105+
if ( beta !== 1.0 ) {
106+
if ( beta === 0.0 ) {
107+
dfill( N, 0.0, y, strideY, offsetY );
108+
} else {
109+
dscal( N, beta, y, strideY, offsetY );
110+
}
111+
}
112+
if ( alpha === 0.0 ) {
113+
return y;
114+
}
115+
ox = offsetX;
116+
oy = offsetY;
117+
118+
// Form: y = alpha*A*x + y
119+
if (
120+
( order === 'row-major' && uplo === 'upper' ) ||
121+
( order === 'column-major' && uplo === 'lower' )
122+
) {
123+
ix = ox;
124+
iy = oy;
125+
for ( i = 0; i < N; i++ ) {
126+
temp1 = alpha * x[ ix ];
127+
temp2 = 0.0;
128+
jmin = max( 0, i - K );
129+
jx = ox + ( jmin * strideX );
130+
jy = oy + ( jmin * strideY );
131+
for ( j = jmin; j < i; j++ ) {
132+
y[ jy ] += temp1 * A[ (i - j) + ( j * (K + 1) ) ];
133+
temp2 += x[ jx ] * A[ (i - j) + ( j * (K + 1) ) ];
134+
jx += strideX;
135+
jy += strideY;
136+
}
137+
y[ iy ] += ( temp1 * A[ 0 + ( i * (K + 1) ) ] ) + ( alpha * temp2 );
138+
ix += strideX;
139+
iy += strideY;
140+
}
141+
return y;
142+
}
143+
144+
// ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' )
145+
if (
146+
( order === 'row-major' && uplo === 'lower' ) ||
147+
( order === 'column-major' && uplo === 'upper' )
148+
) {
149+
ix = ox;
150+
iy = oy;
151+
for ( i = 0; i < N; i++ ) {
152+
temp1 = alpha * x[ ix ];
153+
temp2 = 0.0;
154+
jmin = max( 0, i - K );
155+
jx = ox + ( jmin * strideX );
156+
jy = oy + ( jmin * strideY );
157+
for ( j = jmin; j < i; j++ ) {
158+
y[ jy ] += temp1 * ( A[ (K + j - i) + ( i * (K + 1) ) ] );
159+
temp2 += x[ jx ] * ( A[ (K + j - i) + ( i * (K + 1) ) ] );
160+
jx += strideX;
161+
jy += strideY;
162+
}
163+
y[ iy ] += ( temp1 * ( A[ K + ( i * (K + 1) ) ] ) ) + ( alpha * temp2 );
164+
ix += strideX;
165+
iy += strideY;
166+
}
167+
return y;
168+
}
169+
}
170+
171+
172+
// EXPORTS //
173+
174+
module.exports = dsbmv;

0 commit comments

Comments
 (0)