1 {-# LANGUAGE TypeSynonymInstances #-}
6 import Data.Array.Repa (
19 import Data.Array.Repa.IO.Vector (readVectorFromTextFile)
20 import System.FilePath ()
21 import Test.QuickCheck (Arbitrary(..), Gen)
24 type Values1D = Array DIM1 Double
25 type Values2D = Array DIM2 Double
26 type Values3D = Array DIM3 Double
29 instance Arbitrary Values3D where
31 x_dim <- arbitrary :: Gen Int
32 y_dim <- arbitrary :: Gen Int
33 z_dim <- arbitrary :: Gen Int
34 one_d <- arbitrary :: Gen Values1D
35 let new_shape = (Z :. x_dim :. y_dim :. z_dim)
36 let three_d = reshape new_shape one_d
40 instance Arbitrary Values1D where
42 x <- arbitrary :: Gen [Double]
43 let shape = (Z :. (length x))
44 let one_d = Data.Array.Repa.fromList shape x
48 read_values_1d :: FilePath -> IO Values1D
49 read_values_1d path = readVectorFromTextFile path
52 read_values_3d :: DIM3 -> FilePath -> IO Values3D
53 read_values_3d sh path = do
54 one_d <- read_values_1d path
55 return $ reshape sh one_d
59 empty3d = Data.Array.Repa.fromList (Z :. 0 :. 0 :. 0) []
62 dims :: Values3D -> (Int, Int, Int)
64 let (Z :. x :. y :. z) = extent v3d
69 idx :: Values3D -> Int -> Int -> Int -> Double
74 shape = (Z :. i :. j :. k)