@@ -45,8 +45,7 @@ jttk0(J jt, B b, A a, A w) {
45
45
return z;
46
46
}
47
47
48
- static array
49
- jttks (J jt, array a, array w) { // take_sparse
48
+ static array jttks (J jt, array a, array w) { // take_sparse
50
49
PROLOG (0092 );
51
50
array x, y, z;
52
51
I an, r, *s, *u, *v;
@@ -59,7 +58,7 @@ jttks(J jt, array a, array w) { // take_sparse
59
58
v = AS (z);
60
59
DO (an, v[i] = ABS (u[i]););
61
60
zp = PAV (z);
62
- wp = PAV (w); // pointer to array values
61
+ wp = PAV (w); // pointer to array values
63
62
64
63
if (an <= r) {
65
64
RZ (a = jtvec (jt, INT, r, s));
@@ -69,7 +68,7 @@ jttks(J jt, array a, array w) { // take_sparse
69
68
auto [m, q] = [&] {
70
69
array const a1 = SPA (wp, a);
71
70
return std::pair{AN (a1), jtpaxis (jt, r, a1)};
72
- } ();
71
+ }();
73
72
74
73
RZ (a = jtfrom (jt, q, a));
75
74
u = AV (a);
@@ -87,7 +86,7 @@ jttks(J jt, array a, array w) { // take_sparse
87
86
} // fill cannot be virtual
88
87
else
89
88
x = SPA (wp, x);
90
-
89
+
91
90
// TODO: rename c when we figure out what it is doing
92
91
if (auto const c = algo::is_mismatched (u, u + m, s); c) {
93
92
A j;
@@ -105,18 +104,15 @@ jttks(J jt, array a, array w) { // take_sparse
105
104
yv = CAV (y);
106
105
xv = CAV (x);
107
106
for (i = 0 ; i < n; ++i) {
108
-
109
- auto const cc = algo::zip_found (
110
- [](auto a, auto b, auto c) { return 0 > a ? c < a + b : c >= a; },
111
- u, u + m, s, iv);
112
-
107
+ auto const cc =
108
+ algo::zip_found ([](auto a, auto b, auto c) { return 0 > a ? c < a + b : c >= a; }, u, u + m, s, iv);
113
109
if (!cc) {
114
110
++d;
115
111
memcpy (yv, xv, k);
116
112
yv += k;
117
113
// TODO: create variadic `algo::transform`
118
114
for (int64_t i = 0 ; i < m; ++i) {
119
- t = u[i];
115
+ t = u[i];
120
116
*jv++ = 0 > u[i] ? iv[i] - (u[i] + s[i]) : iv[i];
121
117
}
122
118
}
@@ -158,7 +154,7 @@ jttk(J jt, A a, A w) {
158
154
r - n, if (!s[n + i]) {
159
155
b = 1 ;
160
156
break ;
161
- }); // if empty take, or take from empty cell, set b
157
+ }); // if empty take, or take from empty cell, set b
162
158
if (((b - 1 ) & AN (w)) == 0 ) return jttk0 (jt, b, a, w); // this handles empty w, so PROD OK below b||!AN(w)
163
159
k = bpnoun (t);
164
160
z = w;
@@ -212,10 +208,17 @@ jttake(J jt, A a, A w) {
212
208
wf = wr - wcr;
213
209
RESETRANK;
214
210
if (((af - 1 ) & (acr - 2 )) >= 0 ) {
215
- s = rank2ex (a, w, UNUSED_VALUE, MIN (acr, 1 ), wcr, acr, wcr, reinterpret_cast <AF>(jttake)); // if multiple x values, loop over them
216
- // af>0 or acr>1
217
- // We extracted from w, so mark it (or its backer if virtual) non-pristine. There may be replication (if there
218
- // was fill), so we don't pass pristinity through We overwrite w because it is no longer in use
211
+ s = rank2ex (a,
212
+ w,
213
+ UNUSED_VALUE,
214
+ MIN (acr, 1 ),
215
+ wcr,
216
+ acr,
217
+ wcr,
218
+ reinterpret_cast <AF>(jttake)); // if multiple x values, loop
219
+ // over them af>0 or acr>1
220
+ // We extracted from w, so mark it (or its backer if virtual) non-pristine. There may be replication (if
221
+ // there was fill), so we don't pass pristinity through We overwrite w because it is no longer in use
219
222
PRISTCLRF (w)
220
223
return s;
221
224
}
@@ -225,8 +228,8 @@ jttake(J jt, A a, A w) {
225
228
I* RESTRICT ws = AS (w); // ws->shape of w
226
229
RZ (s =
227
230
jtvib (jt, a)); // convert input to integer, auditing for illegal values; and convert infinities to IMAX/-IMAX
228
- // if the input was not INT/bool, we go through and replace any infinities with the length of the axis. If we do
229
- // this, we have to clone the area, because vib might return a canned value
231
+ // if the input was not INT/bool, we go through and replace any infinities with the length of the axis. If we
232
+ // do this, we have to clone the area, because vib might return a canned value
230
233
if (!(AT (a) & (B01 + INT))) {
231
234
I i;
232
235
for (i = 0 ; i < AN (s); ++i) {
@@ -237,8 +240,9 @@ jttake(J jt, A a, A w) {
237
240
if (i < AN (s)) {
238
241
s = jtca (jt, s);
239
242
if (!(AT (a) & FL))
240
- RZ (a = jtcvt (
241
- jt, FL, a)); // copy area we are going to change; put a in a form where we can recognize infinity
243
+ RZ (a = jtcvt (jt,
244
+ FL,
245
+ a)); // copy area we are going to change; put a in a form where we can recognize infinity
242
246
for (; i < AN (s); ++i) {
243
247
if (DAV (a)[i] == IMIN)
244
248
IAV (s)[i] = IMIN;
@@ -248,8 +252,8 @@ jttake(J jt, A a, A w) {
248
252
}
249
253
}
250
254
a = s;
251
- // correct if(!(ar|wf|(SPARSE&wt)|!wcr|(AFLAG(w)&(AFNJA)))){ // if there is only 1 take axis, w has no frame and is
252
- // not atomic
255
+ // correct if(!(ar|wf|(SPARSE&wt)|!wcr|(AFLAG(w)&(AFNJA)))){ // if there is only 1 take axis, w has no frame
256
+ // and is not atomic
253
257
if (!(ar | wf | ((NOUN & ~(DIRECT | RECURSIBLE)) & wt) | !wcr |
254
258
(AFLAG (w) & (AFNJA)))) { // if there is only 1 take axis, w has no frame and is not atomic NJAwhy
255
259
// if the length of take is within the bounds of the first axis
@@ -278,8 +282,8 @@ jttake(J jt, A a, A w) {
278
282
// full processing for more complex a
279
283
if ((-wcr & (wf - 1 )) >= 0 ) { // if y is an atom, or y has multiple cells:
280
284
RZ (s = jtvec (jt, INT, wf + n, AS (w)));
281
- v = wf + AV (s); // s is a block holding shape of a cell of input to the result: w-frame followed by #$a axes,
282
- // all taken from w. vec is never virtual
285
+ v = wf + AV (s); // s is a block holding shape of a cell of input to the result: w-frame followed by #$a
286
+ // axes, all taken from w. vec is never virtual
283
287
if (!wcr) {
284
288
DO (n, v[i] = 1 ;);
285
289
RZ (w = jtreshape (jt, s, w));
@@ -288,8 +292,8 @@ jttake(J jt, A a, A w) {
288
292
// leaves s with the final shape of the result
289
293
}
290
294
s = jttk (jt, s, w); // go do the general take/drop
291
- // We extracted from w, so mark it (or its backer if virtual) non-pristine. There may be replication (if there was
292
- // fill), so we don't pass pristinity through We overwrite w because it is no longer in use
295
+ // We extracted from w, so mark it (or its backer if virtual) non-pristine. There may be replication (if there
296
+ // was fill), so we don't pass pristinity through We overwrite w because it is no longer in use
293
297
PRISTCLRF (w)
294
298
return s;
295
299
}
@@ -313,8 +317,15 @@ jtdrop(J jt, A a, A w) {
313
317
// special case: if a is atomic 0, and cells of w are not atomic
314
318
if ((-wcr & (ar - 1 )) < 0 && (IAV (a)[0 ] == 0 )) return w; // 0 }. y, return y
315
319
if (((af - 1 ) & (acr - 2 )) >= 0 ) {
316
- s = rank2ex (a, w, UNUSED_VALUE, MIN (acr, 1 ), wcr, acr, wcr, reinterpret_cast <AF>(jtdrop)); // if multiple x values, loop over them
317
- // af>0 or acr>1
320
+ s = rank2ex (a,
321
+ w,
322
+ UNUSED_VALUE,
323
+ MIN (acr, 1 ),
324
+ wcr,
325
+ acr,
326
+ wcr,
327
+ reinterpret_cast <AF>(jtdrop)); // if multiple x values, loop
328
+ // over them af>0 or acr>1
318
329
// We extracted from w, so mark it (or its backer if virtual) non-pristine. There may be replication, so we
319
330
// don't pass pristinity through We overwrite w because it is no longer in use
320
331
PRISTCLRF (w)
@@ -323,8 +334,8 @@ jtdrop(J jt, A a, A w) {
323
334
n = AN (a);
324
335
u = AV (a); // n=#axes to drop, u->1st axis
325
336
// virtual case: scalar a
326
- // correct if(!(ar|wf|(SPARSE&wt)|!wcr|(AFLAG(w)&(AFNJA)))){ // if there is only 1 take axis, w has no frame and is
327
- // not atomic
337
+ // correct if(!(ar|wf|(SPARSE&wt)|!wcr|(AFLAG(w)&(AFNJA)))){ // if there is only 1 take axis, w has no frame
338
+ // and is not atomic
328
339
if (!(ar | wf | ((NOUN & ~(DIRECT | RECURSIBLE)) & wt) | !wcr |
329
340
(AFLAG (w) & (AFNJA)))) { // if there is only 1 take axis, w has no frame and is not atomic BJAwhy
330
341
I* RESTRICT ws = AS (w); // ws->shape of w
@@ -412,23 +423,25 @@ jthead(J jt, A w) {
412
423
wcr--;
413
424
wcr = (wcr < 0 ) ? wr : wcr; // wn=#atoms of w, wcr=rank of cell being created
414
425
A z;
415
- RZ (z = jtvirtual (jtinplace, w, 0 , wcr)); // allocate the cell. Now fill in shape & #atoms
416
- // if w is empty we have to worry about overflow when calculating #atoms
426
+ RZ (z = jtvirtual (
427
+ jtinplace, w, 0 , wcr)); // allocate the cell. Now fill in shape & #atoms
428
+ // if w is empty we have to worry about overflow when calculating #atoms
417
429
I zn;
418
430
PROD (zn, wcr, AS (w) + 1 )
419
- MCISH (AS (z), AS (w) + 1 , wcr) AN (z) = zn; // Since z and w may be the same, the copy destroys AS(w). So
420
- // calc zn first. copy shape of CELL of w into z
431
+ MCISH (AS (z), AS (w) + 1 , wcr)
432
+ AN (z) = zn; // Since z and w may be the same, the copy destroys AS(w). So
433
+ // calc zn first. copy shape of CELL of w into z
421
434
return z;
422
435
} else {
423
- // frame not 0, or non-virtualable type, or cell is an atom. Use from. Note that jt->ranks is still set,
424
- // so this may produce multiple cells left rank is garbage, but since num(0) is an atom it doesn't
436
+ // frame not 0, or non-virtualable type, or cell is an atom. Use from. Note that jt->ranks is still
437
+ // set, so this may produce multiple cells left rank is garbage, but since num(0) is an atom it doesn't
425
438
// matter
426
439
return jtfrom (jtinplace, num (0 ), w); // could call jtfromi directly for non-sparse w
427
440
}
428
441
} else {
429
442
return SPARSE & AT (w) ? jtirs2 (jt, jfalse, jttake (jt, jtrue, w), 0L , 0L , wcr, reinterpret_cast <AF>(jtfrom))
430
- : jtrsh0 (jt, w); // cell of w is empty - create a cell of fills jt->ranks is still set
431
- // for use in take. Left rank is garbage, but that's OK
443
+ : jtrsh0 (jt, w); // cell of w is empty - create a cell of fills jt->ranks is still
444
+ // set for use in take. Left rank is garbage, but that's OK
432
445
}
433
446
// pristinity from the called verb
434
447
}
@@ -442,8 +455,8 @@ jttail(J jt, A w) {
442
455
wcr = wr < wcr ? wr : wcr;
443
456
wf = wr - wcr; // no RESETRANK: rank is passed into from/take/rsh0. Left rank is garbage but that's OK
444
457
return !wcr || AS (w)[wf] ? jtfrom (jtinplace, num (-1 ), w)
445
- : // if cells are atoms, or if the cells are nonempty arrays, result is last cell(s) scaf
446
- // should generate virtual block here for speed
458
+ : // if cells are atoms, or if the cells are nonempty arrays, result is last cell(s)
459
+ // scaf should generate virtual block here for speed
447
460
SPARSE & AT (w) ? jtirs2 (jt, jfalse, jttake (jt, num (-1 ), w), 0L , 0L , wcr, reinterpret_cast <AF>(jtfrom))
448
461
: jtrsh0 (jt, w);
449
462
// pristinity from other verbs
0 commit comments