From 2e3fe35ec3ec07cb042eccbb221eec900d9ee39a Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 30 Apr 2021 21:04:30 -0400 Subject: Rank-less Find implementation --- src/r1.bqn | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/r1.bqn') diff --git a/src/r1.bqn b/src/r1.bqn index 34c90e57..ee634cb1 100644 --- a/src/r1.bqn +++ b/src/r1.bqn @@ -194,6 +194,14 @@ _self←{ 0 Fill (PermInv g) ⊏ g 𝔽 0⊸<β—ΆβŸ¨1, -⟜1 CCβ—‹(βŠ‘βŸœ(kβŠΈΓ—βŒœg)) βŠ’βŸ©βŒœβ†•β‰ π•© } +Find←{ + r←=𝕨 β‹„ d←(=𝕩)-r + "⍷𝕩: Rank of 𝕨 cannot exceed rank of 𝕩" ! 0≀d + i←<0 β‹„ j←β₯ŠβŸœ(↕1Γ—Β΄βŠ’)d↑s←≒𝕩 + (≒𝕨) { Aβ†Γ—βŸœπ•©βŒœβŠΈ(+⌜)βŸœβ†• β‹„ i A↩𝕨 β‹„ j A↩0⌈1+𝕩-𝕨 }Β¨ d↓s + 0 Fill (𝕨 Match (β₯Šπ•©)⊏˜i+⌜<)⌜ j +}β—‹ToArray + Indices←{ "/: Replication argument must have rank 1" ! 1==𝕩 "/: Amounts to replicate must be natural numbers" ! 1Γ—Β΄NatβŒœπ•© @@ -694,13 +702,6 @@ GroupM←{ βŠ” ← GroupInds ⊘ GroupGen ⊐ ← SelfClas ⊘ (1 _search) ∊ ← ⊒_self ⊘ (0 _search˜) -βŽ‰ ← _rankOp_ - -Find←{ - r←=𝕨 - "⍷𝕩: Rank of 𝕨 cannot exceed rank of 𝕩" ! r≀=𝕩 - 0 Fill 𝕨 β‰‘βŽ‰r ((1+r-βŠΈβ†‘β‰’π•©)βŒŠβ‰’π•¨)βŠΈβ†•βŽ‰r 𝕩 -}β—‹ToArray ProgressiveIndexOf ← 0 Fill { c←1-˜=𝕨 @@ -838,6 +839,7 @@ Mod2Inverse ← INFΛ™ _lookup_ ⟨ βŠ‘ ↩ First ⊘ Pick β—Ά ↩ {𝕨((𝕨𝔽𝕩)βŠ‘π•˜){𝔽}𝕩} # Same definition, new Pick βš‡ ← _depthOp_ +βŽ‰ ← _rankOp_ β₯Š ↩ Deshape ⊘ Reshape ≍ ← >∘Pair _fillBy_ (⊒⊘IF) ⍉ ← Transpose ⊘ ReorderAxes -- cgit v1.2.3