Skip to content

Commit 4d08374

Browse files
aman-095kgryte
andauthored
refactor: reduce code duplication
PR-URL: #2479 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent dd343aa commit 4d08374

File tree

1 file changed

+5
-37
lines changed
  • lib/node_modules/@stdlib/blas/base/dcopy/lib

1 file changed

+5
-37
lines changed

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

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
'use strict';
2020

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

23-
var M = 8;
23+
var ndarray = require( './ndarray.js' );
2424

2525

2626
// MAIN //
@@ -47,52 +47,20 @@ var M = 8;
4747
function dcopy( N, x, strideX, y, strideY ) {
4848
var ix;
4949
var iy;
50-
var m;
51-
var i;
5250
if ( N <= 0 ) {
5351
return y;
5452
}
55-
// Use unrolled loops if both strides are equal to `1`...
56-
if ( strideX === 1 && strideY === 1 ) {
57-
m = N % M;
58-
59-
// If we have a remainder, run a clean-up loop...
60-
if ( m > 0 ) {
61-
for ( i = 0; i < m; i++ ) {
62-
y[ i ] = x[ i ];
63-
}
64-
}
65-
if ( N < M ) {
66-
return y;
67-
}
68-
for ( i = m; i < N; i += M ) {
69-
y[ i ] = x[ i ];
70-
y[ i+1 ] = x[ i+1 ];
71-
y[ i+2 ] = x[ i+2 ];
72-
y[ i+3 ] = x[ i+3 ];
73-
y[ i+4 ] = x[ i+4 ];
74-
y[ i+5 ] = x[ i+5 ];
75-
y[ i+6 ] = x[ i+6 ];
76-
y[ i+7 ] = x[ i+7 ];
77-
}
78-
return y;
79-
}
8053
if ( strideX < 0 ) {
81-
ix = (1-N) * strideX;
54+
ix = ( 1 - N ) * strideX;
8255
} else {
8356
ix = 0;
8457
}
8558
if ( strideY < 0 ) {
86-
iy = (1-N) * strideY;
59+
iy = ( 1 - N ) * strideY;
8760
} else {
8861
iy = 0;
8962
}
90-
for ( i = 0; i < N; i++ ) {
91-
y[ iy ] = x[ ix ];
92-
ix += strideX;
93-
iy += strideY;
94-
}
95-
return y;
63+
return ndarray( N, x, strideX, ix, y, strideY, iy );
9664
}
9765

9866

0 commit comments

Comments
 (0)