Skip to content

Commit

Permalink
Fixed zip
Browse files Browse the repository at this point in the history
Ignore-this: 8ff81c589ce4f0b0f8243edb3e43548e

darcs-hash:20090725053458-6295e-1856dd59d2e5b59cc98f84fb3047d6232990ea97.gz
  • Loading branch information
mchakravarty committed Jul 25, 2009
1 parent 0c7a160 commit 4f6fee8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
14 changes: 12 additions & 2 deletions Data/Array/Accelerate/AST.hs
Expand Up @@ -131,13 +131,23 @@ data Comp a where
-> Exp slix -- ^slice value specification
-> Comp (Arr sl a)

{-
-- Pairwise combination of elements of two arrays with the same shape
Zip :: Arr dim a -> Arr dim b -> Comp (Arr dim (ElemRepr (a, b)))
Zip :: Arr dim a -> Arr dim b -> Comp (Arr dim (a, b))
-}

-- Apply the given function to all elements of the given array
-- Apply the given unary function to all elements of the given array
Map :: Fun (a -> b) -> Arr dim a -> Comp (Arr dim b)
-- FIXME: generalise to mapFold

-- Apply a given binary function pairwise to all elements of the given arrays.
-- The length of the result is the length of the shorter of the two argument
-- arrays.
ZipWith :: Fun (a -> b -> c)
-> Arr dim a
-> Arr dim b
-> Comp (Arr dim c)

-- Remove all elements from a linear array that do not satisfy the given
-- predicate
Filter :: Fun (a -> ElemRepr Bool)
Expand Down
6 changes: 5 additions & 1 deletion Data/Array/Accelerate/Language.hs
Expand Up @@ -95,10 +95,13 @@ arr ! ix = wrapComp $

zip :: forall dim a b. (Ix dim, Elem a, Elem b)
=> Arr dim a -> Arr dim b -> AP (Arr dim (a, b))
zip = zipWith (\x y -> x `Pair` y)
{-
zip arr1 arr2
= wrapComp $
mkZip (undefined::dim) (undefined::a) (undefined::b)
(convertArr arr1) (convertArr arr2)
-}

map :: (Ix dim, Elem a, Elem b)
=> (Exp a -> Exp b) -> Arr dim a -> AP (Arr dim b)
Expand All @@ -107,7 +110,8 @@ map f arr = wrapComp $ Map (convertFun1 f) (convertArr arr)
zipWith :: (Ix dim, Elem a, Elem b, Elem c)
=> (Exp a -> Exp b -> Exp c) -> Arr dim a -> Arr dim b -> AP (Arr dim c)
zipWith f arr1 arr2
= zip arr1 arr2 >>= map (\xy -> f (Fst xy) (Snd xy))
-- = zip arr1 arr2 >>= map (\xy -> f (Fst xy) (Snd xy))
= wrapComp $ ZipWith (convertFun2 f) (convertArr arr1) (convertArr arr2)

filter :: Elem a => (Exp a -> Exp Bool) -> Arr DIM1 a -> AP (Arr DIM1 a)
filter p arr = wrapComp $ Filter (convertFun1 p) (convertArr arr)
Expand Down
5 changes: 4 additions & 1 deletion Data/Array/Accelerate/Pretty.hs
Expand Up @@ -85,9 +85,12 @@ prettyComp (Replicate _ty ix arr)
= text "replicate" <+> prettyExp id ix <+> prettyArr arr
prettyComp (Index _ty arr ix)
= prettyArr arr <> char '!' <> prettyExp id ix
prettyComp (Zip arr1 arr2) = text "zip" <+> prettyArr arr1 <+> prettyArr arr2
--prettyComp (Zip arr1 arr2) = text "zip" <+> prettyArr arr1 <+> prettyArr arr2
prettyComp (Map f arr)
= text "map" <+> parens (prettyFun f) <+> prettyArr arr
prettyComp (ZipWith f arr1 arr2)
= text "zipWith" <+> parens (prettyFun f) <+> prettyArr arr1 <+>
prettyArr arr2
prettyComp (Filter p arr)
= text "filter" <+> parens (prettyFun p) <+> prettyArr arr
prettyComp (Scan f e arr)
Expand Down
8 changes: 5 additions & 3 deletions Data/Array/Accelerate/Smart.hs
Expand Up @@ -25,7 +25,7 @@ module Data.Array.Accelerate.Smart (
convertArray, convertArr, convertExp, convertFun1, convertFun2,

-- * Smart constructors for array operations
mkIndex, mkReplicate, mkZip,
mkIndex, mkReplicate, {- mkZip, -}

-- * Smart constructors for literals
exp,
Expand Down Expand Up @@ -394,14 +394,16 @@ mkReplicate :: forall slix e. (SliceIx slix, Elem e)
mkReplicate slix _ e arr
= Replicate (convertSliceIndex slix (sliceIndex (undefined::slix))) e arr

{-
mkZip :: (Ix dim, Elem a, Elem b)
=> dim {- dummy to fix the type variable -}
-> a {- dummy to fix the type variable -}
-> b {- dummy to fix the type variable -}
-> AST.Arr (ElemRepr dim) (ElemRepr a)
-> AST.Arr (ElemRepr dim) (ElemRepr b)
-> AST.Arr (ElemRepr dim) (ElemRepr' b)
-> Comp (AST.Arr (ElemRepr dim) (ElemRepr (a, b)))
mkZip _ _ _ arr1 arr2 = undefined
mkZip _ _ _ arr1 arr2 = Zip arr1 arr2
-}


-- |Smart constructors to construct HOAS AST expressions
Expand Down

0 comments on commit 4f6fee8

Please sign in to comment.