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
391 changes: 391 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/zwhere/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,391 @@
<!--

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

-->

# zwhere

> Take elements from one of two double-precision complex floating-point strided arrays depending on a condition.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### zwhere( N, condition, strideC, x, strideX, y, strideY, out, strideOut )

Takes elements from one of two double-precision complex floating-point strided arrays depending on a condition.

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

var condition = new BooleanArray( [ true, false, true ] );
var x = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] );
var y = new Complex128Array( [ 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 ] );
var out = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zwhere( 3, condition, 1, x, 1, y, 1, out, 1 );
// out => <Complex128Array>[ 1.0, -1.0, 5.0, -5.0, 3.0, -3.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **condition**: condition [`BooleanArray`][@stdlib/array/bool].
- **strideC**: stride length for `condition`.
- **x**: first input [`Complex128Array`][@stdlib/array/complex128].
- **strideX**: stride length for `x`.
- **y**: second input [`Complex128Array`][@stdlib/array/complex128].
- **strideY**: stride length for `y`.
- **out**: output [`Complex128Array`][@stdlib/array/complex128].
- **strideOut**: stride length for `out`.

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

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

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

var condition = new BooleanArray( [ true, false, false, true, true, false ] );
var x = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 ] );
var y = new Complex128Array( [ 7.0, -7.0, 8.0, -8.0, 9.0, -9.0, 10.0, -10.0, 11.0, -11.0, 12.0, -12.0 ] );
var out = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zwhere( 3, condition, 2, x, 2, y, 2, out, 1 );
// out => <Complex128Array>[ 1.0, -1.0, 9.0, -9.0, 5.0, -5.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, max-len -->

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

// Initial arrays...
var condition0 = new BooleanArray( [ false, true, false, true, false, true ] );
var x0 = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 ] );
var y0 = new Complex128Array( [ 7.0, -7.0, 8.0, -8.0, 9.0, -9.0, 10.0, -10.0, 11.0, -11.0, 12.0, -12.0 ] );
var out0 = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Create offset views...
var condition1 = new BooleanArray( condition0.buffer, condition0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
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*1 ); // start at 2nd element
var out1 = new Complex128Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

zwhere( 3, condition1, 2, x1, 2, y1, 2, out1, 1 );
// out0 => <Complex128Array>[ 0.0, 0.0, 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 0.0, 0.0, 0.0, 0.0 ]
```

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

#### zwhere.ndarray( N, condition, strideC, offsetC, x, strideX, offsetX, y, strideY, offsetY, out, strideOut, offsetOut )

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

Takes elements from one of two double-precision complex floating-point strided arrays depending on a condition using alternative indexing semantics.

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

var condition = new BooleanArray( [ true, false, true ] );
var x = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 ] );
var y = new Complex128Array( [ 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 ] );
var out = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0, out, 1, 0 );
// out => <Complex128Array>[ 1.0, -1.0, 5.0, -5.0, 3.0, -3.0 ]
```

The function has the following additional parameters:

- **offsetC**: starting index for `condition`.
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.
- **offsetOut**: starting index for `out`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to select from every other element starting from the second element:

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

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

var condition = new BooleanArray( [ false, true, false, false, false, true ] );
var x = new Complex128Array( [ 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 ] );
var y = new Complex128Array( [ 7.0, -7.0, 8.0, -8.0, 9.0, -9.0, 10.0, -10.0, 11.0, -11.0, 12.0, -12.0 ] );
var out = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

zwhere.ndarray( 3, condition, 2, 1, x, 2, 1, y, 2, 1, out, 1, 0 );
// out => <Complex128Array>[ 2.0, -2.0, 10.0, -10.0, 6.0, -6.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return `out` unchanged.
- The `condition` argument must be a [`BooleanArray`][@stdlib/array/bool].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var uniform = require( '@stdlib/random/array/uniform' );
var BooleanArray = require( '@stdlib/array/bool' );
var Complex128Array = require( '@stdlib/array/complex128' );
var zwhere = require( '@stdlib/blas/ext/base/zwhere' );

var cbuf = bernoulli( 20, 0.5, {
'dtype': 'uint8'
});
var condition = new BooleanArray( cbuf.buffer );
console.log( condition );

