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
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/gnansum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ var v = gnansum.ndarray( 5, x, 2, 1 );
## Notes

- If `N <= 0`, both functions return `0.0`.
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor])
- Depending on the environment, the typed versions ([`dnansum`][@stdlib/blas/ext/base/dnansum], [`snansum`][@stdlib/blas/ext/base/snansum], etc.) are likely to be significantly more performant.

</section>
Expand Down Expand Up @@ -176,6 +177,8 @@ console.log( v );

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

[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor

<!-- <related-links> -->

[@stdlib/blas/ext/base/dnansum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dnansum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

/// <reference types="@stdlib/types"/>

import { NumericArray } from '@stdlib/types/array';
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';

/**
* Input array.
*/
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;

/**
* Interface describing `gnansum`.
Expand All @@ -40,7 +45,7 @@ interface Routine {
* var v = gnansum( x.length, x, 1 );
* // returns 1.0
*/
( N: number, x: NumericArray, strideX: number ): number;
( N: number, x: InputArray, strideX: number ): number;

/**
* Computes the sum of strided array elements, ignoring `NaN` values and using alternative indexing semantics.
Expand All @@ -57,7 +62,7 @@ interface Routine {
* var v = gnansum.ndarray( x.length, x, 1, 0 );
* // returns 1.0
*/
ndarray( N: number, x: NumericArray, strideX: number, offsetX: number ): number;
ndarray( N: number, x: InputArray, strideX: number, offsetX: number ): number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import AccessorArray = require( '@stdlib/array/base/accessor' );
import gnansum = require( './index' );


Expand All @@ -26,6 +27,7 @@ import gnansum = require( './index' );
const x = new Float64Array( 10 );

gnansum( x.length, x, 1 ); // $ExpectType number
gnansum( x.length, new AccessorArray( x ), 1 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a first argument which is not a number...
Expand Down Expand Up @@ -85,6 +87,7 @@ import gnansum = require( './index' );
const x = new Float64Array( 10 );

gnansum.ndarray( x.length, x, 1, 0 ); // $ExpectType number
gnansum.ndarray( x.length, new AccessorArray( x ), 1, 0 ); // $ExpectType number
}

// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
Expand Down
106 changes: 106 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/gnansum/test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var Float64Array = require( '@stdlib/array/float64' );
var gnansum = require( './../lib' );

Expand Down Expand Up @@ -73,6 +74,41 @@ tape( 'the function calculates the sum of strided array elements (ignoring NaN v
t.end();
});

tape( 'the function calculates the sum of strided array elements (ignoring NaN values, accessors)', function test( t ) {
var x;
var v;

x = [ 1.0, -2.0, -4.0, 5.0, 0.0, NaN, 3.0, 0.0, -3.0, 3.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, 3.0, 'returns expected value' );

x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, 3.0, 'returns expected value' );

x = [ -4.0, NaN, -4.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, -8.0, 'returns expected value' );

x = [ NaN, 4.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, 4.0, 'returns expected value' );

x = [ NaN, NaN ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, 0.0, 'returns expected value' );

x = [ NaN ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, 0.0, 'returns expected value' );

x = [ 1.0, 1.0e100, 1.0, -1.0e100 ];
v = gnansum( x.length, toAccessorArray( x ), 1 );
t.strictEqual( v, 2.0, 'returns expected value' );

t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test( t ) {
var x;
var v;
Expand Down Expand Up @@ -123,6 +159,29 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
t.end();
});

tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
var x;
var v;

x = [
1.0, // 0
2.0,
2.0, // 1
-7.0,
-2.0, // 2
3.0,
4.0, // 3
2.0,
NaN, // 4
NaN
];

v = gnansum( 5, toAccessorArray( x ), 2 );

t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});

tape( 'the function supports a negative `stride` parameter', function test( t ) {
var x;
var v;
Expand All @@ -146,6 +205,29 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
t.end();
});

tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
var x;
var v;

x = [
NaN, // 4
NaN,
1.0, // 3
2.0,
2.0, // 2
-7.0,
-2.0, // 1
3.0,
4.0, // 0
2.0
];

v = gnansum( 5, toAccessorArray( x ), -2 );

t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) {
var x;
var v;
Expand All @@ -158,6 +240,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the s
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times (accessors)', function test( t ) {
var x;
var v;

x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];

