Skip to content

Commit 7c52e4c

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 82a217c + 62744b5 commit 7c52e4c

92 files changed

Lines changed: 7981 additions & 44 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/node_modules/@stdlib/array/base/docs/types/index.d.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import minSignedIntegerDataType = require( '@stdlib/array/base/min-signed-intege
131131
import minUnsignedIntegerDataType = require( '@stdlib/array/base/min-unsigned-integer-dtype' );
132132
import mskbinary2d = require( '@stdlib/array/base/mskbinary2d' );
133133
import mskfilter = require( '@stdlib/array/base/mskfilter' );
134+
import mskput = require( '@stdlib/array/base/mskput' );
134135
import mskreject = require( '@stdlib/array/base/mskreject' );
135136
import mskunary2d = require( '@stdlib/array/base/mskunary2d' );
136137
import mskunary3d = require( '@stdlib/array/base/mskunary3d' );
@@ -145,6 +146,7 @@ import ones3d = require( '@stdlib/array/base/ones3d' );
145146
import ones4d = require( '@stdlib/array/base/ones4d' );
146147
import ones5d = require( '@stdlib/array/base/ones5d' );
147148
import onesnd = require( '@stdlib/array/base/onesnd' );
149+
import place = require( '@stdlib/array/base/place' );
148150
import put = require( '@stdlib/array/base/put' );
149151
import quaternary2d = require( '@stdlib/array/base/quaternary2d' );
150152
import quaternary3d = require( '@stdlib/array/base/quaternary3d' );
@@ -182,6 +184,7 @@ import unary4d = require( '@stdlib/array/base/unary4d' );
182184
import unary5d = require( '@stdlib/array/base/unary5d' );
183185
import unarynd = require( '@stdlib/array/base/unarynd' );
184186
import unitspace = require( '@stdlib/array/base/unitspace' );
187+
import where = require( '@stdlib/array/base/where' );
185188
import arrayWith = require( '@stdlib/array/base/with' );
186189
import zeroTo = require( '@stdlib/array/base/zero-to' );
187190
import zeros = require( '@stdlib/array/base/zeros' );
@@ -2874,6 +2877,38 @@ interface Namespace {
28742877
*/
28752878
mskfilter: typeof mskfilter;
28762879

2880+
/**
2881+
* Replaces elements of an array with provided values according to a provided mask array.
2882+
*
2883+
* @param x - input array
2884+
* @param mask - mask array
2885+
* @param values - values to set
2886+
* @param mode - string specifying behavior when the number of values does not equal the number of falsy values in the mask array
2887+
* @returns input array
2888+
*
2889+
* @example
2890+
* var x = [ 1, 2, 3, 4 ];
2891+
*
2892+
* var mask = [ 1, 0, 0, 1 ];
2893+
* var values = [ 20, 30 ];
2894+
*
2895+
* var out = ns.mskput( x, mask, values, 'strict' );
2896+
* // returns [ 1, 20, 30, 4 ]
2897+
*
2898+
* var bool = ( out === x );
2899+
* // returns true
2900+
*
2901+
* @example
2902+
* var x = [ 1, 2, 3, 4 ];
2903+
*
2904+
* var out = ns.mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'strict_broadcast' );
2905+
* // returns [ 1, 30, 30, 4 ]
2906+
*
2907+
* var bool = ( out === x );
2908+
* // returns true
2909+
*/
2910+
mskput: typeof mskput;
2911+
28772912
/**
28782913
* Returns a new array by applying a mask to a provided input array.
28792914
*
@@ -3143,6 +3178,38 @@ interface Namespace {
31433178
*/
31443179
onesnd: typeof onesnd;
31453180

3181+
/**
3182+
* Replaces elements of an array with provided values according to a provided mask array.
3183+
*
3184+
* @param x - input array
3185+
* @param mask - mask array
3186+
* @param values - values to set
3187+
* @param mode - string specifying behavior when the number of values does not equal the number of truthy values in the mask array
3188+
* @returns input array
3189+
*
3190+
* @example
3191+
* var x = [ 1, 2, 3, 4 ];
3192+
*
3193+
* var mask = [ 0, 1, 1, 0 ];
3194+
* var values = [ 20, 30 ];
3195+
*
3196+
* var out = ns.place( x, mask, values, 'strict' );
3197+
* // returns [ 1, 20, 30, 4 ]
3198+
*
3199+
* var bool = ( out === x );
3200+
* // returns true
3201+
*
3202+
* @example
3203+
* var x = [ 1, 2, 3, 4 ];
3204+
*
3205+
* var out = ns.place( x, [ 0, 1, 1, 0 ], [ 30 ], 'strict_broadcast' );
3206+
* // returns [ 1, 30, 30, 4 ]
3207+
*
3208+
* var bool = ( out === x );
3209+
* // returns true
3210+
*/
3211+
place: typeof place;
3212+
31463213
/**
31473214
* Replaces specified elements of an array with provided values.
31483215
*
@@ -4133,6 +4200,38 @@ interface Namespace {
41334200
*/
41344201
unitspace: typeof unitspace;
41354202

4203+
/**
4204+
* Takes elements from either one of two arrays depending on a condition.
4205+
*
4206+
* @param condition - array containing indicator values
4207+
* @param x - first input array
4208+
* @param y - second input array
4209+
* @returns output array
4210+
*
4211+
* @example
4212+
* var x = [ 1, 2, 3, 4 ];
4213+
* var y = [ 5, 6, 7, 8 ];
4214+
*
4215+
* var condition = [ true, false, true, false ];
4216+
*
4217+
* var z = ns.where( condition, x, y );
4218+
* // returns [ 1, 6, 3, 8 ]
4219+
*
4220+
* @example
4221+
* var x = [ 1, 2, 3, 4 ];
4222+
* var y = [ 5, 6, 7, 8 ];
4223+
*
4224+
* var out = [ 0, 0, 0, 0 ];
4225+
* var condition = [ true, false, true, false ];
4226+
*
4227+
* var arr = assign( condition, x, y, out, 1, 0 );
4228+
* // returns [ 1, 6, 3, 8 ]
4229+
*
4230+
* var bool = ( arr === out );
4231+
* // returns true
4232+
*/
4233+
where: typeof where;
4234+
41364235
/**
41374236
* Returns a new array with the element at the specified index replaced with a provided value.
41384237
*

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ var count = context.count;
440440

441441
<a name="method-find-last"></a>
442442

443-
#### Complex64Array.prototype.findLast( predicate\[, thisArg] )
443+
#### BooleanArray.prototype.findLast( predicate\[, thisArg] )
444444

445445
Returns the last element in an array for which a predicate function returns a truthy value.
446446

@@ -790,6 +790,56 @@ v = out.get( 2 );
790790
// returns true
791791
```
792792

793+
<a name="method-to-sorted"></a>
794+
795+
#### BooleanArray.prototype.toSorted( \[compareFcn] )
796+
797+
Returns a new typed array containing the elements in sorted order.
798+
799+
```javascript
800+
function compare( a, b ) {
801+
if ( a === false ) {
802+
if ( b === false ) {
803+
return 0;
804+
}
805+
return 1;
806+
}
807+
if ( b === true ) {
808+
return 0;
809+
}
810+
return -1;
811+
}
812+
813+
var arr = new BooleanArray( 3 );
814+
815+
arr.set( true, 0 );
816+
arr.set( false, 1 );
817+
arr.set( true, 2 );
818+
819+
var out = arr.sort( compare );
820+
// returns <BooleanArray>
821+
822+
var v = out.get( 0 );
823+
// returns true
824+
825+
v = out.get( 1 );
826+
// returns true
827+
828+
v = out.get( 2 );
829+
// returns false
830+
```
831+
832+
The `compareFcn` determines the order of the elements. The function is called with the following arguments:
833+
834+
- **a**: the first boolean value for comparison.
835+
- **b**: the second boolean value for comparison.
836+
837+
The function should return a number where:
838+
839+
- a negative value indicates that `a` should come before `b`.
840+
- a positive value indicates that `a` should come after `b`.
841+
- zero or `NaN` indicates that `a` and `b` are considered equal.
842+
793843
</section>
794844

795845
<!-- /.usage -->
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
// FUNCTIONS //
30+
31+
/**
32+
* Comparison function.
33+
*
34+
* @private
35+
* @param {boolean} a - first boolean value for comparison
36+
* @param {boolean} b - second boolean value for comparison
37+
* @returns {number} comparison result
38+
*/
39+
function compareFcn( a, b ) {
40+
if ( a === true ) {
41+
if ( b === true ) {
42+
return 0;
43+
}
44+
return 1;
45+
}
46+
if ( b === false ) {
47+
return 0;
48+
}
49+
return -1;
50+
}
51+
52+
53+
// MAIN //
54+
55+
bench( pkg+':toSorted', function benchmark( b ) {
56+
var out;
57+
var arr;
58+
var i;
59+
60+
arr = new BooleanArray( [ true, false, false, true, true, false ] );
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
out = arr.toSorted( compareFcn );
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+
});

0 commit comments

Comments
 (0)