Handle empty cells in insert_base; fixes bugs in dyadic Insert

This commit is contained in:
Marshall Lochbaum 2023-05-18 11:53:53 -04:00
parent a8cead1d3d
commit 9dfeb451f8
2 changed files with 12 additions and 13 deletions

View File

@ -32,24 +32,25 @@ B takedrop_highrank(bool take, B w, B x); // from sfns.c
BSS2A X##_slc = TI(X,slice); \
incByG(X, (i64)X##_sn + ((i64)DX-1));
#define S_SLICES(X, SLN) usz* X##_sh = SH(X); S_KSLICES(X, X##_sh, 1, SLN, 0)
#define SLICE(X, S) taga(arr_shSetUO(X##_slc(X, S, X##_csz), X##_cr, X##_csh))
#define SLICEI(X) ({ B r = SLICE(X, X##p); X##p+= X##_csz; r; })
// Used by Insert in fold.c
B insert_base(B f, B x, usz xia, bool has_w, B w) {
B insert_base(B f, B x, bool has_w, B w) {
assert(isArr(x) && RNK(x)>0);
S_SLICES(x, *x_sh)
usz p = xia;
usz* xsh = SH(x);
usz xn = xsh[0];
S_KSLICES(x, xsh, 1, xn, 0)
usz p = xn*x_csz;
B r = w;
if (!has_w) {
p -= x_csz;
p -= x_csz; xn--;
r = SLICE(x, p);
}
FC2 fc2 = c2fn(f);
while(p!=0) {
while (xn--) {
p-= x_csz;
r = fc2(f, SLICE(x, p), r);
}

View File

@ -329,12 +329,11 @@ static B m1c1(B t, B f, B x) { // consumes x
return r;
}
extern B rt_insert;
extern B insert_base(B f, B x, usz xia, bool has_w, B w); // from cells.c
extern B insert_base(B f, B x, bool has_w, B w); // from cells.c
B insert_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || RNK(x)==0) thrM("˝: 𝕩 must have rank at least 1");
usz xia = IA(x);
if (xia==0) { SLOW2("!𝕎˝𝕩", f, x); return m1c1(rt_insert, f, x); }
if (*SH(x)==0) { SLOW2("!𝕎˝𝕩", f, x); return m1c1(rt_insert, f, x); }
if (isFun(f)) {
u8 rtid = v(f)->flags-1;
ur xr = RNK(x);
@ -354,13 +353,12 @@ B insert_c1(Md1D* d, B x) { B f = d->f;
return taga(r);
}
}
return insert_base(f, x, xia, 0, bi_N);
return insert_base(f, x, 0, bi_N);
}
B insert_c2(Md1D* d, B w, B x) { B f = d->f;
if (isAtm(x) || RNK(x)==0) thrM("˝: 𝕩 must have rank at least 1");
usz xia = IA(x);
B r = w;
if (xia==0) { decG(x); return r; }
if (*SH(x)==0) { decG(x); return r; }
if (isFun(f)) {
if (RNK(x)==1 && isPervasiveDyExt(f)) {
@ -373,7 +371,7 @@ B insert_c2(Md1D* d, B w, B x) { B f = d->f;
}
}
}
return insert_base(f, x, xia, 1, w);
return insert_base(f, x, 1, w);
}
// Arithmetic fold/insert on rows of flat rank-2 array x