Calculate the dot product of two double-precision complex floating-point vectors.
The dot product (or scalar product) is defined as
var zdotu = require( '@stdlib/blas/base/zdotu' );
Calculates the dot product of vectors zx
and zy
.
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
var zx = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] );
var zy = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] );
var z = zdotu( 3, zx, 1, zy, 1 );
// returns <Complex128>
var re = real( z );
// returns -52.0
var im = imag( z );
// returns 82.0
The function has the following parameters:
- N: number of indexed elements.
- zx: input
Complex128Array
. - strideX: index increment for
zx
. - zy: input
Complex128Array
. - strideY: index increment for
zy
.
The N
and strides parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other value in zx
and the first N
elements of zy
in reverse order,
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var zy = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
var z = zdotu( 2, zx, 2, zy, -1 );
// returns <Complex128>
var re = real( z );
// returns -2.0
var im = imag( z );
// returns 14.0
Note that indexing is relative to the first index. To introduce an offset, use typed array
views.
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
// Initial arrays...
var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var zy0 = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
// Create offset views...
var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var zy1 = new Complex128Array( zy0.buffer, zy0.BYTES_PER_ELEMENT*2 ); // start at 3th element
var z = zdotu( 1, zx1, 1, zy1, 1 );
// returns <Complex128>
var re = real( z );
// returns -15.0
var im = imag( z );
// returns 80.0
Calculates the dot product of zx
and zy
using alternative indexing semantics.
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
var zx = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] );
var zy = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] );
var z = zdotu.ndarray( zx.length, zx, 1, 0, zy, 1, 0 );
// returns <Complex128>
var re = real( z );
// returns -52.0
var im = imag( z );
// returns 82.0
The function has the following additional parameters:
- offsetX: starting index for
zx
. - offsetY: starting index for
zy
.
While typed array
views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in zx
starting from the second value with the last 2 elements in zy
in reverse order
var Complex128Array = require( '@stdlib/array/complex128' );
var real = require( '@stdlib/complex/float64/real' );
var imag = require( '@stdlib/complex/float64/imag' );
var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var zy = new Complex128Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] ); // eslint-disable-line max-len
var z = zdotu.ndarray( 2, zx, 2, 1, zy, -1, zy.length-1 );
// returns <Complex128>
var re = real( z );
// returns -40.0
var im = imag( z );
// returns 310.0
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var zdotu = require( '@stdlib/blas/base/zdotu' );
function rand() {
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}
var zx = filledarrayBy( 10, 'complex128', rand );
console.log( zx.toString() );
var zy = filledarrayBy( 10, 'complex128', rand );
console.log( zy.toString() );
var out = zdotu.ndarray( zx.length, zx, 1, 0, zy, -1, zy.length-1 );
console.log( out.toString() );