Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

sdot

Calculate the dot product of two one-dimensional single-precision floating-point ndarrays.

The dot product (or scalar product) is defined as

$$\mathbf{x}\cdot\mathbf{y} = \sum_{i=0}^{N-1} x_i y_i = x_0 y_0 + x_1 y_1 + \ldots + x_{N-1} y_{N-1}$$

Usage

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

sdot( arrays )

Computes the dot product of two one-dimensional single-precision floating-point ndarrays.

var Float32Array = require( '@stdlib/array/float32' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );

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

var ybuf = new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );
var y = new ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );

var z = sdot( [ x, y ] );
// returns -5.0

The function has the following parameters:

  • arrays: array-like object containing two one-dimensional input ndarrays.

Examples

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

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

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

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

var out = sdot( [ x, y ] );
console.log( out );