where
import qualified Data.Array.Repa as R
+import qualified Data.Array.Repa.Operators.Traversal as R (unsafeTraverse)
import Test.HUnit (Assertion, assertEqual)
import Test.Framework (Test, testGroup)
import Test.Framework.Providers.HUnit (testCase)
Arbitrary(..),
Gen,
Property,
- choose)
+ choose,
+ vectorOf)
import Assertions (assertAlmostEqual, assertTrue)
import Comparisons ((~=))
import Cube (Cube(Cube),
instance Arbitrary Grid where
arbitrary = do
- fvs <- arbitrary :: Gen Values3D
+ x_dim <- choose (1, 27)
+ y_dim <- choose (1, 27)
+ z_dim <- choose (1, 27)
+ elements <- vectorOf (x_dim * y_dim * z_dim) (arbitrary :: Gen Double)
+ let new_shape = (R.Z R.:. x_dim R.:. y_dim R.:. z_dim)
+ let fvs = R.fromListUnboxed new_shape elements
return $ Grid fvs
f = polynomial t
-zoom :: Values3D -> ScaleFactor -> Values3D
+--
+-- Instead of IO, we could get away with a generic monad 'm'
+-- here. However, /we/ only call this function from within IO.
+--
+zoom :: Values3D -> ScaleFactor -> IO Values3D
zoom v3d scale_factor
- | xsize == 0 || ysize == 0 || zsize == 0 = empty3d
+ | xsize == 0 || ysize == 0 || zsize == 0 = return empty3d
| otherwise =
- R.compute $ R.unsafeTraverse v3d transExtent f
- where
- (xsize, ysize, zsize) = dims v3d
- transExtent = zoom_shape scale_factor
- f = zoom_lookup v3d scale_factor
+ R.computeUnboxedP $ R.unsafeTraverse v3d transExtent f
+ where
+ (xsize, ysize, zsize) = dims v3d
+ transExtent = zoom_shape scale_factor
+ f = zoom_lookup v3d scale_factor
-- | Check all coefficients of tetrahedron0 belonging to the cube