faster 2↕

This commit is contained in:
dzaima 2023-02-18 19:47:22 +02:00
parent 7b57b4ae39
commit 96316f0fe1

View File

@ -84,6 +84,8 @@ B ud_c1(B t, B x) {
return taga(r); return taga(r);
} }
B slash_c2(B t, B w, B x);
B ud_c2(B t, B w, B x) { B ud_c2(B t, B w, B x) {
usz wia=1; usz wia=1;
if (isArr(w)) { if (isArr(w)) {
@ -124,12 +126,16 @@ B ud_c2(B t, B w, B x) {
decG(x); decG(x);
return taga(ra); return taga(ra);
} }
if (wr==1 && wsh[0]==2 && xr==1) {
B t = C2(slash, w, x);
return taga(arr_shSetU(TI(t,slice)(t, 1, IA(t)-2), 2, sh));
}
ur fr=2*wr; // Frame rank in result ur fr=2*wr; // Frame rank in result
usz cia=1; // Cell length usz cia=1; // Cell length
for (usz i=fr; i<rr; i++) if (mulOn(cia, rsh[i])) thrM("↕: result shape too large"); for (usz i=fr; i<rr; i++) if (mulOn(cia, rsh[i])) thrM("↕: result shape too large");
usz ria=cia; usz ria=cia;
for (usz i=0; i<fr; i++) if (mulOn(ria, rsh[i])) thrM("↕: result shape too large"); for (usz i=0; i<fr; i++) if (mulOn(ria, rsh[i])) thrM("↕: result shape too large");
B xf = getFillQ(x);
TALLOC(usz, ri, fr-1); TALLOC(usz, ri, fr-1);
MAKE_MUT(r, ria); mut_init(r, TI(x,elType)); MAKE_MUT(r, ria); mut_init(r, TI(x,elType));
MUTG_INIT(r); MUTG_INIT(r);
@ -141,19 +147,21 @@ B ud_c2(B t, B w, B x) {
for (usz i=0, j=0;;) { for (usz i=0, j=0;;) {
mut_copyG(r, i, x, j, k); mut_copyG(r, i, x, j, k);
usz str = cia*xsh[xr-1]; usz str = cia*xsh[xr-1];
i += k; i+= k;
if (i == ria) break; if (i == ria) break;
j += str; j+= str;
for (usz a=fr-2, b=xr-2; RARE(++ri[a] == rsh[a]); ) { for (usz a=fr-2, b=xr-2; RARE(++ri[a] == rsh[a]); ) {
ri[a] = 0; ri[a] = 0;
j -= rsh[a] * str; j-= rsh[a] * str;
str *= xsh[b]; if (!b) { str=cia; b=xr; } str *= xsh[b]; if (!b) { str=cia; b=xr; }
a--; b--; a--; b--;
j += str; j+= str;
} }
} }
} }
decG(x); TFREE(ri); TFREE(ri);
B xf = getFillQ(x);
decG(x);
return withFill(taga(arr_shSetU(mut_fp(r), rr, sh)), xf); return withFill(taga(arr_shSetU(mut_fp(r), rr, sh)), xf);
} }