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 Apr 15, 2024
1 parent 0adfd83 commit 65d6f68
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 255 deletions.
33 changes: 10 additions & 23 deletions ext/base/sdssum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ The function has the following parameters:

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

The `N` and `stride` parameters determine which elements in `x` 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 in the strided array,

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

var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
var N = floor( x.length / 2 );

var v = sdssum( N, x, 2 );
var v = sdssum( 4, x, 2 );
// returns 5.0
```

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

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

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

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

var v = sdssum( N, x1, 2 );
var v = sdssum( 4, x1, 2 );
// returns 5.0
```

Expand All @@ -102,18 +97,16 @@ var v = sdssum.ndarray( N, x, 1, 0 );

The function has the following additional parameters:

- **offset**: starting index for `x`.
- **offset**: starting index for the strided array.

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 value in the strided array starting from the second value

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

var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var N = floor( x.length / 2 );

var v = sdssum.ndarray( N, x, 2, 1 );
var v = sdssum.ndarray( 4, x, 2, 1 );
// returns 5.0
```

Expand All @@ -139,18 +132,12 @@ var v = sdssum.ndarray( N, x, 2, 1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float32Array = require( '@stdlib/array/float32' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var sdssum = require( '@stdlib/blas/ext/base/sdssum' );

var x;
var i;
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );

x = new Float32Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*100.0 );
}
console.log( x );

var v = sdssum( x.length, x, 1 );
Expand Down
16 changes: 8 additions & 8 deletions ext/base/sdssum/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var pkg = require( './../package.json' ).name;
var sdssum = require( './../lib/sdssum.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,13 +44,8 @@ var sdssum = require( './../lib/sdssum.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float32', rand );

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
return benchmark;

function benchmark( b ) {
Expand Down
12 changes: 4 additions & 8 deletions ext/base/sdssum/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var pkg = require( './../package.json' ).name;


Expand All @@ -36,6 +36,7 @@ var sdssum = tryRequire( resolve( __dirname, './../lib/sdssum.native.js' ) );
var opts = {
'skip': ( sdssum instanceof Error )
};
var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //
Expand All @@ -48,13 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float32', rand );

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
return benchmark;

function benchmark( b ) {
Expand Down
18 changes: 9 additions & 9 deletions ext/base/sdssum/benchmark/benchmark.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var sdssum = require( './../lib/ndarray.js' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -39,13 +44,8 @@ var sdssum = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float32', rand );

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
return benchmark;

function benchmark( b ) {
Expand Down
12 changes: 4 additions & 8 deletions ext/base/sdssum/benchmark/benchmark.ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var pkg = require( './../package.json' ).name;


Expand All @@ -36,6 +36,7 @@ var sdssum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( sdssum instanceof Error )
};
var rand = uniform( -10.0, 10.0 );


// FUNCTIONS //
Expand All @@ -48,13 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;
var x = filledarrayBy( len, 'float32', rand );

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
return benchmark;

function benchmark( b ) {
Expand Down
18 changes: 8 additions & 10 deletions ext/base/sdssum/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Computes the sum of single-precision floating-point strided array elements
using extended accumulation.

The `N` and `stride` parameters determine which elements in `x` are accessed
at runtime.
The `N` and stride parameters determine which elements in
the strided array are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
array view.
Expand Down Expand Up @@ -34,27 +34,26 @@
> {{alias}}( x.length, x, 1 )
1.0

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> var stride = 2;
> {{alias}}( N, x, stride )
> {{alias}}( 3, x, stride )
1.0

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


{{alias}}.ndarray( N, x, stride, offset )
Computes the sum of single-precision floating-point strided array elements
using extended accumulation 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
buffer, the offset parameter supports indexing semantics based on a
starting index.

Parameters
Expand Down Expand Up @@ -85,8 +84,7 @@

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

See Also
Expand Down
12 changes: 3 additions & 9 deletions ext/base/sdssum/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float32Array = require( '@stdlib/array/float32' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var sdssum = require( './../lib' );

var x;
var i;
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );

x = new Float32Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu()*100.0 );
}
console.log( x );

var v = sdssum( x.length, x, 1 );
Expand Down
2 changes: 1 addition & 1 deletion ext/base/sdssum/include.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Source files:
'src_files': [
'<(src_dir)/addon.cpp',
'<(src_dir)/addon.c',
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
],

Expand Down
9 changes: 4 additions & 5 deletions ext/base/sdssum/lib/ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

// MODULES //

var Float32Array = require( '@stdlib/array/float32' );
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var offsetView = require( '@stdlib/strided/base/offset-view' );
var addon = require( './sdssum.native.js' );


Expand All @@ -47,10 +48,8 @@ var addon = require( './sdssum.native.js' );
*/
function sdssum( N, x, stride, offset ) {
var view;
if ( stride < 0 ) {
offset += (N-1) * stride;
}
view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
offset = minViewBufferIndex( N, stride, offset );
view = offsetView( x, offset );
return addon( N, view, stride );
}

Expand Down
Loading

0 comments on commit 65d6f68

Please sign in to comment.