From d07ad5c6b79834a828ea025e56506d92d421a1fc Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 24 Mar 2023 14:57:24 -0500 Subject: [PATCH 1/5] feat: add `array/empty` fix #982 --- .../@stdlib/array/empty/README.md | 144 +++++++++ .../array/empty/benchmark/benchmark.js | 264 ++++++++++++++++ .../benchmark/benchmark.length.complex128.js | 93 ++++++ .../benchmark/benchmark.length.complex64.js | 93 ++++++ .../benchmark/benchmark.length.float32.js | 93 ++++++ .../benchmark/benchmark.length.float64.js | 93 ++++++ .../benchmark/benchmark.length.generic.js | 93 ++++++ .../empty/benchmark/benchmark.length.int16.js | 93 ++++++ .../empty/benchmark/benchmark.length.int32.js | 93 ++++++ .../empty/benchmark/benchmark.length.int8.js | 93 ++++++ .../benchmark/benchmark.length.uint16.js | 93 ++++++ .../benchmark/benchmark.length.uint32.js | 93 ++++++ .../empty/benchmark/benchmark.length.uint8.js | 93 ++++++ .../benchmark/benchmark.length.uint8c.js | 93 ++++++ .../@stdlib/array/empty/docs/repl.txt | 52 ++++ .../@stdlib/array/empty/docs/types/index.d.ts | 281 ++++++++++++++++++ .../@stdlib/array/empty/docs/types/test.ts | 77 +++++ .../@stdlib/array/empty/examples/index.js | 33 ++ .../@stdlib/array/empty/lib/index.js | 46 +++ .../@stdlib/array/empty/lib/main.js | 75 +++++ .../@stdlib/array/empty/package.json | 104 +++++++ .../@stdlib/array/empty/test/test.js | 274 +++++++++++++++++ 22 files changed, 2466 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/empty/README.md create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex128.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex64.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float32.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float64.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.generic.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int16.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int32.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int8.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint16.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint32.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8.js create mode 100644 lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8c.js create mode 100644 lib/node_modules/@stdlib/array/empty/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/empty/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/empty/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/empty/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/empty/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/empty/package.json create mode 100644 lib/node_modules/@stdlib/array/empty/test/test.js diff --git a/lib/node_modules/@stdlib/array/empty/README.md b/lib/node_modules/@stdlib/array/empty/README.md new file mode 100644 index 000000000000..cb8cba05b8b2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/README.md @@ -0,0 +1,144 @@ + + +# empty + +> Create an uninitilized array having a specified length. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var empty = require( '@stdlib/array/empty' ); +``` + +#### empty( length\[, dtype] ) + +Creates an uninitilized array having a specified length. + +```javascript +var arr = empty( 2 ); +// returns +``` + +The function recognizes the following data types: + +- `float64`: double-precision floating-point numbers (IEEE 754) +- `float32`: single-precision floating-point numbers (IEEE 754) +- `complex128`: double-precision complex floating-point numbers +- `complex64`: single-precision complex floating-point numbers +- `int32`: 32-bit two's complement signed integers +- `uint32`: 32-bit unsigned integers +- `int16`: 16-bit two's complement signed integers +- `uint16`: 16-bit unsigned integers +- `int8`: 8-bit two's complement signed integers +- `uint8`: 8-bit unsigned integers +- `uint8c`: 8-bit unsigned integers clamped to `0-255` +- `generic`: generic JavaScript values + +By default, the output array data type is `float64` (i.e., a [typed array][mdn-typed-array]). To specify an alternative data type, provide a `dtype` argument. + +```javascript +var arr = empty( 2, 'int32' ); +// returns +``` + +
+ + + + + +
+ +## Notes + +- In browser environments, the function always returns zero-filled arrays. +- If `dtype` is `'generic'`, the function always returns a zero-filled array. +- In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. + +
+ + + + + +
+ +## Examples + + + +```javascript +var dtypes = require( '@stdlib/array/dtypes' ); +var empty = require( '@stdlib/array/empty' ); + +// Get a list of array data types: +var dt = dtypes(); + +// Generate empty arrays... +var arr; +var i; +for ( i = 0; i < dt.length; i++ ) { + arr = empty( 4, dt[ i ] ); + console.log( arr ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.js new file mode 100644 index 000000000000..4cf8d5b879c1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.js @@ -0,0 +1,264 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var empty = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0 ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=float64', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'float64' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=float32', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'float32' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=complex128', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'complex128' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=complex64', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'complex64' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=int32', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'int32' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=uint32', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'uint32' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=int16', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'int16' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=uint16', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'uint16' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=int8', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'int8' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=uint8', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'uint8' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=uint8c', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'uint8c' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':dtype=generic', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = empty( 0, 'generic' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isArray( arr ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex128.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex128.js new file mode 100644 index 000000000000..03a6aec59ff1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex128.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'complex128' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=complex128,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex64.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex64.js new file mode 100644 index 000000000000..c21e4469acb0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.complex64.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'complex64' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArrayLike( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=complex64,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float32.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float32.js new file mode 100644 index 000000000000..18ce2885e778 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float32.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'float32' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=float32,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float64.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float64.js new file mode 100644 index 000000000000..ff0d09ffff33 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.float64.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'float64' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=float64,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.generic.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.generic.js new file mode 100644 index 000000000000..553c67cfd555 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.generic.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'generic' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isArray( arr ) ) { + b.fail( 'should return an array' ); + } + 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( pkg+':dtype=generic,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int16.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int16.js new file mode 100644 index 000000000000..4c7ced1fd6b5 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int16.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'int16' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=int16,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int32.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int32.js new file mode 100644 index 000000000000..e99124b6f9c9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int32.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'int32' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=int32,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int8.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int8.js new file mode 100644 index 000000000000..dfe7ce82a54a --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.int8.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'int8' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=int8,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint16.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint16.js new file mode 100644 index 000000000000..661def4990c7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint16.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'uint16' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=uint16,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint32.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint32.js new file mode 100644 index 000000000000..f1719042a874 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint32.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'uint32' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=uint32,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8.js new file mode 100644 index 000000000000..d2106d864e58 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'uint8' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=uint8,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8c.js b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8c.js new file mode 100644 index 000000000000..16d786b0ca45 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/benchmark/benchmark.length.uint8c.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 isTypedArray = require( '@stdlib/assert/is-typed-array' ); +var pkg = require( './../package.json' ).name; +var empty = 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 = empty( len, 'uint8c' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isTypedArray( arr ) ) { + b.fail( 'should return a typed array' ); + } + 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( pkg+':dtype=uint8c,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/empty/docs/repl.txt b/lib/node_modules/@stdlib/array/empty/docs/repl.txt new file mode 100644 index 000000000000..80f6ccdb6e57 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/docs/repl.txt @@ -0,0 +1,52 @@ + +{{alias}}( length[, dtype] ) + Creates an uninitilized array having a specified length. + + In browser environments, the function always returns zero-filled arrays. + + If `dtype` is 'generic', the function always returns a zero-filled array. + + In Node.js versions >=3.0.0, the underlying memory of returned typed arrays + is *not* initialized. Memory contents are unknown and may contain + *sensitive* data. + + The function supports the following data types: + + - float64: double-precision floating-point numbers (IEEE 754) + - float32: single-precision floating-point numbers (IEEE 754) + - complex128: double-precision complex floating-point numbers + - complex64: single-precision complex floating-point numbers + - int32: 32-bit two's complement signed integers + - uint32: 32-bit unsigned integers + - int16: 16-bit two's complement signed integers + - uint16: 16-bit unsigned integers + - int8: 8-bit two's complement signed integers + - uint8: 8-bit unsigned integers + - uint8c: 8-bit unsigned integers clamped to 0-255 + - generic: generic JavaScript values + + The default array data type is `float64`. + + Parameters + ---------- + length: integer + Array length. + + dtype: string (optional) + Data type. Default: 'float64'. + + Returns + ------- + out: TypedArray|Array + Output array. + + Examples + -------- + > var arr = {{alias}}( 2 ) + + > arr = {{alias}}( 2, 'float32' ) + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts new file mode 100644 index 000000000000..3ca5d8638668 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts @@ -0,0 +1,281 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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: 2.0 + +/// + +import { Complex128Array, Complex64Array, DataType } from '@stdlib/types/array'; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'float64' ); +* // returns +*/ +declare function empty( length: number, dtype: 'float64' ): Float64Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'float32' ); +* // returns +*/ +declare function empty( length: number, dtype: 'float32' ): Float32Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'complex128' ); +* // returns +*/ +declare function empty( length: number, dtype: 'complex128' ): Complex128Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'complex64' ); +* // returns +*/ +declare function empty( length: number, dtype: 'complex64' ): Complex64Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'int32' ); +* // returns +*/ +declare function empty( length: number, dtype: 'int32' ): Int32Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'int16' ); +* // returns +*/ +declare function empty( length: number, dtype: 'int16' ): Int16Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'int8' ); +* // returns +*/ +declare function empty( length: number, dtype: 'int8' ): Int8Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'uint32' ); +* // returns +*/ +declare function empty( length: number, dtype: 'uint32' ): Uint32Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'uint16' ); +* // returns +*/ +declare function empty( length: number, dtype: 'uint16' ): Uint16Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'uint8' ); +* // returns +*/ +declare function empty( length: number, dtype: 'uint8' ): Uint8Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'uint8c' ); +* // returns +*/ +declare function empty( length: number, dtype: 'uint8c' ): Uint8ClampedArray; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - The function always returns a zero-filled array. +* +* @param length - array length +* @param dtype - data type +* @returns empty array +* +* @example +* var arr = empty( 2, 'generic' ); +* // returns +*/ +declare function empty( length: number, dtype: 'generic' ): Array; + +/** +* Creates an uninitilized array having a specified length. +* +* ## Notes +* +* - In browser environments, the function always returns zero-filled arrays. +* - If `dtype` is `'generic'`, the function always returns a zero-filled array. +* - In Node.js versions `>=3.0.0`, the underlying memory of returned typed arrays is **not** initialized. Memory contents are unknown and may contain **sensitive** data. +* +* The function recognizes the following data types: +* +* - `float64`: double-precision floating-point numbers (IEEE 754) +* - `float32`: single-precision floating-point numbers (IEEE 754) +* - `complex128`: double-precision complex floating-point numbers +* - `complex64`: single-precision complex floating-point numbers +* - `int32`: 32-bit two's complement signed integers +* - `uint32`: 32-bit unsigned integers +* - `int16`: 16-bit two's complement signed integers +* - `uint16`: 16-bit unsigned integers +* - `int8`: 8-bit two's complement signed integers +* - `uint8`: 8-bit unsigned integers +* - `uint8c`: 8-bit unsigned integers clamped to `0-255` +* - `generic`: generic JavaScript values +* +* @param length - array length +* @param dtype - data type (default: 'float64') +* @returns empty array +* +* @example +* var arr = empty( 2 ); +* // returns +* +* @example +* var arr = empty( 2, 'float32' ); +* // returns +*/ +declare function empty( length: number, dtype?: DataType ): Float64Array; + + +// EXPORTS // + +export = empty; diff --git a/lib/node_modules/@stdlib/array/empty/docs/types/test.ts b/lib/node_modules/@stdlib/array/empty/docs/types/test.ts new file mode 100644 index 000000000000..303bb77baaf4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/docs/types/test.ts @@ -0,0 +1,77 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 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 empty = require( './index' ); + + +// TESTS // + +// The function returns an array or typed array... +{ + empty( 10 ); // $ExpectType Float64Array + empty( 10, 'float64' ); // $ExpectType Float64Array + empty( 10, 'float32' ); // $ExpectType Float32Array + empty( 10, 'complex128' ); // $ExpectType Complex128Array + empty( 10, 'complex64' ); // $ExpectType Complex64Array + empty( 10, 'int32' ); // $ExpectType Int32Array + empty( 10, 'int16' ); // $ExpectType Int16Array + empty( 10, 'int8' ); // $ExpectType Int8Array + empty( 10, 'uint32' ); // $ExpectType Uint32Array + empty( 10, 'uint16' ); // $ExpectType Uint16Array + empty( 10, 'uint8' ); // $ExpectType Uint8Array + empty( 10, 'uint8c' ); // $ExpectType Uint8ClampedArray + empty( 10, 'generic' ); // $ExpectType number[] +} + +// The compiler throws an error if the function is not provided a number for the first argument... +{ + empty( '5' ); // $ExpectError + empty( false ); // $ExpectError + empty( true ); // $ExpectError + empty( null ); // $ExpectError + empty( undefined ); // $ExpectError + empty( [] ); // $ExpectError + empty( {} ); // $ExpectError + empty( ( x: number ): number => x ); // $ExpectError + + empty( '5', 'float32' ); // $ExpectError + empty( false, 'float32' ); // $ExpectError + empty( true, 'float32' ); // $ExpectError + empty( null, 'float32' ); // $ExpectError + empty( undefined, 'float32' ); // $ExpectError + empty( [], 'float32' ); // $ExpectError + empty( {}, 'float32' ); // $ExpectError + empty( ( x: number ): number => x, 'float32' ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is an unrecognized/unsupported data type... +{ + empty( 10, '10' ); // $ExpectError + empty( 10, 10 ); // $ExpectError + empty( 10, false ); // $ExpectError + empty( 10, true ); // $ExpectError + empty( 10, null ); // $ExpectError + empty( 10, [] ); // $ExpectError + empty( 10, {} ); // $ExpectError + empty( 10, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + empty( 10, 'float64', 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/empty/examples/index.js b/lib/node_modules/@stdlib/array/empty/examples/index.js new file mode 100644 index 000000000000..88d7f4bc58bb --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 dtypes = require( '@stdlib/array/dtypes' ); +var empty = require( './../lib' ); + +// Get a list of array data types: +var dt = dtypes(); + +// Generate empty arrays... +var arr; +var i; +for ( i = 0; i < dt.length; i++ ) { + arr = empty( 4, dt[ i ] ); + console.log( arr ); +} diff --git a/lib/node_modules/@stdlib/array/empty/lib/index.js b/lib/node_modules/@stdlib/array/empty/lib/index.js new file mode 100644 index 000000000000..da808a8e5200 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/lib/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 an uninitilized array having a specified length. +* +* @module @stdlib/array/empty +* +* @example +* var empty = require( '@stdlib/array/empty' ); +* +* var arr = empty( 2 ); +* // returns +* +* @example +* var empty = require( '@stdlib/array/empty' ); +* +* var arr = empty( 2, 'float32' ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/empty/lib/main.js b/lib/node_modules/@stdlib/array/empty/lib/main.js new file mode 100644 index 000000000000..69953d58e862 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/lib/main.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 Complex128 = require( '@stdlib/complex/float64' ); +var Complex64 = require( '@stdlib/complex/float32' ); +var full = require( '@stdlib/array/full' ); + + +// VARIABLES // + +var Z128 = new Complex128( 1.0, 0.0 ); +var Z64 = new Complex64( 1.0, 0.0 ); + + +// MAIN // + +/** +* Creates an uninitilized array having a specified length. +* +* @param {NonNegativeInteger} length - array length +* @param {string} [dtype="float64"] - data type +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a recognized data type +* @returns {(TypedArray|Array|ComplexArray)} array or typed array +* +* @example +* var arr = empty( 2 ); +* // returns +* +* @example +* var arr = empty( 2, 'float32' ); +* // returns +*/ +function empty( length ) { + var dtype; + var value; + + if ( arguments.length > 1 ) { + dtype = arguments[ 1 ]; + } else { + dtype = 'float64'; + } + if ( dtype === 'complex128' ) { + value = Z128; + } else if ( dtype === 'complex64' ) { + value = Z64; + } else { + value = 1; + } + return full( length, value, dtype ); +} + + +// EXPORTS // + +module.exports = empty; diff --git a/lib/node_modules/@stdlib/array/empty/package.json b/lib/node_modules/@stdlib/array/empty/package.json new file mode 100644 index 000000000000..44a1ed68fe61 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/package.json @@ -0,0 +1,104 @@ +{ + "name": "@stdlib/array/empty", + "version": "0.0.0", + "description": "Create an uninitilized array having a specified length.", + "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", + "data", + "structure", + "typed", + "array", + "typed array", + "typed-array", + "vector", + "ndarray", + "matrix", + "float64array", + "float32array", + "int32array", + "uint32array", + "int16array", + "uint16array", + "int8array", + "uint8array", + "uint8clampedarray", + "complex128array", + "complex64array", + "complex128", + "complex64", + "complex", + "cmplx", + "float64", + "double", + "precision", + "double-precision", + "single", + "float", + "single-precision", + "float32", + "ieee754", + "integer", + "int32", + "signed", + "unsigned", + "uint32", + "int16", + "uint16", + "int8", + "uint8", + "uint8c", + "clamped", + "short", + "long", + "generic", + "empty" + ] +} diff --git a/lib/node_modules/@stdlib/array/empty/test/test.js b/lib/node_modules/@stdlib/array/empty/test/test.js new file mode 100644 index 000000000000..6f55a3c555ac --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/test/test.js @@ -0,0 +1,274 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var empty = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof empty, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -3, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + empty( value ); + }; + } +}); + +tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { + var values; + var i; + + values = [ + '5', + -3, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + empty( value, 'float32' ); + }; + } +}); + +tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'empty', + '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() { + empty( 10, value ); + }; + } +}); + +tape( 'the function returns an empty array (default)', function test( t ) { + var arr; + + arr = empty( 5 ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=float64)', function test( t ) { + var arr; + + arr = empty( 5, 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=float32)', function test( t ) { + var arr; + + arr = empty( 5, 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=complex128)', function test( t ) { + var arr; + + arr = empty( 5, 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=complex64)', function test( t ) { + var arr; + + arr = empty( 5, 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=int32)', function test( t ) { + var arr; + + arr = empty( 5, 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint32)', function test( t ) { + var arr; + + arr = empty( 5, 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=int16)', function test( t ) { + var arr; + + arr = empty( 5, 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint16)', function test( t ) { + var arr; + + arr = empty( 5, 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=int8)', function test( t ) { + var arr; + + arr = empty( 5, 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint8)', function test( t ) { + var arr; + + arr = empty( 5, 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint8c)', function test( t ) { + var arr; + + arr = empty( 5, 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { + var expected; + var arr; + + expected = [ 0, 0, 0, 0, 0 ]; + + arr = empty( 5, 'generic' ); + t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); From 3fc6c405c15bd8f810556f9f4f3d63e7fe62822e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Fri, 24 Mar 2023 13:22:14 -0700 Subject: [PATCH 2/5] refactor: update implementation to return uninitialized memory --- .../@stdlib/array/empty/lib/main.js | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/array/empty/lib/main.js b/lib/node_modules/@stdlib/array/empty/lib/main.js index 69953d58e862..be8e3d7f35ce 100644 --- a/lib/node_modules/@stdlib/array/empty/lib/main.js +++ b/lib/node_modules/@stdlib/array/empty/lib/main.js @@ -20,15 +20,12 @@ // MODULES // -var Complex128 = require( '@stdlib/complex/float64' ); -var Complex64 = require( '@stdlib/complex/float32' ); -var full = require( '@stdlib/array/full' ); - - -// VARIABLES // - -var Z128 = new Complex128( 1.0, 0.0 ); -var Z64 = new Complex64( 1.0, 0.0 ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); +var ctors = require( '@stdlib/array/typed-ctors' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var format = require( '@stdlib/string/format' ); // MAIN // @@ -51,22 +48,48 @@ var Z64 = new Complex64( 1.0, 0.0 ); * // returns */ function empty( length ) { + var nbytes; + var offset; var dtype; - var value; + var ctor; + var buf; + var out; + if ( !isNonNegativeInteger( length ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', length ) ); + } if ( arguments.length > 1 ) { dtype = arguments[ 1 ]; } else { dtype = 'float64'; } + if ( dtype === 'generic' ) { + return zeros( length ); + } + nbytes = bytesPerElement( dtype ); + if ( nbytes === null ) { + throw new TypeError( format( 'invalid argument. Second argument must be a supported data type. Value: `%s`.', dtype ) ); + } + // Resolve typed array constructor: + ctor = ctors( dtype ); + + // Compute the number of bytes to allocate: + nbytes *= length; if ( dtype === 'complex128' ) { - value = Z128; - } else if ( dtype === 'complex64' ) { - value = Z64; - } else { - value = 1; + nbytes += 8; // Note: need to allocate additional bytes to ensure alignment + } + // Allocate binary buffer: + buf = allocUnsafe( nbytes ); + + // Resolve the byte offset: + offset = buf.byteOffset; + if ( dtype === 'complex128' ) { + offset += 8; // Note: ensure alignment } - return full( length, value, dtype ); + // Reinterpret the binary buffer: + out = new ctor( buf.buffer, offset, length ); + + return out; } From 43e1ec78660dd83e8e9313bf17aed58c4eea7525 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Fri, 24 Mar 2023 13:43:16 -0700 Subject: [PATCH 3/5] refactor: add polyfill for browsers and older Node.js environments --- .../@stdlib/array/empty/README.md | 4 +- .../@stdlib/array/empty/docs/repl.txt | 2 +- .../@stdlib/array/empty/docs/types/index.d.ts | 26 +- .../@stdlib/array/empty/lib/index.js | 16 +- .../array/empty/lib/is_buffer_uint8array.js | 47 +++ .../@stdlib/array/empty/lib/main.js | 13 +- .../@stdlib/array/empty/lib/polyfill.js | 56 +++ .../@stdlib/array/empty/package.json | 3 +- .../@stdlib/array/empty/test/test.js | 248 +------------- .../@stdlib/array/empty/test/test.main.js | 274 +++++++++++++++ .../@stdlib/array/empty/test/test.polyfill.js | 324 ++++++++++++++++++ 11 files changed, 758 insertions(+), 255 deletions(-) create mode 100644 lib/node_modules/@stdlib/array/empty/lib/is_buffer_uint8array.js create mode 100644 lib/node_modules/@stdlib/array/empty/lib/polyfill.js create mode 100644 lib/node_modules/@stdlib/array/empty/test/test.main.js create mode 100644 lib/node_modules/@stdlib/array/empty/test/test.polyfill.js diff --git a/lib/node_modules/@stdlib/array/empty/README.md b/lib/node_modules/@stdlib/array/empty/README.md index cb8cba05b8b2..f2d13864c19c 100644 --- a/lib/node_modules/@stdlib/array/empty/README.md +++ b/lib/node_modules/@stdlib/array/empty/README.md @@ -20,7 +20,7 @@ limitations under the License. # empty -> Create an uninitilized array having a specified length. +> Create an uninitialized array having a specified length. @@ -42,7 +42,7 @@ var empty = require( '@stdlib/array/empty' ); #### empty( length\[, dtype] ) -Creates an uninitilized array having a specified length. +Creates an uninitialized array having a specified length. ```javascript var arr = empty( 2 ); diff --git a/lib/node_modules/@stdlib/array/empty/docs/repl.txt b/lib/node_modules/@stdlib/array/empty/docs/repl.txt index 80f6ccdb6e57..8f5ae68fd38e 100644 --- a/lib/node_modules/@stdlib/array/empty/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/empty/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( length[, dtype] ) - Creates an uninitilized array having a specified length. + Creates an uninitialized array having a specified length. In browser environments, the function always returns zero-filled arrays. diff --git a/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts index 3ca5d8638668..59ba49fbcc10 100644 --- a/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { Complex128Array, Complex64Array, DataType } from '@stdlib/types/array'; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -41,7 +41,7 @@ import { Complex128Array, Complex64Array, DataType } from '@stdlib/types/array'; declare function empty( length: number, dtype: 'float64' ): Float64Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -59,7 +59,7 @@ declare function empty( length: number, dtype: 'float64' ): Float64Array; declare function empty( length: number, dtype: 'float32' ): Float32Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -77,7 +77,7 @@ declare function empty( length: number, dtype: 'float32' ): Float32Array; declare function empty( length: number, dtype: 'complex128' ): Complex128Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -95,7 +95,7 @@ declare function empty( length: number, dtype: 'complex128' ): Complex128Array; declare function empty( length: number, dtype: 'complex64' ): Complex64Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -113,7 +113,7 @@ declare function empty( length: number, dtype: 'complex64' ): Complex64Array; declare function empty( length: number, dtype: 'int32' ): Int32Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -131,7 +131,7 @@ declare function empty( length: number, dtype: 'int32' ): Int32Array; declare function empty( length: number, dtype: 'int16' ): Int16Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -149,7 +149,7 @@ declare function empty( length: number, dtype: 'int16' ): Int16Array; declare function empty( length: number, dtype: 'int8' ): Int8Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -167,7 +167,7 @@ declare function empty( length: number, dtype: 'int8' ): Int8Array; declare function empty( length: number, dtype: 'uint32' ): Uint32Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -185,7 +185,7 @@ declare function empty( length: number, dtype: 'uint32' ): Uint32Array; declare function empty( length: number, dtype: 'uint16' ): Uint16Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -203,7 +203,7 @@ declare function empty( length: number, dtype: 'uint16' ): Uint16Array; declare function empty( length: number, dtype: 'uint8' ): Uint8Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -221,7 +221,7 @@ declare function empty( length: number, dtype: 'uint8' ): Uint8Array; declare function empty( length: number, dtype: 'uint8c' ): Uint8ClampedArray; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * @@ -238,7 +238,7 @@ declare function empty( length: number, dtype: 'uint8c' ): Uint8ClampedArray; declare function empty( length: number, dtype: 'generic' ): Array; /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * ## Notes * diff --git a/lib/node_modules/@stdlib/array/empty/lib/index.js b/lib/node_modules/@stdlib/array/empty/lib/index.js index da808a8e5200..103bbbb18981 100644 --- a/lib/node_modules/@stdlib/array/empty/lib/index.js +++ b/lib/node_modules/@stdlib/array/empty/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Create an uninitilized array having a specified length. +* Create an uninitialized array having a specified length. * * @module @stdlib/array/empty * @@ -38,9 +38,21 @@ // MODULES // +var isBufferUint8Array = require( './is_buffer_uint8array.js' ); var main = require( './main.js' ); +var polyfill = require( './polyfill.js' ); + + +// MAIN // + +var empty; +if ( isBufferUint8Array() ) { + empty = main; +} else { + empty = polyfill; +} // EXPORTS // -module.exports = main; +module.exports = empty; diff --git a/lib/node_modules/@stdlib/array/empty/lib/is_buffer_uint8array.js b/lib/node_modules/@stdlib/array/empty/lib/is_buffer_uint8array.js new file mode 100644 index 000000000000..e9a918c9d716 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/lib/is_buffer_uint8array.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); +var isUint8Array = require( '@stdlib/assert/is-uint8array' ); + + +// MAIN // + +/** +* Checks whether an environment supports Node.js buffer instances which inherit from `Uint8Array`. +* +* @private +* @returns {boolean} boolean indicating whether an environment supports Node.js buffer instances inheriting from `Uint8Array` +* +* @example +* var bool = check(); +* // returns +*/ +function check() { + var buf = allocUnsafe( 1 ); + return isUint8Array( buf ); +} + + +// EXPORTS // + +module.exports = check; diff --git a/lib/node_modules/@stdlib/array/empty/lib/main.js b/lib/node_modules/@stdlib/array/empty/lib/main.js index be8e3d7f35ce..6a06092ebfa0 100644 --- a/lib/node_modules/@stdlib/array/empty/lib/main.js +++ b/lib/node_modules/@stdlib/array/empty/lib/main.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Creates an uninitilized array having a specified length. +* Creates an uninitialized array having a specified length. * * @param {NonNegativeInteger} length - array length * @param {string} [dtype="float64"] - data type @@ -54,6 +54,7 @@ function empty( length ) { var ctor; var buf; var out; + var nb; if ( !isNonNegativeInteger( length ) ) { throw new TypeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%s`.', length ) ); @@ -74,17 +75,19 @@ function empty( length ) { ctor = ctors( dtype ); // Compute the number of bytes to allocate: - nbytes *= length; + nb = nbytes * length; if ( dtype === 'complex128' ) { - nbytes += 8; // Note: need to allocate additional bytes to ensure alignment + nb += 8; // Note: need to allocate additional bytes to ensure alignment } // Allocate binary buffer: - buf = allocUnsafe( nbytes ); + buf = allocUnsafe( nb ); // Resolve the byte offset: offset = buf.byteOffset; if ( dtype === 'complex128' ) { - offset += 8; // Note: ensure alignment + if ( !isNonNegativeInteger( offset/nbytes ) ) { + offset += 8; // Note: ensure alignment + } } // Reinterpret the binary buffer: out = new ctor( buf.buffer, offset, length ); diff --git a/lib/node_modules/@stdlib/array/empty/lib/polyfill.js b/lib/node_modules/@stdlib/array/empty/lib/polyfill.js new file mode 100644 index 000000000000..1d66e8cc4a7d --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/lib/polyfill.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 zeros = require( '@stdlib/array/zeros' ); + + +// MAIN // + +/** +* Creates an uninitialized array having a specified length. +* +* @private +* @param {NonNegativeInteger} length - array length +* @param {string} [dtype="float64"] - data type +* @throws {TypeError} first argument must be a nonnegative integer +* @throws {TypeError} second argument must be a recognized data type +* @returns {(TypedArray|Array|ComplexArray)} array or typed array +* +* @example +* var arr = empty( 2 ); +* // returns +* +* @example +* var arr = empty( 2, 'float32' ); +* // returns +*/ +function empty( length ) { + if ( arguments.length > 1 ) { + return zeros( length, arguments[ 1 ] ); + } + return zeros( length ); +} + + +// EXPORTS // + +module.exports = empty; diff --git a/lib/node_modules/@stdlib/array/empty/package.json b/lib/node_modules/@stdlib/array/empty/package.json index 44a1ed68fe61..56921972e659 100644 --- a/lib/node_modules/@stdlib/array/empty/package.json +++ b/lib/node_modules/@stdlib/array/empty/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/empty", "version": "0.0.0", - "description": "Create an uninitilized array having a specified length.", + "description": "Create an uninitialized array having a specified length.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -14,6 +14,7 @@ } ], "main": "./lib", + "browser": "./lib/polyfill.js", "directories": { "benchmark": "./benchmark", "doc": "./docs", diff --git a/lib/node_modules/@stdlib/array/empty/test/test.js b/lib/node_modules/@stdlib/array/empty/test/test.js index 6f55a3c555ac..8e62cb82a57f 100644 --- a/lib/node_modules/@stdlib/array/empty/test/test.js +++ b/lib/node_modules/@stdlib/array/empty/test/test.js @@ -21,18 +21,9 @@ // MODULES // var tape = require( 'tape' ); -var Float64Array = require( '@stdlib/array/float64' ); -var Float32Array = require( '@stdlib/array/float32' ); -var Int32Array = require( '@stdlib/array/int32' ); -var Uint32Array = require( '@stdlib/array/uint32' ); -var Int16Array = require( '@stdlib/array/int16' ); -var Uint16Array = require( '@stdlib/array/uint16' ); -var Int8Array = require( '@stdlib/array/int8' ); -var Uint8Array = require( '@stdlib/array/uint8' ); -var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); -var Complex64Array = require( '@stdlib/array/complex64' ); -var Complex128Array = require( '@stdlib/array/complex128' ); -var instanceOf = require( '@stdlib/assert/instance-of' ); +var proxyquire = require( 'proxyquire' ); +var main = require( './../lib/main.js' ); +var polyfill = require( './../lib/polyfill.js' ); var empty = require( './../lib' ); @@ -44,231 +35,26 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - 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() { - empty( value ); - }; - } -}); - -tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { - var values; - var i; - - values = [ - '5', - -3, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } +tape( 'if an environment supports Node.js buffer instances inheriting from Uint8Array, the main export supports returning arrays having uninitialized memory', function test( t ) { + var empty = proxyquire( './../lib', { + './is_buffer_uint8array.js': mock + }); + t.strictEqual( empty, main, 'returns expected value' ); t.end(); - function badValue( value ) { - return function badValue() { - empty( value, 'float32' ); - }; + function mock() { + return true; } }); -tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'empty', - '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] ); - } +tape( 'if an environment does not support Node.js buffer instances inheriting from Uint8Array, the main export supports returning zero-filled arrays', function test( t ) { + var empty = proxyquire( './../lib', { + './is_buffer_uint8array.js': mock + }); + t.strictEqual( empty, polyfill, 'returns expected value' ); t.end(); - function badValue( value ) { - return function badValue() { - empty( 10, value ); - }; + function mock() { + return false; } }); - -tape( 'the function returns an empty array (default)', function test( t ) { - var arr; - - arr = empty( 5 ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=float64)', function test( t ) { - var arr; - - arr = empty( 5, 'float64' ); - t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=float32)', function test( t ) { - var arr; - - arr = empty( 5, 'float32' ); - t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=complex128)', function test( t ) { - var arr; - - arr = empty( 5, 'complex128' ); - t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=complex64)', function test( t ) { - var arr; - - arr = empty( 5, 'complex64' ); - t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=int32)', function test( t ) { - var arr; - - arr = empty( 5, 'int32' ); - t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=uint32)', function test( t ) { - var arr; - - arr = empty( 5, 'uint32' ); - t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=int16)', function test( t ) { - var arr; - - arr = empty( 5, 'int16' ); - t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=uint16)', function test( t ) { - var arr; - - arr = empty( 5, 'uint16' ); - t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=int8)', function test( t ) { - var arr; - - arr = empty( 5, 'int8' ); - t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=uint8)', function test( t ) { - var arr; - - arr = empty( 5, 'uint8' ); - t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns an empty array (dtype=uint8c)', function test( t ) { - var arr; - - arr = empty( 5, 'uint8c' ); - t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); - t.strictEqual( arr.length, 5, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { - var expected; - var arr; - - expected = [ 0, 0, 0, 0, 0 ]; - - arr = empty( 5, 'generic' ); - t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); - t.strictEqual( arr.length, expected.length, 'returns expected value' ); - t.deepEqual( arr, expected, 'returns expected value' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/array/empty/test/test.main.js b/lib/node_modules/@stdlib/array/empty/test/test.main.js new file mode 100644 index 000000000000..bbf8da859851 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/test/test.main.js @@ -0,0 +1,274 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var empty = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof empty, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -3, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + empty( value ); + }; + } +}); + +tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { + var values; + var i; + + values = [ + '5', + -3, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + empty( value, 'float32' ); + }; + } +}); + +tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'empty', + '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() { + empty( 10, value ); + }; + } +}); + +tape( 'the function returns an empty array (default)', function test( t ) { + var arr; + + arr = empty( 5 ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=float64)', function test( t ) { + var arr; + + arr = empty( 5, 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=float32)', function test( t ) { + var arr; + + arr = empty( 5, 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=complex128)', function test( t ) { + var arr; + + arr = empty( 5, 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=complex64)', function test( t ) { + var arr; + + arr = empty( 5, 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=int32)', function test( t ) { + var arr; + + arr = empty( 5, 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint32)', function test( t ) { + var arr; + + arr = empty( 5, 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=int16)', function test( t ) { + var arr; + + arr = empty( 5, 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint16)', function test( t ) { + var arr; + + arr = empty( 5, 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=int8)', function test( t ) { + var arr; + + arr = empty( 5, 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint8)', function test( t ) { + var arr; + + arr = empty( 5, 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty array (dtype=uint8c)', function test( t ) { + var arr; + + arr = empty( 5, 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { + var expected; + var arr; + + expected = [ 0, 0, 0, 0, 0 ]; + + arr = empty( 5, 'generic' ); + t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js b/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js new file mode 100644 index 000000000000..2aa7a6ed26d7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js @@ -0,0 +1,324 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2022 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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var empty = require( './../lib/polyfill.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof empty, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -3, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + empty( value ); + }; + } +}); + +tape( 'the function throws an error if provided a value other than a nonnegative integer for the first argument (dtype)', function test( t ) { + var values; + var i; + + values = [ + '5', + -3, + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + 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() { + empty( value, 'float32' ); + }; + } +}); + +tape( 'the function throws an error if provided an unrecognized data type', function test( t ) { + var values; + var i; + + values = [ + '5', + 'beep', + 'empty', + '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() { + empty( 10, value ); + }; + } +}); + +tape( 'the function returns a zero-filled array (default)', function test( t ) { + var expected; + var arr; + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + arr = empty( 5 ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=float64)', function test( t ) { + var expected; + var arr; + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + arr = empty( 5, 'float64' ); + t.strictEqual( instanceOf( arr, Float64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=float32)', function test( t ) { + var expected; + var arr; + + expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + + arr = empty( 5, 'float32' ); + t.strictEqual( instanceOf( arr, Float32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=complex128)', function test( t ) { + var expected; + var arr; + + expected = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + arr = empty( 2, 'complex128' ); + t.strictEqual( instanceOf( arr, Complex128Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); + t.deepEqual( reinterpret128( arr, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=complex64)', function test( t ) { + var expected; + var arr; + + expected = new Float32Array( [ 0.0, 0.0, 0.0, 0.0 ] ); + + arr = empty( 2, 'complex64' ); + t.strictEqual( instanceOf( arr, Complex64Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length/2, 'returns expected value' ); + t.deepEqual( reinterpret64( arr, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=int32)', function test( t ) { + var expected; + var arr; + + expected = new Int32Array( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'int32' ); + t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=uint32)', function test( t ) { + var expected; + var arr; + + expected = new Uint32Array( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'uint32' ); + t.strictEqual( instanceOf( arr, Uint32Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=int16)', function test( t ) { + var expected; + var arr; + + expected = new Int16Array( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'int16' ); + t.strictEqual( instanceOf( arr, Int16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=uint16)', function test( t ) { + var expected; + var arr; + + expected = new Uint16Array( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'uint16' ); + t.strictEqual( instanceOf( arr, Uint16Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=int8)', function test( t ) { + var expected; + var arr; + + expected = new Int8Array( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'int8' ); + t.strictEqual( instanceOf( arr, Int8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=uint8)', function test( t ) { + var expected; + var arr; + + expected = new Uint8Array( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'uint8' ); + t.strictEqual( instanceOf( arr, Uint8Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=uint8c)', function test( t ) { + var expected; + var arr; + + expected = new Uint8ClampedArray( [ 0, 0, 0, 0, 0 ] ); + + arr = empty( 5, 'uint8c' ); + t.strictEqual( instanceOf( arr, Uint8ClampedArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a zero-filled array (dtype=generic)', function test( t ) { + var expected; + var arr; + + expected = [ 0, 0, 0, 0, 0 ]; + + arr = empty( 5, 'generic' ); + t.strictEqual( instanceOf( arr, Array ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( arr, expected, 'returns expected value' ); + + t.end(); +}); From eb6361489a3c88f6d6aba4aa2bb19b085642c390 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Fri, 24 Mar 2023 14:20:08 -0700 Subject: [PATCH 4/5] docs: update copyright year --- lib/node_modules/@stdlib/array/empty/README.md | 2 +- lib/node_modules/@stdlib/array/empty/test/test.polyfill.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/empty/README.md b/lib/node_modules/@stdlib/array/empty/README.md index f2d13864c19c..7893db0c179b 100644 --- a/lib/node_modules/@stdlib/array/empty/README.md +++ b/lib/node_modules/@stdlib/array/empty/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2022 The Stdlib Authors. +Copyright (c) 2023 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. diff --git a/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js b/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js index 2aa7a6ed26d7..297fbe08033e 100644 --- a/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js +++ b/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2022 The Stdlib Authors. +* Copyright (c) 2023 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. From 81c2ce12a0ca04e2cafcbaf5dea497b65d1d1353 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Fri, 24 Mar 2023 14:25:37 -0700 Subject: [PATCH 5/5] docs: update function description for returning a generic array --- .../@stdlib/array/empty/docs/types/index.d.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts index 59ba49fbcc10..d91bc1d1807d 100644 --- a/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts @@ -221,15 +221,11 @@ declare function empty( length: number, dtype: 'uint8' ): Uint8Array; declare function empty( length: number, dtype: 'uint8c' ): Uint8ClampedArray; /** -* Creates an uninitialized array having a specified length. -* -* ## Notes -* -* - The function always returns a zero-filled array. +* Creates a zero-filled array having a specified length. * * @param length - array length * @param dtype - data type -* @returns empty array +* @returns zero-filled array * * @example * var arr = empty( 2, 'generic' );