Skip to content

Commit

Permalink
refactor: reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
headlessNode committed Sep 17, 2024
1 parent 0c994ee commit 7037ad9
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

0 comments on commit 7037ad9

Please sign in to comment.