Skip to content

Commit 37ca4b7

Browse files
Jaysukh-409kgryte
andauthored
feat: add boolean dtype support to array/filled-by
PR-URL: #2487 Ref: #2304 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent 88cece6 commit 37ca4b7

File tree

7 files changed

+292
-156
lines changed

7 files changed

+292
-156
lines changed

lib/node_modules/@stdlib/array/filled-by/README.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2021 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,29 +42,14 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
4242

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

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

4747
```javascript
4848
var arr = filledarrayBy();
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-
- `generic`: generic JavaScript values
66-
67-
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.
52+
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.
6853

6954
```javascript
7055
var arr = filledarrayBy( 'int32' );
@@ -261,6 +246,8 @@ for ( i = 0; i < dt.length; i++ ) {
261246

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

249+
[@stdlib/array/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/dtypes
250+
264251
<!-- <related-links> -->
265252

266253
[@stdlib/array/filled]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/filled

lib/node_modules/@stdlib/array/filled-by/benchmark/benchmark.js

Lines changed: 23 additions & 1 deletion
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.
@@ -98,6 +98,28 @@ bench( pkg+':dtype=float32', function benchmark( b ) {
9898
b.end();
9999
});
100100

101+
bench( pkg+':dtype=bool', function benchmark( b ) {
102+
var clbk;
103+
var arr;
104+
var i;
105+
106+
clbk = constantFunction( true );
107+
108+
b.tic();
109+
for ( i = 0; i < b.iterations; i++ ) {
110+
arr = filledarrayBy( 0, 'bool', clbk );
111+
if ( arr.length !== 0 ) {
112+
b.fail( 'should have length 0' );
113+
}
114+
}
115+
b.toc();
116+
if ( !isTypedArrayLike( arr ) ) {
117+
b.fail( 'should return a typed array' );
118+
}
119+
b.pass( 'benchmark finished' );
120+
b.end();
121+
});
122+
101123
bench( pkg+':dtype=complex128', function benchmark( b ) {
102124
var clbk;
103125
var arr;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 constantFunction = require( '@stdlib/utils/constant-function' );
27+
var pkg = require( './../package.json' ).name;
28+
var filledarray = 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+
return benchmark;
42+
43+
/**
44+
* Benchmark function.
45+
*
46+
* @private
47+
* @param {Benchmark} b - benchmark instance
48+
*/
49+
function benchmark( b ) {
50+
var clbk;
51+
var arr;
52+
var i;
53+
54+
clbk = constantFunction( true );
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
arr = filledarray( len, 'bool', clbk );
59+
if ( arr.length !== len ) {
60+
b.fail( 'unexpected length' );
61+
}
62+
}
63+
b.toc();
64+
if ( !isTypedArrayLike( arr ) ) {
65+
b.fail( 'should return a typed array' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
}
70+
}
71+
72+
73+
// MAIN //
74+
75+
/**
76+
* Main execution sequence.
77+
*
78+
* @private
79+
*/
80+
function main() {
81+
var len;
82+
var min;
83+
var max;
84+
var f;
85+
var i;
86+
87+
min = 1; // 10^min
88+
max = 6; // 10^max
89+
90+
for ( i = min; i <= max; i++ ) {
91+
len = pow( 10, i );
92+
f = createBenchmark( len );
93+
bench( pkg+':dtype=bool,len='+len, f );
94+
}
95+
}
96+
97+
main();

lib/node_modules/@stdlib/array/filled-by/docs/repl.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,6 @@
22
{{alias}}( [dtype] )
33
Creates a filled 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-
- generic: generic JavaScript values
19-
20-
The default array data type is `float64`.
21-
225
Parameters
236
----------
247
dtype: string (optional)

0 commit comments

Comments
 (0)