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.hs21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
index fececdb..583143a 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
@@ -16,11 +16,13 @@ Arbitrary instances for vectors, matrices.
16module Numeric.LinearAlgebra.Tests.Instances( 16module Numeric.LinearAlgebra.Tests.Instances(
17 Sq(..), 17 Sq(..),
18 Rot(..), 18 Rot(..),
19 Her(..) 19 Her(..),
20 WC(..)
20) where 21) where
21 22
22import Numeric.LinearAlgebra 23import Numeric.LinearAlgebra
23import Test.QuickCheck 24import Test.QuickCheck
25import Control.Monad(replicateM)
24 26
25instance (Arbitrary a, RealFloat a) => Arbitrary (Complex a) where 27instance (Arbitrary a, RealFloat a) => Arbitrary (Complex a) where
26 arbitrary = do 28 arbitrary = do
@@ -45,6 +47,7 @@ instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where
45 return $ (m><n) l 47 return $ (m><n) l
46 coarbitrary = undefined 48 coarbitrary = undefined
47 49
50-- a square matrix
48newtype (Sq a) = Sq (Matrix a) deriving Show 51newtype (Sq a) = Sq (Matrix a) deriving Show
49instance (Element a, Arbitrary a) => Arbitrary (Sq a) where 52instance (Element a, Arbitrary a) => Arbitrary (Sq a) where
50 arbitrary = do 53 arbitrary = do
@@ -53,6 +56,7 @@ instance (Element a, Arbitrary a) => Arbitrary (Sq a) where
53 return $ Sq $ (n><n) l 56 return $ Sq $ (n><n) l
54 coarbitrary = undefined 57 coarbitrary = undefined
55 58
59-- a unitary matrix
56newtype (Rot a) = Rot (Matrix a) deriving Show 60newtype (Rot a) = Rot (Matrix a) deriving Show
57instance (Field a, Arbitrary a) => Arbitrary (Rot a) where 61instance (Field a, Arbitrary a) => Arbitrary (Rot a) where
58 arbitrary = do 62 arbitrary = do
@@ -61,6 +65,7 @@ instance (Field a, Arbitrary a) => Arbitrary (Rot a) where
61 return (Rot q) 65 return (Rot q)
62 coarbitrary = undefined 66 coarbitrary = undefined
63 67
68-- a complex hermitian or real symmetric matrix
64newtype (Her a) = Her (Matrix a) deriving Show 69newtype (Her a) = Her (Matrix a) deriving Show
65instance (Field a, Arbitrary a) => Arbitrary (Her a) where 70instance (Field a, Arbitrary a) => Arbitrary (Her a) where
66 arbitrary = do 71 arbitrary = do
@@ -68,3 +73,17 @@ instance (Field a, Arbitrary a) => Arbitrary (Her a) where
68 let m' = m/2 73 let m' = m/2
69 return $ Her (m' + ctrans m') 74 return $ Her (m' + ctrans m')
70 coarbitrary = undefined 75 coarbitrary = undefined
76
77-- a well-conditioned matrix (the singular values are between 1 and 100)
78newtype (WC a) = WC (Matrix a) deriving Show
79instance (Field a, Arbitrary a) => Arbitrary (WC a) where
80 arbitrary = do
81 m <- arbitrary
82 let (u,_,v) = svd m
83 r = rows m
84 c = cols m
85 n = min r c
86 sv <- replicateM n (choose (1,100))
87 let s = diagRect (fromList sv) r c
88 return $ WC (u <> real s <> trans v)
89 coarbitrary = undefined