diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-04-25 12:45:18 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-04-25 12:45:18 -0400 |
| commit | 18a1aa00ae3c7dfc04d3689ce740502b1671fdf8 (patch) | |
| tree | 568a06fbe46c14f1c4ca62296b6a51a6380216e3 /src | |
| parent | 88d91422ce044d65bc86ae44da2c49ff85a161a6 (diff) | |
Continued runtime rearrangement
Diffstat (limited to 'src')
| -rw-r--r-- | src/r.bqn | 105 |
1 files changed, 52 insertions, 53 deletions
@@ -62,6 +62,20 @@ GetCells←(1==∘⊢)◶{ } _fillBy_ ⊢ ⊏ ← GetCells # LIMITED to depth-1 natural number left argument +_lookup_ ← { + s ← 2⊸×⌜↕(≠𝕘)÷2 + (s⊏𝕘) _glyphLookup_ (((1⊸+⌜s)⊏𝕘)∾⟨𝕗⟩) +} +Identity ← {𝕏0} ("´: Identity not found"!0˙) _lookup_ ⟨ + '+',0 , '-',0 + '×',1 , '÷',1 + '⋆',1 , '¬',1 + '⌊',∞ , '⌈',¯∞ + '∨',0 , '∧',1 + '≠',0 , '=',1 + '>',0 , '≥',1 +⟩ + _eachd←{ _d←{ # Equal ranks p←≢𝕨 @@ -389,6 +403,19 @@ Join←(2⌊=)◶⟨ (r≤⊣)◶⟨⊑⟜𝕨⊸×,⊢⟩⟜(⊑⟜𝕩)⌜↕d } ⊣ "∾𝕩: 𝕩 must be an array"!IsArray +structPrimClass ← {(Join1𝕩)_glyphLookup_((Indices∾⟜Pair≠)≠⌜𝕩)} ⟨ + "⊢⊣˜∘○⊸⟜⊘◶" + "=≠≢" + "<" + "≍" + "↕/»«⊔" + "⥊↑↓⌽⍉⊏⊑" +# ">" +# "∾" +# "˘⎉¨⌜" +# "⚇" +⟩ + _takeDrop←{ ⟨gl,Noop,_inds⟩←𝕗 pre ← "𝕨"∾gl∾"𝕩: 𝕨 must " @@ -523,6 +550,16 @@ Reshape←{ } ⥊ ↩ Deshape ⊘ ⥊ +Pick1←{ + "𝕨⊑𝕩: Indices in compound 𝕨 must be lists" ! 1==𝕨 + "𝕨⊑𝕩: Index length in 𝕨 must match rank of 𝕩" ! 𝕨=○≠s←≢𝕩 + ChkInd⌜𝕨 ⋄ eRange ! 1∧´𝕨(≥⟜-∧<)s + 𝕨↩𝕨+s×𝕨<0 + (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´-↕⊸¬≠𝕨 +} +Pickd←(0∨´IsArray⌜∘⥊∘⊣)◶Pick1‿{Pickd⟜𝕩⌜𝕨} +Pick←IsArray∘⊣◶Pick0‿Pickd + Range←{ I←{"↕𝕩: 𝕩 must consist of natural numbers"!Nat𝕩⋄↕𝕩} M←{"↕𝕩: 𝕩 must be a number or list"!1==𝕩⋄(0⌜𝕩)Fill(<⟨⟩)⥊⊸∾⌜´I⌜𝕩} @@ -565,8 +602,6 @@ _insert←{ } 𝕨 (0<≠)⊘1◶Id‿{𝕨F´<˘𝕩} 𝕩 } -˝ ← _insert - JoinTo←∨○(1<=)◶(∾○⥊)‿{ s←𝕨Pair○≢𝕩 @@ -589,6 +624,20 @@ Replicate ← (0<=∘⊣)◶{ 𝕨 Rep 𝕩 } _onAxes_ (1-0=≠) _fillBy_ ⊢ +_repeat_←{ + F←𝔽 ⋄ b←𝕨{𝕏⊣}˙⊘{𝕨˙{𝔽𝕏⊣}}0 + n←𝕨𝔾𝕩 + Multi←{ + l←u←0 + {"⍟: Repetition numbers in 𝕨𝔾𝕩 must be integers"!Int𝕩⋄l↩l⌊𝕩⋄u↩u⌈𝕩}_perv n + i←⟨𝕩⟩⋄P←B⊸{𝕎`i∾↕𝕩} + pos←f P u + neg←f 0⊸<◶⟨i,Inverse⊸P⟩ -l + (|⊑<⟜0⊑pos‿neg˙)_perv n + } + (Nat n)◶Multi‿{𝕩(B f)∘⊢´↕n} 𝕩 +} + ↑ ← Prefixes ⊘ Take ↓ ← Suffixes ⊘ Drop ↕ ↩ Range ⊘ Windows @@ -626,16 +675,7 @@ GroupGen←{ (LS 0⌜𝕨) Fill dr (1≠≠∘⊢)◶⟨S _group○(0⊸⊑), S⌜ ·+⌜⌜´ (⌽×`1»⌽l) × ⊢_group¨⟩ 𝕨 } -Pick1←{ - "𝕨⊑𝕩: Indices in compound 𝕨 must be lists" ! 1==𝕨 - "𝕨⊑𝕩: Index length in 𝕨 must match rank of 𝕩" ! 𝕨=○≠s←≢𝕩 - ChkInd⌜𝕨 ⋄ eRange ! 1∧´𝕨(≥⟜-∧<)s - 𝕨↩𝕨+s×𝕨<0 - (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´-↕⊸¬≠𝕨 -} -Pickd←(0∨´IsArray⌜∘⥊∘⊣)◶Pick1‿{Pickd⟜𝕩⌜𝕨} -Pick←IsArray∘⊣◶Pick0‿Pickd - +˝ ← _insert ⎉ ← _rankOp_ # Searching @@ -693,47 +733,6 @@ ProgressiveIndexOf ← 0 Fill { 𝕨⊐○(Pair¨⟜(≢⥊OccurrenceCount∘⥊) 𝕨⊸⊐)𝕩 } -_repeat_←{ - F←𝔽 ⋄ b←𝕨{𝕏⊣}˙⊘{𝕨˙{𝔽𝕏⊣}}0 - n←𝕨𝔾𝕩 - Multi←{ - l←u←0 - {"⍟: Repetition numbers in 𝕨𝔾𝕩 must be integers"!Int𝕩⋄l↩l⌊𝕩⋄u↩u⌈𝕩}_perv n - i←⟨𝕩⟩⋄P←B⊸{𝕎`i∾↕𝕩} - pos←f P u - neg←f 0⊸<◶⟨i,Inverse⊸P⟩ -l - (|⊑<⟜0⊑pos‿neg˙)_perv n - } - (Nat n)◶Multi‿{𝕩(B f)∘⊢´↕n} 𝕩 -} - -_lookup_ ← { - s ← 2×↕(≠𝕘)÷2 - (s⊏𝕘) _glyphLookup_ (((1+s)⊏𝕘)∾⟨𝕗⟩) -} -Identity ← {𝕏0} ("´: Identity not found"!0˙) _lookup_ ⟨ - '+',0 , '-',0 - '×',1 , '÷',1 - '⋆',1 , '¬',1 - '⌊',∞ , '⌈',¯∞ - '∨',0 , '∧',1 - '≠',0 , '=',1 - '>',0 , '≥',1 -⟩ - -structPrimClass ← {(Join1𝕩)_glyphLookup_((/∾⟜⥊≠)≠⌜𝕩)} ⥊⌜ ⟨ - '⊢'‿'⊣'‿'˜'‿'∘'‿'○'‿'⊸'‿'⟜'‿'⊘'‿'◶' - '='‿'≠'‿'≢' - '<' - '≍' - '↕'‿'/'‿'»'‿'«'‿'⊔' - '⥊'‿'↑'‿'↓'‿'⌽'‿'⍉'‿'⊏'‿'⊑' -# > -# ∾ -# ˘⎉¨⌜ -# ⚇ -⟩ - ⁼ ← {Inverse 𝕗} _inv_ ← {𝕘⋄𝕨𝔽𝕩} _undo ← {𝕗 (≢∧INF˙⊸≢)◶0‿((5=0⊸⊑)◶1‿(inv˙≢(≠-2˙)⊸⊑)∘Decompose⊢)◶⊢‿{𝕏_inv_(𝕎_invChk_𝕏)} Inverse 𝕗} |
