diff --git a/lib/node_modules/@stdlib/array/typed/README.md b/lib/node_modules/@stdlib/array/typed/README.md index 760178a9f5ee..f5cd4e25b55c 100644 --- a/lib/node_modules/@stdlib/array/typed/README.md +++ b/lib/node_modules/@stdlib/array/typed/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2024 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. @@ -18,7 +18,7 @@ limitations under the License. --> -# Typed Arrays +# typedarray > Create a typed array. @@ -42,28 +42,14 @@ var typedarray = require( '@stdlib/array/typed' ); #### typedarray( \[dtype] ) -Creates a [typed array][mdn-typed-array] having a specified data type `dtype`. +Creates a [typed array][mdn-typed-array] having a specified [data type][@stdlib/array/typed-dtypes]. ```javascript var arr = typedarray(); // 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` - -By default, the output [typed array][mdn-typed-array] data type is `float64`. To specify an alternative data type, provide a `dtype` argument. +By default, the output [typed array][mdn-typed-array] data type is `float64`. To specify an alternative data type, provide a [`dtype`][@stdlib/array/typed-dtypes] argument. ```javascript var arr = typedarray( 'int32' ); @@ -109,7 +95,7 @@ var arr2 = typedarray( [ 0.5, 0.5, 0.5 ], 'float32' ); // returns [ 0.5, 0.5, 0.5 ] ``` -If `dtype` is complex number data type and an array-like object contains interleaved real and imaginary components, the array-like object must have a length which is a multiple of two. +If [`dtype`][@stdlib/array/typed-dtypes] is complex number data type and an array-like object contains interleaved real and imaginary components, the array-like object must have a length which is a multiple of two. #### typedarray( buffer\[, byteOffset\[, length]]\[, dtype] ) @@ -148,7 +134,7 @@ var arr6 = typedarray( buf, 10, 4, 'int16' ); ## Notes -- When providing a complex number array, if `dtype` is unspecified or the specified data type is not a complex number data type, the returned array contains interleaved real and imaginary components. +- When providing a complex number array, if [`dtype`][@stdlib/array/typed-dtypes] is unspecified or the specified data type is not a complex number data type, the returned array contains interleaved real and imaginary components. @@ -219,6 +205,8 @@ console.log( arr ); [mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer +[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/typed-dtypes + [@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128 diff --git a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js index 56ff712e8484..265d7f3f6714 100644 --- a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -23,6 +23,7 @@ var bench = require( '@stdlib/bench' ); var isTypedArray = require( '@stdlib/assert/is-typed-array' ); var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' ); +var isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); var pkg = require( './../package.json' ).name; var typedarray = require( './../lib' ); @@ -119,6 +120,24 @@ bench( pkg+':dtype=complex64', function benchmark( b ) { b.end(); }); +bench( pkg+':dtype=bool', function benchmark( b ) { + var arr; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr = typedarray( 0, 'bool' ); + if ( arr.length !== 0 ) { + b.fail( 'should have length 0' ); + } + } + b.toc(); + if ( !isBooleanArray( arr ) ) { + b.fail( 'should return a boolean array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + bench( pkg+':dtype=int32', function benchmark( b ) { var arr; var i; diff --git a/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.bool.js b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.bool.js new file mode 100644 index 000000000000..08097a6f0874 --- /dev/null +++ b/lib/node_modules/@stdlib/array/typed/benchmark/benchmark.length.bool.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); +var pkg = require( './../package.json' ).name; +var typedarray = 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 = typedarray( len, 'bool' ); + if ( arr.length !== len ) { + b.fail( 'unexpected length' ); + } + } + b.toc(); + if ( !isBooleanArray( arr ) ) { + b.fail( 'should return a boolean 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=bool,len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/typed/docs/repl.txt b/lib/node_modules/@stdlib/array/typed/docs/repl.txt index ae4ee8495b64..11b947d01d92 100644 --- a/lib/node_modules/@stdlib/array/typed/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/typed/docs/repl.txt @@ -2,22 +2,6 @@ {{alias}}( [dtype] ) Creates a typed array. - 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 - - The default typed array data type is `float64`. - Parameters ---------- dtype: string (optional) diff --git a/lib/node_modules/@stdlib/array/typed/lib/main.js b/lib/node_modules/@stdlib/array/typed/lib/main.js index 0c099da63078..d8f75e2c1379 100644 --- a/lib/node_modules/@stdlib/array/typed/lib/main.js +++ b/lib/node_modules/@stdlib/array/typed/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -24,6 +24,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var ctors = require( '@stdlib/array/typed-ctors' ); var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); var defaults = require( '@stdlib/array/defaults' ); var format = require( '@stdlib/string/format' ); @@ -33,6 +34,7 @@ var format = require( '@stdlib/string/format' ); var DEFAULT_DTYPE = defaults.get( 'dtypes.default' ); var Complex64Array = ctors( 'complex64' ); var Complex128Array = ctors( 'complex128' ); +var BooleanArray = ctors( 'bool' ); // MAIN // @@ -147,6 +149,8 @@ function typedarray() { arg = reinterpret64( arg, 0 ); } else if ( arg instanceof Complex128Array ) { arg = reinterpret128( arg, 0 ); + } else if ( arg instanceof BooleanArray ) { + arg = reinterpretBoolean( arg, 0 ); } return new ctor( arg ); } diff --git a/lib/node_modules/@stdlib/array/typed/test/test.js b/lib/node_modules/@stdlib/array/typed/test/test.js index 2b74e534bca3..4ab76711baea 100644 --- a/lib/node_modules/@stdlib/array/typed/test/test.js +++ b/lib/node_modules/@stdlib/array/typed/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -32,10 +32,12 @@ var Uint8Array = require( '@stdlib/array/uint8' ); var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); var Complex128Array = require( '@stdlib/array/complex128' ); var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); var ArrayBuffer = require( '@stdlib/array/buffer' ); var instanceOf = require( '@stdlib/assert/instance-of' ); var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); var typedarray = require( './../lib' ); @@ -320,6 +322,13 @@ tape( 'the function returns a typed array (dtype=complex64)', function test( t ) t.end(); }); +tape( 'the function returns a typed array (dtype=bool)', function test( t ) { + var arr = typedarray( 'bool' ); + t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 0, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32)', function test( t ) { var arr = typedarray( 'int32' ); t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); @@ -404,6 +413,13 @@ tape( 'the function returns a typed array (dtype=complex64, length)', function t t.end(); }); +tape( 'the function returns a typed array (dtype=bool, length)', function test( t ) { + var arr = typedarray( 10, 'bool' ); + t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, 10, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32, length)', function test( t ) { var arr = typedarray( 10, 'int32' ); t.strictEqual( instanceOf( arr, Int32Array ), true, 'returns expected value' ); @@ -524,6 +540,25 @@ tape( 'the function returns a typed array (dtype=complex64, array)', function te t.end(); }); +tape( 'the function returns a typed array (dtype=bool, array)', function test( t ) { + var view; + var arr; + var out; + + arr = [ 1, 0, 0, 1 ]; + out = typedarray( arr, 'bool' ); + t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 4, 'returns expected value' ); + + view = reinterpretBoolean( out, 0 ); + t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); + t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32, array)', function test( t ) { var arr = [ 1.0, 2.0, 3.0 ]; var out = typedarray( arr, 'int32' ); @@ -672,6 +707,25 @@ tape( 'the function returns a typed array (dtype=complex64, typed array)', funct t.end(); }); +tape( 'the function returns a typed array (dtype=bool, typed array)', function test( t ) { + var view; + var arr; + var out; + + arr = new Uint8Array( [ 1, 0, 1, 0 ] ); + out = typedarray( arr, 'bool' ); + t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 4, 'returns expected value' ); + + view = reinterpretBoolean( out, 0 ); + t.strictEqual( view[ 0 ], arr[ 0 ], 'returns expected value' ); + t.strictEqual( view[ 1 ], arr[ 1 ], 'returns expected value' ); + t.strictEqual( view[ 2 ], arr[ 2 ], 'returns expected value' ); + t.strictEqual( view[ 3 ], arr[ 3 ], 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32, typed array)', function test( t ) { var arr = new Float32Array( [ 1.0, 2.0, 3.0 ] ); var out = typedarray( arr, 'int32' ); @@ -1043,6 +1097,23 @@ tape( 'the function returns a typed array (dtype=complex64, arraybuffer)', funct t.end(); }); +tape( 'the function returns a typed array (dtype=bool, arraybuffer)', function test( t ) { + var view; + var buf; + var out; + + buf = new ArrayBuffer( 2 ); + out = typedarray( buf, 'bool' ); + t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + + view = reinterpretBoolean( out, 0 ); + t.strictEqual( view[ 0 ], 0, 'returns expected value' ); + t.strictEqual( view[ 1 ], 0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32, arraybuffer)', function test( t ) { var buf = new ArrayBuffer( 8 ); var out = typedarray( buf, 'int32' ); @@ -1202,6 +1273,22 @@ tape( 'the function returns a typed array (dtype=complex64, arraybuffer, byteoff t.end(); }); +tape( 'the function returns a typed array (dtype=bool, arraybuffer, byteoffset)', function test( t ) { + var view; + var buf; + var out; + + buf = new ArrayBuffer( 2 ); + out = typedarray( buf, 1, 'bool' ); + t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 1, 'returns expected value' ); + + view = reinterpretBoolean( out, 0 ); + t.strictEqual( view[ 0 ], 0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset)', function test( t ) { var buf = new ArrayBuffer( 16 ); var out = typedarray( buf, 4, 'int32' ); @@ -1380,6 +1467,23 @@ tape( 'the function returns a typed array (dtype=complex64, arraybuffer, byteoff t.end(); }); +tape( 'the function returns a typed array (dtype=bool, arraybuffer, byteoffset, length)', function test( t ) { + var view; + var buf; + var out; + + buf = new ArrayBuffer( 4 ); + out = typedarray( buf, 1, 2, 'bool' ); + t.strictEqual( instanceOf( out, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( out.length, 2, 'returns expected value' ); + + view = reinterpretBoolean( out, 0 ); + t.strictEqual( view[ 0 ], 0, 'returns expected value' ); + t.strictEqual( view[ 1 ], 0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a typed array (dtype=int32, arraybuffer, byteoffset, length)', function test( t ) { var buf = new ArrayBuffer( 16 ); var out = typedarray( buf, 4, 2, 'int32' );