blas-ddot v1.0.0
ddot
Computes the dot product of
xandy.
The algebraic definition of the dot product between two vectors x and y is
Installation
$ npm install blas-ddotUsage
var ddot = require( 'blas-ddot' );ddot( N, x, strideX, offsetX, y, strideY, offsetY )
Computes the dot product of x and y.
var x = [ 1, 2, 3, 4, 5 ];
var y = [ 6, 7, 8, 9, 10 ];
var val = ddot( x.length, x, 1, 0, y, 1, 0 );
// returns 6+14+24+36+50 = 130The function accepts the following parameters:
- N: number of accessed elements.
__x__: input [`array`][array] or [`typed array`][typed-array].- strideX: index increment for
x. - offsetX: starting index for
x. - y: input
arrayortyped array. - strideY: index increment for
y. - offsetY: starting index for
y.
The N, stride, and offset parameters determine how elements are accessed during runtime. For example, to compute the dot product between every other element in x starting from its second element and the last N elements in y starting from its last element,
var x = [ 1, 2, 3, 4, 5, 6 ];
var y = [ 7, 8, 9, 10, 11, 12 ];
var N = Math.floor( x.length / 2 );
var val = ddot( N, x, 2, 1, y, -1, y.length-1 );
// returns 24+44+60 = 128If N <= 0, the function returns undefined.
Notes
Examples
var ddot = require( 'blas-ddot' );
var x;
var y;
var i;
x = new Float64Array( 10 );
y = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = Math.round( Math.random()*500 );
y[ i ] = Math.round( Math.random()*10 );
}
// Compute the dot product between `x` and the reverse of `y`:
console.log( ddot( x.length, x, 1, 0, y, -1, y.length-1 ) );To run the example code from the top-level application directory,
$ node ./examples/index.jsTests
Unit
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make testAll new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covBrowser Support
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsersTo view the tests in a local web browser,
$ make view-browser-testsLicense
Copyright
Copyright © 2016. The Compute.io Authors.