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
sv=stride*2;// note: multiply by 2, as real-valued values array consists of interleaved real and imaginary components
171
+
iv=0;
172
+
for(i=0;i<idata.length;i++){
173
+
j=getIndex(iget(idata,i),maxIndex);
174
+
k=j*2;
175
+
x[k]=values[iv];
176
+
x[k+1]=values[iv+1];
177
+
iv+=sv;
178
+
}
179
+
returnx;
180
+
}
181
+
182
+
29
183
// MAIN //
30
184
31
185
/**
@@ -36,7 +190,7 @@ var format = require( '@stdlib/string/format' );
36
190
* @param {Collection} values - values to set
37
191
* @param {string} mode - index mode
38
192
* @throws {Error} third argument must be broadcast compatible with the second argument
39
-
* @returns {Array} output array
193
+
* @returns {Collection} input array
40
194
*
41
195
* @example
42
196
* var x = [ 1, 2, 3, 4 ];
@@ -64,47 +218,49 @@ var format = require( '@stdlib/string/format' );
64
218
*/
65
219
functionput(x,indices,values,mode){
66
220
vargetIndex;
67
-
varxset;
68
-
variget;
69
-
varvget;
221
+
varstride;
70
222
varmax;
71
-
varvs;
223
+
varxo;
224
+
vario;
72
225
varvo;
73
-
varN;
74
-
vari;
75
-
varj;
76
-
77
-
// Resolve accessors for accessing array elements:
78
-
xset=resolveSetter(x);
79
-
iget=resolveGetter(indices);
80
-
vget=resolveGetter(values);
81
-
82
-
// Resolve a function for returning an index according to the specified index mode:
83
-
getIndex=ind(mode);
84
-
85
-
// Resolve the maximum index:
86
-
max=x.length-1;
87
226
88
227
// Broadcast the `values` array...
89
-
N=indices.length;
90
-
if(N>0){// note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements
228
+
if(indices.length>0){// note: this allows `indices` to be empty and `values` to be non-empty (and not broadcast compatible with `indices`) to allow the potential use case where having an empty `indices` array is expected behavior and you don't want to trigger an exception simply because `values` has elements
91
229
// Note that this effectively in-lines logic from `@stdlib/array/base/broadcast-array` in order to avoid unnecessary object creation...
92
-
if(values.length===N){
93
-
vs=1;
230
+
if(values.length===indices.length){
231
+
stride=1;
94
232
}elseif(values.length===1){
95
-
vs=0;
233
+
stride=0;
96
234
}else{
97
-
thrownewError(format('invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).',values.length,N));
235
+
thrownewError(format('invalid argument. The third argument must be broadcast compatible with the second argument. Array shape: (%d). Desired shape: (%d).',values.length,indices.length));
98
236
}
99
237
}
100
-
vo=0;
238
+
// Resolve a function for returning an index according to the specified index mode:
239
+
getIndex=ind(mode);
101
240
102
-
// Replace each desired element in the provided array...
103
-
for(i=0;i<N;i++){
104
-
j=getIndex(iget(indices,i),max);
105
-
xset(x,j,vget(values,vo));
106
-
vo+=vs;
241
+
// Resolve the maximum index:
242
+
max=x.length-1;
243
+
244
+
xo=arraylike2object(x);
245
+
io=arraylike2object(indices);
246
+
vo=arraylike2object(values);
247
+
if(
248
+
xo.accessorProtocol||
249
+
io.accessorProtocol||
250
+
vo.accessorProtocol
251
+
){
252
+
// Note: we only explicitly support complex-to-complex, as this function should not be concerned with casting rules, etc. That is left to userland...
0 commit comments