Skip to content

Commit 48fd331

Browse files
Jaysukh-409kgryte
andauthored
feat: add boolean dtype support to array/convert-same
PR-URL: #2494 Ref: #2304 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent d2d46ed commit 48fd331

File tree

7 files changed

+277
-41
lines changed

7 files changed

+277
-41
lines changed

Diff for: lib/node_modules/@stdlib/array/convert-same/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) 2018 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.
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# convertSame
2222

23-
> Convert an array to the same data type as a second input array.
23+
> Convert an array to the same [data type][@stdlib/array/dtypes] as a second input array.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -42,7 +42,7 @@ var convertSame = require( '@stdlib/array/convert-same' );
4242

4343
#### convertSame( x, y )
4444

45-
Converts an array to the same data type as a second input array.
45+
Converts an array to the same [data type][@stdlib/array/dtypes] as a second input array.
4646

4747
```javascript
4848
var Float32Array = require( '@stdlib/array/float32' );
@@ -54,21 +54,6 @@ var out = convertSame( x, y );
5454
// returns <Float32Array>[ 1.0, 2.0, 3.0 ]
5555
```
5656

57-
The function supports input arrays having the following data types:
58-
59-
- `float32`: single-precision floating-point numbers.
60-
- `float64`: double-precision floating-point numbers.
61-
- `complex64`: single-precision complex floating-point numbers.
62-
- `complex128`: double-precision complex floating-point numbers.
63-
- `generic`: values of any type.
64-
- `int16`: signed 16-bit integers.
65-
- `int32`: signed 32-bit integers.
66-
- `int8`: signed 8-bit integers.
67-
- `uint16`: unsigned 16-bit integers.
68-
- `uint32`: unsigned 32-bit integers.
69-
- `uint8`: unsigned 8-bit integers.
70-
- `uint8c`: unsigned clamped 8-bit integers.
71-
7257
</section>
7358

