~pmikkelsen/dyalog-competition-2022

eb993b53172b2ddf02d1232e8dadf7e63c0791cb — Peter Mikkelsen 2 years ago 8df5d5a
Finish reshape
1 files changed, 15 insertions(+), 2 deletions(-)

M reshape.apln
M reshape.apln => reshape.apln +15 -2
@@ 5,7 5,20 @@
          ⊃{⊖⍤⍺⊢⍵}⌿rotations,⊂data
      }
      reshape2←{
          (dims data)←⍺ process ⍵
          dims reshape data
          (absDims data)←⍺ process ⍵
          (absDims××⍺) reshape data
      }
      process←{
          absDims←|⍺
          dataLength←≢,⍵
          specialMask←∨⌿0.5 1.5 2.5(=⍤0 1)absDims
          specialDim←specialMask⌿absDims
          restDims←(~specialMask)⌿absDims
          upSize←⌈dataLength÷×⌿restDims
          downSize←⌊dataLength÷×⌿restDims
          0=≢specialDim:absDims ⍵ ⍝ no special values in dims
          0.5=specialDim: (downSize@(⍸specialMask)⊢absDims) ⍵
          1.5=specialDim: (upSize@(⍸specialMask)⊢absDims) ⍵
          2.5=specialDim: (upSize@(⍸specialMask)⊢absDims) (⍵↑⍨×⌿upSize,restDims)
      }
:EndNamespace