Skip to content

Commit d9580f5

Browse files
authored
refactor: reduce code duplication in blas/ext/base/sfill
PR-URL: #2916 Reviewed-by: Athan Reines <[email protected]>
1 parent f387603 commit d9580f5

File tree

1 file changed

+4
-44
lines changed
  • lib/node_modules/@stdlib/blas/ext/base/sfill/lib

1 file changed

+4
-44
lines changed

lib/node_modules/@stdlib/blas/ext/base/sfill/lib/sfill.js

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
'use strict';
2020

21-
// VARIABLES //
21+
// MODULES //
2222

23-
var M = 8;
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
24+
var ndarray = require( './ndarray.js' );
2425

2526

2627
// MAIN //
@@ -43,48 +44,7 @@ var M = 8;
4344
* // x => <Float32Array>[ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]
4445
*/
4546
function sfill( N, alpha, x, stride ) {
46-
var ix;
47-
var i;
48-
var m;
49-
50-
if ( N <= 0 ) {
51-
return x;
52-
}
53-
// Use loop unrolling if the stride is equal to `1`...
54-
if ( stride === 1 ) {
55-
m = N % M;
56-
57-
// If we have a remainder, run a clean-up loop...
58-
if ( m > 0 ) {
59-
for ( i = 0; i < m; i++ ) {
60-
x[ i ] = alpha;
61-
}
62-
}
63-
if ( N < M ) {
64-
return x;
65-
}
66-
for ( i = m; i < N; i += M ) {
67-
x[ i ] = alpha;
68-
x[ i+1 ] = alpha;
69-
x[ i+2 ] = alpha;
70-
x[ i+3 ] = alpha;
71-
x[ i+4 ] = alpha;
72-
x[ i+5 ] = alpha;
73-
x[ i+6 ] = alpha;
74-
x[ i+7 ] = alpha;
75-
}
76-
return x;
77-
}
78-
if ( stride < 0 ) {
79-
ix = (1-N) * stride;
80-
} else {
81-
ix = 0;
82-
}
83-
for ( i = 0; i < N; i++ ) {
84-
x[ ix ] = alpha;
85-
ix += stride;
86-
}
87-
return x;
47+
return ndarray( N, alpha, x, stride, stride2offset( N, stride ) );
8848
}
8949

9050

0 commit comments

Comments
 (0)