From dc66969bc009714486da40254aa3eff3ea57b035 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 4 Aug 2025 18:05:05 +0200 Subject: Failed experiment to add replicate/transpose combination --- src/Data/Array/Nested/Mixed.hs | 7 +++++++ src/Data/Array/Nested/Permutation.hs | 9 +++++++++ src/Data/Array/Nested/Shaped.hs | 9 +++++++++ 3 files changed, 25 insertions(+) (limited to 'src/Data/Array/Nested') diff --git a/src/Data/Array/Nested/Mixed.hs b/src/Data/Array/Nested/Mixed.hs index 144230e..4028b1d 100644 --- a/src/Data/Array/Nested/Mixed.hs +++ b/src/Data/Array/Nested/Mixed.hs @@ -5,6 +5,7 @@ {-# LANGUAGE DerivingVia #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE InstanceSigs #-} {-# LANGUAGE RankNTypes #-} @@ -287,6 +288,8 @@ mremArray = mliftNumElt2 (liftO2 . intEltRem) matan2Array :: (FloatElt a, PrimElt a) => Mixed sh a -> Mixed sh a -> Mixed sh a matan2Array = mliftNumElt2 (liftO2 . floatEltAtan2) +type MRepTrans = RepTrans (SMayNat Int SNat) + -- | Allowable element types in a mixed array, and by extension in a 'Ranked' or -- 'Shaped' array. Note the polymorphic instance for 'Elt' of @'Primitive' -- a@; see the documentation for 'Primitive' for more details. @@ -340,6 +343,8 @@ class Elt a where mtranspose :: forall is sh. (IsPermutation is, Rank is <= Rank sh) => Perm is -> Mixed sh a -> Mixed (PermutePrefix is sh) a + mreptransPartial :: Proxy sh' -> MRepTrans sh1 sh2 -> Mixed (sh1 ++ sh') a -> Mixed (sh2 ++ sh') a + -- | All arrays in the input must have equal shapes, including subarrays -- inside their elements. mconcat :: NonEmpty (Mixed (Nothing : sh) a) -> Mixed (Nothing : sh) a @@ -445,6 +450,8 @@ instance Storable a => Elt (Primitive a) where M_Primitive (shxPermutePrefix perm sh) (X.transpose (ssxFromShX sh) perm arr) + mreptransPartial p descr (M_Primitive sh arr) = _ + mconcat :: forall sh. NonEmpty (Mixed (Nothing : sh) (Primitive a)) -> Mixed (Nothing : sh) (Primitive a) mconcat l@(M_Primitive (_ :$% sh) _ :| _) = let result = X.concat (ssxFromShX sh) (fmap (\(M_Primitive _ arr) -> arr) l) diff --git a/src/Data/Array/Nested/Permutation.hs b/src/Data/Array/Nested/Permutation.hs index 03d1640..c893dac 100644 --- a/src/Data/Array/Nested/Permutation.hs +++ b/src/Data/Array/Nested/Permutation.hs @@ -281,3 +281,12 @@ lemRankDropLen ZKX (_ `PCons` _) = error "1 <= 0" lemIndexSucc :: Proxy i -> Proxy a -> Proxy l -> Index (i + 1) (a : l) :~: Index i l lemIndexSucc _ _ _ = unsafeCoerceRefl + + +-- * Replication-transpositions + +data RepTrans f sh sh' where + RTNil :: RepTrans f sh '[] + RTUse :: SNat i -> RepTrans f sh sh' -> RepTrans f sh (Index i sh : sh') + RTRep :: f n -> RepTrans f sh sh' -> RepTrans f sh (n : sh') + diff --git a/src/Data/Array/Nested/Shaped.hs b/src/Data/Array/Nested/Shaped.hs index 198a068..2c64bb4 100644 --- a/src/Data/Array/Nested/Shaped.hs +++ b/src/Data/Array/Nested/Shaped.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -199,6 +200,14 @@ srerank :: forall sh1 sh2 sh a b. (PrimElt a, PrimElt b) srerank sh sh2 f (stoPrimitive -> arr) = sfromPrimitive $ srerankP sh sh2 (stoPrimitive . f . sfromPrimitive) arr +-- data RepTrans sh sh' where +-- RTNil :: RepTrans sh '[] +-- RTUse :: SNat i -> RepTrans sh sh' -> RepTrans sh (Index i sh : sh') +-- RTRep :: SNat n -> RepTrans sh sh' -> RepTrans sh (n : sh') + +-- sreptrans :: RepTrans sh sh' -> Shaped sh a -> Shaped sh' a +-- sreptrans + sreplicate :: forall sh sh' a. Elt a => ShS sh -> Shaped sh' a -> Shaped (sh ++ sh') a sreplicate sh (Shaped arr) | Refl <- lemMapJustApp sh (Proxy @sh') -- cgit v1.2.3-70-g09d2