Skip to content

Commit 320429f

Browse files
committed
refactor: reduce code duplication
1 parent 4436cd1 commit 320429f

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

lib/node_modules/@stdlib/strided/base/zmap/lib/main.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
24+
var ndarray = require( './ndarray.js' );
25+
26+
2127
// MAIN //
2228

2329
/**
@@ -58,28 +64,7 @@
5864
* // returns 10.0
5965
*/
6066
function zmap( N, x, strideX, y, strideY, fcn ) {
61-
var ix;
62-
var iy;
63-
var i;
64-
if ( N <= 0 ) {
65-
return y;
66-
}
67-
if ( strideX < 0 ) {
68-
ix = (1-N) * strideX;
69-
} else {
70-
ix = 0;
71-
}
72-
if ( strideY < 0 ) {
73-
iy = (1-N) * strideY;
74-
} else {
75-
iy = 0;
76-
}
77-
for ( i = 0; i < N; i++ ) {
78-
y.set( fcn( x.get( ix ) ), iy );
79-
ix += strideX;
80-
iy += strideY;
81-
}
82-
return y;
67+
return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), fcn ); // eslint-disable-line max-len
8368
}
8469

8570

lib/node_modules/@stdlib/strided/base/zmap/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
],
3333
"libraries": [],
3434
"libpath": [],
35-
"dependencies": []
35+
"dependencies": [
36+
"@stdlib/strided/base/stride2offset"
37+
]
3638
}
3739
]
3840
}

lib/node_modules/@stdlib/strided/base/zmap/src/main.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include "stdlib/strided/base/zmap.h"
20+
#include "stdlib/strided/base/stride2offset.h"
2021
#include <stdint.h>
2122
#include <complex.h>
2223

@@ -55,16 +56,8 @@ void stdlib_strided_zmap( const int64_t N, const double complex *X, const int64_
5556
if ( N <= 0 ) {
5657
return;
5758
}
58-
if ( strideX < 0 ) {
59-
ix = (1-N) * strideX;
60-
} else {
61-
ix = 0;
62-
}
63-
if ( strideY < 0 ) {
64-
iy = (1-N) * strideY;
65-
} else {
66-
iy = 0;
67-
}
59+
ix = stdlib_strided_stride2offset( N, strideX );
60+
iy = stdlib_strided_stride2offset( N, strideY );
6861
for ( i = 0; i < N; i++ ) {
6962
Y[ iy ] = fcn( X[ ix ] );
7063
ix += strideX;

0 commit comments

Comments
 (0)