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
140 changes: 128 additions & 12 deletions lib/node_modules/@stdlib/blas/ext/base/dsnansum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,26 @@ limitations under the License.
var dsnansum = require( '@stdlib/blas/ext/base/dsnansum' );
```

#### dsnansum( N, x, stride )
#### dsnansum( N, x, strideX )

Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using extended accumulation, and returning an extended precision result.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );
var N = x.length;

var v = dsnansum( N, x, 1 );
var v = dsnansum( x.length, x, 1 );
// returns 1.0
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Float32Array`][@stdlib/array/float32].
- **stride**: index increment for `x`.
- **strideX**: stride length for `x`.

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

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand All @@ -81,24 +80,24 @@ var v = dsnansum( 4, x1, 2 );
// returns 5.0
```

#### dsnansum.ndarray( N, x, stride, offset )
#### dsnansum.ndarray( N, x, strideX, offsetX )

Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using extended accumulation and alternative indexing semantics.
Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using extended accumulation and alternative indexing semantics, and returning an extended precision result.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );

var v = dsnansum.ndarray( 4, x, 1, 0 );
var v = dsnansum.ndarray( x.length, x, 1, 0 );
// returns 1.0
```

The function has the following additional parameters:

- **offset**: starting index for `x`.
- **offsetX**: starting index for `x`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other value in `x` starting from the second value
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other element starting from the second element:

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -136,14 +135,14 @@ var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var dsnansum = require( '@stdlib/blas/ext/base/dsnansum' );

function clbk() {
function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

var x = filledarrayBy( 10, 'float64', clbk );
var x = filledarrayBy( 10, 'float32', rand );
console.log( x );

var v = dsnansum( x.length, x, 1 );
Expand All @@ -154,6 +153,123 @@ console.log( v );

<!-- /.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/dsnansum.h"
```

#### stdlib_strided_dsnansum( N, \*X, strideX )

Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using extended accumulation, and returning an extended precision result.

```c
const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };

double v = stdlib_strided_dsnansum( 4, x, 1 );
// returns 1.0
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] float*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.

```c
double stdlib_strided_dsnansum( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
```

#### stdlib_strided_dsnansum_ndarray( N, \*X, strideX, offsetX )

Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values, using extended accumulation and alternative indexing semantics, and returning an extended precision result.

```c
const float x[] = { 1.0f, -2.0f, 0.0f/0.0f, 2.0f };

double v = stdlib_strided_dsnansum_ndarray( 4, x, 1, 0 );
// returns 1.0
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] float*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.

```c
double stdlib_strided_dsnansum_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</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/dsnansum.h"
#include <stdio.h>

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

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

// Specify the stride length:
const int strideX = 2;

// Compute the sum:
double v = stdlib_strided_dsnansum( N, x, strideX );

// Print the result:
printf( "sum: %lf\n", v );
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<section class="references">

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
Expand All @@ -32,6 +32,19 @@ var dsnansum = require( './../lib/dsnansum.js' );

// FUNCTIONS //

/**
* Returns a random number.
*
* @private
* @returns {number} random number
*/
function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return NaN;
}
return uniform( -10, 10 );
}

/**
* Creates a benchmark function.
*
Expand All @@ -43,13 +56,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

function benchmark( b ) {
var v;
var i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
Expand All @@ -41,6 +41,19 @@ var opts = {

// FUNCTIONS //

/**
* Returns a random number.
*
* @private
* @returns {number} random number
*/
function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return NaN;
}
return uniform( -10, 10 );
}

/**
* Creates a benchmark function.
*
Expand All @@ -52,13 +65,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

function benchmark( b ) {
var v;
var i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var bench = require( '@stdlib/bench' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
Expand All @@ -32,6 +32,19 @@ var dsnansum = require( './../lib/ndarray.js' );

// FUNCTIONS //

/**
* Returns a random number.
*
* @private
* @returns {number} random number
*/
function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return NaN;
}
return uniform( -10, 10 );
}

/**
* Creates a benchmark function.
*
Expand All @@ -43,13 +56,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

function benchmark( b ) {
var v;
var i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
Expand All @@ -41,6 +41,19 @@ var opts = {

// FUNCTIONS //

/**
* Returns a random number.
*
* @private
* @returns {number} random number
*/
function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return NaN;
}
return uniform( -10, 10 );
}

/**
* Creates a benchmark function.
*
Expand All @@ -52,13 +65,6 @@ function createBenchmark( len ) {
var x = filledarrayBy( len, 'float32', rand );
return benchmark;

function rand() {
if ( bernoulli( 0.7 ) > 0 ) {
return discreteUniform( -10, 10 );
}
return NaN;
}

function benchmark( b ) {
var v;
var i;
Expand Down
Loading