Skip to content

Commit 9f4e007

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 2827035 + a7947d0 commit 9f4e007

24 files changed

Lines changed: 896 additions & 9 deletions

File tree

lib/node_modules/@stdlib/array/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Lastly, the namespace contains various other functions for dealing with arrays,
189189
- <span class="signature">[`ones( length[, dtype] )`][@stdlib/array/ones]</span><span class="delimiter">: </span><span class="description">create an array filled with ones and having a specified length.</span>
190190
- <span class="signature">[`typedarraypool()`][@stdlib/array/pool]</span><span class="delimiter">: </span><span class="description">allocate typed arrays from a typed array memory pool.</span>
191191
- <span class="signature">[`promotionRules( [dtype1, dtype2] )`][@stdlib/array/promotion-rules]</span><span class="delimiter">: </span><span class="description">return the array data type with the smallest size and closest "kind" to which array data types can be **safely** cast.</span>
192+
- <span class="signature">[`put( x, indices, values[, options] )`][@stdlib/array/put]</span><span class="delimiter">: </span><span class="description">replace specified elements of an array with provided values.</span>
192193
- <span class="signature">[`typedarrayReviver( key, value )`][@stdlib/array/reviver]</span><span class="delimiter">: </span><span class="description">revive a JSON-serialized typed array.</span>
193194
- <span class="signature">[`safeCasts( [dtype] )`][@stdlib/array/safe-casts]</span><span class="delimiter">: </span><span class="description">return a list of array data types to which a provided array data type can be safely cast.</span>
194195
- <span class="signature">[`sameKindCasts( [dtype] )`][@stdlib/array/same-kind-casts]</span><span class="delimiter">: </span><span class="description">return a list of array data types to which a provided array data type can be safely cast or cast within the same "kind".</span>
@@ -319,6 +320,8 @@ console.log( objectKeys( ns ) );
319320

320321
[@stdlib/array/promotion-rules]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/promotion-rules
321322

323+
[@stdlib/array/put]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/put
324+
322325
[@stdlib/array/reviver]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/reviver
323326

324327
[@stdlib/array/safe-casts]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/safe-casts

lib/node_modules/@stdlib/array/base/assert/has-same-values/lib/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );
2424
var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' );
25+
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
2526
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
2627
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
2728
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
29+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2830
var isSameValue = require( '@stdlib/assert/is-same-value' );
2931

3032

