From e0680c5d2f1140094843cb0b292d631142d8dae7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 26 Jun 2024 23:10:24 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 2 + empty/README.md | 21 +----- empty/benchmark/benchmark.js | 20 ++++- empty/benchmark/benchmark.length.bool.js | 93 ++++++++++++++++++++++++ empty/docs/repl.txt | 17 ----- empty/docs/types/index.d.ts | 15 ---- empty/docs/types/test.ts | 3 +- empty/package.json | 1 + empty/test/test.main.js | 13 +++- empty/test/test.polyfill.js | 18 ++++- 10 files changed, 150 insertions(+), 53 deletions(-) create mode 100644 empty/benchmark/benchmark.length.bool.js diff --git a/CHANGELOG.md b/CHANGELOG.md index f26156d0..5e286dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1508,6 +1508,7 @@ This release closes the following issue: ##### Features +- [`d4815b6`](https://github.com/stdlib-js/stdlib/commit/d4815b6becd6231209dfdf39808a0014bcf24b84) - add boolean dtype support to `array/empty` [(#2459)](https://github.com/stdlib-js/stdlib/pull/2459) - [`819d2e4`](https://github.com/stdlib-js/stdlib/commit/819d2e407146d4dcc17f8bab53b591b3d573f8a1) - add data type maps and replace use of overloads [(#1317)](https://github.com/stdlib-js/stdlib/pull/1317) @@ -2284,6 +2285,7 @@ A total of 13 people contributed to this release. Thank you to the following con
+- [`d4815b6`](https://github.com/stdlib-js/stdlib/commit/d4815b6becd6231209dfdf39808a0014bcf24b84) - **feat:** add boolean dtype support to `array/empty` [(#2459)](https://github.com/stdlib-js/stdlib/pull/2459) _(by Jaysukh Makvana, Athan Reines)_ - [`bddc8fa`](https://github.com/stdlib-js/stdlib/commit/bddc8fac1c445fe07cae159c3697ad2734432657) - **feat:** add boolean dtype support to `array/full-like` [(#2462)](https://github.com/stdlib-js/stdlib/pull/2462) _(by Jaysukh Makvana, Athan Reines)_ - [`3fdfa90`](https://github.com/stdlib-js/stdlib/commit/3fdfa902945e503766b1ae4592a2d094efb0ff7f) - **feat:** add boolean dtype support to `array/full` [(#2461)](https://github.com/stdlib-js/stdlib/pull/2461) _(by Jaysukh Makvana, Athan Reines)_ - [`b586995`](https://github.com/stdlib-js/stdlib/commit/b586995441d335964383ac2d3195ab9a55e091f4) - **feat:** add boolean dtype support to `array/base/mskreject` [(#2452)](https://github.com/stdlib-js/stdlib/pull/2452) _(by Jaysukh Makvana, Athan Reines)_ diff --git a/empty/README.md b/empty/README.md index 47e5da20..dd19f093 100644 --- a/empty/README.md +++ b/empty/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2023 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. @@ -49,22 +49,7 @@ 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. +By default, the output array [data type][@stdlib/array/dtypes] is `float64` (i.e., a [typed array][mdn-typed-array]). To specify an alternative [data type][@stdlib/array/dtypes], provide a `dtype` argument. ```javascript var arr = empty( 2, 'int32' ); @@ -149,6 +134,8 @@ for ( i = 0; i < dt.length; i++ ) { [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +[@stdlib/array/dtypes]: https://github.com/stdlib-js/array/tree/main/dtypes + [@stdlib/array/empty-like]: https://github.com/stdlib-js/array/tree/main/empty-like diff --git a/empty/benchmark/benchmark.js b/empty/benchmark/benchmark.js index 4cf8d5b8..7f7ffb83 100644 --- a/empty/benchmark/benchmark.js +++ b/empty/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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. @@ -83,6 +83,24 @@ bench( pkg+':dtype=float32', 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 = empty( 0, 'bool' ); + 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; diff --git a/empty/benchmark/benchmark.length.bool.js b/empty/benchmark/benchmark.length.bool.js new file mode 100644 index 00000000..3b1bf8d8 --- /dev/null +++ b/empty/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 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, 'bool' ); + 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=bool,len='+len, f ); + } +} + +main(); diff --git a/empty/docs/repl.txt b/empty/docs/repl.txt index 8f5ae68f..2411a691 100644 --- a/empty/docs/repl.txt +++ b/empty/docs/repl.txt @@ -10,23 +10,6 @@ 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 diff --git a/empty/docs/types/index.d.ts b/empty/docs/types/index.d.ts index 41c408b6..598c2b36 100644 --- a/empty/docs/types/index.d.ts +++ b/empty/docs/types/index.d.ts @@ -25,21 +25,6 @@ import { DataTypeMap } from '@stdlib/types/array'; /** * Creates an uninitialized array having a specified length. * -* 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 -* * ## Notes * * - In browser environments, the function always returns zero-filled arrays. diff --git a/empty/docs/types/test.ts b/empty/docs/types/test.ts index 303bb77b..78de0828 100644 --- a/empty/docs/types/test.ts +++ b/empty/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 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. @@ -28,6 +28,7 @@ import empty = require( './index' ); empty( 10, 'float32' ); // $ExpectType Float32Array empty( 10, 'complex128' ); // $ExpectType Complex128Array empty( 10, 'complex64' ); // $ExpectType Complex64Array + empty( 10, 'bool' ); // $ExpectType BooleanArray empty( 10, 'int32' ); // $ExpectType Int32Array empty( 10, 'int16' ); // $ExpectType Int16Array empty( 10, 'int8' ); // $ExpectType Int8Array diff --git a/empty/package.json b/empty/package.json index 56921972..fbc53bc9 100644 --- a/empty/package.json +++ b/empty/package.json @@ -100,6 +100,7 @@ "short", "long", "generic", + "bool", "empty" ] } diff --git a/empty/test/test.main.js b/empty/test/test.main.js index 4b54a3da..89545c52 100644 --- a/empty/test/test.main.js +++ b/empty/test/test.main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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,6 +32,7 @@ var Uint8Array = require( './../../uint8' ); var Uint8ClampedArray = require( './../../uint8c' ); var Complex64Array = require( './../../complex64' ); var Complex128Array = require( './../../complex128' ); +var BooleanArray = require( './../../bool' ); var instanceOf = require( '@stdlib/assert/instance-of' ); var empty = require( './../lib/main.js' ); @@ -169,6 +170,16 @@ tape( 'the function returns an empty array (dtype=float32)', function test( t ) t.end(); }); +tape( 'the function returns an empty array (dtype=bool)', function test( t ) { + var arr; + + arr = empty( 5, 'bool' ); + t.strictEqual( instanceOf( arr, BooleanArray ), 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; diff --git a/empty/test/test.polyfill.js b/empty/test/test.polyfill.js index 3d437779..c63985d3 100644 --- a/empty/test/test.polyfill.js +++ b/empty/test/test.polyfill.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 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,8 +32,10 @@ var Uint8Array = require( './../../uint8' ); var Uint8ClampedArray = require( './../../uint8c' ); var Complex64Array = require( './../../complex64' ); var Complex128Array = require( './../../complex128' ); +var BooleanArray = require( './../../bool' ); var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); +var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); var instanceOf = require( '@stdlib/assert/instance-of' ); var empty = require( './../lib/polyfill.js' ); @@ -183,6 +185,20 @@ tape( 'the function returns a zero-filled array (dtype=float32)', function test( t.end(); }); +tape( 'the function returns a zero-filled array (dtype=bool)', function test( t ) { + var expected; + var arr; + + expected = new Uint8Array( [ 0, 0, 0, 0 ] ); + + arr = empty( 4, 'bool' ); + t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' ); + t.strictEqual( arr.length, expected.length, 'returns expected value' ); + t.deepEqual( reinterpretBoolean( arr, 0 ), expected, 'returns expected value' ); + + t.end(); +}); + tape( 'the function returns a zero-filled array (dtype=complex128)', function test( t ) { var expected; var arr;