more uniform F¨ fill behavior

This commit is contained in:
dzaima 2025-03-11 04:32:14 +02:00
parent b14ea82218
commit 3ae7d134d2
4 changed files with 14 additions and 3 deletions

View File

@ -40,7 +40,7 @@ B each_c1(Md1D* d, B x) { B f = d->f;
B r, xf;
if (EACH_FILLS) xf = getFillR(x);
if (isAtm(x)) r = m_hunit(c1(f, x));
if (isAtm(x)) r = squeezed_unit(c1(f, x));
else if (isFun(f)) {
u8 rtid = RTID(f);
if (rtid==n_ltack || rtid==n_rtack) {
@ -134,7 +134,7 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
}
static B eachd(B f, B w, B x) {
if (isAtm(w) & isAtm(x)) return m_hunit(c2(f, w, x));
if (isAtm(w) & isAtm(x)) return squeezed_unit(c2(f, w, x));
return eachd_fn(f, w, x, c2fn(f));
}

View File

@ -12,7 +12,7 @@ B eachd_fn(B fo, B w, B x, FC2 f) {
bool wg = wr>xr;
ur rM = wg? wr : xr;
ur rm = wg? xr : wr;
if (rM==0) return m_funit(f(fo, w, x));
if (rM==0) return squeezed_unit(f(fo, w, x));
if (rm && !eqShPart(SH(w), SH(x), rm)) thrF("Mapping: Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
bool rw = rM==wr && reusable(w) && TY(w)==t_harr; // dereferencing is safe as rank>0 from rM==
bool rx = rM==xr && reusable(x) && TY(x)==t_harr;

View File

@ -3,6 +3,9 @@
B eachd_fn(B fo, B w, B x, FC2 f); // consumes w,x; assumes at least one is array
B eachm_fn(B fo, B x, FC1 f); // consumes x; x must be array
static inline B squeezed_unit(B x) { // same fill as any_squeeze(m_hunit(x))
return isAtm(x)? m_unit(x) : m_hunit(x);
}
#if SEMANTIC_CATCH
NOINLINE B arith_recd(FC2 f, B w, B x);

View File

@ -1,4 +1,5 @@
%DEF fill Fill•internal.HasFill'e'{10𝕩}
%DEF eqall EqAll {!(𝕩)¨ 𝕩 𝕩}
%USE fill F 0,1,{},+,@,'𝕩' FillF , 00, 0, 020, "", 20"" %!HEAPVERIFY %% 24/['e',00,0,0,'e','e','e','e','e','e','e','e']
%USE fill F+ 0,1,{},+,@,'𝕩' FillF , 00, 0, 020, "", 20"" %!HEAPVERIFY %% 66'e',00,0,0,' ',' ','e',00,0,0,' ',' ','e','e','e','e','e','e','e','e','e','e','e','e','e'," ",' ',' ','e','e','e'," ",' ',' ','e','e'
@ -34,6 +35,13 @@
{3 (22)-˝𝕩2<<'x'}¨ 56 %!HEAPVERIFY %% <¨¨ "vv ", 220
{3 "ee"-˝𝕩2<<'a'}¨ 56 %!HEAPVERIFY %% <¨¨ ¯4¯40, "ee "
%DEF sqfill SqFill {•internal.Squeeze "Ah"•internal.Variation 𝕩}
%USE fill %USE eqall %USE sqfill F•internal.Keep {EqAll Fill¨ SqFill 𝕩, F¨<𝕩, @F¨<𝕩, @F¨𝕩}¨ "abc", 4, 'a', {}
%USE fill %USE eqall %USE sqfill F•internal.Keep {EqAll Fill¨ SqFill 𝕩, F¨ 𝕩, @F¨ 𝕩 }¨ "abc", 4, 'a', {}
2 'a'+¨ 1 %% "b "
2 {} 'a'+¨ 1 %% "b "
# TODO:
# ⟨↑‿3⥊↕10 ⋄ ↑‿3⥊<¨↕10 ⋄ ↑‿3⥊<˘↕10⟩
# 5‿¯5↑⌜⟨↕2 ⋄ "ab" ⋄ <¨↕2 ⋄ <˘↕2⟩