Skip to content

Commit

Permalink
refactor: reduce code duplication in blas/ext/base/sfill
Browse files Browse the repository at this point in the history
PR-URL: #2916
Reviewed-by: Athan Reines <kgryte@gmail.com>
  • Loading branch information
headlessNode authored Sep 17, 2024
1 parent f387603 commit d9580f5
Showing 1 changed file with 4 additions and 44 deletions.
48 changes: 4 additions & 44 deletions lib/node_modules/@stdlib/blas/ext/base/sfill/lib/sfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

'use strict';

// VARIABLES //
// MODULES //

var M = 8;
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
var ndarray = require( './ndarray.js' );


// MAIN //
Expand All @@ -43,48 +44,7 @@ var M = 8;
* // x => <Float32Array>[ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]
*/
function sfill( N, alpha, x, stride ) {
var ix;
var i;
var m;

if ( N <= 0 ) {
return x;
}
// Use loop unrolling if the stride is equal to `1`...
if ( stride === 1 ) {
m = N % M;

// If we have a remainder, run a clean-up loop...
if ( m > 0 ) {
for ( i = 0; i < m; i++ ) {
x[ i ] = alpha;
}
}
if ( N < M ) {
return x;
}
for ( i = m; i < N; i += M ) {
x[ i ] = alpha;
x[ i+1 ] = alpha;
x[ i+2 ] = alpha;
x[ i+3 ] = alpha;
x[ i+4 ] = alpha;
x[ i+5 ] = alpha;
x[ i+6 ] = alpha;
x[ i+7 ] = alpha;
}
return x;
}
if ( stride < 0 ) {
ix = (1-N) * stride;
} else {
ix = 0;
}
for ( i = 0; i < N; i++ ) {
x[ ix ] = alpha;
ix += stride;
}
return x;
return ndarray( N, alpha, x, stride, stride2offset( N, stride ) );
}


Expand Down

1 comment on commit d9580f5

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/sfill $\color{green}396/396$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}396/396$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.