Skip to content

Latest commit

 

History

History
126 lines (77 loc) · 2.86 KB

File metadata and controls

126 lines (77 loc) · 2.86 KB

dapx

Add a scalar constant to each element in a double-precision floating-point ndarray.

Usage

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

dapx( x, alpha )

Adds a scalar constant to each element in a double-precision floating-point ndarray.

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

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

var out = dapx( x, 5.0 );
// returns <ndarray>[ 6.0, 7.0, 8.0, 9.0 ]

The function has the following parameters:

  • x: input ndarray.
  • alpha: scalar constant.

Note that indexing is relative to the first index. To introduce an offset, use ndarray view creation.

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

// Initial array:
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );

// Create an ndarray view:
var x = new ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 2, 'row-major' );

var out = dapx( x, 5.0 );
// returns <ndarray>[ 8.0, 9.0, 10.0 ]

Notes

  • The function mutates the input ndarray.

Examples

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

var xbuf = discreteUniform( 10, 0, 100, {
    'dtype': 'float64'
});
var x = new ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' );

console.log( x.data );

dapx( x, 5.0 );

console.log( x.data );