diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-22 18:15:59 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-06-22 18:15:59 -0400 |
| commit | 17b0366422fa101a88226fbc5f0858128143c34e (patch) | |
| tree | f00ea0013eb37e754118118897b398bb62b82905 /spec/reference.bqn | |
| parent | 1b72a4a5141a4e935228fa547bd92cb62f40f783 (diff) | |
Many fixes to reference implementations
Diffstat (limited to 'spec/reference.bqn')
| -rw-r--r-- | spec/reference.bqn | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/spec/reference.bqn b/spec/reference.bqn index 3955dbdd..315e26f2 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -83,7 +83,7 @@ _reduce←{ {r↩(𝕩⊑v)F r}¨(l-1)⊸-¨↕l r } -Length ← (0<0⊑≢)◶⟨0⋄0⊑⊢⟩∘≢ +Length ← (0<0⊑≢)◶⟨1⋄0⊑⊢⟩∘≢ ⍝⌜ @@ -106,14 +106,14 @@ _eachd←{ _e←{ ⍝ 𝕨 has smaller or equal rank k←≠p←≢𝕨 ⋄ q←≢𝕩 ! ∧´(⊑⟜p=⊑⟜q)¨↕k - l←×´(p⊑˜k⊸+)¨↕q≠⊸-k - a←⥊𝕨 ⋄ b←⥊𝕩 ⋄ F←𝔽 - (≠a) (⊑⟜a𝔽l⊸×⊸+⊑b˜)_table○↕ l + l←×´(q⊑˜k⊸+)¨↕q≠⊸-k + a←⥊𝕨 ⋄ b←⥊𝕩 + q⥊⥊(≠a) (⊑⟜a𝔽l⊸×⊸+⊑b˜)_table○↕ l } (>○(≠≢))◶⟨𝔽_e⋄𝔽˜_e˜⟩ } _perv←{ ⍝ Pervasion - (¬∧○IsArray)◶⟨𝔽⋄𝔽¨⟩ + (⊢⊘∨○IsArray)◶⟨𝔽⋄𝔽{𝕨𝔽_perv𝕩}¨⟩ } ⌜ ← {(𝔽_eachm)⊘(𝔽_table)○ToArray} @@ -149,10 +149,10 @@ Pick1←{ ! ∧´Int¨𝕨 ! ∧´𝕨(≥⟜-∧<)s 𝕨↩𝕨+s×𝕨<0 - (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´↕≠𝕨 + (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´-↕⊸¬≠𝕨 } Pickd←(∨´IsArray¨∘⊣)◶Pick1‿{Pickd⟜𝕩¨𝕨} -Pick←IsArray∘⊣◶{!1=≠≢𝕨⋄𝕩⊑𝕨}‿Pickd +Pick←IsArray◶⥊‿⊢⊸Pickd match←{¬∘(0⊑𝕨)◶(1⊑𝕨)‿𝕩}´⟨ ⟨≠○IsArray , 0⟩ @@ -161,8 +161,8 @@ match←{¬∘(0⊑𝕨)◶(1⊑𝕨)‿𝕩}´⟨ ⟨∨´≠○≢ , 0⟩ {∧´⥊𝕨Match¨𝕩} ⟩ - -Depth←IsArray◶0‿{1⌈´Depth¨⥊𝕩} + +Depth←IsArray◶0‿{1+0⌈´Depth¨⥊𝕩} ⊑ ↩ (0¨∘≢)⊸Pick ⊘ Pick ⥊ ↩ Deshape ⊘ Reshape @@ -184,7 +184,8 @@ Depth←IsArray◶0‿{1⌈´Depth¨⥊𝕩} ˘ ← ⎉¯1 ` ← _scan -Cell ← {⊑⟜𝕩¨𝕨+↕𝕨-˜≠𝕩}⟜≢ ⍝ ↓⟜≢ +DropV← {⊑⟜𝕩¨𝕨+↕𝕨-˜≠𝕩} +Cell ← DropV⟜≢ Pair ← {⟨𝕩⟩} ⊘ {⟨𝕨,𝕩⟩} Unbox←(0<≠∘⥊)◶⊢‿{ @@ -195,11 +196,11 @@ Unbox←(0<≠∘⥊)◶⊢‿{ _ranks ← {⟨2⟩⊘⟨1,0⟩((⊣-1+|)˜⟜≠⊑¨<∘⊢)⥊∘𝔽} _depthOp_←{ neg←0>n←𝕨𝔾_ranks𝕩 ⋄ F←𝔽 - _d←{(∧´(neg∧𝕗=0)∨(0⌈𝕗)≥Pair○≡)◶⟨(𝕗+neg)_d¨⋄F⟩} + _d←{𝕨(∧´(neg∧𝕗≥0)∨(0⌈𝕗)≥Pair○≡)◶⟨(𝕗+neg)_d¨⋄F⟩𝕩} 𝕨 n _d 𝕩 } _rankOp_←{ - k←𝕨(Pair○(≠≢) (0<⊣)◶⟨0⌈+,⌊⟩ 𝔾_ranks)𝕩 + k←𝕨(Pair○(≠≢) (0≤⊢)◶⟨⌊⟜-,0⌈-⟩ 𝔾_ranks)𝕩 Enc←{ f←⊑⟜(≢𝕩)¨↕𝕨 c←×´s←𝕨Cell𝕩 @@ -246,20 +247,20 @@ _onAxes_←{ }‿{ ⍝ Multiple axes ! 1≥≠≢𝕨 ! 𝕨≤○≠≢𝕩 - R←{(⊑𝕨)F(1↓𝕨)⊸R˘𝕩}⍟{0<≠𝕨} + R←{(⊑𝕨)F(1 DropV 𝕨)⊸R˘𝕩}⍟{0<≠𝕨} 𝕨R𝕩 } } SelSub←{ ! IsArray 𝕨 - ! Int¨ 𝕨 + ! ∧´⥊Int¨ 𝕨 ! ∧´⥊ 𝕨 (≥⟜-∧<) ≠𝕩 𝕨↩𝕨+(≠𝕩)×𝕨<0 c←×´s←1 Cell 𝕩 ⊑⟜(⥊𝕩)¨(c×𝕨)+⌜s⥊↕c } -Select←ToArray⊸(SelSub _onAxes_ (1-0=≠)) +Select←ToArray⊸(SelSub _onAxes_ 1) JoinTo←{ s←𝕨Pair○≢𝕩 @@ -268,17 +269,17 @@ JoinTo←{ c←(a-k)+⟜(↕a-1)⊸⊏¨s ! ≡´c l←+´(a=k)⊣◶1‿(⊑⊢)¨s - (⟨l⟩∾c)⥊𝕨∾○⥊𝕩 + (⟨l⟩∾⊑c)⥊𝕨∾○⥊𝕩 } Take←{ T←{ ! Int 𝕨 - l←≠x + l←≠𝕩 i←((𝕨<0)×𝕨+l)+↕|𝕨 - ((l+1)|¯1⌈l⌊i)⊏𝕩∾(1 Cell 𝕩)⥊Type 𝕩 + ((l+1)|¯1⌈l⌊i)⊏𝕩 JoinTo (1 Cell 𝕩)⥊Type 𝕩 } - T _onAxes_ 0 (⟨1⟩⥊˜0⌈𝕨-○≠⊢)⊸∾∘≢⊸⥊𝕩 + 𝕨 T _onAxes_ 0 (⟨1⟩⥊˜0⌈𝕨-○≠⊢)⊸∾∘≢⊸⥊𝕩 } Drop←{ s←(≠𝕨)(⊣↑⊢∾⥊˜0⌈-⟜≠)≢𝕩 @@ -298,14 +299,15 @@ Windows←{ } Reverse ← {!1≤≠≢𝕩 ⋄ (-↕⊸¬≠𝕩)⊏𝕩} -Rotate ← {!Nat𝕨 ⋄ l←≠x⋄(l|𝕨+↕l)⊏𝕩} _onAxes_ 0 +Rotate ← {!Nat𝕨 ⋄ l←≠𝕩⋄(l|𝕨+↕l)⊏𝕩} _onAxes_ 0 Indices←{ ! 1=≠≢𝕩 ! ∧´Nat¨𝕩 ⟨⟩∾´𝕩⥊¨↕≠𝕩 } -Replicate ← {0<≠≢𝕨}◶(⥊˜⟜≠/⊸⊏⊢)‿{!𝕨=○≠𝕩⋄𝕨/⊸⊏𝕩} _onAxes_ 1 +Rep ← Indices⊸⊏ +Replicate ← {0<≠≢𝕨}◶(⥊˜⟜≠Rep⊢)‿{!𝕨=○≠𝕩⋄𝕨Rep𝕩} _onAxes_ (1-0=≠) ⍝⌜ |
