Calculate the dot product of two single-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 x and y.
var Complex128Array = require( '@stdlib/array/complex128' );
var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] );
var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] );
var z = zdotu( 3, x, 1, y, 1 );
// returns <Complex128>[ -52.0, 82.0 ]The function has the following parameters:
- N: number of indexed elements.
- x: input
Complex128Array. - strideX: stride length for
x. - y: input
Complex128Array. - strideY: stride length for
y.
The N and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other element in x and the first N elements of y in reverse order,
var Complex128Array = require( '@stdlib/array/complex128' );
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
var z = zdotu( 2, x, 2, y, -1 );
// returns <Complex128>[ -2.0, 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' );
// Initial arrays...
var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y0 = new Complex128Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
// Create offset views...
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Complex128Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element
var z = zdotu( 1, x1, 1, y1, 1 );
// returns <Complex128>[ -15.0, 80.0 ]Calculates the dot product of x and y using alternative indexing semantics.
var Complex128Array = require( '@stdlib/array/complex128' );
var x = new Complex128Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] );
var y = new Complex128Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] );
var z = zdotu.ndarray( x.length, x, 1, 0, y, 1, 0 );
// returns <Complex128>[ -52.0, 82.0 ]The function has the following additional parameters:
- offsetX: starting index for
x. - offsetY: starting index for
y.
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 element in x starting from the second element with the last 2 elements in y in reverse order
var Complex128Array = require( '@stdlib/array/complex128' );
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex128Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] );
var z = zdotu.ndarray( 2, x, 2, 1, y, -1, y.length-1 );
// returns <Complex128>[ -40.0, 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 x = filledarrayBy( 10, 'complex128', rand );
console.log( x.toString() );
var y = filledarrayBy( 10, 'complex128', rand );
console.log( y.toString() );
// Compute the dot product:
var out = zdotu( x.length, x, 1, y, -1 );
console.log( out.toString() );
// Compute the dot product using alternative indexing semantics:
out = zdotu.ndarray( x.length, x, 1, 0, y, -1, y.length-1 );
console.log( out.toString() );#include "stdlib/blas/base/zdotu.h"Calculates the dot product of two single-precision complex floating-point vectors.
#include "stdlib/complex/float64/ctor.h"
const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 };
const double y[] = { 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 };
stdlib_complex128_t dot;
c_zdotu( 3, (void *)x, 1, (void *)y, 1, (void *)&dot );The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - X:
[in] void*first input array. - strideX:
[in] CBLAS_INTindex increment forX. - Y:
[in] void*second input array. - strideY:
[in] CBLAS_INTindex increment forY. - dot:
[out] void*output variable.
void c_zdotu( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const void *Y, const CBLAS_INT strideY, void *dot );Calculates the dot product of two single-precision complex floating-point vectors using alternative indexing semantics.
#include "stdlib/complex/float64/ctor.h"
const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 };
const double y[] = { 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 };
stdlib_complex128_t dot;
c_zdotu_ndarray( 3, (void *)x, 1, 0, (void *)y, 1, 0, (void *)&dot );The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - X:
[in] void*first input array. - strideX:
[in] CBLAS_INTindex increment forX. - offsetX:
[in] CBLAS_INTstarting index forX. - Y:
[in] void*second input array. - strideY:
[in] CBLAS_INTindex increment forY. - offsetY:
[in] CBLAS_INTstarting index forY. - dot:
[out] void*output variable.
void c_zdotu_ndarray( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const void *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, void *dot );#include "stdlib/blas/base/zdotu.h"
#include "stdlib/complex/float64/real.h"
#include "stdlib/complex/float64/imag.h"
#include "stdlib/complex/float64/ctor.h"
#include <stdio.h>
int main( void ) {
// Create strided arrays:
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
const double y[] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
// Specify the number of elements:
const int N = 4;
// Specify strides:
const int strideX = 1;
const int strideY = 1;
// Create a complex number to store the result:
stdlib_complex128_t z;
// Compute the dot product:
c_zdotu( N, (const void *)x, strideX, (const void *)y, strideY, (void *)&z );
// Print the result:
printf( "dot: %lf + %lfi\n", stdlib_complex128_real( z ), stdlib_complex128_imag( z ) );
// Compute the dot product:
c_zdotu_ndarray( N, (const void *)x, strideX, 0, (const void *)y, strideY, 0, (void *)&z );
// Print the result:
printf( "dot: %lf + %lfi\n", stdlib_complex128_real( z ), stdlib_complex128_imag( z ) );
}