Skip to content

Commit 3a3e7d5

Browse files
committed
Auto-generated commit
1 parent a822136 commit 3a3e7d5

File tree

7 files changed

+233
-39
lines changed

7 files changed

+233
-39
lines changed

CHANGELOG.md

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

19891989
##### Features
19901990

1991+
- [`4816901`](https://github.com/stdlib-js/stdlib/commit/481690174833259628032a259dbe7d26bbde807d) - add boolean dtype support to `array/typed` [(#2419)](https://github.com/stdlib-js/stdlib/pull/2419)
19911992
- [`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)
19921993

19931994
</section>
@@ -2187,6 +2188,7 @@ A total of 13 people contributed to this release. Thank you to the following con
21872188

21882189
<details>
21892190

2191+
- [`4816901`](https://github.com/stdlib-js/stdlib/commit/481690174833259628032a259dbe7d26bbde807d) - **feat:** add boolean dtype support to `array/typed` [(#2419)](https://github.com/stdlib-js/stdlib/pull/2419) _(by Jaysukh Makvana, Athan Reines)_
21902192
- [`bd678e5`](https://github.com/stdlib-js/stdlib/commit/bd678e56ad259f1424590d1e1ce213dc038cc676) - **feat:** update namespace TypeScript declarations [(#2425)](https://github.com/stdlib-js/stdlib/pull/2425) _(by stdlib-bot, Athan Reines)_
21912193
- [`4f30f21`](https://github.com/stdlib-js/stdlib/commit/4f30f213c8ec0a95cdcd7dfe7e7a6bf4bec8bd36) - **feat:** add boolean dtype support to `array/reviver` [(#2420)](https://github.com/stdlib-js/stdlib/pull/2420) _(by Jaysukh Makvana)_
21922194
- [`42c67e7`](https://github.com/stdlib-js/stdlib/commit/42c67e76cdf919e4e43ff9333d9acc6177eb5558) - **feat:** add `every` and `some` methods to `array/bool` [(#2421)](https://github.com/stdlib-js/stdlib/pull/2421) _(by Jaysukh Makvana, Athan Reines)_

typed/README.md

+8-20
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.
@@ -18,7 +18,7 @@ limitations under the License.
1818
1919
-->
2020

21-
# Typed Arrays
21+
# typedarray
2222

2323
> Create a typed array.
2424
@@ -42,28 +42,14 @@ var typedarray = require( '@stdlib/array/typed' );
4242

4343
#### typedarray( \[dtype] )
4444

45-
Creates a [typed array][mdn-typed-array] having a specified data type `dtype`.
45+
Creates a [typed array][mdn-typed-array] having a specified [data type][@stdlib/array/typed-dtypes].
4646

4747
```javascript
4848
var arr = typedarray();
4949
// returns <Float64Array>
5050
```
5151

52-
The function recognizes the following data types:
53-
54-
- `float64`: double-precision floating-point numbers (IEEE 754)
55-
- `float32`: single-precision floating-point numbers (IEEE 754)
56-
- `complex128`: double-precision complex floating-point numbers
57-
- `complex64`: single-precision complex floating-point numbers
58-
- `int32`: 32-bit two's complement signed integers
59-
- `uint32`: 32-bit unsigned integers
60-
- `int16`: 16-bit two's complement signed integers
61-
- `uint16`: 16-bit unsigned integers
62-
- `int8`: 8-bit two's complement signed integers
63-
- `uint8`: 8-bit unsigned integers
64-
- `uint8c`: 8-bit unsigned integers clamped to `0-255`
65-
66-
By default, the output [typed array][mdn-typed-array] data type is `float64`. To specify an alternative data type, provide a `dtype` argument.
52+
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.
6753

6854
```javascript
6955
var arr = typedarray( 'int32' );
@@ -109,7 +95,7 @@ var arr2 = typedarray( [ 0.5, 0.5, 0.5 ], 'float32' );
10995
// returns <Float32Array>[ 0.5, 0.5, 0.5 ]
11096
```
11197

112-
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.
98+
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.
11399

114100
#### typedarray( buffer\[, byteOffset\[, length]]\[, dtype] )
115101

@@ -148,7 +134,7 @@ var arr6 = typedarray( buf, 10, 4, 'int16' );
148134

149135
## Notes
150136

151-
- 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.
137+
- 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.
152138

153139
</section>
154140

@@ -219,6 +205,8 @@ console.log( arr );
219205

220206
[mdn-arraybuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
221207

208+
[@stdlib/array/typed-dtypes]: https://github.com/stdlib-js/array/tree/main/typed-dtypes
209+
222210
<!-- <related-links> -->
223211

224212
[@stdlib/array/complex128]: https://github.com/stdlib-js/array/tree/main/complex128

typed/benchmark/benchmark.js

+20-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.
@@ -23,6 +23,7 @@
2323
var bench = require( '@stdlib/bench' );
2424
var isTypedArray = require( '@stdlib/assert/is-typed-array' );
2525
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
26+
var isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
2627
var pkg = require( './../package.json' ).name;
2728
var typedarray = require( './../lib' );
2829

@@ -119,6 +120,24 @@ bench( pkg+':dtype=complex64', function benchmark( b ) {
119120
b.end();
120121
});
121122

123+
bench( pkg+':dtype=bool', function benchmark( b ) {
124+
var arr;
125+
var i;
126+
b.tic();
127+
for ( i = 0; i < b.iterations; i++ ) {
128+
arr = typedarray( 0, 'bool' );
129+
if ( arr.length !== 0 ) {
130+
b.fail( 'should have length 0' );
131+
}
132+
}
133+
b.toc();
134+
if ( !isBooleanArray( arr ) ) {
135+
b.fail( 'should return a boolean array' );
136+
}
137+
b.pass( 'benchmark finished' );
138+
b.end();
139+
});
140+
122141
bench( pkg+':dtype=int32', function benchmark( b ) {
123142
var arr;
124143
var i;
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
26+
var pkg = require( './../package.json' ).name;
27+
var typedarray = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Creates a benchmark function.
34+
*
35+
* @private
36+
* @param {PositiveInteger} len - array length
37+
* @returns {Function} benchmark function
38+
*/
39+
function createBenchmark( len ) {
40+
return benchmark;
41+
42+
/**
43+
* Benchmark function.
44+
*
45+
* @private
46+
* @param {Benchmark} b - benchmark instance
47+
*/
48+
function benchmark( b ) {
49+
var arr;
50+
var i;
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
arr = typedarray( len, 'bool' );
55+
if ( arr.length !== len ) {
56+
b.fail( 'unexpected length' );
57+
}
58+
}
59+
b.toc();
60+
if ( !isBooleanArray( arr ) ) {
61+
b.fail( 'should return a boolean array' );
62+
}
63+
b.pass( 'benchmark finished' );
64+
b.end();
65+
}
66+
}
67+
68+
69+
// MAIN //
70+
71+
/**
72+
* Main execution sequence.
73+
*
74+
* @private
75+
*/
76+
function main() {
77+
var len;
78+
var min;
79+
var max;
80+
var f;
81+
var i;
82+
83+
min = 1; // 10^min
84+
max = 6; // 10^max
85+
86+
for ( i = min; i <= max; i++ ) {
87+
len = pow( 10, i );
88+
f = createBenchmark( len );
89+
bench( pkg+':dtype=bool,len='+len, f );
90+
}
91+
}
92+
93+
main();

typed/docs/repl.txt

-16
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22
{{alias}}( [dtype] )
33
Creates a typed array.
44

5-
The function supports the following data types:
6-
7-
- float64: double-precision floating-point numbers (IEEE 754)
8-
- float32: single-precision floating-point numbers (IEEE 754)
9-
- complex128: double-precision complex floating-point numbers
10-
- complex64: single-precision complex floating-point numbers
11-
- int32: 32-bit two's complement signed integers
12-
- uint32: 32-bit unsigned integers
13-
- int16: 16-bit two's complement signed integers
14-
- uint16: 16-bit unsigned integers
15-
- int8: 8-bit two's complement signed integers
16-
- uint8: 8-bit unsigned integers
17-
- uint8c: 8-bit unsigned integers clamped to 0-255
18-
19-
The default typed array data type is `float64`.
20-
215
Parameters
226
----------
237
dtype: string (optional)

typed/lib/main.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.
@@ -24,6 +24,7 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2424
var ctors = require( './../../typed-ctors' );
2525
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
2626
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
27+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2728
var defaults = require( './../../defaults' );
2829
var format = require( '@stdlib/string/format' );
2930

@@ -33,6 +34,7 @@ var format = require( '@stdlib/string/format' );
3334
var DEFAULT_DTYPE = defaults.get( 'dtypes.default' );
3435
var Complex64Array = ctors( 'complex64' );
3536
var Complex128Array = ctors( 'complex128' );
37+
var BooleanArray = ctors( 'bool' );
3638

3739

3840
// MAIN //
@@ -147,6 +149,8 @@ function typedarray() {
147149
arg = reinterpret64( arg, 0 );
148150
} else if ( arg instanceof Complex128Array ) {
149151
arg = reinterpret128( arg, 0 );
152+
} else if ( arg instanceof BooleanArray ) {
153+
arg = reinterpretBoolean( arg, 0 );
150154
}
151155
return new ctor( arg );
152156
}

0 commit comments

Comments
 (0)