Skip to content

Commit e678f88

Browse files
committed
refactor: add base implementation for blas/base/ssymv
--- 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 e678f88

File tree

2 files changed

+146
-82
lines changed

2 files changed

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

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

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

2121
// MODULES //
2222

23-
var sfill = require( '@stdlib/blas/ext/base/sfill' ).ndarray;
24-
var sscal = require( '@stdlib/blas/base/sscal' ).ndarray;
2523
var max = require( '@stdlib/math/base/special/max' );
26-
var f32 = require( '@stdlib/number/float64/base/to-float32' );
2724
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
2825
var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
26+
var base = require( './base.js' );
2927

3028

3129
// MAIN //
@@ -65,20 +63,6 @@ var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' );
6563
* // y => <Float32Array>[ 1.0, 2.0, 3.0 ]
6664
*/
6765
function ssymv( order, uplo, N, 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 jmax;
72-
var ix;
73-
var iy;
74-
var jx;
75-
var jy;
76-
var ox;
77-
var oy;
78-
var i;
79-
var j;
80-
var k;
81-
8266
if ( !isLayout( order ) ) {
8367
throw new TypeError( 'invalid argument. First argument must be a valid order. Value: `%s`.', order );
8468
}
@@ -100,71 +84,7 @@ function ssymv( order, uplo, N, alpha, A, LDA, x, strideX, offsetX, beta, y, str
10084
if ( N === 0 || ( alpha === 0.0 && beta === 1.0 ) ) {
10185
return y;
10286
}
103-
// Form: y = beta*y
104-
if ( beta !== 1.0 ) {
105-
if ( beta === 0.0 ) {
106-
sfill( N, 0.0, y, strideY, offsetY );
107-
} else {
108-
sscal( N, beta, y, strideY, offsetY );
109-
}
110-
}
111-
if ( alpha === 0.0 ) {
112-
return y;
113-
}
114-
ox = offsetX;
115-
oy = offsetY;
116-
117-
// Form: y = alpha*A*x + y
118-
if (
119-
( order === 'row-major' && uplo === 'upper' ) ||
120-
( order === 'column-major' && uplo === 'lower' )
121-
) {
122-
ix = ox;
123-
iy = oy;
124-
for ( i = 0; i < N; i++ ) {
125-
temp1 = f32( alpha * x[ ix ] );
126-
temp2 = 0.0;
127-
jmin = i + 1;
128-
jmax = N;
129-
jx = ox + ( jmin*strideX );
130-
jy = oy + ( jmin*strideY );
131-
y[ iy ] += f32( temp1 * A[(LDA*i)+i] );
132-
for ( j = jmin; j < jmax; j++ ) {
133-
k = ( LDA*i ) + j;
134-
y[ jy ] += f32( temp1 * A[k] );
135-
temp2 = f32( temp2 + f32( x[jx] * A[k] ) );
136-
jx += strideX;
137-
jy += strideY;
138-
}
139-
y[ iy ] += f32( alpha * temp2 );
140-
ix += strideX;
141-
iy += strideY;
142-
}
143-
return y;
144-
}
145-
// ( order === 'row-major' && uplo === 'lower') || ( order === 'column-major' && uplo === 'upper' )
146-
ix = ox + ( (N-1)*strideX );
147-
iy = oy + ( (N-1)*strideY );
148-
for ( i = N-1; i >= 0; i-- ) {
149-
temp1 = f32( alpha * x[ ix ] );
150-
temp2 = 0.0;
151-
jmin = 0;
152-
jmax = i;
153-
jx = ox + ( jmin*strideX );
154-
jy = oy + ( jmin*strideY );
155-
y[ iy ] += f32( temp1 * A[(LDA*i)+i] );
156-
for ( j = jmin; j < jmax; j++ ) {
157-
k = ( LDA*i ) + j;
158-
y[ jy ] += f32( temp1 * A[k] );
159-
temp2 = f32( temp2 + f32( x[jx] * A[k] ) );
160-
jx += strideX;
161-
jy += strideY;
162-
}
163-
y[ iy ] += f32( alpha * temp2 );
164-
ix -= strideX;
165-
iy -= strideY;
166-
}
167-
return y;
87+
return base( order, uplo, N, alpha, A, LDA, x, strideX, offsetX, beta, y, strideY, offsetY ); // eslint-disable-line max-len
16888
}
16989

17090

0 commit comments

Comments
 (0)