From 9d42a6bf9a4eb4bd9165e0aaf9547b36c17b8f42 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 2 Oct 2026 12:35:26 +0200 Subject: [PATCH] feat: add blas/ext/base/ndarray/gnancount Provide the maintainer-requested ndarray interface for counting non-NaN values. Honor selected shape, stride and offset using the existing strided implementation, with declarations, examples and regression coverage. Assisted-by: OpenAI Codex --- .../blas/ext/base/ndarray/gnancount/README.md | 109 +++++++++++ .../ndarray/gnancount/benchmark/benchmark.js | 108 +++++++++++ .../ext/base/ndarray/gnancount/docs/repl.txt | 25 +++ .../ndarray/gnancount/docs/types/index.d.ts | 50 +++++ .../base/ndarray/gnancount/docs/types/test.ts | 66 +++++++ .../base/ndarray/gnancount/examples/index.js | 30 +++ .../ext/base/ndarray/gnancount/lib/index.js | 43 +++++ .../ext/base/ndarray/gnancount/lib/main.js | 60 ++++++ .../ext/base/ndarray/gnancount/package.json | 66 +++++++ .../ext/base/ndarray/gnancount/test/test.js | 179 ++++++++++++++++++ 10 files changed, 736 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/README.md new file mode 100644 index 000000000000..10654cb56804 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/README.md @@ -0,0 +1,109 @@ + + +# gnancount + +> Count the number of non-`NaN` elements in a one-dimensional ndarray. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gnancount = require( '@stdlib/blas/ext/base/ndarray/gnancount' ); +``` + +#### gnancount( arrays ) + +Counts the number of non-`NaN` elements in a one-dimensional ndarray. + +```javascript +var vector = require( '@stdlib/ndarray/vector/ctor' ); + +var x = vector( [ 1.0, NaN, 4.0, NaN ], 'generic' ); + +var v = gnancount( [ x ] ); +// returns 2 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `0`. +- The function supports arbitrary strides and offsets, including negative and zero strides. +- The function supports input ndarrays whose underlying data buffers use accessor protocols. + +
+ + + +
+ +## Examples + + + +```javascript +var vector = require( '@stdlib/ndarray/vector/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gnancount = require( '@stdlib/blas/ext/base/ndarray/gnancount' ); + +var x = vector( [ 1.0, NaN, -2.0, NaN, 3.0 ], 'generic' ); +console.log( ndarray2array( x ) ); + +var v = gnancount( [ x ] ); +console.log( v ); +// => 3 +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/benchmark/benchmark.js new file mode 100644 index 000000000000..afd674cb9c11 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/benchmark/benchmark.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gnancount = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x; + var i; + + x = uniform( [ len ], -10.0, 10.0, options ); + for ( i = 0; i < len; i += 2 ) { + x.set( i, NaN ); + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = gnancount( [ x ] ); + if ( v !== len/2 ) { + b.fail( 'should return expected count' ); + } + } + b.toc(); + if ( v !== len/2 ) { + b.fail( 'should return expected count' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/repl.txt new file mode 100644 index 000000000000..29f7ad13dcf1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/repl.txt @@ -0,0 +1,25 @@ + +{{alias}}( arrays ) + Counts the number of non-NaN elements in a one-dimensional ndarray. + + If provided an empty ndarray, the function returns `0`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Count. + + Examples + -------- + > var vector = {{alias:@stdlib/ndarray/vector/ctor}}; + > var x = vector( [ 1.0, NaN, 3.0 ], 'generic' ); + > {{alias}}( [ x ] ) + 2 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/index.d.ts new file mode 100644 index 000000000000..1820e1c64add --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Counts the number of non-`NaN` elements in a one-dimensional ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* +* @param arrays - array-like object containing ndarrays +* @returns count +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* +* var x = vector( [ 1.0, NaN, 4.0, NaN ], 'generic' ); +* +* var v = gnancount( [ x ] ); +* // returns 2 +*/ +declare function gnancount = typedndarray>( arrays: [ T ] ): number; + + +// EXPORTS // + +export = gnancount; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/test.ts new file mode 100644 index 000000000000..e2309b364185 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import gnancount = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gnancount( [ x ] ); // $ExpectType number + + const y = zeros( [ 10 ], { + 'dtype': 'generic' + }); + gnancount( [ y ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gnancount( '10' ); // $ExpectError + gnancount( 10 ); // $ExpectError + gnancount( true ); // $ExpectError + gnancount( false ); // $ExpectError + gnancount( null ); // $ExpectError + gnancount( undefined ); // $ExpectError + gnancount( [] ); // $ExpectError + gnancount( {} ); // $ExpectError + gnancount( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gnancount( x ); // $ExpectError + gnancount( [ x, x ] ); // $ExpectError + gnancount( [ [ 1, 2, 3 ] ] ); // $ExpectError + + gnancount(); // $ExpectError + gnancount( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/examples/index.js new file mode 100644 index 000000000000..768b79723ac2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var vector = require( '@stdlib/ndarray/vector/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gnancount = require( './../lib' ); + +var x = vector( [ 1.0, NaN, -2.0, NaN, 3.0 ], 'generic' ); +console.log( ndarray2array( x ) ); + +var v = gnancount( [ x ] ); +console.log( v ); +// => 3 diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/index.js new file mode 100644 index 000000000000..22d506ca7f19 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Count the number of non-`NaN` elements in a one-dimensional ndarray. +* +* @module @stdlib/blas/ext/base/ndarray/gnancount +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var gnancount = require( '@stdlib/blas/ext/base/ndarray/gnancount' ); +* +* var x = vector( [ 1.0, NaN, 4.0, NaN ], 'generic' ); +* +* var v = gnancount( [ x ] ); +* // returns 2 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/main.js new file mode 100644 index 000000000000..85f49567dbc1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/lib/main.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/gnancount' ).ndarray; + + +// MAIN // + +/** +* Counts the number of non-`NaN` elements in a one-dimensional ndarray. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {NonNegativeInteger} count +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* +* var x = vector( [ 1.0, NaN, 4.0, NaN ], 'generic' ); +* +* var v = gnancount( [ x ] ); +* // returns 2 +*/ +function gnancount( arrays ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gnancount; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/package.json new file mode 100644 index 000000000000..9369882fc792 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gnancount", + "version": "0.0.0", + "description": "Count the number of non-NaN elements in a one-dimensional ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "blas", + "extended", + "count", + "nan", + "number", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/test/test.js new file mode 100644 index 000000000000..a4a1b7826525 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnancount/test/test.js @@ -0,0 +1,179 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gnancount = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gnancount, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( gnancount.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function counts the number of non-`NaN` elements in a one-dimensional ndarray', function test( t ) { + var x; + var v; + + x = [ 1.0, NaN, -2.0, NaN, 0.0, -0.0, Infinity, -Infinity ]; + v = gnancount( [ vector( x, x.length, 1, 0 ) ] ); + t.strictEqual( v, 6, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = gnancount( [ vector( x, x.length, 1, 0 ) ] ); + t.strictEqual( v, 0, 'returns expected value' ); + + x = [ -4.0, 5.0 ]; + v = gnancount( [ vector( x, x.length, 1, 0 ) ] ); + t.strictEqual( v, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `0`', function test( t ) { + var x; + + x = vector( [], 0, 1, 0 ); + t.strictEqual( gnancount( [ x ] ), 0, 'returns expected value' ); + + x = vector( [ 1.0, 2.0 ], 0, 1, 1 ); + t.strictEqual( gnancount( [ x ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays containing a single element', function test( t ) { + var x; + + x = vector( [ 1.0 ], 1, 1, 0 ); + t.strictEqual( gnancount( [ x ] ), 1, 'returns expected value' ); + + x = vector( [ NaN ], 1, 1, 0 ); + t.strictEqual( gnancount( [ x ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + + x = [ 1.0, NaN, 2.0, NaN, 3.0, NaN, 4.0 ]; + t.strictEqual( gnancount( [ vector( x, 4, 2, 0 ) ] ), 4, 'returns expected value' ); + + x = [ NaN, 1.0, NaN, 2.0, NaN, 3.0, NaN ]; + t.strictEqual( gnancount( [ vector( x, 4, 2, 0 ) ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + + x = [ NaN, 1.0, NaN, 2.0, NaN, 3.0, NaN ]; + t.strictEqual( gnancount( [ vector( x, 3, -2, 5 ) ] ), 3, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 4, -2, 6 ) ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + + x = [ 42.0, NaN, 1.0, NaN, NaN, 99.0 ]; + t.strictEqual( gnancount( [ vector( x, 3, 1, 1 ) ] ), 1, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 2, 2, 1 ) ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having zero strides', function test( t ) { + var x; + + x = [ NaN, 1.0 ]; + t.strictEqual( gnancount( [ vector( x, 5, 0, 1 ) ] ), 5, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 5, 0, 0 ) ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having typed array buffers', function test( t ) { + var x; + + x = new Float64Array( [ NaN, 1.0, NaN, 2.0, NaN ] ); + x = new ndarray( 'float64', x, [ 2 ], [ 2 ], 1, 'row-major' ); + t.strictEqual( gnancount( [ x ] ), 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having accessor array buffers', function test( t ) { + var x; + + x = toAccessorArray( [ NaN, 1.0, NaN, 2.0, NaN, 3.0, NaN ] ); + t.strictEqual( gnancount( [ vector( x, 7, 1, 0 ) ] ), 3, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 3, 2, 1 ) ] ), 3, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 3, -2, 5 ) ] ), 3, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 4, -2, 6 ) ] ), 0, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 5, 0, 1 ) ] ), 5, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 5, 0, 0 ) ] ), 0, 'returns expected value' ); + t.strictEqual( gnancount( [ vector( x, 0, 1, 0 ) ] ), 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an array-like object containing the input ndarray', function test( t ) { + var arrays; + + arrays = { + '0': vector( [ 1.0, NaN, 2.0 ], 3, 1, 0 ), + 'length': 1 + }; + t.strictEqual( gnancount( arrays ), 2, 'returns expected value' ); + t.end(); +});