reduce reshape+replicate-based Arith⌜ constant overhead
This commit is contained in:
parent
0a561bce2b
commit
c90674313b
@ -64,6 +64,8 @@ B tbl_c1(Md1D* d, B x) {
|
|||||||
|
|
||||||
B slash_c2(B t, B w, B x);
|
B slash_c2(B t, B w, B x);
|
||||||
B shape_c2(B t, B w, B x);
|
B shape_c2(B t, B w, B x);
|
||||||
|
Arr* reshape_cycle(usz nia, usz xia, B x); // from sfns.c
|
||||||
|
static B replicate_by(usz rep, usz xia, B x) { return C2(slash, m_usz(rep), taga(arr_shVec(TI(x,slice)(incG(x), 0, xia)))); }
|
||||||
B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||||
if (isAtm(w)) w = m_unit(w);
|
if (isAtm(w)) w = m_unit(w);
|
||||||
if (isAtm(x)) x = m_unit(x);
|
if (isAtm(x)) x = m_unit(x);
|
||||||
@ -84,20 +86,30 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
|||||||
rsh = arr_shAlloc(ra, rr);
|
rsh = arr_shAlloc(ra, rr);
|
||||||
r = taga(ra);
|
r = taga(ra);
|
||||||
} else if (RTID(f) == n_ltack) {
|
} else if (RTID(f) == n_ltack) {
|
||||||
Arr* wd = arr_shVec(TI(w,slice)(incG(w), 0, wia));
|
r = replicate_by(xia, wia, w);
|
||||||
r = C2(slash, m_i32(xia), taga(wd));
|
|
||||||
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));
|
r = C2(shape, m_f64(ria), incG(x));
|
||||||
goto arith_finish;
|
goto arith_finish;
|
||||||
} else if (TI(w,arrD1) && isPervasiveDyExt(f)) {
|
} else if (isPervasiveDyExt(f)) {
|
||||||
|
if (ria == 0) goto arith_empty;
|
||||||
|
if (!TI(w,arrD1)) goto generic;
|
||||||
if (TI(x,arrD1) && wia>=4 && xia<2560>>arrTypeBitsLog(TY(x))) {
|
if (TI(x,arrD1) && wia>=4 && xia<2560>>arrTypeBitsLog(TY(x))) {
|
||||||
Arr* wd = arr_shVec(TI(w,slice)(incG(w), 0, wia));
|
B expW, expX;
|
||||||
r = fc2(f, C2(slash, m_i32(xia), taga(wd)), C2(shape, m_f64(ria), incG(x)));
|
if (0) {
|
||||||
|
arith_empty:;
|
||||||
|
expW = taga(emptyArr(w, 1));
|
||||||
|
expX = taga(emptyArr(x, 1));
|
||||||
|
} else {
|
||||||
|
assert(wia>1); // implies ria > xia, a requirement of reshape_cycle
|
||||||
|
expW = replicate_by(xia, wia, w);
|
||||||
|
expX = taga(arr_shVec(reshape_cycle(ria, xia, incG(x))));
|
||||||
|
}
|
||||||
|
r = fc2(f, expW, expX);
|
||||||
arith_finish:;
|
arith_finish:;
|
||||||
if(RARE(!reusable(r))) r = taga(cpyWithShape(r));
|
if(RARE(!reusable(r))) r = taga(cpyWithShape(r));
|
||||||
arr_shErase(a(r), 1);
|
arr_shErase(a(r), 1);
|
||||||
} else if (xia>7 && wia>0) {
|
} else if (xia>7) {
|
||||||
SGet(w)
|
SGet(w)
|
||||||
M_APD_TOT(rm, ria)
|
M_APD_TOT(rm, ria)
|
||||||
incByG(x, wia);
|
incByG(x, wia);
|
||||||
|
|||||||
@ -312,7 +312,7 @@ NOINLINE B shape_c2_listw(B t, B w, B x) {
|
|||||||
return taga(arr_shSetUO(reshape_unshaped(nia, x), nr, sh));
|
return taga(arr_shSetUO(reshape_unshaped(nia, x), nr, sh));
|
||||||
}
|
}
|
||||||
|
|
||||||
Arr* reshape_cycle(usz nia, usz xia, B x) {
|
Arr* reshape_cycle(usz nia, usz xia, B x) { // used directly by tbl_c2
|
||||||
assert(nia > xia);
|
assert(nia > xia);
|
||||||
Arr* r;
|
Arr* r;
|
||||||
if (xia <= 1) {
|
if (xia <= 1) {
|
||||||
|
|||||||
@ -606,6 +606,8 @@ b←1↓1∾a←"hello" ⋄ b ⌽⎊'e' ⥊⟜1⍟2 5 ⋄ a ≡○•Hash b %% 1
|
|||||||
|
|
||||||
# ⌜
|
# ⌜
|
||||||
!"𝕨𝔽⌜𝕩: Result rank too large (200≡=𝕨, 200≡=𝕩)" % +⌜˜(200⥊1)⥊1
|
!"𝕨𝔽⌜𝕩: Result rank too large (200≡=𝕨, 200≡=𝕩)" % +⌜˜(200⥊1)⥊1
|
||||||
|
%USE eqvar ⋄ (! + ○•internal.Keep⌜ ≡ + ⌜)○↕⌜˜ ↕6 # TODO _eqvar once it's consistent
|
||||||
|
%USE eqvar ⋄ (! -˜○•internal.Keep⌜ ≡ -˜⌜)○↕⌜˜ ↕6 # TODO _eqvar once it's consistent
|
||||||
|
|
||||||
# ˜
|
# ˜
|
||||||
5˜˝ "ab" %% 5
|
5˜˝ "ab" %% 5
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user