From b495e0b54d78fa6bfc543c58abf6e0273a7ae346 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 26 Mar 2026 02:52:37 +0500 Subject: [PATCH 1/2] feat: add ndarray/base/nulls --- .../@stdlib/ndarray/base/nulls/README.md | 121 +++++++++++++++ .../ndarray/base/nulls/benchmark/benchmark.js | 48 ++++++ .../nulls/benchmark/benchmark.size.generic.js | 94 ++++++++++++ .../@stdlib/ndarray/base/nulls/docs/repl.txt | 29 ++++ .../ndarray/base/nulls/docs/types/index.d.ts | 47 ++++++ .../ndarray/base/nulls/docs/types/test.ts | 73 +++++++++ .../ndarray/base/nulls/examples/index.js | 25 +++ .../@stdlib/ndarray/base/nulls/lib/index.js | 44 ++++++ .../@stdlib/ndarray/base/nulls/lib/main.js | 54 +++++++ .../@stdlib/ndarray/base/nulls/package.json | 66 ++++++++ .../@stdlib/ndarray/base/nulls/test/test.js | 142 ++++++++++++++++++ 11 files changed, 743 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.size.generic.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/nulls/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/README.md b/lib/node_modules/@stdlib/ndarray/base/nulls/README.md new file mode 100644 index 000000000000..e9409795582e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/README.md @@ -0,0 +1,121 @@ + + +# nulls + +> Create a null-filled [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var nulls = require( '@stdlib/ndarray/base/nulls' ); +``` + +#### nulls( dtype, shape, order ) + +Creates a null-filled [ndarray][@stdlib/ndarray/base/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes]. + +```javascript +var getDType = require( '@stdlib/ndarray/dtype' ); + +var arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); +// returns [ [ null, null ], [ null, null ] ] + +var dt = String( getDType( arr ) ); +// returns 'generic' +``` + +The function accepts the following arguments: + +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be `'generic'`. +- **shape**: array shape. +- **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nulls = require( '@stdlib/ndarray/base/nulls' ); + +var arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); +console.log( ndarray2array( arr ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.js new file mode 100644 index 000000000000..b48f903c32ba --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nulls = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:dtype=generic', pkg ), function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nulls( 'generic', [ 0 ], 'row-major' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.size.generic.js b/lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.size.generic.js new file mode 100644 index 000000000000..438260772fbe --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/benchmark/benchmark.size.generic.js @@ -0,0 +1,94 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nulls = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var arr; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = nulls( 'generic', [ len ], 'row-major' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isndarrayLike( arr ) ) { + b.fail( 'should return an ndarray' ); + } + 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:dtype=generic,size=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt new file mode 100644 index 000000000000..638b5b154f55 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( dtype, shape, order ) + Returns a null-filled ndarray having a specified shape and data type. + + Parameters + ---------- + dtype: string|DataType + Underlying data type. Must be "generic". + + shape: ArrayLikeObject + Array shape. + + order: string + Specifies whether an array is row-major (C-style) or column-major + (Fortran-style). + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var arr = {{alias}}( 'generic', [ 2, 2 ], 'row-major' ) + [ [ null, null ], [ null, null ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/index.d.ts new file mode 100644 index 000000000000..98ce13475457 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/index.d.ts @@ -0,0 +1,47 @@ +/* +* @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 { Shape, Order, genericndarray, GenericDataType } from '@stdlib/types/ndarray'; + +/** +* Creates a null-filled array having a specified shape and data type. +* +* @param dtype - underlying data type +* @param shape - array shape +* @param order - specifies whether an array is row-major (C-style) or column-major (Fortran-style) +* @returns null-filled array +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); +* // returns [ [ null, null ], [ null, null ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'generic' +*/ +declare function nulls( dtype: GenericDataType, shape: Shape, order: Order ): genericndarray; + + +// EXPORTS // + +export = nulls; diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/test.ts new file mode 100644 index 000000000000..8a6d5426f9a8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/types/test.ts @@ -0,0 +1,73 @@ +/* +* @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. +*/ + +import nulls = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + nulls( 'generic', [ 2, 2 ], 'row-major' ); // $ExpectType genericndarray + nulls( 'generic', [ 2, 2 ], 'column-major' ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is an unrecognized/unsupported data type... +{ + nulls( '10', [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( 10, [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( false, [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( true, [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( null, [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( [], [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( {}, [ 2, 2 ], 'row-major' ); // $ExpectError + nulls( ( x: number ): number => x, [ 2, 2 ], 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid shape for the second argument... +{ + nulls( 'generic', '10', 'row-major' ); // $ExpectError + nulls( 'generic', 10, 'row-major' ); // $ExpectError + nulls( 'generic', false, 'row-major' ); // $ExpectError + nulls( 'generic', true, 'row-major' ); // $ExpectError + nulls( 'generic', null, 'row-major' ); // $ExpectError + nulls( 'generic', undefined, 'row-major' ); // $ExpectError + nulls( 'generic', [ '5' ], 'row-major' ); // $ExpectError + nulls( 'generic', {}, 'row-major' ); // $ExpectError + nulls( 'generic', ( x: number ): number => x, 'row-major' ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a valid order for the third argument... +{ + nulls( 'generic', [ 2, 2 ], '10' ); // $ExpectError + nulls( 'generic', [ 2, 2 ], 10 ); // $ExpectError + nulls( 'generic', [ 2, 2 ], false ); // $ExpectError + nulls( 'generic', [ 2, 2 ], true ); // $ExpectError + nulls( 'generic', [ 2, 2 ], null ); // $ExpectError + nulls( 'generic', [ 2, 2 ], undefined ); // $ExpectError + nulls( 'generic', [ 2, 2 ], [ '5' ] ); // $ExpectError + nulls( 'generic', [ 2, 2 ], {} ); // $ExpectError + nulls( 'generic', [ 2, 2 ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + nulls( 'generic' ); // $ExpectError + nulls( 'generic', [ 2, 2 ] ); // $ExpectError + nulls( 'generic', [ 2, 2 ], 'row-major', 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/nulls/examples/index.js new file mode 100644 index 000000000000..42a07ad42e09 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/examples/index.js @@ -0,0 +1,25 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var nulls = require( './../lib' ); + +var arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); +console.log( ndarray2array( arr ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/nulls/lib/index.js new file mode 100644 index 000000000000..79565aa29fc2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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'; + +/** +* Create a null-filled ndarray having a specified shape and data type. +* +* @module @stdlib/ndarray/base/nulls +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* var nulls = require( '@stdlib/ndarray/base/nulls' ); +* +* var arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); +* // returns [ [ null, null ], [ null, null ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'generic' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nulls/lib/main.js new file mode 100644 index 000000000000..b0273faf68fa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/lib/main.js @@ -0,0 +1,54 @@ +/** +* @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 empty = require( '@stdlib/ndarray/base/empty' ); +var fill = require( '@stdlib/ndarray/base/fill' ); + + +// MAIN // + +/** +* Creates a null-filled ndarray having a specified shape and data type. +* +* @param {*} dtype - data type +* @param {NonNegativeIntegerArray} shape - array shape +* @param {string} order - array order +* @throws {TypeError} first argument must be a recognized data type +* @returns {ndarray} ndarray +* +* @example +* var getDType = require( '@stdlib/ndarray/dtype' ); +* +* var arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); +* // returns [ [ null, null ], [ null, null ] ] +* +* var dt = String( getDType( arr ) ); +* // returns 'generic' +*/ +function nulls( dtype, shape, order ) { + return fill( empty( dtype, shape, order ), null ); +} + + +// EXPORTS // + +module.exports = nulls; diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/package.json b/lib/node_modules/@stdlib/ndarray/base/nulls/package.json new file mode 100644 index 000000000000..84b37920cd9b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/nulls", + "version": "0.0.0", + "description": "Create a null-filled ndarray having a specified shape and data type.", + "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", + "stdtypes", + "types", + "base", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "fill", + "filled", + "nulls", + "null" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nulls/test/test.js new file mode 100644 index 000000000000..14d6d4012e3c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/test/test.js @@ -0,0 +1,142 @@ +/** +* @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 instanceOf = require( '@stdlib/assert/instance-of' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var nulls = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nulls, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'nulls', + 'Int32', + 'Uint32', + 'Int16', + 'Uint16', + 'Int8', + 'Uint8', + 'Uint8c', + 'uint8_clamped', + 'Float64', + 'Float32', + 'FLOAT64', + 'FLOAT32', + 'GENERIC' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nulls( value, 10, 'row-major' ); + }; + } +}); + +tape( 'the function returns a null-filled array (dtype=generic, order=row-major)', function test( t ) { + var expected; + var arr; + + expected = [ null, null, null, null ]; + + arr = nulls( 'generic', [ 2, 2 ], 'row-major' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a null-filled array (dtype=generic, order=column-major)', function test( t ) { + var expected; + var arr; + + expected = [ null, null, null, null ]; + + arr = nulls( 'generic', [ 2, 2 ], 'column-major' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'column-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports zero-dimensional arrays', function test( t ) { + var expected; + var arr; + + expected = [ null ]; + + arr = nulls( 'generic', [], 'row-major' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports empty arrays', function test( t ) { + var expected; + var arr; + + expected = []; + + arr = nulls( 'generic', [ 2, 0, 2 ], 'row-major' ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 0, 2 ], 'returns expected value' ); + t.strictEqual( instanceOf( getData( arr ), Array ), true, 'returns expected value' ); + t.deepEqual( getData( arr ), expected, 'returns expected value' ); + t.strictEqual( getOrder( arr ), 'row-major', 'returns expected value' ); + + t.end(); +}); From 9cb7d735d5ca048d7907068851fb28be619b7998 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 25 Mar 2026 20:39:33 -0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/nulls/README.md | 2 +- lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/README.md b/lib/node_modules/@stdlib/ndarray/base/nulls/README.md index e9409795582e..d2278cf40738 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nulls/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/README.md @@ -56,7 +56,7 @@ var dt = String( getDType( arr ) ); The function accepts the following arguments: -- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be `'generic'`. +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a "generic" [data type][@stdlib/ndarray/dtypes]. - **shape**: array shape. - **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). diff --git a/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt index 638b5b154f55..8b070b1f9feb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/nulls/docs/repl.txt @@ -5,7 +5,7 @@ Parameters ---------- dtype: string|DataType - Underlying data type. Must be "generic". + Underlying data type. Must be a "generic" data type. shape: ArrayLikeObject Array shape.