Hello,
I'm trying to learn accelerate-hs, but... I have problems with understanding how to work with variable length shapes.
For example, simple (according
to my expectations) task2:
1. convert shape with generally unknown length (n1, n2, ... nm) to matrix shape (n1*n2*...*nm-1, nm)
2. convert shape with generally unknown length (n1, n2, ... nm) to matrix shape (n1, n2*...*nm)
I'm trying to do something like
cnv :: (Slice (Z :. sh)) => Exp (Z :. sh :. Int) -> Exp (Z :. Int :. Int)but I have
Could not deduce: sh1 ~ sh
Expected type: Exp (Plain ((Z :. Exp sh1) :. Exp Int))
Actual type: Exp ((Z :. sh) :. Int)
In the first argument of ‘unlift’, namely ‘a’
What am I doing wrong? And what is the correct way to solve such a problem?
--
You received this message because you are subscribed to the Google Groups "Accelerate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelerate-hask...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/accelerate-haskell/d9af4819-0394-4468-bfc1-05ed57aae2e7n%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Accelerate" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/accelerate-haskell/u_l2Mm3GusU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to accelerate-hask...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/accelerate-haskell/dab36020-8c49-48c2-8308-c2300692d9a3n%40googlegroups.com.
{-# LANGUAGE GADTs #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} import Data.Array.Accelerate import Data.Array.Accelerate.Numeric.LinearAlgebra -- accelerate-blas import Data.Array.Accelerate.AST.Idx import Data.Array.Accelerate.Representation.Shape import Data.Array.Accelerate.Sugar.Shape import Data.Array.Accelerate.Smart import qualified Prelude as P test :: (Shape sh, Numeric e) => Acc (Array (sh :. Int) e) -> Acc (Array (sh :. Int) e) -> Acc (Matrix e) test as bs = let rest1 :> nm = shape as n1 :< rest2 = shape bs as' = reshape (I2 (shapeSize rest1) nm) as bs' = reshape (I2 n1 (shapeSize rest2)) bs in as' <> bs' infixl 3 :> pattern (:>) :: Shape sh => Exp sh -> Exp Int -> Exp (sh :. Int) pattern sh :> sz = sh ::. sz infixr 3 :< pattern (:<) :: Shape sh => Exp Int -> Exp sh -> Exp (sh :. Int) pattern (:<) sz sh <- (uncons -> (sz, sh)) where (:<) = cons cons :: forall sh. Shape sh => Exp Int -> Exp sh -> Exp (sh :. Int) cons (Exp _i) (Exp _sh) = Exp $ cons' (shapeR @sh) _i _sh where cons' :: ShapeR t -> SmartExp Int -> SmartExp t -> SmartExp (t, Int) cons' ShapeRz i _ = SmartExp (Pair (SmartExp Nil) i) cons' (ShapeRsnoc shR) i sh = let h = SmartExp (Prj PairIdxRight sh) t = SmartExp (Prj PairIdxLeft sh) sh' = cons' shR i t in SmartExp (Pair sh' h) uncons :: forall sh. Shape sh => Exp (sh :. Int) -> (Exp Int, Exp sh) uncons (Exp _sh) = let (i, t) = uncons' (shapeR @(sh :. Int)) _sh in (Exp i, Exp t) where uncons' :: ShapeR (t,Int) -> SmartExp (t,Int) -> (SmartExp Int, SmartExp t) uncons' (ShapeRsnoc ShapeRz) sh = (SmartExp (Prj PairIdxRight sh), SmartExp Nil) uncons' (ShapeRsnoc shR@ShapeRsnoc{}) sh = let h = SmartExp (Prj PairIdxRight sh) t = SmartExp (Prj PairIdxLeft sh) (i, t') = uncons' shR t in (i, SmartExp (Pair t' h))
To view this discussion on the web, visit https://groups.google.com/d/msgid/accelerate-haskell/c6029570-f63f-4d3d-af33-bc346b74aec6n%40googlegroups.com.