summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Tests
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-09-06 09:59:08 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-09-06 09:59:08 +0000
commit9004922ad91c0b4ad8498c31171a3a1a1e27d9f2 (patch)
treec6d4759e584b7933029e405a73974e173046ddcc /lib/Numeric/LinearAlgebra/Tests
parent29099e3bfb4eec87ac3d4d675d7cfc82234c20d6 (diff)
Merged changes with conversion-linear
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests')
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Instances.hs14
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Properties.hs6
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
29import System.Random
29 30
30import Numeric.LinearAlgebra 31import Numeric.LinearAlgebra
31import Control.Monad(replicateM) 32import 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)
139newtype (WC a) = WC (Matrix a) deriving Show 140newtype (WC a) = WC (Matrix a) deriving Show
140instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (WC a) where 141instance (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)
158newtype (SqWC a) = SqWC (Matrix a) deriving Show 159newtype (SqWC a) = SqWC (Matrix a) deriving Show
159instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (SqWC a) where 160instance (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)
175newtype (PosDef a) = PosDef (Matrix a) deriving Show 176newtype (PosDef a) = PosDef (Matrix a) deriving Show
176instance (AutoReal a, Field a, Arbitrary a, Num (Vector a)) => Arbitrary (PosDef a) where 177instance (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
45import Numeric.LinearAlgebra hiding (real,complex) 45import Numeric.LinearAlgebra --hiding (real,complex)
46import Numeric.LinearAlgebra.LAPACK 46import Numeric.LinearAlgebra.LAPACK
47import Debug.Trace 47import Debug.Trace
48#include "quickCheckCompat.h" 48#include "quickCheckCompat.h"
49 49
50 50
51real x = real'' x 51--real x = real'' x
52complex x = complex'' x 52--complex x = complex'' x
53 53
54debug x = trace (show x) x 54debug x = trace (show x) x
55 55