aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-08 23:44:03 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-08 23:47:21 -0400
commit52f8a6655c65584cf0740021dcd6fed428fc9b6c (patch)
tree521474b6ad6127bd2c969ab22c23c683780c6a4c /src
parent2ff502e46f9d7e6929059479da2e160d0cbbf5de (diff)
Faster high-rank Join implementation
Diffstat (limited to 'src')
-rw-r--r--src/r.bqn19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/r.bqn b/src/r.bqn
index 05ae9fac..56802762 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -314,20 +314,21 @@ Replicate ← {0<=𝕨}β—Ά{π•¨Λ˜βŠΈRep𝕩}β€Ώ{"𝕨/𝕩: lengths of component
Join←(1β‰ =)β—ΆβŸ¨βˆ¨Β΄1β‰ =⌜,1βŸ©β—Ά{
# List of lists
- i←j←¯1β‹„eβ†βŸ¨βŸ©β‹„a←𝕩
+ i←j←¯1 β‹„ eβ†βŸ¨βŸ© β‹„ a←𝕩
{{e↩aβŠ‘Λœi↩𝕩⋄j↩¯1}⍟(iβŠΈβ‰ )𝕩⋄(j↩j+1)βŠ‘e}⌜/β‰ βŒœπ•©
}β€Ώ{
# Multidimensional
- C←(<⟨⟩)β₯ŠβŠΈβˆΎβŒœΒ΄βŠ’ # Cartesian array product
"βˆΎπ•©: 𝕩 must be an array" ! IsArray 𝕩
- sβ†β‰’βŒœπ•©
- d←≠0βŠ‘β₯Šs
- "βˆΎπ•©: elements of 𝕩 must all have the same rank" ! ∧´β₯Šd=β‰ βŒœs
+ n←≠z←β₯Šπ•© β‹„ sβ†β‰’βŒœz β‹„ d←≠0βŠ‘s
+ "βˆΎπ•©: elements of 𝕩 must all have the same rank" ! ∧´d=β‰ βŒœs
"βˆΎπ•©: 𝕩 element rank must be at least argument rank" ! dβ‰₯=𝕩
- l←(≒𝕩){(π•©βŠ‘βŸœβ‰’a Pick1˜(j=𝕩)βŠΈΓ—)βŒœβ†•π•¨}Β¨j←↕r←=a←𝕩
- "βˆΎπ•©: 𝕩 element shapes must be compatible" ! (rβŠΈβ†‘βŒœs)≑C l
- i←C{p←+Β΄βŒœβ†‘π•©β‹„(↕0βŠ‘βŒ½p)-𝕩/Β―1↓p}⌜l
- >i<⌜⊸⊏¨l/𝕩
+ scm←"βˆΎπ•©: 𝕩 element shapes must be compatible"
+ q←1 β‹„ l←(≒𝕩){mβ†π•©βŠΈβŠ‘βŒœs β‹„ rβ†βŠ‘βŸœm⌜q×↕𝕨 β‹„ scm!m≑nβ₯ŠrβŠ£βŒœβ†•q β‹„ q×↩𝕨 β‹„ r}Β¨β—‹βŒ½β†•=𝕩
+ t←(=𝕩)↓0βŠ‘s
+ "βˆΎπ•©: 𝕩 element trailing shapes must match" ! ∧´(t≑(=𝕩)βŠΈβ†“)⌜s
+ i←<0 β‹„ q↩<1
+ {s←0β‹„p←{o←sβ‹„s+↩𝕩⋄o}βŒœπ•© β‹„ j←↕s β‹„ i↩(j⊒⌜i)+(j-𝕩/p)Γ—βŒœq β‹„ qΓ—βŒœΛœβ†©π•©/𝕩}⌜l
+ i(0<β‰ t)β—ΆβŸ¨βŠ‘βŸœβ₯ŠΒ¨,{ti←tβ₯Šβ†•tp←×´tβ‹„((tp×𝕨)+⌜ti)βŠ‘βŸœβ₯ŠΒ¨π•©βŠ£βŒœti}⟩(⌽l)/𝕩
}⍟(0<β‰ βˆ˜β₯Š)
_group←{