1 {-# LANGUAGE TypeSynonymInstances #-}
6 import Data.Array.Repa (
20 import Data.Array.Repa.IO.Vector (readVectorFromTextFile,
21 writeVectorToTextFile)
22 import System.FilePath ()
23 import Test.QuickCheck (Arbitrary(..), Gen)
26 type Values1D = Array DIM1 Double
27 type Values2D = Array DIM2 Double
28 type Values3D = Array DIM3 Double
31 instance Arbitrary Values3D where
33 x_dim <- arbitrary :: Gen Int
34 y_dim <- arbitrary :: Gen Int
35 z_dim <- arbitrary :: Gen Int
36 one_d <- arbitrary :: Gen Values1D
37 let new_shape = (Z :. x_dim :. y_dim :. z_dim)
38 let three_d = reshape new_shape one_d
42 instance Arbitrary Values1D where
44 x <- arbitrary :: Gen [Double]
45 let shape = (Z :. (length x))
46 let one_d = Data.Array.Repa.fromList shape x
50 read_values_1d :: FilePath -> IO Values1D
51 read_values_1d path = readVectorFromTextFile path
54 read_values_3d :: DIM3 -> FilePath -> IO Values3D
55 read_values_3d sh path = do
56 one_d <- read_values_1d path
57 return $ reshape sh one_d
59 write_values_1d :: Values3D -> FilePath -> IO ()
60 write_values_1d v3d path = do
61 let size3d = size $ extent v3d
62 let shape1d = (Z :. size3d)
63 let v1d = reshape shape1d v3d
64 writeVectorToTextFile v1d path
67 empty3d = Data.Array.Repa.fromList (Z :. 0 :. 0 :. 0) []
70 dims :: Values3D -> (Int, Int, Int)
72 let (Z :. x :. y :. z) = extent v3d
77 idx :: Values3D -> Int -> Int -> Int -> Double
82 shape = (Z :. i :. j :. k)