use getFillQ less
This commit is contained in:
parent
d62c77af41
commit
0598ce8357
@ -6,7 +6,7 @@
|
||||
#include <math.h>
|
||||
|
||||
static inline B arith_recm(FC1 f, B x) {
|
||||
B fx = getFillQ(x);
|
||||
B fx = getFillR(x);
|
||||
B r = eachm_fn(bi_N, x, f);
|
||||
return withFill(r, fx);
|
||||
}
|
||||
|
||||
@ -61,11 +61,9 @@ B insert_base(B f, B x, usz xia, bool has_w, B w) {
|
||||
i32 fullCellFills = 2*CATCH_ERRORS;
|
||||
i32 cellFillErrored = 0;
|
||||
#define DO_CELL_CATCH (fullCellFills==2)
|
||||
#define getFillQ2 (fullCellFills? getFillR : getFillQ)
|
||||
#define SET_FILL_ERRORED cellFillErrored = 1
|
||||
#else
|
||||
#define DO_CELL_CATCH CATCH_ERRORS
|
||||
#define getFillQ2 getFillQ
|
||||
#define SET_FILL_ERRORED
|
||||
#endif
|
||||
|
||||
@ -261,7 +259,7 @@ static NOINLINE B transp_cells(ur ax, ur k, B x) {
|
||||
|
||||
// helpers
|
||||
static NOINLINE B to_fill_cell(B x, ur k, u32 chr) { // consumes x
|
||||
B xf = getFillQ2(x);
|
||||
B xf = getFillR(x);
|
||||
if (noFill(xf)) xf = m_f64(0);
|
||||
ur cr = RNK(x)-k;
|
||||
usz* sh = SH(x)+k;
|
||||
@ -279,7 +277,7 @@ static NOINLINE B to_fill_cell(B x, ur k, u32 chr) { // consumes x
|
||||
static NOINLINE B merge_fill_result(B rc, ur k, usz* sh, u32 chr) {
|
||||
u64 rr = k; if (isArr(rc)) rr+= RNK(rc);
|
||||
if (rr>UR_MAX) thrF("%c: Result rank too large", chr);
|
||||
Arr* r = m_fillarrpEmpty(getFillQ2(rc));
|
||||
Arr* r = m_fillarrpEmpty(getFillR(rc));
|
||||
usz* rsh = arr_shAlloc(r, rr);
|
||||
if (rr>1) {
|
||||
shcpy(rsh, sh, k);
|
||||
|
||||
@ -143,7 +143,7 @@ B ud_c2(B t, B w, B x) {
|
||||
for (usz i=wr; i<xr; i++) wsh[i] = xsh[i];
|
||||
|
||||
if (empty) {
|
||||
Arr* ra = arr_shSetUG(m_fillarrpEmpty(getFillQ(x)), rr, sh);
|
||||
Arr* ra = arr_shSetUG(m_fillarrpEmpty(getFillR(x)), rr, sh);
|
||||
decG(x);
|
||||
return taga(ra);
|
||||
}
|
||||
@ -181,7 +181,7 @@ B ud_c2(B t, B w, B x) {
|
||||
}
|
||||
}
|
||||
TFREE(ri);
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
decG(x);
|
||||
return withFill(taga(arr_shSetUG(mut_fp(r), rr, sh)), xf);
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ B SORT_C1(B t, B x) {
|
||||
RADIX_SORT_i32(u32, SORT,);
|
||||
}
|
||||
} else {
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
HArr* r0 = (HArr*)cpyHArr(incG(x));
|
||||
CAT(GRADE_UD(bA,bD),tim_sort)(r0->a, n);
|
||||
r = withFill(taga(r0), xf);
|
||||
|
||||
@ -84,7 +84,7 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) {
|
||||
Arr* r = m_fillarr0p(ria);
|
||||
B* rp = fillarr_ptr(r);
|
||||
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
Arr* rf = m_fillarrpEmpty(xf);
|
||||
if (xr==1) arr_shVec(rf); else arr_shChangeLen(rf, xr, xsh, 0);
|
||||
|
||||
@ -297,8 +297,7 @@ B group_c2(B t, B w, B x) {
|
||||
for (usz i = 0; i < xn; i++) len[o2i64G(GetU(w, i))]++;
|
||||
|
||||
Arr* r = m_fillarr0p(ria);
|
||||
B xf = getFillQ(x);
|
||||
incBy(xf, ria);
|
||||
B xf = incBy(getFillN(x), ria+1);
|
||||
B* rp = fillarr_ptr(r);
|
||||
for (usz i = 0; i < ria; i++) {
|
||||
Arr* c = m_fillarrp(len[i]);
|
||||
|
||||
@ -186,7 +186,7 @@ B variation_c2(B t, B w, B x) {
|
||||
else if (u8_get(&wp, wpE, "h" )) res = taga(cpyHArr (incG(x)));
|
||||
else if (u8_get(&wp, wpE, "f")) {
|
||||
Arr* r = m_fillarrp(xia);
|
||||
fillarr_setFill(r, getFillQ(x));
|
||||
fillarr_setFill(r, getFillR(x));
|
||||
arr_shCopy(r, x);
|
||||
COPY_TO(fillarr_ptr(r), el_B, 0, x, 0, xia);
|
||||
NOGC_E;
|
||||
@ -251,7 +251,7 @@ static B unshare(B x) {
|
||||
}
|
||||
case t_fillarr: case t_fillslice: {
|
||||
Arr* r = arr_shCopy(m_fillarr0p(xia), x);
|
||||
fillarr_setFill(r, unshare(getFillQ(x)));
|
||||
fillarr_setFill(r, unshare(getFillR(x)));
|
||||
B* rp = fillarr_ptr(r);
|
||||
B* xp = fillarr_ptr(a(x));
|
||||
for (usz i = 0; i < xia; i++) rp[i] = unshare(xp[i]);
|
||||
|
||||
@ -39,7 +39,7 @@ static NOINLINE B homFil2(B f, B r, B wf, B xf) {
|
||||
|
||||
B each_c1(Md1D* d, B x) { B f = d->f;
|
||||
B r, xf;
|
||||
if (EACH_FILLS) xf = getFillQ(x);
|
||||
if (EACH_FILLS) xf = getFillR(x);
|
||||
|
||||
if (isAtm(x)) r = m_hunit(c1(f, x));
|
||||
else if (isFun(f)) r = eachm_fn(f, x, c(Fun,f)->c1);
|
||||
@ -103,8 +103,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
}
|
||||
B wf, xf;
|
||||
if (EACH_FILLS) {
|
||||
assert(isArr(w)); wf=getFillQ(w);
|
||||
assert(isArr(x)); xf=getFillQ(x);
|
||||
assert(isArr(w)); wf=getFillR(w);
|
||||
assert(isArr(x)); xf=getFillR(x);
|
||||
decG(w); decG(x);
|
||||
return homFil2(f, r, wf, xf);
|
||||
} else {
|
||||
@ -120,8 +120,8 @@ static B eachd(B f, B w, B x) {
|
||||
|
||||
B each_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (!EACH_FILLS) return eachd(f, w, x);
|
||||
B wf = getFillQ(w);
|
||||
B xf = getFillQ(x);
|
||||
B wf = getFillR(w);
|
||||
B xf = getFillR(x);
|
||||
return homFil2(f, eachd(f, w, x), wf, xf);
|
||||
}
|
||||
|
||||
|
||||
@ -213,7 +213,7 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
|
||||
}
|
||||
base:;
|
||||
SLOW2("𝕎` 𝕩", f, x);
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
|
||||
bool reuse = TY(x)==t_harr && reusable(x);
|
||||
HArr_p r = reuse? harr_parts(REUSE(x)) : m_harr0c(x);
|
||||
@ -277,7 +277,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
}
|
||||
base:;
|
||||
SLOW3("𝕨 F` 𝕩", w, x, f);
|
||||
B wf = getFillQ(w);
|
||||
B wf = getFillR(w);
|
||||
|
||||
bool reuse = (TY(x)==t_harr && reusable(x)) | !ia;
|
||||
usz i = 0;
|
||||
|
||||
@ -163,7 +163,7 @@ B select_c2(B t, B w, B x) {
|
||||
goto setsh;
|
||||
}
|
||||
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
usz xn = *SH(x);
|
||||
if (xn==0) goto base;
|
||||
usz csz = arr_csz(x);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include "../builtins.h"
|
||||
|
||||
NOINLINE Arr* emptyArr(B x, ur xr) {
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
if (xr==1) {
|
||||
if (isF64(xf)) return a(emptyIVec());
|
||||
if (noFill(xf)) return a(emptyHVec());
|
||||
@ -251,12 +251,12 @@ B shape_c2(B t, B w, B x) {
|
||||
if (bi == 1) { memset(rp, rp[0], bf); bi=bf; }
|
||||
} else {
|
||||
if (TI(x,elType) == el_B) {
|
||||
B xf = getFillQ(x);
|
||||
MAKE_MUT_INIT(m, nia, el_B); MUTG_INIT(m);
|
||||
i64 div = nia/xia;
|
||||
i64 mod = nia%xia;
|
||||
for (i64 i = 0; i < div; i++) mut_copyG(m, i*xia, x, 0, xia);
|
||||
mut_copyG(m, div*xia, x, 0, mod);
|
||||
B xf = getFillR(x);
|
||||
decG(x);
|
||||
return withFill(taga(arr_shSetUO(mut_fp(m), nr, sh)), xf);
|
||||
}
|
||||
@ -682,7 +682,6 @@ B join_c1(B t, B x) {
|
||||
}
|
||||
ur ir = RNK(xf);
|
||||
if (ir<xr) thrF("∾: Empty array 𝕩 fill rank must be at least rank of 𝕩 (shape %H and fill shape %H)", x, xf);
|
||||
B xff = getFillQ(xf);
|
||||
HArr_p r = m_harrUp(0);
|
||||
usz* sh = arr_shAlloc((Arr*)r.c, ir);
|
||||
if (sh) {
|
||||
@ -694,13 +693,14 @@ B join_c1(B t, B x) {
|
||||
}
|
||||
shcpy(sh+xr, fsh+xr, ir-xr);
|
||||
}
|
||||
B xff = getFillR(xf);
|
||||
dec(xf); decG(x);
|
||||
return withFill(r.b, xff);
|
||||
|
||||
} else if (xr==1) {
|
||||
SGetU(x)
|
||||
B x0 = GetU(x,0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillQ(x0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillR(x0);
|
||||
ur rm = isAtm(x0) ? 0 : RNK(x0); // Maximum element rank seen
|
||||
ur rr = rm; // Result rank, or minimum possible so far
|
||||
ur rd = 0; // Difference of max and min lengths (0 or 1)
|
||||
@ -760,7 +760,7 @@ B join_c1(B t, B x) {
|
||||
} else {
|
||||
SGetU(x)
|
||||
B x0 = GetU(x,0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillQ(x0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillR(x0);
|
||||
ur r0 = isAtm(x0) ? 0 : RNK(x0);
|
||||
|
||||
usz xia = IA(x);
|
||||
@ -1090,7 +1090,7 @@ B reverse_c1(B t, B x) {
|
||||
else { SGet(x) for (usz i=0; i<n; i++) rp.a[i] = Get(x, n-i-1); }
|
||||
NOGC_E;
|
||||
r = rp.b;
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
decG(x);
|
||||
return withFill(r, xf);
|
||||
}
|
||||
@ -1098,7 +1098,7 @@ B reverse_c1(B t, B x) {
|
||||
decG(x);
|
||||
return r;
|
||||
}
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
SLOW1("⌽𝕩", x);
|
||||
usz csz = arr_csz(x);
|
||||
usz cam = SH(x)[0];
|
||||
@ -1212,20 +1212,20 @@ B reverse_c2(B t, B w, B x) {
|
||||
MAKE_MUT_INIT(r, xia, TI(x,elType)); MUTG_INIT(r);
|
||||
mut_copyG(r, 0, x, am, xia-am);
|
||||
mut_copyG(r, xia-am, x, 0, am);
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
return withFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
|
||||
|
||||
B pick_uc1(B t, B o, B x) { // TODO do in-place like pick_ucw; maybe just call it?
|
||||
if (isAtm(x) || IA(x)==0) return def_fn_uc1(t, o, x);
|
||||
B xf = getFillQ(x);
|
||||
usz ia = IA(x);
|
||||
B arg = IGet(x, 0);
|
||||
B rep = c1(o, arg);
|
||||
MAKE_MUT_INIT(r, ia, el_or(TI(x,elType), selfElType(rep))); MUTG_INIT(r);
|
||||
mut_setG(r, 0, rep);
|
||||
mut_copyG(r, 1, x, 1, ia-1);
|
||||
B xf = getFillR(x);
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
|
||||
@ -1242,7 +1242,7 @@ B pick_ucw(B t, B o, B w, B x) {
|
||||
xp = fillarr_ptr(a(x));
|
||||
} else {
|
||||
Arr* x2 = m_fillarrp(xia);
|
||||
fillarr_setFill(x2, getFillQ(x));
|
||||
fillarr_setFill(x2, getFillR(x));
|
||||
xp = fillarr_ptr(x2);
|
||||
COPY_TO(xp, el_B, 0, x, 0, xia);
|
||||
NOGC_E;
|
||||
@ -1271,7 +1271,7 @@ B pick_ucw(B t, B o, B w, B x) {
|
||||
mut_setG(r, wi, rep);
|
||||
mut_copyG(r, 0, x, 0, wi);
|
||||
mut_copyG(r, wi+1, x, wi+1, xia-wi-1);
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ static B compress_grouped(u64* wp, B x, usz wia, usz wsum, u8 xt) {
|
||||
for (usz i = 0; i < wia; i++) if (bitp_get(wp,i)) {
|
||||
for (usz j = 0; j < csz; j++) HARR_ADDA(rp, Get(x,i*csz+j));
|
||||
}
|
||||
return withFill(HARR_FV(rp), getFillQ(x));
|
||||
return withFill(HARR_FV(rp), getFillR(x));
|
||||
}
|
||||
|
||||
rh = m_harrUv(ria);
|
||||
@ -213,7 +213,7 @@ static B compress_grouped(u64* wp, B x, usz wia, usz wsum, u8 xt) {
|
||||
if (is_B) {
|
||||
for (usz i = 0; i < wsum*csz; i++) inc(((B*)rp)[i]);
|
||||
NOGC_E;
|
||||
r = withFill(rh.b, getFillQ(x));
|
||||
r = withFill(rh.b, getFillR(x));
|
||||
a(r)->ia = wsum; // Shape-setting code at end of compress expects this
|
||||
}
|
||||
} else { // Bits
|
||||
@ -492,7 +492,7 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) {
|
||||
case 6:
|
||||
if (TI(x,elType)!=el_B) { BLOCK_OR_GROUPED(u64) }
|
||||
else {
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
B* xp = arr_bptr(x);
|
||||
if (xp!=NULL) {
|
||||
COMPRESS_BLOCK_PREP(B, HArr_p rh = m_harrUv(wsum); B *rp = rh.a;);
|
||||
@ -684,7 +684,7 @@ B slash_c2(B t, B w, B x) {
|
||||
if (RARE(TI(x,elType)==el_B)) { // Slow case
|
||||
arrW_base:
|
||||
SLOW2("𝕨/𝕩", w, x);
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
usz csz = arr_csz(x);
|
||||
MAKE_MUT_INIT(r0, s*csz, TI(x,elType)); MUTG_INIT(r0);
|
||||
SGetU(w)
|
||||
@ -765,7 +765,7 @@ B slash_c2(B t, B w, B x) {
|
||||
if (xlen == 0) return x;
|
||||
usz s = xlen * wv;
|
||||
if (xl>6 || (xl<3 && xl!=0) || TI(x,elType)==el_B) {
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
if (xr!=1) {
|
||||
MAKE_MUT_INIT(r0, IA(x) * wv, TI(x,elType)); MUTG_INIT(r0);
|
||||
usz csz = arr_csz(x);
|
||||
|
||||
@ -186,7 +186,7 @@ B squeeze_deep(B x) {
|
||||
usz ia = IA(x);
|
||||
M_HARR(r, ia)
|
||||
B* xp = arr_bptr(x);
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
if (xp!=NULL) {
|
||||
for (usz i=0; i<ia; i++) { HARR_ADD(r, i, squeeze_deep(inc(xp[i]))); }
|
||||
} else {
|
||||
|
||||
@ -222,7 +222,7 @@ B transp_c2(B t, B w, B x) {
|
||||
|
||||
// Empty result
|
||||
if (IA(x) == 0) {
|
||||
Arr* ra = m_fillarrpEmpty(getFillQ(x));
|
||||
Arr* ra = m_fillarrpEmpty(getFillR(x));
|
||||
shSet(ra, rr, sh);
|
||||
decG(x);
|
||||
r = taga(ra); goto ret;
|
||||
@ -281,7 +281,7 @@ B transp_c2(B t, B w, B x) {
|
||||
AXIS_LOOP(na, csz, mut_copyG(rm, i, x, j, csz));
|
||||
Arr* ra = mut_fp(rm);
|
||||
shSet(ra, rr, sh);
|
||||
r = withFill(taga(ra), getFillQ(x));
|
||||
r = withFill(taga(ra), getFillR(x));
|
||||
decG(x); goto ret;
|
||||
}
|
||||
#undef AXIS_LOOP
|
||||
|
||||
@ -21,7 +21,7 @@ B asFill(B x) { // consumes
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
if (noFill(HARR_ADD(r, i, asFill(Get(x,i))))) { HARR_ABANDON(r); decG(x); return bi_noFill; }
|
||||
}
|
||||
B xf = getFillQ(x);
|
||||
B xf = getFillR(x);
|
||||
return withFill(HARR_FCD(r, x), xf);
|
||||
}
|
||||
if (isF64(x)) return m_i32(0);
|
||||
|
||||
@ -424,7 +424,7 @@ B bqn_merge(B x, u32 type) {
|
||||
B xf = getFillE(x);
|
||||
if (isAtm(xf)) { dec(xf); return x; }
|
||||
i32 xfr = RNK(xf);
|
||||
Arr* r = m_fillarrpEmpty(getFillQ(xf));
|
||||
Arr* r = m_fillarrpEmpty(getFillR(xf));
|
||||
if (xr+xfr > UR_MAX) thrM(">: Result rank too large");
|
||||
usz* rsh = arr_shAlloc(r, xr+xfr);
|
||||
if (rsh) {
|
||||
|
||||
@ -118,9 +118,9 @@ B eachm_fn(B fo, B x, FC1 f) {
|
||||
|
||||
#if CATCH_ERRORS
|
||||
B arith_recd(FC2 f, B w, B x) {
|
||||
B fx = getFillQ(x);
|
||||
B fx = getFillR(x);
|
||||
if (noFill(fx)) return eachd_fn(bi_N, w, x, f);
|
||||
B fw = getFillQ(w);
|
||||
B fw = getFillR(w);
|
||||
B r = eachd_fn(bi_N, w, x, f);
|
||||
if (noFill(fw)) { dec(fx); return r; }
|
||||
if (CATCH) { freeThrown(); return r; }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user