summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Tests/Instances.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests/Instances.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Instances.hs20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
index aaaff28..21a6f88 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
@@ -27,13 +27,10 @@ module Numeric.LinearAlgebra.Tests.Instances(
27) where 27) where
28 28
29 29
30import Numeric.LinearAlgebra hiding (real,complex) 30import Numeric.LinearAlgebra
31import Control.Monad(replicateM) 31import Control.Monad(replicateM)
32#include "quickCheckCompat.h" 32#include "quickCheckCompat.h"
33 33
34real x = real'' x
35complex x = complex'' x
36
37#if MIN_VERSION_QuickCheck(2,0,0) 34#if MIN_VERSION_QuickCheck(2,0,0)
38shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] 35shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]]
39shrinkListElementwise [] = [] 36shrinkListElementwise [] = []
@@ -72,7 +69,7 @@ instance (Field a, Arbitrary a) => Arbitrary (Vector a) where
72#if MIN_VERSION_QuickCheck(2,0,0) 69#if MIN_VERSION_QuickCheck(2,0,0)
73 -- shrink any one of the components 70 -- shrink any one of the components
74 shrink = map fromList . shrinkListElementwise . toList 71 shrink = map fromList . shrinkListElementwise . toList
75 72
76#else 73#else
77 coarbitrary = undefined 74 coarbitrary = undefined
78#endif 75#endif
@@ -140,7 +137,7 @@ instance (Field a, Arbitrary a, Num (Vector a)) => Arbitrary (Her a) where
140 137
141-- a well-conditioned general matrix (the singular values are between 1 and 100) 138-- a well-conditioned general matrix (the singular values are between 1 and 100)
142newtype (WC a) = WC (Matrix a) deriving Show 139newtype (WC a) = WC (Matrix a) deriving Show
143instance (Field a, Arbitrary a) => Arbitrary (WC a) where 140instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (WC a) where
144 arbitrary = do 141 arbitrary = do
145 m <- arbitrary 142 m <- arbitrary
146 let (u,_,v) = svd m 143 let (u,_,v) = svd m
@@ -149,7 +146,7 @@ instance (Field a, Arbitrary a) => Arbitrary (WC a) where
149 n = min r c 146 n = min r c
150 sv' <- replicateM n (choose (1,100)) 147 sv' <- replicateM n (choose (1,100))
151 let s = diagRect (fromList sv') r c 148 let s = diagRect (fromList sv') r c
152 return $ WC (u <> real s <> trans v) 149 return $ WC (u <> real'' s <> trans v)
153 150
154#if MIN_VERSION_QuickCheck(2,0,0) 151#if MIN_VERSION_QuickCheck(2,0,0)
155#else 152#else
@@ -159,14 +156,14 @@ instance (Field a, Arbitrary a) => Arbitrary (WC a) where
159 156
160-- a well-conditioned square matrix (the singular values are between 1 and 100) 157-- a well-conditioned square matrix (the singular values are between 1 and 100)
161newtype (SqWC a) = SqWC (Matrix a) deriving Show 158newtype (SqWC a) = SqWC (Matrix a) deriving Show
162instance (Field a, Arbitrary a) => Arbitrary (SqWC a) where 159instance (AutoReal a, Field a, Arbitrary a) => Arbitrary (SqWC a) where
163 arbitrary = do 160 arbitrary = do
164 Sq m <- arbitrary 161 Sq m <- arbitrary
165 let (u,_,v) = svd m 162 let (u,_,v) = svd m
166 n = rows m 163 n = rows m
167 sv' <- replicateM n (choose (1,100)) 164 sv' <- replicateM n (choose (1,100))
168 let s = diag (fromList sv') 165 let s = diag (fromList sv')
169 return $ SqWC (u <> real s <> trans v) 166 return $ SqWC (u <> real'' s <> trans v)
170 167
171#if MIN_VERSION_QuickCheck(2,0,0) 168#if MIN_VERSION_QuickCheck(2,0,0)
172#else 169#else
@@ -176,14 +173,14 @@ instance (Field a, Arbitrary a) => Arbitrary (SqWC a) where
176 173
177-- a positive definite square matrix (the eigenvalues are between 0 and 100) 174-- a positive definite square matrix (the eigenvalues are between 0 and 100)
178newtype (PosDef a) = PosDef (Matrix a) deriving Show 175newtype (PosDef a) = PosDef (Matrix a) deriving Show
179instance (Field a, Arbitrary a, Num (Vector a)) => Arbitrary (PosDef a) where 176instance (AutoReal a, Field a, Arbitrary a, Num (Vector a)) => Arbitrary (PosDef a) where
180 arbitrary = do 177 arbitrary = do
181 Her m <- arbitrary 178 Her m <- arbitrary
182 let (_,v) = eigSH m 179 let (_,v) = eigSH m
183 n = rows m 180 n = rows m
184 l <- replicateM n (choose (0,100)) 181 l <- replicateM n (choose (0,100))
185 let s = diag (fromList l) 182 let s = diag (fromList l)
186 p = v <> real s <> ctrans v 183 p = v <> real'' s <> ctrans v
187 return $ PosDef (0.5 * p + 0.5 * ctrans p) 184 return $ PosDef (0.5 * p + 0.5 * ctrans p)
188 185
189#if MIN_VERSION_QuickCheck(2,0,0) 186#if MIN_VERSION_QuickCheck(2,0,0)
@@ -243,3 +240,4 @@ cPosDef (PosDef m) = m :: CM
243 240
244rConsist (Consistent (a,b)) = (a,b::RM) 241rConsist (Consistent (a,b)) = (a,b::RM)
245cConsist (Consistent (a,b)) = (a,b::CM) 242cConsist (Consistent (a,b)) = (a,b::CM)
243