summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/parallel.hs5
-rw-r--r--hmatrix.cabal22
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h33
-rw-r--r--packages/tests/CHANGES5
-rw-r--r--packages/tests/LICENSE2
-rw-r--r--packages/tests/Setup.lhs4
-rw-r--r--packages/tests/hmatrix-tests.cabal44
-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
3import System.Environment(getArgs) 4import System.Environment(getArgs)
4import Numeric.LinearAlgebra 5import Numeric.LinearAlgebra
@@ -7,7 +8,6 @@ import System.Time
7 8
8inParallel = parMap rwhnf id 9inParallel = parMap rwhnf id
9 10
10
11-- matrix product decomposed into p parallel subtasks 11-- matrix product decomposed into p parallel subtasks
12parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] 12parMul 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 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.12.0.2 2Version: 0.13.0.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -27,11 +27,9 @@ cabal-version: >=1.6
27 27
28build-type: Custom 28build-type: Custom
29 29
30extra-source-files: lib/Numeric/LinearAlgebra/Tests/quickCheckCompat.h 30extra-source-files: Config.hs THANKS INSTALL CHANGES
31 Config.hs THANKS INSTALL CHANGES
32 31
33extra-source-files: examples/tests.hs 32extra-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
60extra-source-files: lib/Numeric/LinearAlgebra/LAPACK/lapack-aux.h, 58extra-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
63flag tests
64 description: Build tests
65 default: True
66
67flag dd 61flag 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)
6import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector
7 ,sized,classify,Testable,Property
8
9 ,quickCheckWith,maxSize,stdArgs,shrink)
10
11#else
12import 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)
21trivial :: Testable a => Bool -> a -> Property
22trivial = (`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)
29qCheck n = quickCheckWith stdArgs {maxSize = n}
30#else
31qCheck 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 @@
10.1
2===
3
4Created 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 @@
1Copyright Alberto Ruiz 2010
2GPL 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 @@
1Name: hmatrix-tests
2Version: 0.1.0.0
3License: GPL
4License-file: LICENSE
5Author: Alberto Ruiz
6Maintainer: Alberto Ruiz <aruiz@um.es>
7Stability: provisional
8Homepage: http://perception.inf.um.es/hmatrix
9Synopsis: Tests for hmatrix
10Description: Tests for hmatrix
11Category: Math
12tested-with: GHC==7.0.4
13
14cabal-version: >=1.6
15
16build-type: Simple
17
18extra-source-files: CHANGES
19 src/tests.hs
20
21library
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
37source-repository head
38 type: git
39 location: https://github.com/AlbertoRuiz/hmatrix
40
41Test-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{- |
5Module : Numeric.LinearAlgebra.Tests 5Module : Numeric.LinearAlgebra.Tests
6Copyright : (c) Alberto Ruiz 2007-9 6Copyright : (c) Alberto Ruiz 2007-11
7License : GPL-style 7License : GPL-style
8 8
9Maintainer : Alberto Ruiz (aruiz at um dot es) 9Maintainer : Alberto Ruiz (aruiz at um dot es)
@@ -17,11 +17,14 @@ Some tests.
17module Numeric.LinearAlgebra.Tests( 17module 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
24import Data.Packed.Random 27--import Data.Packed.Random
25import Numeric.LinearAlgebra 28import Numeric.LinearAlgebra
26import Numeric.LinearAlgebra.LAPACK 29import Numeric.LinearAlgebra.LAPACK
27import Numeric.LinearAlgebra.Tests.Instances 30import Numeric.LinearAlgebra.Tests.Instances
@@ -38,9 +41,11 @@ import Data.Packed.Development(unsafeFromForeignPtr,unsafeToForeignPtr)
38import Control.Arrow((***)) 41import Control.Arrow((***))
39import Debug.Trace 42import Debug.Trace
40 43
41#include "Tests/quickCheckCompat.h" 44import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector
45 ,sized,classify,Testable,Property
46 ,quickCheckWith,maxSize,stdArgs,shrink)
42 47
43debug x = trace (show x) x 48qCheck n = quickCheckWith stdArgs {maxSize = n}
44 49
45a ^ b = a Prelude.^ (b :: Int) 50a ^ 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
348successive_ t v = maybe False (\_ -> True) $ evalState (runMaybeT (mapVectorM_ stp (subVector 1 (dim v - 1) v))) (v @> 0) 353successive_ 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
357successive f v = evalState (mapVectorM stp (subVector 1 (dim v - 1) v)) (v @> 0) 362successive 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
600findNaN :: Int -> Bool 606findNaN :: Int -> Bool
601findNaN n = all (bugProp . eye) (take n $ cycle [1..20]) 607findNaN 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.
607runBenchmarks :: IO () 614runBenchmarks :: IO ()
608runBenchmarks = do 615runBenchmarks = 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
712cholBenchN n = do 719cholBenchN 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
718cholBench = do 725cholBench = 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
31import Numeric.LinearAlgebra 31import Numeric.LinearAlgebra
32import Control.Monad(replicateM) 32import Control.Monad(replicateM)
33#include "quickCheckCompat.h" 33import 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)
36shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] 38shrinkListElementwise :: (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 (
46import Numeric.LinearAlgebra --hiding (real,complex) 46import Numeric.LinearAlgebra --hiding (real,complex)
47import Numeric.LinearAlgebra.LAPACK 47import Numeric.LinearAlgebra.LAPACK
48import Debug.Trace 48import Debug.Trace
49#include "quickCheckCompat.h" 49import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector
50 ,sized,classify,Testable,Property
51 ,quickCheckWith,maxSize,stdArgs,shrink)
50 52
53trivial :: Testable a => Bool -> a -> Property
54trivial = (`classify` "trivial")
51 55
52--real x = real'' x
53--complex x = complex'' x
54
55debug x = trace (show x) x
56 56
57-- relative error 57-- relative error
58dist :: (Normed c t, Num (c t)) => c t -> c t -> Double 58dist :: (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
229rqProp2 m = unitary q 229rqProp2 m = unitary q
230 where (r,q) = rq m 230 where (_r,q) = rq m
231 231
232rqProp3 m = upperTriang' r 232rqProp3 m = upperTriang' r
233 where (r,q) = rq m 233 where (r,_q) = rq m
234 234
235upperTriang' r = upptr (rows r) (cols r) * r |~| r 235upperTriang' 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