From 999576c62823479bd840e11e4802913d88c22cc5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 15 Apr 2015 21:35:08 -0400 Subject: [PATCH] Import cleanup in Grid. --- src/Grid.hs | 72 +++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/Grid.hs b/src/Grid.hs index 269b37c..b40f655 100644 --- a/src/Grid.hs +++ b/src/Grid.hs @@ -5,38 +5,43 @@ module Grid ( cube_at, grid_tests, slow_tests, - zoom - ) + zoom ) 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) -import Test.Framework.Providers.QuickCheck2 (testProperty) -import Test.QuickCheck ((==>), - Arbitrary(..), - Gen, - Property, - choose, - vectorOf) -import Assertions (assertAlmostEqual, assertTrue) -import Comparisons ((~=)) -import Cube (Cube(Cube), - find_containing_tetrahedron, - tetrahedra, - tetrahedron) -import Examples (trilinear, trilinear9x9x9, zeros) -import FunctionValues (make_values, value_at) -import Point (Point(..)) -import ScaleFactor (ScaleFactor) +import Data.Array.Repa ( + (:.)( (:.) ), + DIM3, + Z( Z ), + computeUnboxedP, + fromListUnboxed ) +import Data.Array.Repa.Operators.Traversal ( unsafeTraverse ) +import Test.HUnit ( Assertion, assertEqual ) +import Test.Framework ( Test, testGroup ) +import Test.Framework.Providers.HUnit ( testCase ) +import Test.Framework.Providers.QuickCheck2 ( testProperty ) +import Test.QuickCheck ( + (==>), + Arbitrary(..), + Gen, + Property, + choose, + vectorOf ) +import Assertions ( assertAlmostEqual, assertTrue ) +import Comparisons ( (~=) ) +import Cube ( + Cube( Cube ), + find_containing_tetrahedron, + tetrahedra, + tetrahedron ) +import Examples ( trilinear, trilinear9x9x9, zeros ) +import FunctionValues ( make_values, value_at ) +import Point ( Point(..) ) +import ScaleFactor ( ScaleFactor ) import Tetrahedron ( Tetrahedron(v0,v1,v2,v3), c, - polynomial, - ) -import Values (Values3D, dims, empty3d, zoom_shape) + polynomial ) +import Values ( Values3D, dims, empty3d, zoom_shape ) -- | Our problem is defined on a Grid. The grid size is given by the @@ -44,6 +49,7 @@ import Values (Values3D, dims, empty3d, zoom_shape) -- performance reasons (and simplicity). The function values are the -- values of the function at the grid points, which are distance h=1 -- from one another in each direction (x,y,z). +-- data Grid = Grid { function_values :: Values3D } deriving (Show) @@ -54,8 +60,8 @@ instance Arbitrary Grid where 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 + let new_shape = (Z :. x_dim :. y_dim :. z_dim) + let fvs = fromListUnboxed new_shape elements return $ Grid fvs @@ -104,13 +110,13 @@ find_containing_cube g (Point x y z) = k = calculate_containing_cube_coordinate g z -zoom_lookup :: Values3D -> ScaleFactor -> a -> (R.DIM3 -> Double) +zoom_lookup :: Values3D -> ScaleFactor -> a -> (DIM3 -> Double) zoom_lookup v3d scale_factor _ = zoom_result v3d scale_factor -zoom_result :: Values3D -> ScaleFactor -> R.DIM3 -> Double -zoom_result v3d (sfx, sfy, sfz) (R.Z R.:. m R.:. n R.:. o) = +zoom_result :: Values3D -> ScaleFactor -> DIM3 -> Double +zoom_result v3d (sfx, sfy, sfz) (Z :. m :. n :. o) = f p where g = Grid v3d @@ -132,7 +138,7 @@ zoom :: Values3D -> ScaleFactor -> IO Values3D zoom v3d scale_factor | xsize == 0 || ysize == 0 || zsize == 0 = return empty3d | otherwise = - R.computeUnboxedP $ R.unsafeTraverse v3d transExtent f + computeUnboxedP $ unsafeTraverse v3d transExtent f where (xsize, ysize, zsize) = dims v3d transExtent = zoom_shape scale_factor -- 2.44.2