diff options
author | Alberto Ruiz <aruiz@um.es> | 2011-12-14 13:08:43 +0100 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2011-12-14 13:08:43 +0100 |
commit | 77552d080e88fc70312f55fd3303fac3464ab46e (patch) | |
tree | 1dc87dd22ce0da0f1807765568fbc04285bf3621 | |
parent | c3bda2d38c432fb53ce456cba295b097fd4d6ad1 (diff) |
new package hmatrix-tests
-rw-r--r-- | examples/parallel.hs | 5 | ||||
-rw-r--r-- | hmatrix.cabal | 22 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h | 33 | ||||
-rw-r--r-- | packages/tests/CHANGES | 5 | ||||
-rw-r--r-- | packages/tests/LICENSE | 2 | ||||
-rw-r--r-- | packages/tests/Setup.lhs | 4 | ||||
-rw-r--r-- | packages/tests/hmatrix-tests.cabal | 44 | ||||
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests.hs (renamed from lib/Numeric/LinearAlgebra/Tests.hs) | 28 | ||||
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs (renamed from lib/Numeric/LinearAlgebra/Tests/Instances.hs) | 4 | ||||
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs (renamed from lib/Numeric/LinearAlgebra/Tests/Properties.hs) | 14 | ||||
-rw-r--r-- | packages/tests/src/tests.hs (renamed from examples/tests.hs) | 0 |
11 files changed, 90 insertions, 71 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs index 566b729..e875407 100644 --- a/examples/parallel.hs +++ b/examples/parallel.hs | |||
@@ -1,4 +1,5 @@ | |||
1 | -- $ runhaskell parallel.hs 2000 | 1 | -- $ ghc --make -O -rtsopts -threaded parallel.hs |
2 | -- $ ./parallel 3000 +RTS -N4 -s -A200M | ||
2 | 3 | ||
3 | import System.Environment(getArgs) | 4 | import System.Environment(getArgs) |
4 | import Numeric.LinearAlgebra | 5 | import Numeric.LinearAlgebra |
@@ -7,7 +8,6 @@ import System.Time | |||
7 | 8 | ||
8 | inParallel = parMap rwhnf id | 9 | inParallel = parMap rwhnf id |
9 | 10 | ||
10 | |||
11 | -- matrix product decomposed into p parallel subtasks | 11 | -- matrix product decomposed into p parallel subtasks |
12 | parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] | 12 | parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] |
13 | where [ys] = toBlocksEvery (rows y) (cols y `div` p) y | 13 | where [ys] = toBlocksEvery (rows y) (cols y `div` p) y |
@@ -25,3 +25,4 @@ time act = do | |||
25 | act | 25 | act |
26 | t1 <- getClockTime | 26 | t1 <- getClockTime |
27 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 | 27 | print $ tdSec $ normalizeTimeDiff $ diffClockTimes t1 t0 |
28 | |||
diff --git a/hmatrix.cabal b/hmatrix.cabal index bfe875d..44ec865 100644 --- a/hmatrix.cabal +++ b/hmatrix.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix | 1 | Name: hmatrix |
2 | Version: 0.12.0.2 | 2 | Version: 0.13.0.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -27,11 +27,9 @@ cabal-version: >=1.6 | |||
27 | 27 | ||
28 | build-type: Custom | 28 | build-type: Custom |
29 | 29 | ||
30 | extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h | 30 | extra-source-files: Config.hs THANKS INSTALL CHANGES |
31 | Config.hs THANKS INSTALL CHANGES | ||
32 | 31 | ||
33 | extra-source-files: examples/tests.hs | 32 | extra-source-files: examples/deriv.hs |
34 | examples/deriv.hs | ||
35 | examples/integrate.hs | 33 | examples/integrate.hs |
36 | examples/minimize.hs | 34 | examples/minimize.hs |
37 | examples/root.hs | 35 | examples/root.hs |
@@ -60,10 +58,6 @@ extra-source-files: examples/tests.hs | |||
60 | extra-source-files: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h, | 58 | extra-source-files: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h, |
61 | lib/Numeric/LinearAlgebra/LAPACK/clapack.h | 59 | lib/Numeric/LinearAlgebra/LAPACK/clapack.h |
62 | 60 | ||
63 | flag tests | ||
64 | description: Build tests | ||
65 | default: True | ||
66 | |||
67 | flag dd | 61 | flag dd |
68 | description: svd = zgesdd | 62 | description: svd = zgesdd |
69 | default: True | 63 | default: True |
@@ -152,12 +146,6 @@ library | |||
152 | Build-Depends: binary | 146 | Build-Depends: binary |
153 | cpp-options: -DBINARY | 147 | cpp-options: -DBINARY |
154 | 148 | ||
155 | if flag(tests) | ||
156 | Build-Depends: QuickCheck, HUnit, random | ||
157 | exposed-modules: Numeric.LinearAlgebra.Tests | ||
158 | other-modules: Numeric.LinearAlgebra.Tests.Instances, | ||
159 | Numeric.LinearAlgebra.Tests.Properties | ||
160 | |||
161 | -- ghc-prof-options: -auto | 149 | -- ghc-prof-options: -auto |
162 | 150 | ||
163 | ghc-options: -Wall -fno-warn-missing-signatures | 151 | ghc-options: -Wall -fno-warn-missing-signatures |
@@ -220,7 +208,5 @@ source-repository head | |||
220 | type: git | 208 | type: git |
221 | location: https://github.com/AlbertoRuiz/hmatrix | 209 | location: https://github.com/AlbertoRuiz/hmatrix |
222 | 210 | ||
223 | -- Test-Suite tests | 211 | -- The tests are in package hmatrix-tests |
224 | -- type: exitcode-stdio-1.0 | ||
225 | -- main-is: examples/tests.hs | ||
226 | 212 | ||
diff --git a/lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h b/lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h deleted file mode 100644 index 714587b..0000000 --- a/lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | #ifndef MIN_VERSION_QuickCheck | ||
2 | #define MIN_VERSION_QuickCheck(A,B,C) 1 | ||
3 | #endif | ||
4 | |||
5 | #if MIN_VERSION_QuickCheck(2,0,0) | ||
6 | import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector | ||
7 | ,sized,classify,Testable,Property | ||
8 | |||
9 | ,quickCheckWith,maxSize,stdArgs,shrink) | ||
10 | |||
11 | #else | ||
12 | import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector | ||
13 | ,sized,classify,Testable,Property | ||
14 | |||
15 | ,check,configSize,defaultConfig,trivial) | ||
16 | #endif | ||
17 | |||
18 | |||
19 | |||
20 | #if MIN_VERSION_QuickCheck(2,0,0) | ||
21 | trivial :: Testable a => Bool -> a -> Property | ||
22 | trivial = (`classify` "trivial") | ||
23 | #else | ||
24 | #endif | ||
25 | |||
26 | |||
27 | -- define qCheck, which used to be in Tests.hs | ||
28 | #if MIN_VERSION_QuickCheck(2,0,0) | ||
29 | qCheck n = quickCheckWith stdArgs {maxSize = n} | ||
30 | #else | ||
31 | qCheck n = check defaultConfig {configSize = const n} | ||
32 | #endif | ||
33 | |||
diff --git a/packages/tests/CHANGES b/packages/tests/CHANGES new file mode 100644 index 0000000..e4e8b2f --- /dev/null +++ b/packages/tests/CHANGES | |||
@@ -0,0 +1,5 @@ | |||
1 | 0.1 | ||
2 | === | ||
3 | |||
4 | Created a separate testing package. | ||
5 | |||
diff --git a/packages/tests/LICENSE b/packages/tests/LICENSE new file mode 100644 index 0000000..f2125ec --- /dev/null +++ b/packages/tests/LICENSE | |||
@@ -0,0 +1,2 @@ | |||
1 | Copyright Alberto Ruiz 2010 | ||
2 | GPL license | ||
diff --git a/packages/tests/Setup.lhs b/packages/tests/Setup.lhs new file mode 100644 index 0000000..6b32049 --- /dev/null +++ b/packages/tests/Setup.lhs | |||
@@ -0,0 +1,4 @@ | |||
1 | #! /usr/bin/env runhaskell | ||
2 | |||
3 | > import Distribution.Simple | ||
4 | > main = defaultMain | ||
diff --git a/packages/tests/hmatrix-tests.cabal b/packages/tests/hmatrix-tests.cabal new file mode 100644 index 0000000..cd32a4e --- /dev/null +++ b/packages/tests/hmatrix-tests.cabal | |||
@@ -0,0 +1,44 @@ | |||
1 | Name: hmatrix-tests | ||
2 | Version: 0.1.0.0 | ||
3 | License: GPL | ||
4 | License-file: LICENSE | ||
5 | Author: Alberto Ruiz | ||
6 | Maintainer: Alberto Ruiz <aruiz@um.es> | ||
7 | Stability: provisional | ||
8 | Homepage: http://perception.inf.um.es/hmatrix | ||
9 | Synopsis: Tests for hmatrix | ||
10 | Description: Tests for hmatrix | ||
11 | Category: Math | ||
12 | tested-with: GHC==7.0.4 | ||
13 | |||
14 | cabal-version: >=1.6 | ||
15 | |||
16 | build-type: Simple | ||
17 | |||
18 | extra-source-files: CHANGES | ||
19 | src/tests.hs | ||
20 | |||
21 | library | ||
22 | |||
23 | Build-Depends: base >= 4 && < 5, | ||
24 | hmatrix >= 0.13, | ||
25 | QuickCheck >= 2, HUnit, random | ||
26 | |||
27 | hs-source-dirs: src | ||
28 | |||
29 | exposed-modules: Numeric.LinearAlgebra.Tests | ||
30 | |||
31 | other-modules: Numeric.LinearAlgebra.Tests.Instances, | ||
32 | Numeric.LinearAlgebra.Tests.Properties | ||
33 | |||
34 | ghc-options: -Wall -fno-warn-missing-signatures -fno-warn-orphans | ||
35 | |||
36 | |||
37 | source-repository head | ||
38 | type: git | ||
39 | location: https://github.com/AlbertoRuiz/hmatrix | ||
40 | |||
41 | Test-Suite tests | ||
42 | type: exitcode-stdio-1.0 | ||
43 | main-is: src/tests.hs | ||
44 | |||
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs index e859450..69ef1b3 100644 --- a/lib/Numeric/LinearAlgebra/Tests.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs | |||
@@ -3,7 +3,7 @@ | |||
3 | ----------------------------------------------------------------------------- | 3 | ----------------------------------------------------------------------------- |
4 | {- | | 4 | {- | |
5 | Module : Numeric.LinearAlgebra.Tests | 5 | Module : Numeric.LinearAlgebra.Tests |
6 | Copyright : (c) Alberto Ruiz 2007-9 | 6 | Copyright : (c) Alberto Ruiz 2007-11 |
7 | License : GPL-style | 7 | License : GPL-style |
8 | 8 | ||
9 | Maintainer : Alberto Ruiz (aruiz at um dot es) | 9 | Maintainer : Alberto Ruiz (aruiz at um dot es) |
@@ -17,11 +17,14 @@ Some tests. | |||
17 | module Numeric.LinearAlgebra.Tests( | 17 | module Numeric.LinearAlgebra.Tests( |
18 | -- module Numeric.LinearAlgebra.Tests.Instances, | 18 | -- module Numeric.LinearAlgebra.Tests.Instances, |
19 | -- module Numeric.LinearAlgebra.Tests.Properties, | 19 | -- module Numeric.LinearAlgebra.Tests.Properties, |
20 | qCheck, runTests, runBenchmarks, findNaN | 20 | -- qCheck, |
21 | runTests, | ||
22 | runBenchmarks | ||
23 | -- , findNaN | ||
21 | --, runBigTests | 24 | --, runBigTests |
22 | ) where | 25 | ) where |
23 | 26 | ||
24 | import Data.Packed.Random | 27 | --import Data.Packed.Random |
25 | import Numeric.LinearAlgebra | 28 | import Numeric.LinearAlgebra |
26 | import Numeric.LinearAlgebra.LAPACK | 29 | import Numeric.LinearAlgebra.LAPACK |
27 | import Numeric.LinearAlgebra.Tests.Instances | 30 | import Numeric.LinearAlgebra.Tests.Instances |
@@ -38,9 +41,11 @@ import Data.Packed.Development(unsafeFromForeignPtr,unsafeToForeignPtr) | |||
38 | import Control.Arrow((***)) | 41 | import Control.Arrow((***)) |
39 | import Debug.Trace | 42 | import Debug.Trace |
40 | 43 | ||
41 | #include "Tests/quickCheckCompat.h" | 44 | import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector |
45 | ,sized,classify,Testable,Property | ||
46 | ,quickCheckWith,maxSize,stdArgs,shrink) | ||
42 | 47 | ||
43 | debug x = trace (show x) x | 48 | qCheck n = quickCheckWith stdArgs {maxSize = n} |
44 | 49 | ||
45 | a ^ b = a Prelude.^ (b :: Int) | 50 | a ^ b = a Prelude.^ (b :: Int) |
46 | 51 | ||
@@ -343,7 +348,7 @@ lift_maybe m = MaybeT $ do | |||
343 | res <- m | 348 | res <- m |
344 | return $ Just res | 349 | return $ Just res |
345 | 350 | ||
346 | -- | apply a test to successive elements of a vector, evaluates to true iff test passes for all pairs | 351 | -- apply a test to successive elements of a vector, evaluates to true iff test passes for all pairs |
347 | --successive_ :: Storable a => (a -> a -> Bool) -> Vector a -> Bool | 352 | --successive_ :: Storable a => (a -> a -> Bool) -> Vector a -> Bool |
348 | successive_ t v = maybe False (\_ -> True) $ evalState (runMaybeT (mapVectorM_ stp (subVector 1 (dim v - 1) v))) (v @> 0) | 353 | successive_ t v = maybe False (\_ -> True) $ evalState (runMaybeT (mapVectorM_ stp (subVector 1 (dim v - 1) v))) (v @> 0) |
349 | where stp e = do | 354 | where stp e = do |
@@ -352,7 +357,7 @@ successive_ t v = maybe False (\_ -> True) $ evalState (runMaybeT (mapVectorM_ s | |||
352 | then lift_maybe $ state_put e | 357 | then lift_maybe $ state_put e |
353 | else (fail "successive_ test failed") | 358 | else (fail "successive_ test failed") |
354 | 359 | ||
355 | -- | operate on successive elements of a vector and return the resulting vector, whose length 1 less than that of the input | 360 | -- operate on successive elements of a vector and return the resulting vector, whose length 1 less than that of the input |
356 | --successive :: (Storable a, Storable b) => (a -> a -> b) -> Vector a -> Vector b | 361 | --successive :: (Storable a, Storable b) => (a -> a -> b) -> Vector a -> Vector b |
357 | successive f v = evalState (mapVectorM stp (subVector 1 (dim v - 1) v)) (v @> 0) | 362 | successive f v = evalState (mapVectorM stp (subVector 1 (dim v - 1) v)) (v @> 0) |
358 | where stp e = do | 363 | where stp e = do |
@@ -596,20 +601,22 @@ makeUnitary v | realPart n > 1 = v / scalar n | |||
596 | -- runBigTests :: IO () | 601 | -- runBigTests :: IO () |
597 | -- runBigTests = undefined | 602 | -- runBigTests = undefined |
598 | 603 | ||
599 | -- testcase for nonempty fpu stack | 604 | {- |
605 | -- | testcase for nonempty fpu stack | ||
600 | findNaN :: Int -> Bool | 606 | findNaN :: Int -> Bool |
601 | findNaN n = all (bugProp . eye) (take n $ cycle [1..20]) | 607 | findNaN n = all (bugProp . eye) (take n $ cycle [1..20]) |
602 | where eye m = ident m :: Matrix ( Double) | 608 | where eye m = ident m :: Matrix ( Double) |
609 | -} | ||
603 | 610 | ||
604 | -------------------------------------------------------------------------------- | 611 | -------------------------------------------------------------------------------- |
605 | 612 | ||
606 | -- | Performance measurements. | 613 | -- | Performance measurements. |
607 | runBenchmarks :: IO () | 614 | runBenchmarks :: IO () |
608 | runBenchmarks = do | 615 | runBenchmarks = do |
609 | --cholBench | ||
610 | solveBench | 616 | solveBench |
611 | subBench | 617 | subBench |
612 | multBench | 618 | multBench |
619 | cholBench | ||
613 | svdBench | 620 | svdBench |
614 | eigBench | 621 | eigBench |
615 | putStrLn "" | 622 | putStrLn "" |
@@ -712,10 +719,11 @@ solveBench = do | |||
712 | cholBenchN n = do | 719 | cholBenchN n = do |
713 | let x = uniformSample 777 (2*n) (replicate n (-1,1)) | 720 | let x = uniformSample 777 (2*n) (replicate n (-1,1)) |
714 | a = trans x <> x | 721 | a = trans x <> x |
715 | a `seq` putStrLn "" | 722 | a `seq` putStr "" |
716 | time ("chol " ++ show n) (chol a) | 723 | time ("chol " ++ show n) (chol a) |
717 | 724 | ||
718 | cholBench = do | 725 | cholBench = do |
726 | putStrLn "" | ||
719 | cholBenchN 1200 | 727 | cholBenchN 1200 |
720 | cholBenchN 600 | 728 | cholBenchN 600 |
721 | cholBenchN 300 | 729 | cholBenchN 300 |
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs index 6dd9cfe..647a06c 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs | |||
@@ -30,7 +30,9 @@ import System.Random | |||
30 | 30 | ||
31 | import Numeric.LinearAlgebra | 31 | import Numeric.LinearAlgebra |
32 | import Control.Monad(replicateM) | 32 | import Control.Monad(replicateM) |
33 | #include "quickCheckCompat.h" | 33 | import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector |
34 | ,sized,classify,Testable,Property | ||
35 | ,quickCheckWith,maxSize,stdArgs,shrink) | ||
34 | 36 | ||
35 | #if MIN_VERSION_QuickCheck(2,0,0) | 37 | #if MIN_VERSION_QuickCheck(2,0,0) |
36 | shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] | 38 | shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] |
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs index fe13544..c96d3de 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs | |||
@@ -46,13 +46,13 @@ module Numeric.LinearAlgebra.Tests.Properties ( | |||
46 | import Numeric.LinearAlgebra --hiding (real,complex) | 46 | import Numeric.LinearAlgebra --hiding (real,complex) |
47 | import Numeric.LinearAlgebra.LAPACK | 47 | import Numeric.LinearAlgebra.LAPACK |
48 | import Debug.Trace | 48 | import Debug.Trace |
49 | #include "quickCheckCompat.h" | 49 | import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector |
50 | ,sized,classify,Testable,Property | ||
51 | ,quickCheckWith,maxSize,stdArgs,shrink) | ||
50 | 52 | ||
53 | trivial :: Testable a => Bool -> a -> Property | ||
54 | trivial = (`classify` "trivial") | ||
51 | 55 | ||
52 | --real x = real'' x | ||
53 | --complex x = complex'' x | ||
54 | |||
55 | debug x = trace (show x) x | ||
56 | 56 | ||
57 | -- relative error | 57 | -- relative error |
58 | dist :: (Normed c t, Num (c t)) => c t -> c t -> Double | 58 | dist :: (Normed c t, Num (c t)) => c t -> c t -> Double |
@@ -227,10 +227,10 @@ rqProp1 m = r <> q |~| m | |||
227 | where (r,q) = rq m | 227 | where (r,q) = rq m |
228 | 228 | ||
229 | rqProp2 m = unitary q | 229 | rqProp2 m = unitary q |
230 | where (r,q) = rq m | 230 | where (_r,q) = rq m |
231 | 231 | ||
232 | rqProp3 m = upperTriang' r | 232 | rqProp3 m = upperTriang' r |
233 | where (r,q) = rq m | 233 | where (r,_q) = rq m |
234 | 234 | ||
235 | upperTriang' r = upptr (rows r) (cols r) * r |~| r | 235 | upperTriang' r = upptr (rows r) (cols r) * r |~| r |
236 | where upptr f c = buildMatrix f c $ \(r',c') -> if r'-t > c' then 0 else 1 | 236 | where upptr f c = buildMatrix f c $ \(r',c') -> if r'-t > c' then 0 else 1 |
diff --git a/examples/tests.hs b/packages/tests/src/tests.hs index 23fd675..23fd675 100644 --- a/examples/tests.hs +++ b/packages/tests/src/tests.hs | |||