diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 4572a247..c59a419e 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -853,7 +853,6 @@ B drop_c2(B t, B w, B x) { return c2(rt_drop, w, x); } -extern B rt_join; B join_c1(B t, B x) { if (isAtm(x)) thrM("∾: Argument must be an array"); @@ -956,7 +955,7 @@ B join_c1(B t, B x) { B rf; if(SFNS_FILLS) rf = getFillQ(x0); ur r0 = isAtm(x0) ? 0 : rnk(x0); - usz ia = a(x)->ia; + usz xia = a(x)->ia; usz* xsh = a(x)->sh; usz tlen = 4*xr+2*r0; for (usz a=0; aa; // Temp buffer @@ -965,16 +964,20 @@ B join_c1(B t, B x) { // Length buffer i is lp+lp[i] usz* lp = tsh+xr+r0; lp[0]=xr; for (usz a=1; a r0) thrM("∾: Ranks of argument items too small"); - continue; + if (!tr) thrM("∾: Ranks of argument items too small"); + st[a] = ll[0] = a(x0)->sh[r0-tr]; + tr--; continue; } usz step = st[a]; - usz *ll = lp+lp[a]; ll[0] = r0; for (usz i=1; ir1s) r1s=ll[i]; ur r1 = r1s; - ur add = r1==r0; - if (au+add > r0) thrM("∾: Ranks of argument items too small"); + ur a0 = r1==r0; // Root has axis a + if (tr < a0) thrM("∾: Ranks of argument items too small"); for (usz i=0; ish[au]; + ll[i] = a(c)->sh[r0-tr]; } } // Check shapes - for (usz j=0; jsh; - lr = r-(r0-au); + lr = r - tr; shcpy(tsh,sh,r); shcpy(tsh0,sh,r); - if (!add) shcpy(tsh +lr+1, tsh +lr , r-lr ); - else shcpy(tsh0+lr , tsh0+lr+1, r-lr-1); + if (!a0) shcpy(tsh +lr+1, tsh +lr , tr ); + else shcpy(tsh0+lr , tsh0+lr+1, tr-1); } for (usz i=1; ish + r0-tr : NULL; // Trailing shape + usz csz = shProd(csh, 0, tr); + MAKE_MUT(r, shProd(st, 0, xr)*csz); + // Element index and effective shape, updated progressively + usz *ei =tsh; for (usz i=0; iia; + if (eia) { + usz rj = ri; + usz *ii=tsh0; for (usz k=0; k