From 3ae7d134d2d89f1375059ffe323b8cfbabf982ea Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 11 Mar 2025 04:32:14 +0200 Subject: [PATCH] =?UTF-8?q?more=20uniform=20F=C2=A8=20fill=20behavior?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/md1.c | 4 ++-- src/utils/each.c | 2 +- src/utils/each.h | 3 +++ test/cases/fills.bqn | 8 ++++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/builtins/md1.c b/src/builtins/md1.c index dfbd2db4..7a7f2527 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -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)); } diff --git a/src/utils/each.c b/src/utils/each.c index b55b0cae..c43be484 100644 --- a/src/utils/each.c +++ b/src/utils/each.c @@ -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; diff --git a/src/utils/each.h b/src/utils/each.h index 50b6d0e5..2808653c 100644 --- a/src/utils/each.h +++ b/src/utils/each.h @@ -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); diff --git a/test/cases/fills.bqn b/test/cases/fills.bqn index 5cf46826..a3d571c1 100644 --- a/test/cases/fills.bqn +++ b/test/cases/fills.bqn @@ -1,4 +1,5 @@ %DEF fill Fill←•internal.HasFill◶'e'‿{⊑1↑0⥊𝕩} +%DEF eqall EqAll ← {!∘≡⟜(⊑𝕩)¨ 𝕩 ⋄ ⊑𝕩} %USE fill ⋄ F←⌊ ⋄ ⟨0,1,{⇐},+,@,'𝕩'⟩ Fill∘F⌜ ⟨⟨⟩, ↕0‿0, ↕0, 0‿2⥊↕0, "", 2‿0⥊""⟩ %!HEAPVERIFY %% 2‿4/[⟨'e',0‿0,0,0,'e','e'⟩,⟨'e','e','e','e','e','e'⟩] %USE fill ⋄ F←+ ⋄ ⟨0,1,{⇐},+,@,'𝕩'⟩ Fill∘F⌜ ⟨⟨⟩, ↕0‿0, ↕0, 0‿2⥊↕0, "", 2‿0⥊""⟩ %!HEAPVERIFY %% 6‿6⥊⟨'e',0‿0,0,0,' ',' ','e',0‿0,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↑ (2⥊2)-˝𝕩‿2⥊<<'x'}¨ 5‿6 %!HEAPVERIFY %% <¨¨ ⟨"vv ", 2‿2‿0⟩ {3↑ "ee"-˝𝕩‿2⥊<<'a'}¨ 5‿6 %!HEAPVERIFY %% <¨¨ ⟨¯4‿¯4‿0, "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⟩