Skip to content

Commit 51ac0e6

Browse files
committed
Auto-generated commit
1 parent e0680c5 commit 51ac0e6

File tree

9 files changed

+161
-53
lines changed

9 files changed

+161
-53
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ This release closes the following issue:
15311531

15321532
##### Features
15331533

1534+
- [`a3132d2`](https://github.com/stdlib-js/stdlib/commit/a3132d275df3729f7d91008bc81610736622ee7a) - add boolean dtype support to `array/empty-like` [(#2460)](https://github.com/stdlib-js/stdlib/pull/2460)
15341535
- [`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)
15351536

15361537
</section>
@@ -2285,6 +2286,7 @@ A total of 13 people contributed to this release. Thank you to the following con
22852286

22862287
<details>
22872288

2289+
- [`a3132d2`](https://github.com/stdlib-js/stdlib/commit/a3132d275df3729f7d91008bc81610736622ee7a) - **feat:** add boolean dtype support to `array/empty-like` [(#2460)](https://github.com/stdlib-js/stdlib/pull/2460) _(by Jaysukh Makvana, Athan Reines)_
22882290
- [`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)_
22892291
- [`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)_
22902292
- [`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)_

empty-like/README.md

+5-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2023 The Stdlib Authors.
5+
Copyright (c) 2024 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ var emptyLike = require( '@stdlib/array/empty-like' );
4242

4343
#### emptyLike( x\[, dtype] )
4444

45-
Creates an uninitialized array having the same length and data type as a provided array `x`.
45+
Creates an uninitialized array having the same length and [data type][@stdlib/array/dtypes] as a provided array `x`.
4646

4747
```javascript
4848
var x = [ 1, 2, 3, 4, 5 ];
@@ -51,22 +51,7 @@ var arr = emptyLike( x );
5151
// returns [ 0, 0, 0, 0, 0 ];
5252
```
5353

54-
The function recognizes the following data types:
55-
56-
- `float64`: double-precision floating-point numbers (IEEE 754)
57-
- `float32`: single-precision floating-point numbers (IEEE 754)
58-
- `complex128`: double-precision complex floating-point numbers
59-
- `complex64`: single-precision complex floating-point numbers
60-
- `int32`: 32-bit two's complement signed integers
61-
- `uint32`: 32-bit unsigned integers
62-
- `int16`: 16-bit two's complement signed integers
63-
- `uint16`: 16-bit unsigned integers
64-
- `int8`: 8-bit two's complement signed integers
65-
- `uint8`: 8-bit unsigned integers
66-
- `uint8c`: 8-bit unsigned integers clamped to `0-255`
67-
- `generic`: generic JavaScript values
68-
69-
By default, the output array data type is inferred from the provided array `x`. To return an array having a different data type, provide a `dtype` argument.
54+
By default, the output array [data type][@stdlib/array/dtypes] is inferred from the provided array `x`. To return an array having a different [data type][@stdlib/array/dtypes], provide a `dtype` argument.
7055

7156
```javascript
7257
var x = [ 1, 1 ];
@@ -155,6 +140,8 @@ for ( i = 0; i < dt.length; i++ ) {
155140

156141
<section class="links">
157142

143+
[@stdlib/array/dtypes]: https://github.com/stdlib-js/array/tree/main/dtypes
144+
158145
<!-- <related-links> -->
159146

160147
[@stdlib/array/empty]: https://github.com/stdlib-js/array/tree/main/empty

empty-like/benchmark/benchmark.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2023 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -96,6 +96,28 @@ bench( pkg+':dtype=float32', function benchmark( b ) {
9696
b.end();
9797
});
9898

99+
bench( pkg+':dtype=bool', function benchmark( b ) {
100+
var arr;
101+
var x;
102+
var i;
103+
104+
x = zeros( 0, 'bool' );
105+
106+
b.tic();
107+
for ( i = 0; i < b.iterations; i++ ) {
108+
arr = emptyLike( x );
109+
if ( arr.length !== 0 ) {
110+
b.fail( 'should have length 0' );
111+
}
112+
}
113+
b.toc();
114+
if ( !isTypedArrayLike( arr ) ) {
115+
b.fail( 'should return a typed array' );
116+
}
117+
b.pass( 'benchmark finished' );
118+
b.end();
119+
});
120+
99121
bench( pkg+':dtype=complex128', function benchmark( b ) {
100122
var arr;
101123
var x;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
26+
var zeros = require( './../../zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var emptyLike = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var x = zeros( len, 'bool' );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var arr;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
arr = emptyLike( x );
57+
if ( arr.length !== len ) {
58+
b.fail( 'unexpected length' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isTypedArrayLike( arr ) ) {
63+
b.fail( 'should return a typed array' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
f = createBenchmark( len );
91+
bench( pkg+':dtype=bool,len='+len, f );
92+
}
93+
}
94+
95+
main();

empty-like/docs/repl.txt

-15
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@
1111
is *not* initialized. Memory contents are unknown and may contain
1212
*sensitive* data.
1313

14-
The function supports the following data types:
15-
16-
- float64: double-precision floating-point numbers (IEEE 754)
17-
- float32: single-precision floating-point numbers (IEEE 754)
18-
- complex128: double-precision complex floating-point numbers
19-
- complex64: single-precision complex floating-point numbers
20-
- int32: 32-bit two's complement signed integers
21-
- uint32: 32-bit unsigned integers
22-
- int16: 16-bit two's complement signed integers
23-
- uint16: 16-bit unsigned integers
24-
- int8: 8-bit two's complement signed integers
25-
- uint8: 8-bit unsigned integers
26-
- uint8c: 8-bit unsigned integers clamped to 0-255
27-
- generic: generic JavaScript values
28-
2914
Parameters
3015
----------
3116
x: TypedArray|Array

empty-like/docs/types/index.d.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { AnyArray, DataTypeMap, TypedArray, ComplexTypedArray } from '@stdlib/types/array';
23+
import { AnyArray, DataTypeMap, TypedArray, BooleanTypedArray, ComplexTypedArray } from '@stdlib/types/array';
2424

2525
/**
2626
* Creates an uninitialized array having the same length and data type as a provided input array.
@@ -64,7 +64,7 @@ declare function emptyLike( x: Array<any> ): Array<number>;
6464
* var arr = emptyLike( x, 'float32' );
6565
* // returns <Float32Array>
6666
*/
67-
declare function emptyLike<T extends TypedArray | ComplexTypedArray>( x: T ): T;
67+
declare function emptyLike<T extends TypedArray | ComplexTypedArray | BooleanTypedArray>( x: T ): T;
6868

6969
/**
7070
* Creates an uninitialized array having the same length as a provided input array.
@@ -75,21 +75,6 @@ declare function emptyLike<T extends TypedArray | ComplexTypedArray>( x: T ): T;
7575
* - If `dtype` is `'generic'`, the function always returns a zero-filled array.
7676
* - 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.
7777
*
78-
* The function recognizes the following data types:
79-
*
80-
* - `float64`: double-precision floating-point numbers (IEEE 754)
81-
* - `float32`: single-precision floating-point numbers (IEEE 754)
82-
* - `complex128`: double-precision complex floating-point numbers
83-
* - `complex64`: single-precision complex floating-point numbers
84-
* - `int32`: 32-bit two's complement signed integers
85-
* - `uint32`: 32-bit unsigned integers
86-
* - `int16`: 16-bit two's complement signed integers
87-
* - `uint16`: 16-bit unsigned integers
88-
* - `int8`: 8-bit two's complement signed integers
89-
* - `uint8`: 8-bit unsigned integers
90-
* - `uint8c`: 8-bit unsigned integers clamped to `0-255`
91-
* - `generic`: generic JavaScript values
92-
*
9378
* @param x - input array from which to derive the output array length
9479
* @param dtype - data type
9580
* @returns empty array

empty-like/docs/types/test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2023 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import Complex128Array = require( './../../../complex128' );
2020
import Complex64Array = require( './../../../complex64' );
21+
import BooleanArray = require( './../../../bool' );
2122
import emptyLike = require( './index' );
2223

2324

@@ -39,6 +40,7 @@ import emptyLike = require( './index' );
3940
emptyLike( new Uint16Array( [ 0, 0 ] ) ); // $ExpectType Uint16Array
4041
emptyLike( new Uint8Array( [ 0, 0 ] ) ); // $ExpectType Uint8Array
4142
emptyLike( new Uint8ClampedArray( [ 0, 0 ] ) ); // $ExpectType Uint8ClampedArray
43+
emptyLike( new BooleanArray( [ 0, 0 ] ) ); // $ExpectType BooleanArray
4244
emptyLike( [ 'a', 'b', 'c' ] ); // $ExpectType number[]
4345

4446
emptyLike( [ 0, 0 ], 'float64' ); // $ExpectType Float64Array
@@ -47,6 +49,7 @@ import emptyLike = require( './index' );
4749
emptyLike( [ 0, 0 ], 'complex128' ); // $ExpectType Complex128Array
4850
emptyLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array
4951
emptyLike( [ 0, 0 ], 'complex64' ); // $ExpectType Complex64Array
52+
emptyLike( [ 0, 0 ], 'bool' ); // $ExpectType BooleanArray
5053
emptyLike( [ 0, 0 ], 'int32' ); // $ExpectType Int32Array
5154
emptyLike( [ 0, 0 ], 'int16' ); // $ExpectType Int16Array
5255
emptyLike( [ 0, 0 ], 'int8' ); // $ExpectType Int8Array

empty-like/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"uint8clampedarray",
7373
"complex128array",
7474
"complex64array",
75+
"booleanarray",
7576
"complex128",
7677
"complex64",
7778
"complex",
@@ -98,6 +99,7 @@
9899
"clamped",
99100
"short",
100101
"long",
102+
"bool",
101103
"generic",
102104
"empty",
103105
"empty-like"

empty-like/test/test.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2023 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ var Uint8Array = require( './../../uint8' );
3232
var Uint8ClampedArray = require( './../../uint8c' );
3333
var Complex64Array = require( './../../complex64' );
3434
var Complex128Array = require( './../../complex128' );
35+
var BooleanArray = require( './../../bool' );
3536
var instanceOf = require( '@stdlib/assert/instance-of' );
3637
var emptyLike = require( './../lib' );
3738

@@ -189,6 +190,32 @@ tape( 'the function returns an empty array (dtype=float32)', function test( t )
189190
t.end();
190191
});
191192

193+
tape( 'the function returns an empty array (bool)', function test( t ) {
194+
var arr;
195+
var x;
196+
197+
x = new BooleanArray( 2 );
198+
199+
arr = emptyLike( x );
200+
t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' );
201+
t.strictEqual( arr.length, x.length, 'returns expected value' );
202+
203+
t.end();
204+
});
205+
206+
tape( 'the function returns an empty array (dtype=bool)', function test( t ) {
207+
var arr;
208+
var x;
209+
210+
x = new Float64Array( 5 );
211+
212+
arr = emptyLike( x, 'bool' );
213+
t.strictEqual( instanceOf( arr, BooleanArray ), true, 'returns expected value' );
214+
t.strictEqual( arr.length, x.length, 'returns expected value' );
215+
216+
t.end();
217+
});
218+
192219
tape( 'the function returns an empty array (complex128)', function test( t ) {
193220
var arr;
194221
var x;

0 commit comments

Comments
 (0)