@@ -45,8 +45,7 @@ jttk0(J jt, B b, A a, A w) {
4545 return z;
4646}
4747
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
5049 PROLOG (0092 );
5150 array x, y, z;
5251 I an, r, *s, *u, *v;
@@ -59,7 +58,7 @@ jttks(J jt, array a, array w) { // take_sparse
5958 v = AS (z);
6059 DO (an, v[i] = ABS (u[i]););
6160 zp = PAV (z);
62- wp = PAV (w); // pointer to array values
61+ wp = PAV (w); // pointer to array values
6362
6463 if (an <= r) {
6564 RZ (a = jtvec (jt, INT, r, s));
@@ -69,7 +68,7 @@ jttks(J jt, array a, array w) { // take_sparse
6968 auto [m, q] = [&] {
7069 array const a1 = SPA (wp, a);
7170 return std::pair{AN (a1), jtpaxis (jt, r, a1)};
72- } ();
71+ }();
7372
7473 RZ (a = jtfrom (jt, q, a));
7574 u = AV (a);
@@ -87,7 +86,7 @@ jttks(J jt, array a, array w) { // take_sparse
8786 } // fill cannot be virtual
8887 else
8988 x = SPA (wp, x);
90-
89+
9190 // TODO: rename c when we figure out what it is doing
9291 if (auto const c = algo::is_mismatched (u, u + m, s); c) {
9392 A j;
@@ -105,18 +104,15 @@ jttks(J jt, array a, array w) { // take_sparse
105104 yv = CAV (y);
106105 xv = CAV (x);
107106 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);
113109 if (!cc) {
114110 ++d;
115111 memcpy (yv, xv, k);
116112 yv += k;
117113 // TODO: create variadic `algo::transform`
118114 for (int64_t i = 0 ; i < m; ++i) {
119- t = u[i];
115+ t = u[i];
120116 *jv++ = 0 > u[i] ? iv[i] - (u[i] + s[i]) : iv[i];
121117 }
122118 }
@@ -158,7 +154,7 @@ jttk(J jt, A a, A w) {
158154 r - n, if (!s[n + i]) {
159155 b = 1 ;
160156 break ;
161- }); // if empty take, or take from empty cell, set b
157+ }); // if empty take, or take from empty cell, set b
162158 if (((b - 1 ) & AN (w)) == 0 ) return jttk0 (jt, b, a, w); // this handles empty w, so PROD OK below b||!AN(w)
163159 k = bpnoun (t);
164160 z = w;
@@ -212,10 +208,17 @@ jttake(J jt, A a, A w) {
212208 wf = wr - wcr;
213209 RESETRANK;
214210 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
219222 PRISTCLRF (w)
220223 return s;
221224 }
@@ -225,8 +228,8 @@ jttake(J jt, A a, A w) {
225228 I* RESTRICT ws = AS (w); // ws->shape of w
226229 RZ (s =
227230 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
230233 if (!(AT (a) & (B01 + INT))) {
231234 I i;
232235 for (i = 0 ; i < AN (s); ++i) {
@@ -237,8 +240,9 @@ jttake(J jt, A a, A w) {
237240 if (i < AN (s)) {
238241 s = jtca (jt, s);
239242 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
242246 for (; i < AN (s); ++i) {
243247 if (DAV (a)[i] == IMIN)
244248 IAV (s)[i] = IMIN;
@@ -248,8 +252,8 @@ jttake(J jt, A a, A w) {
248252 }
249253 }
250254 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
253257 if (!(ar | wf | ((NOUN & ~(DIRECT | RECURSIBLE)) & wt) | !wcr |
254258 (AFLAG (w) & (AFNJA)))) { // if there is only 1 take axis, w has no frame and is not atomic NJAwhy
255259 // if the length of take is within the bounds of the first axis
@@ -278,8 +282,8 @@ jttake(J jt, A a, A w) {
278282 // full processing for more complex a
279283 if ((-wcr & (wf - 1 )) >= 0 ) { // if y is an atom, or y has multiple cells:
280284 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
283287 if (!wcr) {
284288 DO (n, v[i] = 1 ;);
285289 RZ (w = jtreshape (jt, s, w));
@@ -288,8 +292,8 @@ jttake(J jt, A a, A w) {
288292 // leaves s with the final shape of the result
289293 }
290294 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
293297 PRISTCLRF (w)
294298 return s;
295299}
@@ -313,8 +317,15 @@ jtdrop(J jt, A a, A w) {
313317 // special case: if a is atomic 0, and cells of w are not atomic
314318 if ((-wcr & (ar - 1 )) < 0 && (IAV (a)[0 ] == 0 )) return w; // 0 }. y, return y
315319 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
318329 // We extracted from w, so mark it (or its backer if virtual) non-pristine. There may be replication, so we
319330 // don't pass pristinity through We overwrite w because it is no longer in use
320331 PRISTCLRF (w)
@@ -323,8 +334,8 @@ jtdrop(J jt, A a, A w) {
323334 n = AN (a);
324335 u = AV (a); // n=#axes to drop, u->1st axis
325336 // 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
328339 if (!(ar | wf | ((NOUN & ~(DIRECT | RECURSIBLE)) & wt) | !wcr |
329340 (AFLAG (w) & (AFNJA)))) { // if there is only 1 take axis, w has no frame and is not atomic BJAwhy
330341 I* RESTRICT ws = AS (w); // ws->shape of w
@@ -412,23 +423,25 @@ jthead(J jt, A w) {
412423 wcr--;
413424 wcr = (wcr < 0 ) ? wr : wcr; // wn=#atoms of w, wcr=rank of cell being created
414425 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
417429 I zn;
418430 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
421434 return z;
422435 } 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
425438 // matter
426439 return jtfrom (jtinplace, num (0 ), w); // could call jtfromi directly for non-sparse w
427440 }
428441 } else {
429442 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
432445 }
433446 // pristinity from the called verb
434447}
@@ -442,8 +455,8 @@ jttail(J jt, A w) {
442455 wcr = wr < wcr ? wr : wcr;
443456 wf = wr - wcr; // no RESETRANK: rank is passed into from/take/rsh0. Left rank is garbage but that's OK
444457 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
447460 SPARSE & AT (w) ? jtirs2 (jt, jfalse, jttake (jt, num (-1 ), w), 0L , 0L , wcr, reinterpret_cast <AF>(jtfrom))
448461 : jtrsh0 (jt, w);
449462 // pristinity from other verbs
0 commit comments