Skip to content

Latest commit

 

History

History
127 lines (78 loc) · 3.16 KB

File metadata and controls

127 lines (78 loc) · 3.16 KB

dasum

Calculate the sum of absolute values for all elements in a one-dimensional double-precision floating-point ndarray.

The L1 norm is defined as

$$\|\mathbf{x}\|_1 = \sum_{i=0}^{n-1} \vert x_i \vert$$

Usage

var dasum = require( '@stdlib/blas/base/ndarray/dasum' );

dasum( arrays )

Computes the sum of absolute values for all elements in a one-dimensional double-precision floating-point ndarray.

var Float64Array = require( '@stdlib/array/float64' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );

var xbuf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] );
var x = new ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );

var y = dasum( [ x ] );
// returns 15.0

The function has the following parameters:

  • arrays: array-like object containing a one-dimensional input ndarray.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var dasum = require( '@stdlib/blas/base/ndarray/dasum' );

var opts = {
    'dtype': 'float64'
};

var xbuf = discreteUniform( 10, -500, 500, opts );
var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );

var out = dasum( [ x ] );
console.log( out );