Skip to content

Commit 32870e7

Browse files
committed
refactor: add base implementation for blas/base/dsymv
--- 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 58747ab commit 32870e7

File tree

2 files changed

+144
-81
lines changed

2 files changed

+144
-81
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
26+
27+
// MAIN //
28+
29+
/**
30+
* 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 matrix.
31+
*
32+
* @param {string} order - storage layout
33+
* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced
34+
* @param {NonNegativeInteger} N - number of elements along each dimension of `A`
35+
* @param {number} alpha - scalar constant
36+
* @param {Float64Array} A - matrix
37+
* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
38+
* @param {Float64Array} x - first input array
39+
* @param {integer} strideX - `x` stride length
40+
* @param {NonNegativeInteger} offsetX - starting `x` index
41+
* @param {number} beta - scalar constant
42+
* @param {Float64Array} y - second input array
43+
* @param {integer} strideY - `y` stride length
44+
* @param {NonNegativeInteger} offsetY - starting `y` index
45+
* @returns {Float64Array} `y`
46+
*
47+
* @example
48+
* var Float64Array = require( '@stdlib/array/float64' );
49+
*
50+
* var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0 ] );
51+
* var x = new Float64Array( [ 1.0, 1.0, 1.0 ] );
52+
* var y = new Float64Array( [ 0.0, 0.0, 0.0 ] );
53+
*
54+
* dsymv( 'row-major', 'lower', 3, 1.0, A, 3, x, 1, 0, 0.0, y, 1, 0 );
55+
* // y => <Float64Array>[ 1.0, 2.0, 3.0 ]
56+
*/
57+
function dsymv( order, uplo, N, alpha, A, LDA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
58+
var temp1;
59+
var temp2;
60+
var jmin;
61+
var jmax;
62+
var ix;
63+
var iy;
64+
var jx;
65+
var jy;
66+
var ox;
67+
var oy;
68+
var i;
69+
var j;
70+
var k;
71+
72+
// Form: y = beta*y
73+
if ( beta !== 1.0 ) {
74+
if ( beta === 0.0 ) {
75+
dfill( N, 0.0, y, strideY, offsetY );
76+
} else {
77+
dscal( N, beta, y, strideY, offsetY );
78+
}
79+
}
80+
if ( alpha === 0.0 ) {
81+
return y;
82+
}
83+
ox = offsetX;
84+
oy = offsetY;
85+
86+
// Form: y = alpha*A*x + y
87+
if (
88+
( order === 'row-major' && uplo === 'upper' ) ||
89+
( order === 'column-major' && uplo === 'lower' )
90+
) {
91+
ix = ox;
92+
iy = oy;
93+
for ( i = 0; i < N; i++ ) {
94+
temp1 = alpha * x[ ix ];
95+
temp2 = 0.0;
96+
jmin = i + 1;
97+
jmax = N;
98+
jx = ox + ( jmin * strideX );
99+
jy = oy + ( jmin * strideY );
100+
y[ iy ] += temp1 * A[ ( LDA * i ) + i ];
101+
for ( j = jmin; j < jmax; j++ ) {
102+
k = ( LDA * i ) + j;
103+
y[ jy ] += temp1 * A[ k ];
104+
temp2 += x[ jx ] * A[ k ];
105+
jx += strideX;
106+
jy += strideY;
107+
}
108+
y[ iy ] += alpha * temp2;
109+
ix += strideX;
110+
iy += strideY;
111+
}
112+
return y;
113+
}
114+
// ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' )
115+
ix = ox + ( ( N - 1 ) * strideX );
116+
iy = oy + ( ( N - 1 ) * strideY );
117+
for ( i = N - 1; i >= 0; i-- ) {
118+
temp1 = alpha * x[ ix ];
119+
temp2 = 0.0;
120+
jmin = 0;
121+
jmax = i;
122+
jx = ox + ( jmin * strideX );
123+
jy = oy + ( jmin * strideY );
124+
y[ iy ] += temp1 * A[ ( LDA * i ) + i ];
125+
for ( j = jmin; j < jmax; j++ ) {
126+
k = ( LDA * i ) + j;
127+
y[ jy ] += temp1 * A[ k ];
128+
temp2 += x[ jx ] * A[ k ];
129+
jx += strideX;
130+
jy += strideY;
131+
}
132+
y[ iy ] += alpha * temp2;
133+
ix -= strideX;
134+
iy -= strideY;
135+
}
136+
return y;
137+
}
138+
139+
140+
// EXPORTS //
141+
142+
module.exports = dsymv;

