module Data.Repa.Array.Meta.RowWise
( RW (..)
, Name (..)
, Array (..)
, rowWise
, DIM1, DIM2, DIM3, DIM4, DIM5
, ix1, ix2, ix3, ix4, ix5)
where
import Data.Repa.Array.Internals.Shape
import Data.Repa.Array.Internals.Layout
import Data.Repa.Array.Internals.Bulk
import Control.Monad
import GHC.Base (quotInt, remInt)
#include "repa-array.h"
data RW sh
= RowWise
{ rowWiseShape :: !sh }
deriving instance Eq sh => Eq (RW sh)
deriving instance Show sh => Show (RW sh)
instance Shape sh
=> Shape (RW sh) where
rank (RowWise sh)
= rank sh
zeroDim = RowWise zeroDim
unitDim = RowWise unitDim
intersectDim (RowWise sh1) (RowWise sh2)
= RowWise (intersectDim sh1 sh2)
addDim (RowWise sh1) (RowWise sh2)
= RowWise (addDim sh1 sh2)
size (RowWise sh)
= size sh
inShapeRange (RowWise sh1) (RowWise sh2) (RowWise sh3)
= inShapeRange sh1 sh2 sh3
listOfShape (RowWise sh)
= listOfShape sh
shapeOfList xx
= liftM RowWise $ shapeOfList xx
instance Layout (RW Z) where
data Name (RW Z) = RZ
type Index (RW Z) = Z
name = RZ
create RZ Z = RowWise Z
extent _ = Z
toIndex _ _ = 0
fromIndex _ _ = Z
deriving instance Eq (Name (RW Z))
deriving instance Show (Name (RW Z))
instance ( Layout (RW sh)
, Index (RW sh) ~ sh)
=> Layout (RW (sh :. Int)) where
data Name (RW (sh :. Int)) = RC (Name (RW sh))
type Index (RW (sh :. Int)) = sh :. Int
name = RC name
create (RC nSh) (sh :. i)
= let RowWise iSh = create nSh sh
in RowWise (iSh :. i)
extent (RowWise sh) = sh
toIndex (RowWise (sh1 :. sh2)) (sh1' :. sh2')
= toIndex (RowWise sh1) sh1' * sh2 + sh2'
fromIndex (RowWise (ds :. d)) n
= fromIndex (RowWise ds) (n `quotInt` d) :. r
where r | rank ds == 0 = n
| otherwise = n `remInt` d
deriving instance Eq (Name (RW sh)) => Eq (Name (RW (sh :. Int)))
deriving instance Show (Name (RW sh)) => Show (Name (RW (sh :. Int)))
instance (Layout (RW sh), Index (RW sh) ~ sh)
=> Bulk (RW sh) sh where
data Array (RW sh) sh = RArray sh
layout (RArray sh) = RowWise sh
index (RArray _) ix = ix
rowWise :: sh -> Array (RW sh) sh
rowWise sh = RArray sh
type DIM1 = RW SH1
type DIM2 = RW SH2
type DIM3 = RW SH3
type DIM4 = RW SH4
type DIM5 = RW SH5
ix1 :: Int -> DIM1
ix1 x = RowWise (Z :. x)
ix2 :: Int -> Int -> DIM2
ix2 y x = RowWise (Z :. y :. x)
ix3 :: Int -> Int -> Int -> DIM3
ix3 z y x = RowWise (Z :. z :. y :. x)
ix4 :: Int -> Int -> Int -> Int -> DIM4
ix4 a z y x = RowWise (Z :. a :. z :. y :. x)
ix5 :: Int -> Int -> Int -> Int -> Int -> DIM5
ix5 b a z y x = RowWise (Z :. b :. a :. z :. y :. x)