aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-01 19:09:08 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-01 19:09:08 -0400
commit35b312299a40ac6fc1725901e99b62239be2e5c9 (patch)
tree6bb99ae4c4870ac4aee235a18a6967c8145ad0eb
parent01fe8ee5bbba4631b12290a6f50b5412b7aaf096 (diff)
Test layer 6 structural and search functions
-rwxr-xr-xspec/dzref64
-rw-r--r--spec/reference.bqn46
-rw-r--r--test/testref.bqn49
3 files changed, 99 insertions, 60 deletions
diff --git a/spec/dzref b/spec/dzref
index 6034fa78..db98ef89 100755
--- a/spec/dzref
+++ b/spec/dzref
@@ -64,20 +64,7 @@ _perv←{ ⍝ Pervasion
Int←IsArray◶⟨⌊⊸=,0⟩
Nat←IsArray◶⟨0⊸≤∧⌊⊸=,0⟩
-Pick1←{
- ! 1=≠≢𝕨
- ! 𝕨=○≠s←≢𝕩
- ! ∧´Int¨𝕨
- ! ∧´𝕨(≥⟜-∧<)s
- 𝕨↩𝕨+s×𝕨<0
- (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´-↕⊸¬≠𝕨
-}
-Pickd←(0∨´⟜⥊IsArray¨∘⊣)◶Pick1‿{Pickd⟜𝕩¨𝕨}
-Pick←IsArray◶⥊‿⊢⊸Pickd
-
Depth←IsArray◶0‿{1+0⌈´Depth¨⥊𝕩}
-
-⊑ ↩ (0¨∘≢)⊸Pick ⊘ Pick
≡ ← Depth ⊘ ≡
@@ -223,11 +210,11 @@ Join←{
C←(<⟨⟩)⥊⊸∾⌜´⊢ ⍝ Cartesian array product
! IsArray 𝕩
s←≢¨𝕩
- c←≠⊑s
- ! ∧´c=≠¨s
- ! c≥≠≢𝕩
- l←(≢𝕩){(𝕩⊑a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕≠≢a←𝕩
- ! s≡C l
+ d←≠⊑s
+ ! ∧´⥊d=≠¨s
+ ! d≥≠≢𝕩
+ l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←≠≢a←𝕩
+ ! (r↑¨s)≡C l
i←C{p←+´¨↑𝕩⋄(↕⊑⌽p)-𝕩/¯1↓p}¨l
>i<¨⊸⊏¨l/𝕩
}⍟(0<≠∘⥊)
@@ -238,43 +225,47 @@ Group←{
l←(1<≡)◶Chk‿{!1=≠≢𝕩⋄Chk¨𝕩}𝕨
! l≤○≠≢𝕩
! ∧´l=l≠⊸↑≢𝕩
- (𝕨⊸=/𝕩˜)¨↕1+0⌈´⚇1𝕨
+ (𝕨⊸=/𝕩˜)¨↕1+¯1⌈´⚇1𝕨
}
-ReorderAxes←{
- 𝕩↩<⍟(0=≡)𝕩
- ! 𝕨≤○≠≢𝕩
- r←(≠≢𝕩)-+´¬∊𝕨
- ! ∧´𝕨<r
- 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
- (𝕨⊸⊏⊑𝕩˜)¨↕1×´¨𝕨⊔≢𝕩
-}
-Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
-
∾ ↩ Join ⊘ JoinTo
-⊔ ← ⊔⟜(↕∘≠⚇1) ⊘ Group
-⍉ ← Transpose ⊘ ReorderAxes
+⊔ ← Group⟜(↕≠⚇1) ⊘ Group
⍝ Searching
IndexOf←{
c←1-˜≠≢𝕨
! 0≤c
- 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉∞‿c⟩ 𝕩
+ 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩
}
UniqueMask←{
! 1≤≠≢𝕩
u←0↑𝕩
- {𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩
+ {(≠u)>⊑u IndexOf 𝕩}◶{u↩u∾𝕩⋄1}‿0˘𝕩
}
Find←{
r←≠s←≢𝕨
- 𝕨≡⎉r s↕⎉r 𝕩
+ ! r≤≠≢𝕩
+ 𝕨 ≡⎉r s ↕⎉r 𝕩
}
⊐ ← !∘0 ⊘ IndexOf
∊ ← UniqueMask ⊘ (⊐˜<≠∘⊢)
⍷ ← ∊⊸/ ⊘ Find
+ReorderAxes←{
+ 𝕩↩<⍟(0=≡)𝕩
+ ! 1≥≠≢𝕨
+ 𝕨↩⥊𝕨
+ ! 𝕨≤○≠≢𝕩
+ ! ∧´Nat¨⥊𝕨
+ r←(≠≢𝕩)-+´¬∊𝕨
+ ! ∧´𝕨<r
+ 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
+ (𝕨⊸⊏⊑𝕩˜)¨↕⌊´¨𝕨⊔≢𝕩
+}
+Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
+⍉ ← Transpose ⊘ ReorderAxes
+
⍝ Sorting
Cmp ← ∨○IsArray◶{ ⍝ No arrays
𝕨(>-<)𝕩 ⍝ Assume they're numbers
@@ -292,7 +283,7 @@ Cmp ← ∨○IsArray◶{ ⍝ No arrays
_grade←{
! 1≤≠≢𝕩
- i⊐+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
+ i⊐˜+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
}
_bins←{
r←1-˜≠≢𝕨
@@ -314,7 +305,7 @@ ProgressiveIndexOf ← {𝕨⊐○(≍˘⟜OccurrenceCount𝕨⊸⊐)𝕩}
{
chrs←⟨
- "!√∧∨|≡∾↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔"
+ "!√∧∨|≡∾↑↓↕⌽⍉/⍋⍒⊏⊐⊒∊⍷⊔"
"˘¨⌜´`"
"⎉⚇⍟◶"
@@ -345,7 +336,6 @@ ProgressiveIndexOf ← {𝕨⊐○(≍˘⟜OccurrenceCount𝕨⊸⊐)𝕩}
⍎"Type ← ⟨⟩⥊0⊸⥊"
'!' Mod "{𝕩 ⋄ ≤1}⍟¬"
- '⊑' Mod "⊑"
'↕' Mod "↕"
'≡' Mod "≡"
diff --git a/spec/reference.bqn b/spec/reference.bqn
index 9c82cda1..241be28a 100644
--- a/spec/reference.bqn
+++ b/spec/reference.bqn
@@ -317,7 +317,7 @@ Replicate ← {0<≠≢𝕨}◶(⥊˜⟜≠Rep⊢)‿{!𝕨=○≠𝕩⋄𝕨Rep
⍝ LAYER 6: Everything else
∾ ↩ Join ⊘ JoinTo
-⊔ ← ⊔⟜(↕∘≠⚇1) ⊘ Group
+⊔ ← ⊔⟜(↕≠⚇1) ⊘ Group
⍉ ← Transpose ⊘ ReorderAxes
⊐ ← !∘0 ⊘ IndexOf
∊ ← UniqueMask ⊘ (⊐˜<≠∘⊢)
@@ -332,11 +332,11 @@ Join←{
C←(<⟨⟩)⥊⊸∾⌜´⊢ ⍝ Cartesian array product
! IsArray 𝕩
s←≢¨𝕩
- c←≠⊑s
- ! ∧´c=≠¨s
- ! c≥≠≢𝕩
- l←(≢𝕩){(𝕩⊑a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕≠≢a←𝕩
- ! s≡C l
+ d←≠⊑s
+ ! ∧´⥊d=≠¨s
+ ! d≥≠≢𝕩
+ l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←≠≢a←𝕩
+ ! (r↑¨s)≡C l
i←C{p←+´¨↑𝕩⋄(↕⊑⌽p)-𝕩/¯1↓p}¨l
>i<¨⊸⊏¨l/𝕩
}⍟(0<≠∘⥊)
@@ -347,35 +347,39 @@ Group←{
l←(1<≡)◶Chk‿{!1=≠≢𝕩⋄Chk¨𝕩}𝕨
! l≤○≠≢𝕩
! ∧´l=l≠⊸↑≢𝕩
- (𝕨⊸=/𝕩˜)¨↕1+0⌈´⚇1𝕨
+ (𝕨⊸=/𝕩˜)¨↕1+¯1⌈´⚇1𝕨
}
-ReorderAxes←{
- 𝕩↩<⍟(0=≡)𝕩
- ! 𝕨≤○≠≢𝕩
- r←(≠≢𝕩)-+´¬∊𝕨
- ! ∧´𝕨<r
- 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
- (𝕨⊸⊏⊑𝕩˜)¨↕×´¨𝕨⊔≢𝕩
-}
-Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
-
⍝ Searching
IndexOf←{
c←1-˜≠≢𝕨
! 0≤c
- 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉∞‿c⟩ 𝕩
+ 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩
}
UniqueMask←{
! 1≤≠≢𝕩
u←0↑𝕩
- {𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩
+ {⊑𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩
}
Find←{
r←≠s←≢𝕨
- 𝕨≡⎉r s↕⎉r 𝕩
+ ! r≤≠≢𝕩
+ 𝕨 ≡⎉r s ↕⎉r 𝕩
}
+ReorderAxes←{
+ 𝕩↩<⍟(0=≡)𝕩
+ ! 1≥≠≢𝕨
+ 𝕨↩⥊𝕨
+ ! 𝕨≤○≠≢𝕩
+ ! ∧´Nat¨⥊𝕨
+ r←(≠≢𝕩)-+´¬∊𝕨
+ ! ∧´𝕨<r
+ 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
+ (𝕨⊸⊏⊑𝕩˜)¨↕⌊´¨𝕨⊔≢𝕩
+}
+Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
+
⍝ Sorting
Cmp ← ∨○IsArray◶{ ⍝ No arrays
𝕨(>-<)𝕩 ⍝ Assume they're numbers
@@ -393,7 +397,7 @@ Cmp ← ∨○IsArray◶{ ⍝ No arrays
_grade←{
! 1≤≠≢𝕩
- i⊐+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
+ i⊐˜+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
}
_bins←{
r←1-˜≠≢𝕨
diff --git a/test/testref.bqn b/test/testref.bqn
index 62758027..59313beb 100644
--- a/test/testref.bqn
+++ b/test/testref.bqn
@@ -1,8 +1,8 @@
⍝ Tests of primitive functionality
⍝ Ordering matches the reference implementations
-•←/¬⟨
- ⍝ LAYER 0
+•←/¬∾⟨
+⟨ ⍝ LAYER 0
⍝ [0,34)
0≡¯2+2
1e4≡5e3+5e3
@@ -251,4 +251,49 @@
3‿3‿3‿2‿2‿1≡/˜3‿2‿1
(≍1∾¨1‿2‿2)≡(↕¨/↕)2‿3
⟨⟩(/≡⊢)≍"ab"
+
+⟩
+⟨ ⍝ LAYER 6
+ ⍝ [230,270)
+ ≡⟜(∾⥊¨)"abc"
+ (∾´≡∾)"ab"‿"cde"‿""
+ 1‿2‿3‿4‿6‿9≡∾(⊢×≠↑↓)1+↕3
+ ≡⟜∾⟨⟩
+ ⟨1‿4,⥊2⟩((∾⋆⌜⌜)≡⋆⌜○∾)⟨2‿3‿4,⟨⟩,⥊5⟩
+ "abcd"≡"abc"∾'d'
+ "abcd"≡"abc"∾<'d'
+ (↕4‿3)≡(↕3‿3)∾3∾¨↕3
+ (∾˜≡·¯1⊸(×´∘↓∾↑)∘≢⊸⥊≍˜)2‿3⥊"abcdef"
+ (∾´≡∾)⟨3‿2‿1,0‿2‿1⟩⥊¨<↕6
+ ⟨1‿2,⥊0,⥊3⟩≡⊔1‿0‿0‿2
+ 4‿3‿2(≍○<≡·(≠¨≍○<∾)/⊸⊔)"abcdefghi"
+ ⟨⟩≡(3⥊¯1)⊔"abc"
+ (≍˘1‿1‿4<∘⥊⎉1 16‿4+⌜↕4)≡2↓⟨3‿2,¯1‿0‿¯1⟩⊔2‿3‿4⥊↕24
+ ⥊⚇0⊸≡○⊔⟜(⥊<)1‿2‿2‿¯1‿0
+ (⊔≡·≍⍟2∘<·∾⌜´/∘(0⊸=)¨)⟨0‿¯1‿0‿0,¯1‿0‿0⟩
+ 2‿0‿4≡"abcd"⊐"cae"
+ ⟨1⟩≡"abcd"⊐"b"
+ (<3)≡⊐⟜(3⊸⊏)"abcd"
+ (5⌊3+↕5)≡⊐⟜(3‿0‿0+⚇1⊢)↕5‿2‿1
+ 1‿0‿0‿1≡"acef"∊"adf"
+ (∊⟜(↕2)≡<⟜2)3⋆⌜○↕5
+ (<1)≡3‿4‿5∊4+⌜○↕3
+ ('0'≠"11010001")≡∊"abacbacd"
+ (↑⟜1≡⟜∊⥊⟜∞)9
+ (⥊⟜1≡∊∘↕)6
+ ≡⟜∊⟨⟩
+ ≡○∊⟜(≍˜˘)"abcadbba"
+ ≡⟜⍷⟨⟩
+ "ba"≡⍷"baa"
+ 0‿1‿0‿0≡"abc"⍷"aabcba"
+ (0‿1≍0‿0)≡(1‿2≍4‿5)⍷3‿3⥊↕9
+ (⌽¨≡⍉)↕2⥊3
+ ∧´⍉⊸≡¨⟨'a',<'a',"a","abc",""⟩
+ (↕4)(-˜⌜˜≡·⍉-⌜)↕3‿2
+ (2×↕3)≡0‿0⍉6+⌜○↕3
+ ⟨⟩(⍉≡⊢)<4
+ (2‿0‿1⥊⟨⟩)≡1‿2‿0‿1⍉↕↕4
+ 2‿0‿3‿1‿4≡⍋"bdace"
+ "edcba"≡∨"bdace"
+⟩