aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-26 12:37:08 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-26 12:37:08 -0400
commitd4acf8e53d6a2c2d3c95a317d25d4c82e440cdd5 (patch)
treeadc06d483f9db78ab2143f7c3405eef922de87a2
parentb8a1bce2591ef56034a1cc320fab2d272a4da278 (diff)
Precompute shape information for cell comparisons
-rwxr-xr-xdzref_full50
1 files changed, 34 insertions, 16 deletions
diff --git a/dzref_full b/dzref_full
index 12cc25fd..a909861c 100755
--- a/dzref_full
+++ b/dzref_full
@@ -331,35 +331,53 @@ Transpose←(=-1˜)⊸ReorderAxes⍟(0<=)
⍉ ← Transpose ⊘ ReorderAxes
# Sorting
-Cmp ← ∨○IsArray◶{ # No arrays
- 𝕨(>-<)𝕩 # Assume they're numbers
-}‿{ # At least one array
- e←𝕨-˜○(∨´0=≢)𝕩
- 𝕨(e=0)◶e‿{
- c←𝕨×∘-○(IsArray+=)𝕩
- s←≢𝕨 ⋄ t←≢𝕩 ⋄ r←𝕨⌊○=𝕩
- l←s{
+_cmpLen ← {
+ e←𝕨-˜○(∨´0⊸=)𝕩
+ c←𝕗
+ 𝕨(e=0)◶⟨0,e⟩‿{
+ c←×c+𝕨-○≠𝕩
+ r←𝕨⌊○≠𝕩
+ l←𝕨{
i←+´∧`𝕨=𝕩
m←×´⊑⟜𝕨¨↕i
{c↩×-´𝕩⋄m↩m×⌊´𝕩}∘(⊑¨⟜𝕨‿𝕩)⍟(r⊸>)i
m
- }○(((-1+↕r)+≠)⊸{⊑⟜𝕩¨𝕨})t
- a←⥊𝕨⋄b←⥊𝕩
- Trav←(=⟜l)◶{Trav∘(1+𝕩)⍟(0⊸=)a Cmp○(𝕩⊸⊑)b}‿c
- Trav 0
+ }○(((-1+↕r)+≠)⊸{⊑⟜𝕩¨𝕨})𝕩
+ ⟨l,c⟩
}𝕩
}
+_getCellCmp ← {
+ Ci←𝔽⋄l←𝕨⋄c←𝕩
+ {
+ a←𝕨⋄b←𝕩
+ S←(l⊸=)◶{S∘(1+𝕩)⍟(0⊸=)a Ci○(𝕩⊸+)b}‿c
+ S 0
+ }
+}
+Cmp ← ∨○IsArray◶{ # No arrays
+ 𝕨(>-<)𝕩 # Assume they're numbers
+}‿{ # At least one array
+ lc←𝕨(𝕨-○IsArray𝕩)_cmpLen○≢𝕩
+ cc ← (⊑⟜(⥊𝕨))⊸Cmp⟜(⊑⟜(⥊𝕩)) _getCellCmp´ lc
+ Cc˜0
+}
_grade←{
! 1≤=𝕩
- i⊐˜+´˘((2⥊≠𝕩)⥊𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
+ m←×´1 Cell 𝕩 ⋄ Ci←𝔽○(⊑⟜(⥊𝕩))
+ cc←m Ci _getCellCmp 0
+ i⊐˜+´˘((Cc⌜˜m×⊢)(⌈⟜0+=⟜0⊸×)>⌜˜)i←↕≠𝕩
}
_bins←{
c←1-˜=𝕨
! 0≤c
- LE←𝔽⎉c≤0˜
- ! (0<≠)◶⟨1,∧´·LE˝˘2↕⊢⟩𝕨
- 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,+˝LE⎉¯1‿∞⟩ 𝕩
+ ! c≤=𝕩
+ lw←×´sw←1↓≢𝕨
+ cw←lw 𝔽○(⊑⟜(⥊𝕨)) _getCellCmp 0
+ ! 0⊸<◶⟨1,∧´0≤˜·cw¨⟜(lw⊸+)lw×↕∘-⟜1⟩≠𝕨
+ sx←c-⊸↑≢𝕩 ⋄ lc←sw 0 _cmpLen sx
+ cc ← (⊑⟜(⥊𝕨))⊸𝔽⟜(⊑⟜(⥊𝕩)) _getCellCmp´ lc
+ ((×´sw)×↕≠𝕨) (0<≠𝕨)◶⟨0¨∘⊢,+˝Cc⌜≤0˜⟩ (×´sx)×(⊢⥊·↕×´)c-⊸↓≢𝕩
}
OccurrenceCount ← ⊐˜(⊢-⊏)⍋∘⍋