From 796d15378aee570675b4d0c34dd5b06c98e013dd Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 26 Mar 2021 08:50:54 -0400 Subject: Switch to index-based primitive lookups for speed --- src/r.bqn | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/r.bqn b/src/r.bqn index a42f1a35..e64ee27e 100644 --- a/src/r.bqn +++ b/src/r.bqn @@ -2,8 +2,8 @@ # Type Fill Log GroupLen GroupOrd _fillBy_ # !+-×÷⋆⌊=≤≢⥊⊑↕⌜`⊘ Decompose ← {0‿𝕩} -Glyph ← {𝕩⋄!0} -SetPrims ← {Decompose‿Glyph ↩ 𝕩} +PrimInd ← {𝕩⋄!0} +SetPrims ← {Decompose‿PrimInd ↩ 𝕩} ◶ ← {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} # LIMITED to number left operand result ⊢ ← {𝕩} @@ -42,6 +42,11 @@ _fold←{ } ´ ← _fold +_glyphLookup_ ← { + g←"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟%" + {PrimInd𝕩} ⊑ ((𝕘⊑˜·+´·×`𝕗(1-=)⌜<)⌜g)˙ +} + Cell←{(𝕨⊸+⊑𝕩˙)⌜↕(≠𝕩)-𝕨}⟜≢ ∾ ← {k←≠𝕨⋄k⊸≤◶⟨⊑⟜𝕨⋄-⟜k⊑𝕩˜⟩⌜↕k+≠𝕩} # LIMITED to two vector arguments @@ -704,12 +709,9 @@ JoinPrim ← ∾ ⊒ ← OccurrenceCount⊘ ProgressiveIndexOf ⍷ ← ∊⊸/ ⊘ Find -_glyphLookup_ ← { - (0+´·∧`𝕗≠{Glyph𝕩})⊑(∾´𝕘)˙ -} _lookup_ ← { s ← 2×↕(≠𝕘)÷2 - (s⊏𝕘) _glyphLookup_ ((1+s)⊏𝕘)‿𝕗 + (s⊏𝕘) _glyphLookup_ (((1+s)⊏𝕘)∾<𝕗) } Identity ← {𝕏0} ("´: Identity not found"!0˙) _lookup_ ⟨ '+',0 , '-',0 @@ -812,7 +814,7 @@ FuncInverse ← (⊑ ⊣◶⟨ Inverse ← Type◶(3‿1‿2/{⊢⊣𝕩IX∘≡⊢}‿FuncInverse‿("Cannot invert modifier"!0˙)) ⁼ ↩ {𝕗 (≢∧INF˙⊸≢)◶0‿(5‿_inv_≢0‿¯2⊏Decompose∘⊢)◶⊢‿{𝕏_inv_(𝕎_invChk_𝕏)} Inverse 𝕗} -structPrimClass ← {(∾𝕩)_glyphLookup_((/≍○<≠)≠¨𝕩)} ⥊¨ ⟨ +structPrimClass ← {(∾𝕩)_glyphLookup_((/∾≠)≠¨𝕩)} ⥊¨ ⟨ '⊢'‿'⊣'‿'˜'‿'∘'‿'○'‿'⊸'‿'⟜'‿'⊘'‿'◶' '='‿'≠'‿'≢' '<' -- cgit v1.2.3