1 {-# LANGUAGE FlexibleInstances #-}
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, Positive(..), vectorOf)
29 type Values1D = Array DIM1 Double
30 type Values2D = Array DIM2 Double
31 type Values3D = Array DIM3 Double
34 instance Arbitrary Values3D where
36 (Positive x_dim) <- arbitrary :: Gen (Positive Int)
37 (Positive y_dim) <- arbitrary :: Gen (Positive Int)
38 (Positive z_dim) <- arbitrary :: Gen (Positive Int)
39 elements <- vectorOf (x_dim * y_dim * z_dim) (arbitrary :: Gen Double)
40 let new_shape = (Z :. x_dim :. y_dim :. z_dim)
41 let three_d = Data.Array.Repa.fromList new_shape elements
45 read_values_1d :: FilePath -> IO Values1D
46 read_values_1d = readVectorFromTextFile
49 read_values_3d :: DIM3 -> FilePath -> IO Values3D
50 read_values_3d sh path = do
51 one_d <- read_values_1d path
52 return $ reshape sh one_d
54 write_values_1d :: Values3D -> FilePath -> IO ()
55 write_values_1d v3d path = do
56 let size3d = size $ extent v3d
57 let shape1d = (Z :. size3d)
58 let v1d = reshape shape1d v3d
59 writeVectorToTextFile v1d path
62 empty3d = Data.Array.Repa.fromList (Z :. 0 :. 0 :. 0) []
65 dims :: Values3D -> (Int, Int, Int)
67 let (Z :. x :. y :. z) = extent v3d
72 idx :: Values3D -> Int -> Int -> Int -> Double
77 shape = (Z :. i :. j :. k)
80 zoom_shape :: ScaleFactor -> DIM3 -> DIM3
81 zoom_shape (sfx, sfy, sfz) sh =
82 let (Z :. x :. y :. z) = sh