Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
362 changes: 362 additions & 0 deletions lib/node_modules/@stdlib/blas/base/cdotu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,362 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# cdotu

> Calculate the dot product of two single-precision complex floating-point vectors.

<section class="intro">

The [dot product][dot-product] (or scalar product) is defined as

<!-- <equation class="equation" label="eq:dot_product" align="center" raw="\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}" alt="Dot product definition."> -->

```math
\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}
```

<!-- <div class="equation" align="center" data-raw-text="\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}" data-equation="eq:dot_product">
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@929657146427564b61e3e6bdda76949ebe2ce923/lib/node_modules/@stdlib/blas/base/ddot/docs/img/equation_dot_product.svg" alt="Dot product definition.">
<br>
</div> -->

<!-- </equation> -->

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var cdotu = require( '@stdlib/blas/base/cdotu' );
```

#### cdotu( N, x, strideX, y, strideY )

Calculates the dot product of vectors `x` and `y`.

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] );
var y = new Complex64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] );

var z = cdotu( 3, x, 1, y, 1 );
// returns <Complex64>[ -52.0, 82.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Complex64Array`][@stdlib/array/complex64].
- **strideX**: stride length for `x`.
- **y**: input [`Complex64Array`][@stdlib/array/complex64].
- **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,

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );

var z = cdotu( 2, x, 2, y, -1 );
// returns <Complex64>[ -2.0, 14.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

// Initial arrays...
var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y0 = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );

// Create offset views...
var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Complex64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element

var z = cdotu( 1, x1, 1, y1, 1 );
// returns <Complex64>[ -15.0, 80.0 ]
```

#### cdotu.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )

Calculates the dot product of `x` and `y` using alternative indexing semantics.

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 7.0 ] );
var y = new Complex64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 9.0 ] );

var z = cdotu.ndarray( x.length, x, 1, 0, y, 1, 0 );
// returns <Complex64>[ -52.0, 82.0 ]
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-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

<!-- eslint-disable max-len -->

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex64Array( [ 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0 ] );

var z = cdotu.ndarray( 2, x, 2, 1, y, -1, y.length-1 );
// returns <Complex64>[ -40.0, 310.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return `0.0 + 0.0i`.
- `cdotu()` corresponds to the [BLAS][blas] level 1 function [`cdotu`][cdotu].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var cdotu = require( '@stdlib/blas/base/cdotu' );

function rand() {
return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}

var x = filledarrayBy( 10, 'complex64', rand );
console.log( x.toString() );

var y = filledarrayBy( 10, 'complex64', rand );
console.log( y.toString() );

// Compute the dot product:
var out = cdotu( x.length, x, 1, y, -1 );
console.log( out.toString() );

// Compute the dot product using alternative indexing semantics:
out = cdotu.ndarray( x.length, x, 1, 0, y, -1, y.length-1 );
console.log( out.toString() );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/base/cdotu.h"
```

#### c_cdotu( N, \*X, strideX, \*Y, strideY, \*dot )

Calculates the dot product of two single-precision complex floating-point vectors.

```c
#include "stdlib/complex/float32/ctor.h"

const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f, 7.0f };
const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f, 9.0f };

stdlib_complex64_t dot;
c_cdotu( 3, (void *)x, 1, (void *)y, 1, (void *)&dot );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] void*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **Y**: `[in] void*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **dot**: `[out] void*` output variable.

```c
void c_cdotu( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const void *Y, const CBLAS_INT strideY, void *dot );
```

#### c_cdotu_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY, \*dot )

Calculates the dot product of two single-precision complex floating-point vectors using alternative indexing semantics.

```c
#include "stdlib/complex/float32/ctor.h"

const float x[] = { 4.0f, 2.0f, -3.0f, 5.0f, -1.0f, 7.0f };
const float y[] = { 2.0f, 6.0f, -1.0f, -4.0f, 8.0f, 9.0f };

stdlib_complex64_t dot;
c_cdotu_ndarray( 3, (void *)x, 1, 0, (void *)y, 1, 0, (void *)&dot );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] void*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[in] void*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
- **dot**: `[out] void*` output variable.

```c
void c_cdotu_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 );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/base/cdotu.h"
#include "stdlib/complex/float32/real.h"
#include "stdlib/complex/float32/imag.h"
#include "stdlib/complex/float32/ctor.h"
#include <stdio.h>

int main( void ) {
// Create strided arrays:
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
const float y[] = { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };

// 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_complex64_t z;

// Compute the dot product:
c_cdotu( N, (const void *)x, strideX, (const void *)y, strideY, (void *)&z );

// Print the result:
printf( "dot: %f + %fi\n", stdlib_complex64_real( z ), stdlib_complex64_imag( z ) );

// Compute the dot product:
c_cdotu_ndarray( N, (const void *)x, strideX, 0, (const void *)y, strideY, 0, (void *)&z );

// Print the result:
printf( "dot: %f + %fi\n", stdlib_complex64_real( z ), stdlib_complex64_imag( z ) );
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[dot-product]: https://en.wikipedia.org/wiki/Dot_product

[blas]: http://www.netlib.org/blas

[cdotu]: https://www.netlib.org/lapack/explore-html/d1/dcc/group__dot_ga2cce681b6aed3728b893a555b3bee55c.html#ga2cce681b6aed3728b893a555b3bee55c

[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

<!-- <related-links> -->

<!-- </related-links> -->

</section>

<!-- /.links -->
Loading
Loading