Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jan 10, 2025
1 parent 4846326 commit e978aee
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 198 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ A total of 8 people contributed to this release. Thank you to the following cont

<details>

- [`bb638df`](https://github.com/stdlib-js/stdlib/commit/bb638df38852d5ba3e341e9d607a0900a5d55723) - **refactor:** update `blas/ext/base/gnannsumkbn` to follow current project conventions [(#4631)](https://github.com/stdlib-js/stdlib/pull/4631) _(by Muhammad Haris)_
- [`0639c11`](https://github.com/stdlib-js/stdlib/commit/0639c11f0aac69a249c9710c9031e4f9cec14f62) - **refactor:** update `blas/ext/base/gsumkbn2` to follow current project conventions [(#4678)](https://github.com/stdlib-js/stdlib/pull/4678) _(by Muhammad Haris)_
- [`c36f0e7`](https://github.com/stdlib-js/stdlib/commit/c36f0e73214c70c686defbaf5adc2d3e86a6595b) - **refactor:** update `blas/ext/base/gsumors` to follow current project conventions [(#4679)](https://github.com/stdlib-js/stdlib/pull/4679) _(by Muhammad Haris)_
- [`dbade8e`](https://github.com/stdlib-js/stdlib/commit/dbade8ed06df1ad8cef3ecf6c1f1f729ad62a53c) - **refactor:** update `blas/ext/base/gsumpw` to follow current project conventions [(#4680)](https://github.com/stdlib-js/stdlib/pull/4680) _(by Muhammad Haris)_
Expand Down
43 changes: 16 additions & 27 deletions ext/base/gnannsumkbn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideX**: index increment for `x`.
- **strideX**: stride length for `x`.
- **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array] whose first element is the sum and whose second element is the number of non-NaN elements.
- **strideOut**: index increment for `out`.
- **strideOut**: stride length for `out`.

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

```javascript
var floor = require( '@stdlib/math/base/special/floor' );

var x = [ 1.0, 2.0, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ];
var out = [ 0.0, 0 ];
var N = floor( x.length / 2 );

var v = gnannsumkbn( N, x, 2, out, 1 );
var v = gnannsumkbn( 4, x, 2, out, 1 );
// returns [ 5.0, 2 ]
```

Expand All @@ -75,17 +72,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

var x0 = new Float64Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var out0 = new Float64Array( 4 );
var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*2 ); // start at 3rd element

var N = floor( x0.length / 2 );

var v = gnannsumkbn( N, x1, 2, out1, 1 );
var v = gnannsumkbn( 4, x1, 2, out1, 1 );
// returns <Float64Array>[ 5.0, 4 ]
```

Expand All @@ -106,16 +100,13 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetOut**: starting index for `out`.

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 parameters support indexing semantics based on starting indices. For example, to calculate the sum of every other element starting from the second element:

```javascript
var floor = require( '@stdlib/math/base/special/floor' );

var x = [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ];
var out = [ 0.0, 0.0, 0.0, 0 ];
var N = floor( x.length / 2 );

var v = gnannsumkbn.ndarray( N, x, 2, 1, out, 2, 1 );
var v = gnannsumkbn.ndarray( 4, x, 2, 1, out, 2, 1 );
// returns <Float64Array>[ 0.0, 5.0, 0.0, 4 ]
```

Expand All @@ -140,22 +131,20 @@ var v = gnannsumkbn.ndarray( N, x, 2, 1, out, 2, 1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Float64Array = require( '@stdlib/array/float64' );
var gnannsumkbn = require( '@stdlib/blas/ext/base/gnannsumkbn' );

var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = round( randu()*100.0 );
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return discreteUniform( 0, 100 );
}
return NaN;
}

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

var out = new Float64Array( 2 );
Expand Down
33 changes: 19 additions & 14 deletions ext/base/gnannsumkbn/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,31 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-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' );
var zeros = require( '@stdlib/array/base/zeros' );
var pkg = require( './../package.json' ).name;
var gnannsumkbn = require( './../lib/main.js' );


// FUNCTIONS //

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

/**
* Creates a benchmark function.
*
Expand All @@ -38,19 +54,8 @@ var gnannsumkbn = require( './../lib/main.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var out;
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x.push( NaN );
} else {
x.push( ( randu()*10.0 ) - 20.0 );
}
}
out = [ 0.0, 0 ];
var out = zeros( 2 );
var x = filledarrayBy( len, 'generic', rand );
return benchmark;

function benchmark( b ) {
Expand Down
33 changes: 19 additions & 14 deletions ext/base/gnannsumkbn/benchmark/benchmark.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,31 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-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' );
var zeros = require( '@stdlib/array/base/zeros' );
var pkg = require( './../package.json' ).name;
var gnannsumkbn = require( './../lib/ndarray.js' );


// FUNCTIONS //

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

/**
* Creates a benchmark function.
*
Expand All @@ -38,19 +54,8 @@ var gnannsumkbn = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var out;
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
if ( randu() < 0.2 ) {
x.push( NaN );
} else {
x.push( ( randu()*10.0 ) - 20.0 );
}
}
out = [ 0.0, 0 ];
var out = zeros( 2 );
var x = filledarrayBy( len, 'generic', rand );
return benchmark;

function benchmark( b ) {
Expand Down
26 changes: 12 additions & 14 deletions ext/base/gnannsumkbn/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Computes the sum of strided array elements, ignoring `NaN` values and using
an improved Kahan–Babuška algorithm.

The `N` and `stride` parameters determine which elements are accessed at
The `N` and stride parameters determine which elements are accessed at
runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
Expand All @@ -20,13 +20,13 @@
Input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

out: Array<number>|TypedArray
Output array.

strideOut: integer
Index increment for `out`.
Stride length for `out`.

Returns
-------
Expand All @@ -42,28 +42,27 @@
> {{alias}}( x.length, x, 1, out, 1 )
[ 1.0, 3 ]

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ];
> out = [ 0.0, 0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}( N, x, 2, out, 1 )
> {{alias}}( 4, x, 2, out, 1 )
[ 1.0, 3 ]

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0, NaN, NaN ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> out = [ 0.0, 0 ];
> {{alias}}( N, x1, 2, out, 1 )
> {{alias}}( 4, x1, 2, out, 1 )
<Float64Array>[ 1.0, 3 ]


{{alias}}.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut )
Computes the sum of strided array elements, ignoring `NaN` values and using
an improved Kahan–Babuška algorithm and alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offset` parameter supports indexing semantics based on a
starting index.
buffer, the offset parameters support indexing semantics based on a starting
indices.

Parameters
----------
Expand All @@ -74,7 +73,7 @@
Input array.

strideX: integer
Index increment for `x`.
Stride length for `x`.

offsetX: integer
Starting index for `x`.
Expand All @@ -83,7 +82,7 @@
Output array.

strideOut: integer
Index increment for `out`.
Stride length for `out`.

offsetOut: integer
Starting index for `out`.
Expand All @@ -104,9 +103,8 @@

// Using offset parameter:
> var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0, NaN, NaN ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> out = [ 0.0, 0 ];
> {{alias}}.ndarray( N, x, 2, 1, out, 1, 0 )
> {{alias}}.ndarray( 4, x, 2, 1, out, 1, 0 )
[ 1.0, 3 ]

See Also
Expand Down
16 changes: 8 additions & 8 deletions ext/base/gnannsumkbn/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param strideX - `x` stride length
* @param strideX - stride length for `x`
* @param out - output array whose first element is the sum and whose second element is the number of non-NaN elements
* @param strideOut - `out` stride length
* @param strideOut - stride length for `out`
* @returns output array
*
* @example
Expand All @@ -50,11 +50,11 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param strideX - `x` stride length
* @param offsetX - `x` starting index
* @param strideX - stride length for `x`
* @param offsetX - starting index for `x`
* @param out - output array whose first element is the sum and whose second element is the number of non-NaN elements
* @param strideOut - `out` stride length
* @param offsetOut - `out` starting index
* @param strideOut - stride length for `out`
* @param offsetOut - starting index for `out`
* @returns output array
*
* @example
Expand All @@ -72,9 +72,9 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
* @param strideX - `x` stride length
* @param strideX - stride length for `x`
* @param out - output array whose first element is the sum and whose second element is the number of non-NaN elements
* @param strideOut - `out` stride length
* @param strideOut - stride length for `out`
* @returns output array
*
* @example
Expand Down
23 changes: 10 additions & 13 deletions ext/base/gnannsumkbn/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Float64Array = require( '@stdlib/array/float64' );
var gnannsumkbn = require( './../lib' );

var out;
var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = round( randu()*100.0 );
function rand() {
if ( bernoulli( 0.8 ) > 0 ) {
return discreteUniform( 0, 100 );
}
return NaN;
}

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

out = new Float64Array( 2 );
var out = new Float64Array( 2 );
gnannsumkbn( x.length, x, 1, out, 1 );
console.log( out );
5 changes: 1 addition & 4 deletions ext/base/gnannsumkbn/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@
* // returns [ 1.0, 3 ]
*
* @example
* var floor = require( '@stdlib/math/base/special/floor' );
* var gnannsumkbn = require( '@stdlib/blas/ext/base/gnannsumkbn' );
*
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ];
* var out = [ 0.0, 0 ];
*
* var N = floor( x.length / 2 );
*
* var v = gnannsumkbn.ndarray( N, x, 2, 1, out, 1, 0 );
* var v = gnannsumkbn.ndarray( 5, x, 2, 1, out, 1, 0 );
* // returns [ 5.0, 4 ]
*/

Expand Down
Loading

0 comments on commit e978aee

Please sign in to comment.