Math array function tools.
var ns = require( '@stdlib/math/array/tools' );
Namespace containing tools for applying mathematical functions to arrays.
var o = ns;
// returns {...}
The namespace contains the following:
unaryFactory( fcn, idtypes, odtypes, policy )
: create a function for applying a unary function to each element in an input array.unary( fcn, idtypes, odtypes, policy )
: constructor for applying a unary function to each element in an input array.
var abs = require( '@stdlib/math/base/special/abs' );
var ns = require( '@stdlib/math/array/tools' );
// Define a list of supported input dtypes:
var idtypes = [
'float64',
'float32',
'generic'
];
// Define a list of supported output dtypes:
var odtypes = [
'float64',
'float32',
'generic'
];
// Create a function for applying a unary function to each element of an array:
var f = new ns.unary( abs, idtypes, odtypes, 'same' );
// Create an input array:
var x = [ -1.0, 2.0, -3.0, 4.0 ];
// Perform element-wise computation:
var out = f.apply( x );
// returns [ 1.0, 2.0, 3.0, 4.0 ]