v = gnansum( x.length, toAccessorArray( x ), 0 );
t.strictEqual( v, 5.0, 'returns expected value' );

t.end();
});

tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', function test( t ) {
var x;
var v;
Expand All @@ -170,6 +264,18 @@ tape( 'if provided a `stride` parameter equal to `0` and the first element is Na
t.end();
});

tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0 (accessors)', function test( t ) {
var x;
var v;

x = [ NaN, -2.0, -4.0, 5.0, 3.0 ];

v = gnansum( x.length, toAccessorArray( x ), 0 );
t.strictEqual( v, 0.0, 'returns expected value' );

t.end();
});

tape( 'the function supports view offsets', function test( t ) {
var x0;
var x1;
Expand Down
129 changes: 129 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/gnansum/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var gnansum = require( './../lib/ndarray.js' );


Expand Down Expand Up @@ -72,6 +73,41 @@ tape( 'the function calculates the sum of strided array elements (ignoring NaN v
t.end();
});

tape( 'the function calculates the sum of strided array elements (ignoring NaN values, accessors)', function test( t ) {
var x;
var v;

x = [ 1.0, -2.0, -4.0, 5.0, 0.0, NaN, 3.0, 0.0, -3.0, 3.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, 3.0, 'returns expected value' );

x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, 3.0, 'returns expected value' );

x = [ -4.0, NaN, -4.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, -8.0, 'returns expected value' );

x = [ NaN, 4.0 ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, 4.0, 'returns expected value' );

x = [ NaN, NaN ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, 0.0, 'returns expected value' );

x = [ NaN ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, 0.0, 'returns expected value' );

x = [ 1.0, 1.0e100, 1.0, -1.0e100 ];
v = gnansum( x.length, toAccessorArray( x ), 1, 0 );
t.strictEqual( v, 2.0, 'returns expected value' );

t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0.0`', function test( t ) {
var x;
var v;
Expand Down Expand Up @@ -122,6 +158,29 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
t.end();
});

tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
var x;
var v;

x = [
1.0, // 0
2.0,
2.0, // 1
-7.0,
-2.0, // 2
3.0,
4.0, // 3
2.0,
NaN, // 4
NaN
];

v = gnansum( 5, toAccessorArray( x ), 2, 0 );

t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});

tape( 'the function supports a negative `stride` parameter', function test( t ) {
var x;
var v;
Expand All @@ -145,6 +204,29 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
t.end();
});

tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
var x;
var v;

x = [
NaN, // 4
NaN,
1.0, // 3
2.0,
2.0, // 2
-7.0,
-2.0, // 1
3.0,
4.0, // 0
2.0
];

v = gnansum( 5, toAccessorArray( x ), -2, 8 );

t.strictEqual( v, 5.0, 'returns expected value' );
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) {
var x;
var v;
Expand All @@ -157,6 +239,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the s
t.end();
});

tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times (accessors)', function test( t ) {
var x;
var v;

x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];

v = gnansum( x.length, toAccessorArray( x ), 0, 0 );
t.strictEqual( v, 5.0, 'returns expected value' );

t.end();
});

tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', function test( t ) {
var x;
var v;
Expand All @@ -169,6 +263,18 @@ tape( 'if provided a `stride` parameter equal to `0` and the first element is Na
t.end();
});

tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0 (accessors)', function test( t ) {
var x;
var v;

x = [ NaN, -2.0, -4.0, 5.0, 3.0 ];

v = gnansum( x.length, toAccessorArray( x ), 0, 0 );
t.strictEqual( v, 0.0, 'returns expected value' );

t.end();
});

tape( 'the function supports an `offset` parameter', function test( t ) {
var x;
var v;
Expand All @@ -191,3 +297,26 @@ tape( 'the function supports an `offset` parameter', function test( t ) {

t.end();
});

tape( 'the function supports an `offset` parameter', function test( t ) {
var x;
var v;

x = [
2.0,
1.0, // 0
2.0,
-2.0, // 1
-2.0,
2.0, // 2
3.0,
4.0, // 3
NaN,
NaN // 4
];

v = gnansum( 5, toAccessorArray( x ), 2, 1 );
t.strictEqual( v, 5.0, 'returns expected value' );

t.end();
});