aboutsummaryrefslogtreecommitdiff
path: root/src/r1.bqn
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2022-02-07 15:50:39 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2022-02-07 20:24:08 -0500
commit0ff6985d61c45675aa36e2edf5dfbe8352c34ce8 (patch)
tree9ba6914ad4b75f313856bad4f0cc62c56cfa893b /src/r1.bqn
parentb7a7b1ff8a43c01d1e193bfee8becb1e0039c7b8 (diff)
Lower-level Reorder Axes control code
Diffstat (limited to 'src/r1.bqn')
-rw-r--r--src/r1.bqn43
1 files changed, 18 insertions, 25 deletions
diff --git a/src/r1.bqn b/src/r1.bqn
index 739505ea..2255f4b1 100644
--- a/src/r1.bqn
+++ b/src/r1.bqn
@@ -226,6 +226,24 @@ TransposeInv←{
(⥊𝕩)⊏˜(↕l)+⟜(l⊸×)⌜c⥊↕1×´c
}_fillBy_⊢⍟{IX IsArray𝕩⋄0<=𝕩}
+_reorderAxesSub_←{
+ "𝕨⍉𝕩: 𝕨 must have rank at most 1" ! 1≥=𝕨
+ 𝕨↩Deshape𝕨 ⋄ 𝕩↩ToArray𝕩
+ "𝕨⍉𝕩: Length of 𝕨 must not exceed rank of 𝕩" ! (≠𝕨)≤r←=𝕩
+ "𝕨⍉𝕩: 𝕨 must consist of valid axis indices" ! 1∧´(Nat∧<⟜r)⌜𝕨
+ r𝔽↩n←GroupLen𝕨
+ a←𝔾 𝕨∾(Indices 0⊸=⌜n)∾{𝕩⊸+⌜↕r-𝕩}≠n
+ l‿s←a⊸Group1⌜⋈⟜Stride≢𝕩
+ (⌊´⌜l) (0<≠∘⊢)◶⟨⥊,((<0)+⌜´s(<+´)⊸(×⌜)⟜↕¨⊣)⊸⊏⟜⥊⟩ _fillBy_ ⊢ 𝕩
+}
+HandleDupAxes←{
+ r←𝕨-0+´(0⌈-⟜1)⌜𝕩
+ "𝕨⍉𝕩: Skipped result axis" ! (≠𝕩)≤r
+ r
+}
+ReorderAxes ← HandleDupAxes _reorderAxesSub_ ⊢
+ReorderAxesInv ← {IA 1≥0⌈´𝕩⋄𝕨} _reorderAxesSub_ PermInv
+
Prefixes←{
"↑𝕩: 𝕩 must have rank at least 1" ! 1≤=𝕩
0⊸⊑⊸Fill ↕⊸⊏⟜𝕩⌜ ↕1+≠𝕩
@@ -710,11 +728,6 @@ _repeat_←{
(Nat n)◶Multi‿{𝕩(B f)∘⊢´↕n} 𝕩
}
-ReorderAxesSub←{
- l‿s←𝕨⊸Group1⌜⋈⟜Stride≢𝕩
- (⌊´⌜l) (0<≠∘⊢)◶⟨⥊,((<0)+⌜´s(<+´)⊸(×⌜)⟜↕¨⊣)⊸⊏⟩ ⥊𝕩
-} _fillBy_ ⊢ ⟜ ToArray
-
÷ ↩ ÷ _perv
⋆ ↩ ⋆ _perv
√ ← ⋆⟜(÷2) ⊘ (⋆⟜÷˜)
@@ -766,26 +779,6 @@ ProgressiveIndexOf ← 0 Fill {
𝕨⊐○(⋈¨⟜(≢⥊OccurrenceCount∘⥊) 𝕨⊸⊐)𝕩
}
-ReorderChk←{
- "𝕨⍉𝕩: 𝕨 must have rank at most 1" ! 1≥=𝕨
- "𝕨⍉𝕩: Length of 𝕨 must not exceed rank of 𝕩" ! 𝕨≤○≠≢𝕩
- "𝕨⍉𝕩: 𝕨 must consist of natural numbers" ! 1∧´Nat⌜⥊𝕨
-}
-ReorderAxes←{
- 𝕨 ReorderChk 𝕩
- 𝕨↩⥊𝕨
- r←(=𝕩)-0+´¬∊𝕨
- "𝕨⍉𝕩: Skipped result axis" ! 1∧´𝕨<r
- (𝕨∾𝕨(¬∘∊˜/⊢)↕r) ReorderAxesSub 𝕩
-}
-ReorderAxesInv←{
- 𝕨 ReorderChk 𝕩
- 𝕨↩⥊𝕨
- r←=𝕩
- IA 1∧´(∊∧<⟜r)𝕨
- (PermInv 𝕨∾𝕨(¬∘∊˜/⊢)↕r) ReorderAxesSub 𝕩
-}
-
⁼ ← {Inverse 𝕗}
IsConstant ← (3≤Type)◶⟨1 ⋄ DIsConst∘{Decompose𝕩}⊢⟩
AtopInverse ← {(𝕏𝕎)⊘(𝕏⟜𝕎)}○{Inverse𝕩}