Skip to content

Commit c63f610

Browse files
committed
refactor: use add-on dispatch utility
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7aa5519 commit c63f610

File tree

1 file changed

+3
-28
lines changed
  • lib/node_modules/@stdlib/math/special/abs/lib

1 file changed

+3
-28
lines changed

lib/node_modules/@stdlib/math/special/abs/lib/native.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020

2121
// MODULES //
2222

23-
var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
24-
var serialize = require( '@stdlib/ndarray/base/serialize-meta-data' );
23+
var dispatch = require( '@stdlib/ndarray/base/unary-addon-dispatch' );
2524
var setProps = require( '@stdlib/ndarray/base/meta-data-props' );
26-
var getData = require( '@stdlib/ndarray/data-buffer' );
2725
var dtypes = require( '@stdlib/ndarray/dtypes' );
2826
var ufunc = require( '@stdlib/math/tools/unary' );
2927
var addon = require( './../src/addon.node' );
3028
var meta = require( './meta.json' );
3129
var types = require( './types.json' );
3230
var policies = require( './policies.json' );
33-
var js = require( './main.js' );
31+
var fallback = require( './main.js' ).assign;
3432

3533

3634
// VARIABLES //
@@ -39,29 +37,6 @@ var idtypes = dtypes( 'numeric_and_generic' );
3937
var odtypes = dtypes( 'real_and_generic' );
4038

4139

42-
// FUNCTIONS //
43-
44-
/**
45-
* Applies a unary function to an input ndarray and assigns results to an output ndarray.
46-
*
47-
* @private
48-
* @param {ndarray} x - input array
49-
* @param {ndarray} y - output array
50-
* @returns {ndarray} output array
51-
*/
52-
function unary( x, y ) { // FIXME: move to separate package
53-
var xdata = getData( x );
54-
var ydata = getData( y );
55-
56-
// WARNING: we assume that, if we're provided something which has a data buffer resembling a typed array, we're provided a typed ndarray buffer; however, this can lead to potential unintended errors as the native add-on cannot work with non-typed array objects (e.g., generic arrays)...
57-
if ( !( isTypedArrayLike( xdata ) && isTypedArrayLike( ydata ) ) ) {
58-
return js.assign( x, y );
59-
}
60-
addon( xdata, serialize( x ), ydata, serialize( y ) );
61-
return y;
62-
}
63-
64-
6540
// MAIN //
6641

6742
/**
@@ -91,7 +66,7 @@ function unary( x, y ) { // FIXME: move to separate package
9166
* var arr = ndarray2array( y );
9267
* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
9368
*/
94-
var abs = ufunc( unary, [ idtypes ], odtypes, policies ); // eslint-disable-line vars-on-top
69+
var abs = ufunc( dispatch( addon, fallback ), [ idtypes ], odtypes, policies );
9570
setProps( meta, types, abs );
9671
setProps( meta, types, abs.assign );
9772

0 commit comments

Comments
 (0)