From 36da1bbc50e2a0f7316e2bdf5bc4cc87aad43bc7 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 19 Jan 2021 21:54:26 -0500 Subject: Allow provided Fill function to set fill, and use it when fill doesn't depend on argument fill --- src/r.bqn | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/r.bqn b/src/r.bqn index 7fb39607..d37be072 100644 --- a/src/r.bqn +++ b/src/r.bqn @@ -18,7 +18,7 @@ Int←(1=Type)◶⟨0,⌊⊸=⟩ Nat←(1=Type)◶⟨0,0⊸≤×⌊⊸=⟩ Deshape←IsArray◶{⟨𝕩⟩}‿⥊ Pair ← {⟨𝕩⟩} ⊘ {⟨𝕨,𝕩⟩} -Box ← {⟨⟩⥊⟨𝕩⟩} +Box ← {𝕩Fill⟨⟩⥊⟨𝕩⟩} ToArray ← Box⍟(1-IsArray) # LIMITED to numeric arguments for arithmetic cases @@ -90,7 +90,7 @@ _grade_←{ d←⥊𝕩 # Counting sort for small-range ints bl←bu←0⋄r←1-{((bu↩⌈´𝕩)-bl↩⌊´𝕩)≤2×l}⟜𝕩⍟⊢((m=1)×320˜ B←l⊸≤◶⊢‿l @@ -108,7 +108,7 @@ _grade_←{ Indices←{ "/: Replication argument must have rank 1" ! 1==𝕩 l←≠𝕩 - { + 0 Fill { "/: Amounts to replicate must be natural numbers" ! 1×´Nat⌜𝕩 k←l-1 N ← ((⊢+-×0=𝕩⊑˜⊢)`k⊸-⌜↕l)⊑˜k-⊢ # Next nonzero @@ -139,12 +139,12 @@ Rot←{ Prefixes←{ "↑𝕩: 𝕩 must have rank at least 1" ! 1≤=𝕩 - ↕⊸⊏⟜𝕩⌜↕1+≠𝕩 + 0⊸⊑⊸Fill ↕⊸⊏⟜𝕩⌜ ↕1+≠𝕩 } Suffixes←{ "↓𝕩: 𝕩 must have rank at least 1" ! 1≤=𝕩 l←≠𝕩 - {𝕩⊸+⌜↕l-𝕩}⊸⊏⟜𝕩⌜↕1+l + 0⊸⊑⊸Fill {𝕩⊸+⌜↕l-𝕩}⊸⊏⟜𝕩⌜ ↕1+l } _sort ← {(𝕗⊑⟨Cmp,Cmp˜⟩)_grade_𝕗 ⊸ ⊏} @@ -319,12 +319,12 @@ _takeDrop←{ _c ← { (×⟜𝕗⌜𝕨) +⌜ 𝕩 } i←<0 ⋄ k←1 ⋄ UIk←{ i (k×𝕨)_c↩ k ↕⊸(𝕨_c)⍟(1-=⟜1) 𝕩 ⋄ k↩1 ⋄ ≠𝕩 } doFil←0 - sh ← (⊑⟜s Noop◶{k×↩𝕨⋄𝕨}‿(⊣ UIk {doFil↩1}_inds) ⊑⟜𝕨)⌜ ↕r + sh ← (⊑⟜s Noop◶{k×↩𝕨⋄𝕨}‿(⊣ UIk {𝕩⋄doFil↩1}_inds) ⊑⟜𝕨)⌜ ↕r (0<=i)◶(s⊸⥊)‿{ sh ∾↩ t ← (s⊑˜r⊸+)⌜↕(≠s)-r {i 𝕩_c↩ ↕𝕩}⍟(1-1⊸=) k×´t Sel ← ⊑⟜(⥊𝕩) - {Sel↩0⊸≤◶⟨(Fill𝕩)˙,Sel⟩}⍟⊢doFil + 𝕩{Sel↩0⊸≤◶⟨(Fill𝕨)˙,Sel⟩}⍟⊢doFil Sel⌜ sh ⥊ i } ToArray 𝕩 } @@ -435,14 +435,14 @@ Reshape←{ {d∾↩(Fill d)⌜↕𝕩-n⋄n}⍟(n⊸<)⍟(3=t)lp×a } s s⥊{ - 𝕩(0∘Pair @@ -655,8 +658,8 @@ ReorderAxesInv←{ } ⍉ ← Transpose ⊘ ReorderAxes -OccurrenceCount ← ⊐˜(⊢-⊏)⍋∘⍋ -ProgressiveIndexOf ← { +OccurrenceCount ← 0 Fill ⊐˜(⊢-⊏)⍋∘⍋ +ProgressiveIndexOf ← 0 Fill { c←1-˜=𝕨 "⊒: Rank of 𝕨 must be at least 1" ! 0≤c "⊒: Rank of 𝕩 must be at least cell rank of 𝕨" ! c≤=𝕩 -- cgit v1.2.3