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..7893db0c179b --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/README.md @@ -0,0 +1,144 @@ + + +# empty + +> Create an uninitialized array having a specified length. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var empty = require( '@stdlib/array/empty' ); +``` + +#### empty( length\[, dtype] ) + +Creates an uninitialized 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..8f5ae68fd38e --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/docs/repl.txt @@ -0,0 +1,52 @@ + +{{alias}}( length[, dtype] ) + Creates an uninitialized 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..d91bc1d1807d --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/docs/types/index.d.ts @@ -0,0 +1,277 @@ +/* +* @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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 uninitialized 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 a zero-filled array having a specified length. +* +* @param length - array length +* @param dtype - data type +* @returns zero-filled array +* +* @example +* var arr = empty( 2, 'generic' ); +* // returns +*/ +declare function empty( length: number, dtype: 'generic' ): Array; + +/** +* Creates an uninitialized 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..103bbbb18981 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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 uninitialized 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 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 = 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 new file mode 100644 index 000000000000..6a06092ebfa0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/lib/main.js @@ -0,0 +1,101 @@ +/** +* @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 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 // + +/** +* Creates an uninitialized 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 nbytes; + var offset; + var dtype; + 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 ) ); + } + 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: + nb = nbytes * length; + if ( dtype === 'complex128' ) { + nb += 8; // Note: need to allocate additional bytes to ensure alignment + } + // Allocate binary buffer: + buf = allocUnsafe( nb ); + + // Resolve the byte offset: + offset = buf.byteOffset; + if ( dtype === 'complex128' ) { + if ( !isNonNegativeInteger( offset/nbytes ) ) { + offset += 8; // Note: ensure alignment + } + } + // Reinterpret the binary buffer: + out = new ctor( buf.buffer, offset, length ); + + return out; +} + + +// EXPORTS // + +module.exports = empty; 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 new file mode 100644 index 000000000000..56921972e659 --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/package.json @@ -0,0 +1,105 @@ +{ + "name": "@stdlib/array/empty", + "version": "0.0.0", + "description": "Create an uninitialized 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", + "browser": "./lib/polyfill.js", + "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..8e62cb82a57f --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/test/test.js @@ -0,0 +1,60 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var main = require( './../lib/main.js' ); +var polyfill = require( './../lib/polyfill.js' ); +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( '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 mock() { + return true; + } +}); + +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 mock() { + return false; + } +}); 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..297fbe08033e --- /dev/null +++ b/lib/node_modules/@stdlib/array/empty/test/test.polyfill.js @@ -0,0 +1,324 @@ +/** +* @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 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(); +});