Skip to content
Draft
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
328 changes: 328 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/zcartesian-square/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
<!--

@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.

-->

# zcartesianSquare

> Compute the Cartesian square for a double-precision complex floating-point strided array.

<section class="usage">

## Usage

```javascript
var zcartesianSquare = require( '@stdlib/blas/ext/base/zcartesian-square' );
```

#### zcartesianSquare( order, N, x, strideX, out, LDO )

Computes the Cartesian square for a double-precision complex floating-point strided array.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Complex128Array( 8 );

zcartesianSquare( 'row-major', x.length, x, 1, out, 2 );
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
- **N**: number of indexed elements.
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
- **strideX**: stride length for `x`.
- **out**: output [`Complex128Array`][@stdlib/array/complex128].
- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`).

The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian square of every other element:

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 1.0, 2.0, 0.0, 0.0, 3.0, 4.0, 0.0, 0.0 ] );
var out = new Complex128Array( 8 );

zcartesianSquare( 'row-major', 2, x, 2, out, 2 );
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

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

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

// Initial array:
var x0 = new Complex128Array( [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] );

// Create an offset view:
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Output array:
var out = new Complex128Array( 8 );

zcartesianSquare( 'row-major', 2, x1, 1, out, 2 );
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

<!-- lint disable maximum-heading-length -->

#### zcartesianSquare.ndarray( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut )

<!-- lint enable maximum-heading-length -->

Computes the Cartesian square for a double-precision complex floating-point strided array using alternative indexing semantics.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Complex128Array( 8 );

zcartesianSquare.ndarray( x.length, x, 1, 0, out, 2, 1, 0 );
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
- **strideX**: stride length for `x`.
- **offsetX**: starting index for `x`.
- **out**: output [`Complex128Array`][@stdlib/array/complex128].
- **strideOut1**: stride length for the first dimension of `out`.
- **strideOut2**: stride length for the second dimension of `out`.
- **offsetOut**: starting index for `out`.

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 access only the last two elements:

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0 ] );
var out = new Complex128Array( 8 );

zcartesianSquare.ndarray( 2, x, 1, 2, out, 2, 1, 0 );
// out => <Complex128Array>[ 1.0, 2.0, 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Pairs are stored as rows in the output matrix, where the first column contains the first element of each pair and the second column contains the second element.
- For an input array of length `N`, the output array must contain at least `N * N * 2` indexed elements.
- For row-major order, the `LDO` parameter must be greater than or equal to `2`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,N*N)`.
- If `N <= 0`, both functions return `out` unchanged.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Complex128Array = require( '@stdlib/array/complex128' );
var zcartesianSquare = require( '@stdlib/blas/ext/base/zcartesian-square' );

var N = 2;
var xbuf = discreteUniform( N*2, 1, 10, {
'dtype': 'float64'
});
var x = new Complex128Array( xbuf.buffer );
console.log( x );

var out = new Complex128Array( N * N * 2 );
zcartesianSquare( 'row-major', N, x, 1, out, 2 );
console.log( out );
```

</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/ext/base/zcartesiansquare.h"
```

#### stdlib_strided_zcartesian_square( order, N, \*X, strideX, \*Out, LDO )

Computes the Cartesian square for a double-precision complex floating-point strided array.

```c
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/blas/base/shared.h"

const double x[] = { 1.0, 2.0, 3.0, 4.0 };
double out[ 16 ];

stdlib_strided_zcartesian_square( CblasRowMajor, 2, (const stdlib_complex128_t *)x, 1, (stdlib_complex128_t *)out, 2 );
```

The function accepts the following arguments:

- **order**: `[in] CBLAS_LAYOUT` storage layout.
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] stdlib_complex128_t*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Out**: `[out] stdlib_complex128_t*` output array.
- **LDO**: `[in] CBLAS_INT` stride length between successive contiguous vectors of the matrix `Out` (a.k.a., leading dimension of `Out`). For row-major order, must be greater than or equal to `2`. For column-major order, must be greater than or equal to `max(1,N*N)`.

```c
void stdlib_strided_zcartesian_square( const CBLAS_LAYOUT order, const CBLAS_INT N, const stdlib_complex128_t *X, const CBLAS_INT strideX, stdlib_complex128_t *Out, const CBLAS_INT LDO );
```

<!-- lint disable maximum-heading-length -->

#### stdlib_strided_zcartesian_square_ndarray( N, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut )

<!-- lint enable maximum-heading-length -->

Computes the Cartesian square for a double-precision complex floating-point strided array using alternative indexing semantics.

```c
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
double out[ 16 ];

stdlib_strided_zcartesian_square_ndarray( 2, (const stdlib_complex128_t *)x, 1, 0, (stdlib_complex128_t *)out, 2, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] stdlib_complex128_t*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Out**: `[out] stdlib_complex128_t*` output array.
- **strideOut1**: `[in] CBLAS_INT` stride length for the first dimension of `Out`.
- **strideOut2**: `[in] CBLAS_INT` stride length for the second dimension of `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.

```c
void stdlib_strided_zcartesian_square_ndarray( const CBLAS_INT N, const stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, stdlib_complex128_t *Out, const CBLAS_INT strideOut1, const CBLAS_INT strideOut2, const CBLAS_INT offsetOut );
```

</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/ext/base/zcartesiansquare.h"
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/blas/base/shared.h"
#include <stdio.h>

int main( void ) {
// Create a strided array of interleaved real and imaginary components:
const double x[] = { 1.0, 2.0, 3.0, 4.0 };

// Specify the number of indexed elements:
const int N = 2;

// Create an output array (N*N pairs, each pair has 2 elements):
double out[ 16 ];

// Specify strides:
const int strideX = 1;
const int LDO = 2;

// Compute the Cartesian square:
stdlib_strided_zcartesian_square( CblasRowMajor, N, (const stdlib_complex128_t *)x, strideX, (stdlib_complex128_t *)out, LDO );

// Print the result:
for ( int i = 0; i < N*N; i++ ) {
printf( "out[ %i ] = ( %lf+%lfi, %lf+%lfi )\n", i, out[ i*4 ], out[ (i*4)+1 ], out[ (i*4)+2 ], out[ (i*4)+3 ] );
}
}
```

</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">

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

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

</section>

<!-- /.links -->
Loading