diff options
author | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-09-06 09:59:08 +0000 |
---|---|---|
committer | Vivian McPhail <haskell.vivian.mcphail@gmail.com> | 2010-09-06 09:59:08 +0000 |
commit | 9004922ad91c0b4ad8498c31171a3a1a1e27d9f2 (patch) | |
tree | c6d4759e584b7933029e405a73974e173046ddcc /lib/Numeric/LinearAlgebra/Tests | |
parent | 29099e3bfb4eec87ac3d4d675d7cfc82234c20d6 (diff) |
Merged changes with conversion-linear
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/Instances.hs | 14 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/Properties.hs | 6 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs index 21a6f88..6046ccb 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs | |||
@@ -26,6 +26,7 @@ module Numeric.LinearAlgebra.Tests.Instances( | |||
26 | FM,ZM, fM,zM | 26 | FM,ZM, fM,zM |
27 | ) where | 27 | ) where |
28 | 28 | ||
29 | import System.Random | ||
29 | 30 | ||
30 | import Numeric.LinearAlgebra | 31 | import Numeric.LinearAlgebra |
31 | import Control.Monad(replicateM) | 32 | import Control.Monad(replicateM) |
@@ -137,7 +138,7 @@ instance (Field a, Arbitrary a, Num (Vector a)) => Arbitrary (Her a) where | |||
137 | 138 | ||
138 | -- a well-conditioned general matrix (the singular values are between 1 and 100) | 139 | -- a well-conditioned general matrix (the singular values are between 1 and 100) |
139 | newtype (WC a) = WC (Matrix a) deriving Show | 140 | newtype (WC a) = WC (Matrix a) deriving Show |
140 | instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (WC a) where | 141 | instance (Convert a, Field a, Arbitrary a, Random (RealOf a)) => Arbitrary (WC a) where |
141 | arbitrary = do | 142 | arbitrary = do |
142 | m <- arbitrary | 143 | m <- arbitrary |
143 | let (u,_,v) = svd m | 144 | let (u,_,v) = svd m |
@@ -146,7 +147,7 @@ instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (WC a) where | |||
146 | n = min r c | 147 | n = min r c |
147 | sv' <- replicateM n (choose (1,100)) | 148 | sv' <- replicateM n (choose (1,100)) |
148 | let s = diagRect (fromList sv') r c | 149 | let s = diagRect (fromList sv') r c |
149 | return $ WC (u <> real'' s <> trans v) | 150 | return $ WC (u <> real s <> trans v) |
150 | 151 | ||
151 | #if MIN_VERSION_QuickCheck(2,0,0) | 152 | #if MIN_VERSION_QuickCheck(2,0,0) |
152 | #else | 153 | #else |
@@ -156,14 +157,14 @@ instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (WC a) where | |||
156 | 157 | ||
157 | -- a well-conditioned square matrix (the singular values are between 1 and 100) | 158 | -- a well-conditioned square matrix (the singular values are between 1 and 100) |
158 | newtype (SqWC a) = SqWC (Matrix a) deriving Show | 159 | newtype (SqWC a) = SqWC (Matrix a) deriving Show |
159 | instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (SqWC a) where | 160 | instance (Convert a, Field a, Arbitrary a, Random (RealOf a)) => Arbitrary (SqWC a) where |
160 | arbitrary = do | 161 | arbitrary = do |
161 | Sq m <- arbitrary | 162 | Sq m <- arbitrary |
162 | let (u,_,v) = svd m | 163 | let (u,_,v) = svd m |
163 | n = rows m | 164 | n = rows m |
164 | sv' <- replicateM n (choose (1,100)) | 165 | sv' <- replicateM n (choose (1,100)) |
165 | let s = diag (fromList sv') | 166 | let s = diag (fromList sv') |
166 | return $ SqWC (u <> real'' s <> trans v) | 167 | return $ SqWC (u <> real s <> trans v) |
167 | 168 | ||
168 | #if MIN_VERSION_QuickCheck(2,0,0) | 169 | #if MIN_VERSION_QuickCheck(2,0,0) |
169 | #else | 170 | #else |
@@ -173,14 +174,15 @@ instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (SqWC a) where | |||
173 | 174 | ||
174 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) | 175 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) |
175 | newtype (PosDef a) = PosDef (Matrix a) deriving Show | 176 | newtype (PosDef a) = PosDef (Matrix a) deriving Show |
176 | instance (AutoReal a, Field a, Arbitrary a, Num (Vector a)) => Arbitrary (PosDef a) where | 177 | instance (Convert a, Field a, Arbitrary a, Num (Vector a), Random (RealOf a)) |
178 | => Arbitrary (PosDef a) where | ||
177 | arbitrary = do | 179 | arbitrary = do |
178 | Her m <- arbitrary | 180 | Her m <- arbitrary |
179 | let (_,v) = eigSH m | 181 | let (_,v) = eigSH m |
180 | n = rows m | 182 | n = rows m |
181 | l <- replicateM n (choose (0,100)) | 183 | l <- replicateM n (choose (0,100)) |
182 | let s = diag (fromList l) | 184 | let s = diag (fromList l) |
183 | p = v <> real'' s <> ctrans v | 185 | p = v <> real s <> ctrans v |
184 | return $ PosDef (0.5 * p + 0.5 * ctrans p) | 186 | return $ PosDef (0.5 * p + 0.5 * ctrans p) |
185 | 187 | ||
186 | #if MIN_VERSION_QuickCheck(2,0,0) | 188 | #if MIN_VERSION_QuickCheck(2,0,0) |
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/lib/Numeric/LinearAlgebra/Tests/Properties.hs index d312e52..b96f53e 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs +++ b/lib/Numeric/LinearAlgebra/Tests/Properties.hs | |||
@@ -42,14 +42,14 @@ module Numeric.LinearAlgebra.Tests.Properties ( | |||
42 | linearSolveProp, linearSolveProp2 | 42 | linearSolveProp, linearSolveProp2 |
43 | ) where | 43 | ) where |
44 | 44 | ||
45 | import Numeric.LinearAlgebra hiding (real,complex) | 45 | import Numeric.LinearAlgebra --hiding (real,complex) |
46 | import Numeric.LinearAlgebra.LAPACK | 46 | import Numeric.LinearAlgebra.LAPACK |
47 | import Debug.Trace | 47 | import Debug.Trace |
48 | #include "quickCheckCompat.h" | 48 | #include "quickCheckCompat.h" |
49 | 49 | ||
50 | 50 | ||
51 | real x = real'' x | 51 | --real x = real'' x |
52 | complex x = complex'' x | 52 | --complex x = complex'' x |
53 | 53 | ||
54 | debug x = trace (show x) x | 54 | debug x = trace (show x) x |
55 | 55 | ||