Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update blas/ext/base/sdsnansum to follow current project conventions #1773

Merged
merged 19 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
48 changes: 19 additions & 29 deletions lib/node_modules/@stdlib/blas/ext/base/sdsnansum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@license Apache-2.0

Copyright (c) 2020 The Stdlib Authors.
Copyright (c) 2024 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.
Expand Down Expand Up @@ -44,28 +44,25 @@ Computes the sum of single-precision floating-point strided array elements, igno
var Float32Array = require( '@stdlib/array/float32' );

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

var v = sdsnansum( N, x, 1 );
var v = sdsnansum( 4, 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`.
- **stride**: index increment for the strided array.

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, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] );
var N = floor( x.length / 2 );

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

Expand All @@ -75,14 +72,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, NaN, -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 = sdsnansum( N, x1, 2 );
var v = sdsnansum( 4, x1, 2 );
// returns 5.0
```

Expand All @@ -102,18 +96,16 @@ var v = sdsnansum.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, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var N = floor( x.length / 2 );

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

Expand All @@ -139,22 +131,20 @@ var v = sdsnansum.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 sdsnansum = require( '@stdlib/blas/ext/base/sdsnansum' );

var x;
var i;

x = new Float32Array( 10 );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = round( randu()*100.0 );
function randOrNan( ) {
var rand100 = discreteUniform( 0, 100 );
var rand10 = discreteUniform( 0, 10 );
if ( rand10() < 2 ) {
return NaN;
}
return rand100();
}

var x = filledarrayBy( 10, 'float32', randOrNan );
console.log( x );

var v = sdsnansum( x.length, x, 1 );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2024 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.
Expand All @@ -21,16 +21,25 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var sdsnansum = require( './../lib/sdsnansum.js' );


// FUNCTIONS //

function randOrNan( ) {
var randReslut = uniform( -20.0, -10.0 );
var rand1 = uniform( 0.0, 1.0 );
if ( rand1() < 0.2 ) {
return NaN;
}
return randReslut();
}

/**
* Creates a benchmark function.
*
Expand All @@ -39,17 +48,7 @@ var sdsnansum = require( './../lib/sdsnansum.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
var x = filledarrayBy( len, 'float32', randOrNan );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2024 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.
Expand All @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -40,6 +40,15 @@ var opts = {

// FUNCTIONS //

function randOrNan( ) {
var randReslut = uniform( -20.0, -10.0 );
var rand1 = uniform( 0.0, 1.0 );
if ( rand1() < 0.2 ) {
return NaN;
}
return randReslut();
}

/**
* Creates a benchmark function.
*
Expand All @@ -48,17 +57,7 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
var x = filledarrayBy( len, 'float32', randOrNan );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2024 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.
Expand All @@ -21,16 +21,25 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var sdsnansum = require( './../lib/ndarray.js' );


// FUNCTIONS //

function randOrNan( ) {
var randReslut = uniform( -20.0, -10.0 );
var rand1 = uniform( 0.0, 1.0 );
if ( rand1() < 0.2 ) {
return NaN;
}
return randReslut();
}

/**
* Creates a benchmark function.
*
Expand All @@ -39,17 +48,7 @@ var sdsnansum = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
var x = filledarrayBy( len, 'float32', randOrNan );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2024 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.
Expand All @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
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 Float32Array = require( '@stdlib/array/float32' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -40,6 +40,15 @@ var opts = {

// FUNCTIONS //

function randOrNan( ) {
var randReslut = uniform( -20.0, -10.0 );
var rand1 = uniform( 0.0, 1.0 );
if ( rand1() < 0.2 ) {
return NaN;
}
return randReslut();
}

/**
* Creates a benchmark function.
*
Expand All @@ -48,17 +57,7 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = new Float32Array( len );
for ( i = 0; i < x.length; i++ ) {
if ( randu() < 0.2 ) {
x[ i ] = NaN;
} else {
x[ i ] = ( randu()*10.0 ) - 20.0;
}
}
var x = filledarrayBy( len, 'float32', randOrNan );
return benchmark;

function benchmark( b ) {
Expand Down
18 changes: 9 additions & 9 deletions lib/node_modules/@stdlib/blas/ext/base/sdsnansum/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

{{alias}}( N, x, stride )
Computes the sum of single-precision floating-point strided array elements,
ignoring `NaN` values and using extended accumulation.
Computes the sum of single-precision
floating-point strided array elements,
ignore `NaN` values and using extended accumulation.
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

The `N` and `stride` parameters determine which elements in `x` are accessed
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
Expand Down Expand Up @@ -36,19 +38,18 @@

// Using `N` and `stride` parameters:
> x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> var stride = 2;
> {{alias}}( N, x, stride )
> {{alias}}( 4, 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, NaN, NaN ] );
> 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}}( 4, x1, stride )
-1.0


{{alias}}.ndarray( N, x, stride, offset )
Computes the sum of single-precision floating-point strided array elements,
ignoring `NaN` values and using extended accumulation and alternative
Expand Down Expand Up @@ -86,8 +87,7 @@

// Using offset parameter:
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] );
kgryte marked this conversation as resolved.
Show resolved Hide resolved
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, x, 2, 1 )
> {{alias}}.ndarray( 4, x, 2, 1 )
-1.0

See Also
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
kgryte marked this conversation as resolved.
Show resolved Hide resolved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading
Loading