some F⌜ shape management refactoring

avoids having two arr_shAlloc invocations, and also makes ⊢⌜ direct
This commit is contained in:
dzaima 2025-06-08 05:58:36 +03:00
parent c90674313b
commit 286067ad51
2 changed files with 21 additions and 11 deletions

View File

@ -78,19 +78,19 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
usz* rsh; usz* rsh;
FC2 fc2 = c2fn(f); FC2 fc2 = c2fn(f);
Arr* ra_nosh;
if (RARE(!isFun(f))) { if (RARE(!isFun(f))) {
if (isMd(f) && ria>0) thrM("Calling a modifier"); if (isMd(f) && ria>0) thrM("Calling a modifier");
MAKE_MUT(rm, ria); ra_nosh = reshape_one(ria, f);
mut_fill(rm, 0, f, ria); goto nosh;
Arr* ra = mut_fp(rm);
rsh = arr_shAlloc(ra, rr);
r = taga(ra);
} else if (RTID(f) == n_ltack) { } else if (RTID(f) == n_ltack) {
r = replicate_by(xia, wia, w); r = replicate_by(xia, wia, w);
goto arith_finish; goto arith_finish;
} else if (RTID(f) == n_rtack) { } else if (RTID(f) == n_rtack) {
r = C2(shape, m_f64(ria), incG(x)); ux xia = IA(x);
goto arith_finish; if (ria<=xia) ra_nosh = TI(x,slice)(incG(x), 0, ria); // ria==0 or ria==xia; necessary as reshape_cycle doesn't handle those
else ra_nosh = reshape_cycle(ria, xia, incG(x));
goto nosh;
} else if (isPervasiveDyExt(f)) { } else if (isPervasiveDyExt(f)) {
if (ria == 0) goto arith_empty; if (ria == 0) goto arith_empty;
if (!TI(w,arrD1)) goto generic; if (!TI(w,arrD1)) goto generic;
@ -107,16 +107,17 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
} }
r = fc2(f, expW, expX); r = fc2(f, expW, expX);
arith_finish:; arith_finish:;
if(RARE(!reusable(r))) r = taga(cpyWithShape(r)); ra_nosh = RARE(!reusable(r))? cpyWithShape(r) : a(r);
arr_shErase(a(r), 1); arr_shErase(ra_nosh, 1);
goto nosh;
} else if (xia>7) { } else if (xia>7) {
SGet(w) SGet(w)
M_APD_TOT(rm, ria) M_APD_TOT(rm, ria)
incByG(x, wia); incByG(x, wia);
for (usz wi = 0; wi < wia; wi++) APDD(rm, fc2(f, Get(w,wi), x)); for (usz wi = 0; wi < wia; wi++) APDD(rm, fc2(f, Get(w,wi), x));
r = taga(arr_shVec(APD_TOT_GET(rm))); ra_nosh = APD_TOT_GET(rm);
goto nosh;
} else goto generic; } else goto generic;
rsh = arr_shAlloc(a(r), rr);
} else { } else {
generic:; generic:;
SGetU(w) SGet(x) SGetU(w) SGet(x)
@ -129,6 +130,12 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
rsh = HARR_FA(r, rr); rsh = HARR_FA(r, rr);
r = HARR_O(r).b; r = HARR_O(r).b;
} }
if (0) {
nosh:
rsh = arr_shAlloc(ra_nosh, rr);
r = taga(ra_nosh);
}
if (rsh) { if (rsh) {
shcpy(rsh , SH(w), wr); shcpy(rsh , SH(w), wr);
shcpy(rsh+wr, SH(x), xr); shcpy(rsh+wr, SH(x), xr);

View File

@ -608,6 +608,9 @@ b←1↓1∾a←"hello" ⋄ b ⌽⎊'e' ⥊⟜1⍟2 5 ⋄ a ≡○•Hash b %% 1
!"𝕨𝔽⌜𝕩: Result rank too large (200≡=𝕨, 200≡=𝕩)" % +˜(2001)1 !"𝕨𝔽⌜𝕩: Result rank too large (200≡=𝕨, 200≡=𝕩)" % +˜(2001)1
%USE eqvar (! + •internal.Keep + )˜ 6 # TODO _eqvar once it's consistent %USE eqvar (! + •internal.Keep + )˜ 6 # TODO _eqvar once it's consistent
%USE eqvar (! -˜•internal.Keep -˜)˜ 6 # TODO _eqvar once it's consistent %USE eqvar (! -˜•internal.Keep -˜)˜ 6 # TODO _eqvar once it's consistent
%USE eqvar (! •internal.Keep _eqvar)˜ 6
%USE eqvar (! •internal.Keep _eqvar)˜ 6
%USE eqvar (! 9•internal.Keep 9_eqvar)˜ 6
# ˜ # ˜
5˜˝ "ab" %% 5 5˜˝ "ab" %% 5