You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/array/base/mskput/README.md
+15-2Lines changed: 15 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,20 +54,33 @@ The function supports the following parameters:
54
54
The function supports the following modes:
55
55
56
56
-`'throw'`: specifies that the function must raise an exception when the function is provided insufficient `values` to satisfy the `mask` array.
57
+
-`'broadcast'`: specifies that the function must broadcast a single-element `values` array and otherwise raise an exception when the function is provided insufficient `values` to satisfy the `mask` array.
57
58
-`'repeat'`: specifies that the function must reuse provided `values` when replacing elements in `x` in order to satisfy the `mask` array.
58
59
59
-
When `mode` is equal to `'repeat`', the function supports broadcasting a `values` array containing a single element against the number of falsy values in the `mask` array.
60
+
When `mode` is equal to `'broadcast`', the function supports broadcasting a `values` array containing a single element against the number of falsy values in the `mask` array.
60
61
61
62
```javascript
62
63
var x = [ 1, 2, 3, 4 ];
63
64
64
-
var out =mskput( x, [ 1, 0, 1, 0 ], [ 20 ], 'repeat' );
65
+
var out =mskput( x, [ 1, 0, 1, 0 ], [ 20 ], 'broadcast' );
65
66
// returns [ 1, 20, 3, 20 ]
66
67
67
68
var bool = ( out === x );
68
69
// returns true
69
70
```
70
71
72
+
When `mode` is equal to `repeat`, the function supports recycling elements in a `values` array to satisfy the number of falsy values in the `mask` array.
73
+
74
+
```javascript
75
+
var x = [ 1, 2, 3, 4 ];
76
+
77
+
var out =mskput( x, [ 0, 0, 1, 0 ], [ 20, 40 ], 'repeat' );
* Mode specifying whether to raise an exception when the number of values to set is less than the number of falsy values in the mask array.
37
+
* Mode specifying behavior when the number of values to set is less than the number of falsy values in the mask array.
38
38
*
39
39
* ## Notes
40
40
*
41
41
* - The function supports the following modes:
42
42
*
43
43
* - `'throw'`: specifies that the function must raise an exception when the function is provided insufficient `values` to satisfy the `mask` array.
44
+
* - `'broadcast'`: specifies that the function must broadcast a single-element `values` array and otherwise raise an exception when the function is provided insufficient `values` to satisfy the `mask` array.
44
45
* - `'repeat'`: specifies that the function must reuse provided `values` when replacing elements in `x` in order to satisfy the `mask` array.
45
46
*/
46
-
typeMode='throw'|'repeat';
47
+
typeMode='throw'|'broadcast'|'repeat';
47
48
48
49
/**
49
50
* Replaces elements of an array with provided values according to a provided mask array.
50
51
*
51
52
* @param x - input array
52
53
* @param mask - mask array
53
54
* @param values - values to set
54
-
* @param mode - string specifying whether to raise an exception when the number of values is less than the number of falsy values in the mask array
55
+
* @param mode - string specifying behavior when the number of values is less than the number of falsy values in the mask array
55
56
* @returns input array
56
57
*
57
58
* @example
@@ -73,7 +74,7 @@ type Mode = 'throw' | 'repeat';
73
74
*
74
75
* var x = new Int32Array( [ 1, 2, 3, 4 ] );
75
76
*
76
-
* var out = mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'repeat' );
77
+
* var out = mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'broadcast' );
77
78
* // returns <Int32Array>[ 1, 30, 30, 4 ]
78
79
*
79
80
* var bool = ( out === x );
@@ -87,7 +88,7 @@ declare function mskput<T extends TypedArray | BooleanTypedArray, U = unknown>(
87
88
* @param x - input array
88
89
* @param mask - mask array
89
90
* @param values - values to set
90
-
* @param mode - string specifying whether to raise an exception when the number of values is less than the number of falsy values in the mask array
91
+
* @param mode - string specifying behavior when the number of values is less than the number of falsy values in the mask array
91
92
* @returns input array
92
93
*
93
94
* @example
@@ -112,7 +113,7 @@ declare function mskput<T extends TypedArray | BooleanTypedArray, U = unknown>(
112
113
* var mask = [ 1, 0, 0, 1 ];
113
114
* var values = new Complex128Array( [ 20.0, 30.0 ] );
114
115
*
115
-
* var out = mskput( x, mask, values, 'repeat' );
116
+
* var out = mskput( x, mask, values, 'broadcast' );
116
117
* // returns <Complex128Array>
117
118
*
118
119
* var bool = ( out === x );
@@ -126,7 +127,7 @@ declare function mskput<T extends ComplexTypedArray>( x: T, mask: MaskArray, val
126
127
* @param x - input array
127
128
* @param mask - mask array
128
129
* @param values - values to set
129
-
* @param mode - string specifying whether to raise an exception when the number of values is less than the number of falsy values in the mask array
130
+
* @param mode - string specifying behavior when the number of values is less than the number of falsy values in the mask array
130
131
* @returns input array
131
132
*
132
133
* @example
@@ -144,7 +145,7 @@ declare function mskput<T extends ComplexTypedArray>( x: T, mask: MaskArray, val
144
145
* @example
145
146
* var x = [ 1, 2, 3, 4 ];
146
147
*
147
-
* var out = mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'repeat' );
148
+
* var out = mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'broadcast' );
148
149
* // returns [ 1, 30, 30, 4 ]
149
150
*
150
151
* var bool = ( out === x );
@@ -158,7 +159,7 @@ declare function mskput<T = unknown, U = unknown>( x: Array<T>, mask: MaskArray,
158
159
* @param x - input array
159
160
* @param mask - mask array
160
161
* @param values - values to set
161
-
* @param mode - string specifying whether to raise an exception when the number of values is less than the number of falsy values in the mask array
162
+
* @param mode - string specifying behavior when the number of values is less than the number of falsy values in the mask array
162
163
* @returns input array
163
164
*
164
165
* @example
@@ -179,7 +180,7 @@ declare function mskput<T = unknown, U = unknown>( x: Array<T>, mask: MaskArray,
179
180
*
180
181
* var x = toAccessorArray( [ 1, 2, 3, 4 ] );
181
182
*
182
-
* var out = mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'repeat' );
183
+
* var out = mskput( x, [ 1, 0, 0, 1 ], [ 30 ], 'broadcast' );
183
184
*
184
185
* var bool = ( out === x );
185
186
* // returns true
@@ -192,7 +193,7 @@ declare function mskput<T = unknown, U = unknown>( x: AccessorArrayLike<T>, mask
192
193
* @param x - input array
193
194
* @param mask - mask array
194
195
* @param values - values to set
195
-
* @param mode - string specifying whether to raise an exception when the number of values is less than the number of falsy values in the mask array
196
+
* @param mode - string specifying behavior when the number of values is less than the number of falsy values in the mask array
@@ -227,7 +227,7 @@ tape( 'the function replaces elements in an array (accessors, broadcasting)', fu
227
227
newComplex64(5.0,6.0),
228
228
newComplex64(100.0,200.0)
229
229
];
230
-
actual=mskput(x,mask,values,'repeat');
230
+
actual=mskput(x,mask,values,'broadcast');
231
231
232
232
t.strictEqual(actual,x,'returns expected value');
233
233
for(i=0;i<mask.length;i++){
@@ -287,7 +287,7 @@ tape( 'the function replaces elements in an array (accessors, complex, broadcast
287
287
newComplex64(5.0,6.0),
288
288
newComplex64(100.0,200.0)
289
289
];
290
-
actual=mskput(x,mask,values,'repeat');
290
+
actual=mskput(x,mask,values,'broadcast');
291
291
292
292
t.strictEqual(actual,x,'returns expected value');
293
293
for(i=0;i<mask.length;i++){
@@ -335,7 +335,7 @@ tape( 'the function replaces elements in an array (accessors, boolean, broadcast
335
335
mask=toAccessorArray([1,0,0,1]);
336
336
values=[true];
337
337
expected=[true,true,true,true];
338
-
actual=mskput(x,mask,values,'repeat');
338
+
actual=mskput(x,mask,values,'broadcast');
339
339
340
340
t.strictEqual(actual,x,'returns expected value');
341
341
for(i=0;i<mask.length;i++){
@@ -359,3 +359,18 @@ tape( 'when the "mode" is "throw", the function throws an error if provided insu
359
359
mskput(x,mask,[200],'throw');
360
360
}
361
361
});
362
+
363
+
tape('when the "mode" is "broadcast", the function throws an error if a provided values array is broadcast incompatible with the number of falsy values in a mask array',functiontest(t){
0 commit comments