@@ -150,6 +152,13 @@ function hasSameValues( x, y ) {
150152
if ( xo.accessorProtocol || yo.accessorProtocol ) {
151153
FLG = 2;
152154

155+
// If provided boolean arrays, reinterpret the arrays to avoid using accessors to access array elements...
156+
if ( isBooleanArray( x ) ) {
157+
if ( isBooleanArray( y ) ) {
158+
return internal( reinterpretBoolean( x, 0 ), reinterpretBoolean( y, 0 ) );
159+
}
160+
return accessors( xo, yo );
161+
}
153162
// If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components...
154163
if ( isComplex128Array( x ) ) {
155164
xr = reinterpret128( x, 0 );

lib/node_modules/@stdlib/array/base/assert/has-same-values/test/test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var AccessorArray = require( '@stdlib/array/base/accessor' );
2525
var Float64Array = require( '@stdlib/array/float64' );
2626
var Complex64Array = require( '@stdlib/array/complex64' );
2727
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var BooleanArray = require( '@stdlib/array/bool' );
2829
var hasSameValues = require( './../lib' );
2930

3031

@@ -111,6 +112,23 @@ tape( 'if provided empty collections, the function returns `true` (mixed)', func
111112
t.end();
112113
});
113114

115+
tape( 'if provided empty collections, the function returns `true` (boolean array)', function test( t ) {
116+
var out;
117+
var x;
118+
var y;
119+
120+
x = new BooleanArray( [] );
121+
out = hasSameValues( x, x );
122+
t.strictEqual( out, true, 'returns expected value' );
123+
124+
x = new BooleanArray( [] );
125+
y = new BooleanArray( [] );
126+
out = hasSameValues( x, y );
127+
t.strictEqual( out, true, 'returns expected value' );
128+
129+
t.end();
130+
});
131+
114132
tape( 'if provided empty collections, the function returns `true` (complex typed array)', function test( t ) {
115133
var out;
116134
var x;
@@ -206,6 +224,23 @@ tape( 'the function returns `true` if both arrays have the same values (mixed)',
206224
t.end();
207225
});
208226

227+
tape( 'the function returns `true` if both arrays have the same values (boolean array)', function test( t ) {
228+
var out;
229+
var x;
230+
var y;
231+
232+
x = new BooleanArray( [ true, false, true ] );
233+
out = hasSameValues( x, x );
234+
t.strictEqual( out, true, 'returns expected value' );
235+
236+
x = new BooleanArray( [ true, false, true ] );
237+
y = new BooleanArray( [ true, false, true ] );
238+
out = hasSameValues( x, y );
239+
t.strictEqual( out, true, 'returns expected value' );
240+
241+
t.end();
242+
});
243+
209244
tape( 'the function returns `true` if both arrays have the same values (real typed array)', function test( t ) {
210245
var out;
211246
var x;
@@ -330,6 +365,19 @@ tape( 'the function returns `false` if both arrays do not have the same values (
330365
t.end();
331366
});
332367

368+
tape( 'the function returns `false` if both arrays do not have the same values (boolean array)', function test( t ) {
369+
var out;
370+
var x;
371+
var y;
372+
373+
x = new BooleanArray( [ true, false, false, true ] );
374+
y = new BooleanArray( [ true, true, false, false ] );
375+
out = hasSameValues( x, y );
376+
t.strictEqual( out, false, 'returns expected value' );
377+
378+
t.end();
379+
});
380+
333381
tape( 'the function returns `false` if both arrays do not have the same values (complex typed array)', function test( t ) {
334382
var out;
335383
var x;

lib/node_modules/@stdlib/array/bool/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,32 @@ var count = context.count;
629629
// returns 3;
630630
```
631631

632+
<a name="method-reverse"></a>
633+
634+
#### BooleanArray.prototype.reverse()
635+
636+
Reverses an array in-place.
637+
638+
```javascript
639+
var arr = new BooleanArray( 3 );
640+
641+
arr.set( true, 0 );
642+
arr.set( false, 1 );
643+
arr.set( false, 2 );
644+
645+
var out = arr.reverse();
646+
// returns <BooleanArray>
647+
648+
var v = out.get( 0 );
649+
// returns false
650+
651+
v = out.get( 1 );
652+
// returns false
653+
654+
v = out.get( 2 );
655+
// returns true
656+
```
657+
632658
<a name="method-set"></a>
633659

634660
#### BooleanArray.prototype.set( v\[, i] )
@@ -738,6 +764,32 @@ The function should return a number where:
738764
- a positive value indicates that `a` should come after `b`.
739765
- zero or `NaN` indicates that `a` and `b` are considered equal.
740766

767+
<a name="method-to-reversed"></a>
768+
769+
#### BooleanArray.prototype.toReversed()
770+
771+
Returns a new typed array containing the elements in reversed order.
772+
773+
```javascript
774+
var arr = new BooleanArray( 3 );
775+
776+
arr.set( true, 0 );
777+
arr.set( false, 1 );
778+
arr.set( false, 2 );
779+
780+
var out = arr.toReversed();
781+
// returns <BooleanArray>
782+
783+
var v = out.get( 0 );
784+
// returns false
785+
786+
v = out.get( 1 );
787+
// returns false
788+
789+
v = out.get( 2 );
790+
// returns true
791+
```
792+
741793
</section>
742794

743795
<!-- /.usage -->
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':reverse', function benchmark( b ) {
32+
var out;
33+
var arr;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
out = arr.reverse();
41+
if ( typeof out !== 'object' ) {
42+
b.fail( 'should return an object' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBooleanArray( out ) ) {
47+
b.fail( 'should return a BooleanArray' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var Boolean = require( '@stdlib/boolean/ctor' );
27+
var pkg = require( './../package.json' ).name;
28+
var BooleanArray = 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 arr;
42+
var i;
43+
44+
arr = [];
45+
for ( i = 0; i < len; i++ ) {
46+
arr.push( Boolean( i%2 ) );
47+
}
48+
arr = new BooleanArray( arr );
49+
50+
return benchmark;
51+
52+
/**
53+
* Benchmark function.
54+
*
55+
* @private
56+
* @param {Benchmark} b - benchmark instance
57+
*/
58+
function benchmark( b ) {
59+
var out;
60+
var i;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
out = arr.reverse();
65+
if ( typeof out !== 'object' ) {
66+
b.fail( 'should return an object' );
67+
}
68+
}
69+
b.toc();
70+
if ( !isBooleanArray( out ) ) {
71+
b.fail( 'should return a BooleanArray' );
72+
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
75+
}
76+
}
77+
78+
79+
// MAIN //
80+
81+
/**
82+
* Main execution sequence.
83+
*
84+
* @private
85+
*/
86+
function main() {
87+
var len;
88+
var min;
89+
var max;
90+
var f;
91+
var i;
92+
93+
min = 1; // 10^min
94+
max = 6; // 10^max
95+
96+
for ( i = min; i <= max; i++ ) {
97+
len = pow( 10, i );
98+
f = createBenchmark( len );
99+
bench( pkg+':reverse:len='+len, f );
100+
}
101+
}
102+
103+
main();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':toReversed', function benchmark( b ) {
32+
var out;
33+
var arr;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
out = arr.toReversed();
41+
if ( typeof out !== 'object' ) {
42+
b.fail( 'should return an object' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBooleanArray( out ) ) {
47+
b.fail( 'should return a BooleanArray' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});

0 commit comments

Comments
 (0)