var xbuf = uniform( 40, 0.0, 100.0, {
'dtype': 'float64'
});
var x = new Complex128Array( xbuf.buffer );
console.log( x );

var ybuf = uniform( 40, -100.0, 0.0, {
'dtype': 'float64'
});
var y = new Complex128Array( ybuf.buffer );
console.log( y );

var out = new Complex128Array( condition.length );
console.log( out );

zwhere( condition.length, condition, 1, x, 1, y, 1, out, 1 );
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/zwhere.h"
```

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

#### stdlib_strided_zwhere( N, \*Condition, strideC, \*X, strideX, \*Y, strideY, \*Out, strideOut )

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

Takes elements from one of two double-precision complex floating-point strided arrays depending on a condition.

```c
#include "stdlib/complex/float64/ctor.h"
#include <stdbool.h>

const bool condition[] = { true, false, true };
const double x[] = { 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 };
const double y[] = { 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_zwhere( 3, condition, 1, (const stdlib_complex128_t *)x, 1, (const stdlib_complex128_t *)y, 1, (stdlib_complex128_t *)out, 1 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **Condition**: `[in] bool*` condition array.
- **strideC**: `[in] CBLAS_INT` stride length for `Condition`.
- **X**: `[in] stdlib_complex128_t*` first input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Y**: `[in] stdlib_complex128_t*` second input array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
- **Out**: `[out] stdlib_complex128_t*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.

```c
void stdlib_strided_zwhere( const CBLAS_INT N, const bool *Condition, const CBLAS_INT strideC, const stdlib_complex128_t *X, const CBLAS_INT strideX, const stdlib_complex128_t *Y, const CBLAS_INT strideY, stdlib_complex128_t *Out, const CBLAS_INT strideOut );
```

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

#### stdlib_strided_zwhere_ndarray( N, \*Condition, strideC, offsetC, \*X, strideX, offsetX, \*Y, strideY, offsetY, \*Out, strideOut, offsetOut )

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

Takes elements from one of two double-precision complex floating-point strided arrays depending on a condition using alternative indexing semantics.

```c
#include "stdlib/complex/float64/ctor.h"
#include <stdbool.h>

const bool condition[] = { true, false, true };
const double x[] = { 1.0, -1.0, 2.0, -2.0, 3.0, -3.0 };
const double y[] = { 4.0, -4.0, 5.0, -5.0, 6.0, -6.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_zwhere_ndarray( 3, condition, 1, 0, (const stdlib_complex128_t *)x, 1, 0, (const stdlib_complex128_t *)y, 1, 0, (stdlib_complex128_t *)out, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **Condition**: `[in] bool*` condition array.
- **strideC**: `[in] CBLAS_INT` stride length for `Condition`.
- **offsetC**: `[in] CBLAS_INT` starting index for `Condition`.
- **X**: `[in] stdlib_complex128_t*` first input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[in] stdlib_complex128_t*` second input array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
- **Out**: `[out] stdlib_complex128_t*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.

```c
void stdlib_strided_zwhere_ndarray( const CBLAS_INT N, const bool *Condition, const CBLAS_INT strideC, const CBLAS_INT offsetC, const stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const stdlib_complex128_t *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, stdlib_complex128_t *Out, const CBLAS_INT strideOut, 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/zwhere.h"
#include "stdlib/complex/float64/ctor.h"
#include <stdio.h>
#include <stdbool.h>

int main( void ) {
// Create strided arrays:
const bool condition[] = { true, false, true, false, true };
const double x[] = { 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0, 5.0, -5.0 };
const double y[] = { 6.0, -6.0, 7.0, -7.0, 8.0, -8.0, 9.0, -9.0, 10.0, -10.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

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

// Specify stride lengths:
const int strideC = 1;
const int strideX = 1;
const int strideY = 1;
const int strideOut = 1;

// Select from `x` or `y` based on the condition array:
stdlib_strided_zwhere( N, condition, strideC, (const stdlib_complex128_t *)x, strideX, (const stdlib_complex128_t *)y, strideY, (stdlib_complex128_t *)out, strideOut );

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

</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/bool]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/bool

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