Skip to content

Commit

Permalink
refactor: reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jul 6, 2024
1 parent 3656b32 commit 07f85a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
29 changes: 7 additions & 22 deletions lib/node_modules/@stdlib/strided/base/smap/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

'use strict';

// MODULES //

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


// MAIN //

/**
Expand Down Expand Up @@ -47,28 +53,7 @@
* // => <Float32Array>[ 10.0, 20.0, 30.0, 40.0, 50.0 ]
*/
function smap( N, x, strideX, y, strideY, fcn ) {
var ix;
var iy;
var i;
if ( N <= 0 ) {
return y;
}
if ( strideX < 0 ) {
ix = (1-N) * strideX;
} else {
ix = 0;
}
if ( strideY < 0 ) {
iy = (1-N) * strideY;
} else {
iy = 0;
}
for ( i = 0; i < N; i++ ) {
y[ iy ] = fcn( x[ ix ] );
ix += strideX;
iy += strideY;
}
return y;
return ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ), fcn ); // eslint-disable-line max-len
}


Expand Down
4 changes: 3 additions & 1 deletion lib/node_modules/@stdlib/strided/base/smap/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
],
"libraries": [],
"libpath": [],
"dependencies": []
"dependencies": [
"@stdlib/strided/base/stride2offset"
]
}
]
}
13 changes: 3 additions & 10 deletions lib/node_modules/@stdlib/strided/base/smap/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "stdlib/strided/base/smap.h"
#include "stdlib/strided/base/stride2offset.h"
#include <stdint.h>

/**
Expand Down Expand Up @@ -51,16 +52,8 @@ void stdlib_strided_smap( const int64_t N, const float *X, const int64_t strideX
if ( N <= 0 ) {
return;
}
if ( strideX < 0 ) {
ix = (1-N) * strideX;
} else {
ix = 0;
}
if ( strideY < 0 ) {
iy = (1-N) * strideY;
} else {
iy = 0;
}
ix = stdlib_strided_stride2offset( N, strideX );
iy = stdlib_strided_stride2offset( N, strideY );
for ( i = 0; i < N; i++ ) {
Y[ iy ] = fcn( X[ ix ] );
ix += strideX;
Expand Down

1 comment on commit 07f85a1

@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
strided/base/map-by2 $\color{green}608/608$
$\color{green}+100.00\%$
$\color{green}42/42$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}608/608$
$\color{green}+100.00\%$
strided/base/mskunary $\color{green}646/646$
$\color{green}+100.00\%$
$\color{green}40/40$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}646/646$
$\color{green}+100.00\%$
strided/base/nullary $\color{green}524/524$
$\color{green}+100.00\%$
$\color{red}25/27$
$\color{green}+92.59\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}524/524$
$\color{green}+100.00\%$
strided/base/quaternary $\color{green}257/257$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}257/257$
$\color{green}+100.00\%$
strided/base/quinary $\color{green}269/269$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}269/269$
$\color{green}+100.00\%$
strided/base/smap $\color{green}206/206$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}206/206$
$\color{green}+100.00\%$

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

Please sign in to comment.