Calculate the dot product
x^H * yofxandy.
The dot product (or scalar product) is defined as
var cdotc = require( '@stdlib/blas/base/cdotc' );Calculates the dot product x^H * y of x and y.
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var x = new Complex64Array( [ 7.0, -8.0, -1.0, -9.0 ] );
var y = new Complex64Array( [ 6.0, -6.0, -9.0, 5.0 ] );
var out = cdotc( x.length, x, 1, y, 1 );
// returns <Complex64>[ 54.0, -80.0 ]The function has the following parameters:
- N: number of indexed elements.
- x: input
Complex64Array. - strideX: index increment for
x. - y: input
Complex64Array. - strideY: index increment 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 value in x and the first N elements of y in reverse order,
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var x = new Complex64Array( [ -1.0, -9.0, 2.0, -8.0 ] );
var y = new Complex64Array( [ -5.0, 1.0, -6.0, 7.0 ] );
var out = cdotc( x.length, x, 1, y, -1 );
// returns <Complex64>[ -75.0, -99.0 ]Calculates the dot product x^H * y of x and y using alternative indexing semantics.
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var x = new Complex64Array( [ 7.0, -8.0, -1.0, -9.0 ] );
var y = new Complex64Array( [ 6.0, -6.0, -9.0, 5.0 ] );
var out = cdotc.ndarray( x.length, x, 1, 0, y, 1, 0 );
// returns <Complex64>[ 54.0, -80.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 value in x starting from the second value with the last 2 elements in y in reverse order
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var x = new Complex64Array( [ 7.0, -8.0, -1.0, -9.0 ] );
var y = new Complex64Array( [ 6.0, -6.0, -9.0, 5.0 ] );
var out = cdotc.ndarray( x.length, x, 1, 0, y, -1, y.length-1 );
// returns <Complex64>[ -55.0, 23.0 ]var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var cdotc = require( '@stdlib/blas/base/cdotc' );
function rand() {
return new Complex64( discreteUniform( 0, 10 ), discreteUniform( 1, 5 ) );
}
var x = filledarrayBy( 10, 'complex64', rand );
console.log( x.toString() );
var y = filledarrayBy( 10, 'complex64', rand );
console.log( y.toString() );
// Perform dot product of x and y
var out = cdotc.ndarray( x.length, x, 1, 0, y, -1, y.length-1 );
console.log( out );#include "stdlib/blas/base/cdotc.h"Calculates the dot product x^H * y of x and y.
#include "stdlib/complex/float32/ctor.h"
float x[] = { 7.0f, -8.0f, -1.0f, -9.0f };
float y[] = { 6.0f, -6.0f, -9.0f, 5.0f };
stdlib_complex64_t out = c_cdotc( 2, (void *)x, 1, (void *)y, 1 );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.
stdlib_complex64_t c_cdotc( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const void *Y, const CBLAS_INT strideY );Calculates the dot product x^H * y of x and y using alternative indexing semantics.
#include "stdlib/complex/float32/ctor.h"
float x[] = { 7.0f, -8.0f, -1.0f, -9.0f };
float y[] = { 6.0f, -6.0f, -9.0f, 5.0f };
stdlib_complex64_t out = c_cdotc_ndarray( 2, (void *)x, 1, 0, (void *)y, 1, 0 );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.
stdlib_complex64_t c_cdotc_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 );#include "stdlib/blas/base/cdotc.h"
#include "stdlib/complex/float32/ctor.h"
#include "stdlib/complex/float32/reim.h"
#include <stdio.h>
int main( void ) {
// Create strided arrays of interleaved real and imaginary components:
float x[] = { 7.0f, -8.0f, -1.0f, -9.0f };
float y[] = { 6.0f, -6.0f, -9.0f, 5.0f };
// Specify the number of elements:
const int N = 2;
// Specify stride lengths:
const int strideX = 1;
const int strideY = 1;
// Compute the dot product:
stdlib_complex64_t dot = c_cdotc( N, (void *)x, strideX, (void *)y, strideY );
// Print the result:
float re;
float im;
stdlib_complex64_reim( dot, &re, &im );
printf( "cdotc( x, y ) = %f + %fi\n", re, im );
// Compute the dot product using alternative indexing semantics:
dot = c_cdotc_ndarray( N, (void *)x, -strideX, 1, (void *)y, strideY, 0 );
// Print the result:
stdlib_complex64_reim( dot, &re, &im );
printf( "cdotc( x, y ) = %f + %fi\n", re, im );
}@stdlib/blas/base/cdotu: calculate the dot product of two single-precision complex floating-point vectors.@stdlib/blas/base/zdotc: calculate the dot product of two double-precision complex floating-point vectors, conjugating the first vector.