7459
<!-- /.usage -->
@@ -147,6 +132,8 @@ for ( i = 0; i < DTYPES.length; i++ ) {
147132

148133
[@stdlib/array/convert]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/convert
149134

135+
[@stdlib/array/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dtypes
136+
150137
<!-- </related-links> -->
151138

152139
</section>

Diff for: lib/node_modules/@stdlib/array/convert-same/benchmark/benchmark.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 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.
@@ -33,6 +33,7 @@ var Uint8Array = require( '@stdlib/array/uint8' );
3333
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
3434
var Complex64Array = require( '@stdlib/array/complex64' );
3535
var Complex128Array = require( '@stdlib/array/complex128' );
36+
var BooleanArray = require( '@stdlib/array/bool' );
3637
var pkg = require( './../package.json' ).name;
3738
var convertArraySame = require( './../lib' );
3839

@@ -120,6 +121,34 @@ bench( pkg+':dtype=float32', function benchmark( b ) {
120121
b.end();
121122
});
122123

124+
bench( pkg+':dtype=bool', function benchmark( b ) {
125+
var arr;
126+
var out;
127+
var v;
128+
var i;
129+
130+
arr = [];
131+
for ( i = 0; i < 10; i++ ) {
132+
arr.push( i );
133+
}
134+
v = new BooleanArray( 0 );
135+
136+
b.tic();
137+
for ( i = 0; i < b.iterations; i++ ) {
138+
arr[ 0 ] += 1;
139+
out = convertArraySame( arr, v );
140+
if ( out.length !== arr.length ) {
141+
b.fail( 'should have expected length' );
142+
}
143+
}
144+
b.toc();
145+
if ( !isCollection( out ) ) {
146+
b.fail( 'should return an array-like object' );
147+
}
148+
b.pass( 'benchmark finished' );
149+
b.end();
150+
});
151+
123152
bench( pkg+':dtype=complex128', function benchmark( b ) {
124153
var arr;
125154
var out;

Diff for: lib/node_modules/@stdlib/array/convert-same/benchmark/benchmark.length.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2018 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.
@@ -34,6 +34,7 @@ var Uint8Array = require( '@stdlib/array/uint8' );
3434
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
3535
var Complex64Array = require( '@stdlib/array/complex64' );
3636
var Complex128Array = require( '@stdlib/array/complex128' );
37+
var BooleanArray = require( '@stdlib/array/bool' );
3738
var pkg = require( './../package.json' ).name;
3839
var convertArraySame = require( './../lib' );
3940

@@ -135,6 +136,9 @@ function main() {
135136
f = createBenchmark( len, new Uint8ClampedArray( 0 ) );
136137
bench( pkg+':len='+len+',dtype=uint8c', f );
137138

139+
f = createBenchmark( len, new BooleanArray( 0 ) );
140+
bench( pkg+':len='+len+',dtype=bool', f );
141+
138142
f = createBenchmark( len, new Complex128Array( 0 ) );
139143
bench( pkg+':len='+len+',dtype=complex128', f );
140144

Diff for: lib/node_modules/@stdlib/array/convert-same/docs/repl.txt

-15
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@
22
{{alias}}( x, y )
33
Converts an input array to the same data type as a second input array.
44

5-
The function supports input arrays having the following data types:
6-
7-
- float32: single-precision floating-point numbers.
8-
- float64: double-precision floating-point numbers.
9-
- complex64: single-precision complex floating-point numbers.
10-
- complex128: double-precision complex floating-point numbers.
11-
- generic: values of any type.
12-
- int16: signed 16-bit integers.
13-
- int32: signed 32-bit integers.
14-
- int8: signed 8-bit integers.
15-
- uint16: unsigned 16-bit integers.
16-
- uint32: unsigned 32-bit integers.
17-
- uint8: unsigned 8-bit integers.
18-
- uint8c: unsigned clamped 8-bit integers.
19-
205
Parameters
216
----------
227
x: ArrayLikeObject

Diff for: lib/node_modules/@stdlib/array/convert-same/docs/types/index.d.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 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.
@@ -20,7 +20,7 @@
2020

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

23-
import { AnyArray, Collection, Complex128Array, Complex64Array } from '@stdlib/types/array';
23+
import { AnyArray, Collection, Complex128Array, Complex64Array, BooleanArray } from '@stdlib/types/array';
2424

2525
/**
2626
* Converts an array to the same data type as a `Float64Array`.
@@ -184,6 +184,24 @@ declare function convertSame( x: Collection, y: Uint8Array ): Uint8Array;
184184
*/
185185
declare function convertSame( x: Collection, y: Uint8ClampedArray ): Uint8ClampedArray;
186186

187+
/**
188+
* Converts an array to a `BooleanArray`.
189+
*
190+
* @param x - array to convert
191+
* @param y - array having the desired output data type
192+
* @returns output array
193+
*
194+
* @example
195+
* var BooleanArray = require( '@stdlib/array/bool' );
196+
*
197+
* var x = [ -1, 0, 1, 2 ];
198+
* var y = new BooleanArray( 0 );
199+
*
200+
* var out = convertSame( x, y );
201+
* // returns <BooleanArray>
202+
*/
203+
declare function convertSame( x: Collection, y: BooleanArray ): BooleanArray;
204+
187205
/**
188206
* Converts an array to a `Complex128Array`.
189207
*

Diff for: lib/node_modules/@stdlib/array/convert-same/docs/types/test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 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( '@stdlib/array/complex128' );
2020
import Complex64Array = require( '@stdlib/array/complex64' );
21+
import BooleanArray = require( '@stdlib/array/bool' );
2122
import convertSame = require( './index' );
2223

2324

@@ -36,6 +37,7 @@ import convertSame = require( './index' );
3637
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Uint8ClampedArray( 0 ) ); // $ExpectType Uint8ClampedArray
3738
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Complex128Array( 0 ) ); // $ExpectType Complex128Array
3839
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new Complex64Array( 0 ) ); // $ExpectType Complex64Array
40+
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], new BooleanArray( 0 ) ); // $ExpectType BooleanArray
3941
convertSame( [ 1.0, 2.0, 3.0, 4.0 ], [] ); // $ExpectType any[]
4042
}
4143

0 commit comments

Comments
 (0)