lib/node_modules/@stdlib/blas/base/dsymv/lib/ndarray.js

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020

2121
// MODULES //
2222

23-
var dfill = require( '@stdlib/blas/ext/base/dfill' ).ndarray;
24-
var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
2523
var max = require( '@stdlib/math/base/special/max' );
2624
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
2725
var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
26+
var base = require( './base.js' );
2827

2928

3029
// MAIN //
@@ -64,20 +63,6 @@ var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
6463
* // y => <Float64Array>[ 1.0, 2.0, 3.0 ]
6564
*/
6665
function dsymv( order, uplo, N, alpha, A, LDA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
67-
var temp1;
68-
var temp2;
69-
var jmin;
70-
var jmax;
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-
var k;
80-
8166
if ( !isLayout( order ) ) {
8267
throw new TypeError( 'invalid argument. First argument must be a valid order. Value: `%s`.', order );
8368
}
@@ -99,71 +84,7 @@ function dsymv( order, uplo, N, alpha, A, LDA, x, strideX, offsetX, beta, y, str
9984
if ( N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) {
10085
return y;
10186
}
102-
// Form: y = beta*y
103-
if ( beta !== 1.0 ) {
104-
if ( beta === 0.0 ) {
105-
dfill( N, 0.0, y, strideY, offsetY );
106-
} else {
107-
dscal( N, beta, y, strideY, offsetY );
108-
}
109-
}
110-
if ( alpha === 0.0 ) {
111-
return y;
112-
}
113-
ox = offsetX;
114-
oy = offsetY;
115-
116-
// Form: y = alpha*A*x + y
117-
if (
118-
( order === 'row-major' && uplo === 'upper' ) ||
119-
( order === 'column-major' && uplo === 'lower' )
120-
) {
121-
ix = ox;
122-
iy = oy;
123-
for ( i = 0; i < N; i++ ) {
124-
temp1 = alpha * x[ ix ];
125-
temp2 = 0.0;
126-
jmin = i + 1;
127-
jmax = N;
128-
jx = ox + ( jmin * strideX );
129-
jy = oy + ( jmin * strideY );
130-
y[ iy ] += temp1 * A[ ( LDA * i ) + i ];
131-
for ( j = jmin; j < jmax; j++ ) {
132-
k = ( LDA * i ) + j;
133-
y[ jy ] += temp1 * A[ k ];
134-
temp2 += x[ jx ] * A[ k ];
135-
jx += strideX;
136-
jy += strideY;
137-
}
138-
y[ iy ] += alpha * temp2;
139-
ix += strideX;
140-
iy += strideY;
141-
}
142-
return y;
143-
}
144-
// ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' )
145-
ix = ox + ( ( N - 1 ) * strideX );
146-
iy = oy + ( ( N - 1 ) * strideY );
147-
for ( i = N - 1; i >= 0; i-- ) {
148-
temp1 = alpha * x[ ix ];
149-
temp2 = 0.0;
150-
jmin = 0;
151-
jmax = i;
152-
jx = ox + ( jmin * strideX );
153-
jy = oy + ( jmin * strideY );
154-
y[ iy ] += temp1 * A[ ( LDA * i ) + i ];
155-
for ( j = jmin; j < jmax; j++ ) {
156-
k = ( LDA * i ) + j;
157-
y[ jy ] += temp1 * A[ k ];
158-
temp2 += x[ jx ] * A[ k ];
159-
jx += strideX;
160-
jy += strideY;
161-
}
162-
y[ iy ] += alpha * temp2;
163-
ix -= strideX;
164-
iy -= strideY;
165-
}
166-
return y;
87+
return base( order, uplo, N, alpha, A, LDA, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len
16788
}
16889

16990

0 commit comments

Comments
 (0)