Skip to content

Commit 665020a

Browse files
Shabareesh ShettyShabareesh Shetty
authored andcommitted
refactor: reduce arithmetic operations
--- 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 1081121 commit 665020a

File tree

1 file changed

+24
-14
lines changed
  • lib/node_modules/@stdlib/blas/base/dsyrk/lib

1 file changed

+24
-14
lines changed

lib/node_modules/@stdlib/blas/base/dsyrk/lib/base.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ function scal( uplo, N, beta, X, strideX1, strideX2, offsetX ) { // TODO: consid
164164
// MAIN //
165165

166166
/**
167-
* Performs one of the symmetric rank `K` operations `C = α*A*A**T + β*C` or `C = α*A**T*A + β*C` where `α` and `β` are scalars, `C` is an `N` by `N` symmetric matrix and `A` is an `N` by `K` matrix in the first case and a `K` by `N` matrix in the second case.
167+
* Performs one of the symmetric rank `K` operations `C = α*A*A^T + β*C` or `C = α*A^T*A + β*C` where `α` and `β` are scalars, `C` is an `N` by `N` symmetric matrix and `A` is an `N` by `K` matrix in the first case and a `K` by `N` matrix in the second case.
168168
*
169169
* @private
170-
* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `C` is supplied
170+
* @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `C` to be referenced
171171
* @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed
172172
* @param {NonNegativeInteger} N - order of the matrix `C`
173173
* @param {NonNegativeInteger} K - number of columns or number of rows of the matrix `A`
@@ -206,6 +206,8 @@ function dsyrk( uplo, trans, N, K, alpha, A, strideA1, strideA2, offsetA, beta,
206206
var i2;
207207
var i1;
208208
var i0;
209+
var ia;
210+
var ic;
209211

210212
isrma = isRowMajor( [ strideA1, strideA2 ] );
211213

@@ -242,13 +244,15 @@ function dsyrk( uplo, trans, N, K, alpha, A, strideA1, strideA2, offsetA, beta,
242244
) {
243245
for ( i2 = 0; i2 < N; i2++ ) {
244246
for ( i1 = i2; i1 < N; i1++ ) {
247+
ic = offsetC + ( i1 * sc0 );
245248
tmp = 0.0;
246249
for ( i0 = 0; i0 < K; i0++ ) {
247-
oa1 = oa + ( i2 * sa1 ) + ( i0 * sa0 );
248-
oa2 = oa + ( i1 * sa1 ) + ( i0 * sa0 );
250+
ia = oa + ( i0 * sa0 );
251+
oa1 = ia + ( i2 * sa1 );
252+
oa2 = ia + ( i1 * sa1 );
249253
tmp += A[ oa1 ] * A[ oa2 ];
250254
}
251-
idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 );
255+
idx = ic + ( i2 * sc1 );
252256
C[ idx ] += alpha * tmp;
253257
}
254258
}
@@ -261,12 +265,14 @@ function dsyrk( uplo, trans, N, K, alpha, A, strideA1, strideA2, offsetA, beta,
261265
for ( i2 = 0; i2 < N; i2++ ) {
262266
for ( i1 = 0; i1 <= i2; i1++ ) {
263267
tmp = 0.0;
268+
ic = offsetC + ( i1 * sc0 );
264269
for ( i0 = 0; i0 < K; i0++ ) {
265-
oa1 = oa + ( i2 * sa1 ) + ( i0 * sa0 );
266-
oa2 = oa + ( i1 * sa1 ) + ( i0 * sa0 );
270+
ia = oa + ( i0 * sa0 );
271+
oa1 = ia + ( i2 * sa1 );
272+
oa2 = ia + ( i1 * sa1 );
267273
tmp += A[ oa1 ] * A[ oa2 ];
268274
}
269-
idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 );
275+
idx = ic + ( i2 * sc1 );
270276
C[ idx ] += alpha * tmp;
271277
}
272278
}
@@ -278,13 +284,15 @@ function dsyrk( uplo, trans, N, K, alpha, A, strideA1, strideA2, offsetA, beta,
278284
) {
279285
for ( i2 = 0; i2 < N; i2++ ) {
280286
for ( i1 = i2; i1 < N; i1++ ) {
287+
ic = offsetC + ( i1 * sc0 );
281288
tmp = 0.0;
282289
for ( i0 = 0; i0 < K; i0++ ) {
283-
oa1 = oa + ( i0 * sa1 ) + ( i2 * sa0 );
284-
oa2 = oa + ( i0 * sa1 ) + ( i1 * sa0 );
290+
ia = oa + ( i0 * sa1 );
291+
oa1 = ia + ( i2 * sa0 );
292+
oa2 = ia + ( i1 * sa0 );
285293
tmp += A[ oa1 ] * A[ oa2 ];
286294
}
287-
idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 );
295+
idx = ic + ( i2 * sc1 );
288296
C[ idx ] += alpha * tmp;
289297
}
290298
}
@@ -293,13 +301,15 @@ function dsyrk( uplo, trans, N, K, alpha, A, strideA1, strideA2, offsetA, beta,
293301
// ( isrma && trans !== 'no-transpose' && uplo === 'lower' ) || ( !isrma && trans === 'no-transpose' && uplo === 'upper' )
294302
for ( i2 = 0; i2 < N; i2++ ) {
295303
for ( i1 = 0; i1 <= i2; i1++ ) {
304+
ic = offsetC + ( i1 * sc0 );
296305
tmp = 0.0;
297306
for ( i0 = 0; i0 < K; i0++ ) {
298-
oa1 = oa + ( i0 * sa1 ) + ( i2 * sa0 );
299-
oa2 = oa + ( i0 * sa1 ) + ( i1 * sa0 );
307+
ia = oa + ( i0 * sa1 );
308+
oa1 = ia + ( i2 * sa0 );
309+
oa2 = ia + ( i1 * sa0 );
300310
tmp += A[ oa1 ] * A[ oa2 ];
301311
}
302-
idx = offsetC + ( i2 * sc1 ) + ( i1 * sc0 );
312+
idx = ic + ( i2 * sc1 );
303313
C[ idx ] += alpha * tmp;
304314
}
305315
}

0 commit comments

Comments
 (0)