aboutsummaryrefslogtreecommitdiff
path: root/src/r.bqn
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-08 10:33:48 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-08-08 10:33:48 -0400
commite34577b432ad308d4f88e65784b68f81eebd4ed4 (patch)
treee11789b643f6c392e595e10923e98d760d4b74fc /src/r.bqn
parente82d439a595d472d12f85b3879cd9d0728c48e8f (diff)
Fast monadic transpose
Diffstat (limited to 'src/r.bqn')
-rw-r--r--src/r.bqn9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/r.bqn b/src/r.bqn
index 0bfd5da4..d153a53d 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -31,6 +31,7 @@ _fold←{
ToArray ← <⍟(1-IsArray)
Int←IsArray◶⟨⌊⊸=,0⟩
Nat←IsArray◶⟨0⊸≤×⌊⊸=,0⟩
+Cell←{(𝕨⊸+⊑𝕩˜)⌜↕(≠𝕩)-𝕨}⟜≢
∾ ← {k←≠𝕨⋄k⊸≤◶⟨⊑⟜𝕨⋄-⟜k⊑𝕩˜⟩⌜↕k+≠𝕩} # LIMITED to two vector arguments
@@ -96,6 +97,11 @@ Indices←{
}⍟(0<l)𝕩
}
+Transpose←{
+ l←≠𝕩 ⋄ m←1×´c←1 Cell 𝕩
+ (c⥊↕m)(+⟜(m⊸×)⊑(⥊𝕩)˜)⌜↕l
+}⍟(0<=)
+
_under_←{
i←↕l←1×´s←≢𝕩
v←⥊𝕨𝔽○𝔾𝕩
@@ -174,8 +180,6 @@ Depth←IsArray◶0‿{1+0⌈´Depth⌜⥊𝕩}
≢ ↩ ≢ ⊘ (¬Match)
-DropV← {⊑⟜𝕩⌜𝕨+↕𝕨-˜≠𝕩}
-Cell ← DropV⟜≢
Pair ← {⟨𝕩⟩} ⊘ {⟨𝕨,𝕩⟩}
Merge←{
@@ -352,7 +356,6 @@ ReorderAxes←{
𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
(𝕨⊸⊏Pick𝕩˜)⌜↕⌊´⌜𝕨⊔≢𝕩
}
-Transpose←(=-1˜)⊸ReorderAxes⍟(0<=)
⍉ ← Transpose ⊘ ReorderAxes
# Sorting