Skip to content

Latest commit

 

History

History
121 lines (76 loc) · 3.25 KB

File metadata and controls

121 lines (76 loc) · 3.25 KB

daxpy

Multiply a one-dimensional double-precision floating-point ndarray x by a constant alpha and add the result to a one-dimensional double-precision floating-point ndarray y.

Usage

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

daxpy( arrays )

Multiplies a one-dimensional double-precision floating-point ndarray x by a constant alpha and adds the result to a one-dimensional double-precision floating-point ndarray y.

var Float64Array = require( '@stdlib/array/float64' );
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
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 ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
var y = new ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );

var alpha = scalar2ndarray( 5.0, 'float64', 'row-major' );
var z = daxpy( [ x, y, alpha ] );
// returns <ndarray>[ 6.0, 11.0, 16.0, 21.0, 26.0 ]

The function has the following parameters:

  • arrays: array-like object containing an input ndarray, an output ndarray, and a zero-dimensional ndarray containing a scalar constant.

Examples

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

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

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

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

var alpha = scalar2ndarray( 5.0, opts );
var out = daxpy( [ x, y, alpha ] );
console.log( ndarray2array( out ) );