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

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

-->

# dwhere

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

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

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

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

```javascript
var BooleanArray = require( '@stdlib/array/bool' );
var Float64Array = require( '@stdlib/array/float64' );

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

dwhere( 3, condition, 1, x, 1, y, 1, out, 1 );
// out => <Float64Array>[ 1.0, 5.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 [`Float64Array`][@stdlib/array/float64].
- **strideX**: stride length for `x`.
- **y**: second input [`Float64Array`][@stdlib/array/float64].
- **strideY**: stride length for `y`.
- **out**: output [`Float64Array`][@stdlib/array/float64].
- **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:

```javascript
var BooleanArray = require( '@stdlib/array/bool' );
var Float64Array = require( '@stdlib/array/float64' );

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

dwhere( 3, condition, 2, x, 2, y, 2, out, 1 );
// out => <Float64Array>[ 1.0, 9.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 Float64Array = require( '@stdlib/array/float64' );

// Initial arrays...
var condition0 = new BooleanArray( [ false, true, false, true, false, true ] );
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var out0 = new Float64Array( [ 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 Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

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

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

#### dwhere.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 floating-point strided arrays depending on a condition using alternative indexing semantics.

```javascript
var BooleanArray = require( '@stdlib/array/bool' );
var Float64Array = require( '@stdlib/array/float64' );

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

dwhere.ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0, out, 1, 0 );
// out => <Float64Array>[ 1.0, 5.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:

```javascript
var BooleanArray = require( '@stdlib/array/bool' );
var Float64Array = require( '@stdlib/array/float64' );

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

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

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return `out` unchanged.

</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 Float64Array = require( '@stdlib/array/float64' );
var dwhere = require( '@stdlib/blas/ext/base/dwhere' );

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

var x = uniform( 20, 0.0, 100.0, {
'dtype': 'float64'
});
console.log( x );

var y = uniform( 20, -100.0, 0.0, {
'dtype': 'float64'
});
console.log( y );

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

dwhere( 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/dwhere.h"
```

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

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

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

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

```c
#include <stdbool.h>

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

stdlib_strided_dwhere( 3, condition, 1, x, 1, y, 1, 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] double*` first input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Y**: `[in] double*` second input array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
- **Out**: `[out] double*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.

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

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

#### stdlib_strided_dwhere_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 floating-point strided arrays depending on a condition using alternative indexing semantics.

```c
#include <stdbool.h>

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

stdlib_strided_dwhere_ndarray( 3, condition, 1, 0, x, 1, 0, y, 1, 0, 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] double*` first input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[in] double*` second input array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
- **Out**: `[out] double*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.

```c
void stdlib_strided_dwhere_ndarray( const CBLAS_INT N, const bool *Condition, const CBLAS_INT strideC, const CBLAS_INT offsetC, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, double *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/dwhere.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, 2.0, 3.0, 4.0, 5.0 };
const double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 };
double out[] = { 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_dwhere( N, condition, strideC, x, strideX, y, strideY, out, strideOut );

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

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

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

</section>

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