diff options
Diffstat (limited to 'lib/Numeric/LinearAlgebra')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Algorithms.hs | 2 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/LAPACK.hs | 8 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests.hs | 2 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests/Instances.hs | 12 |
4 files changed, 14 insertions, 10 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs index f2f5473..3cd200e 100644 --- a/lib/Numeric/LinearAlgebra/Algorithms.hs +++ b/lib/Numeric/LinearAlgebra/Algorithms.hs | |||
@@ -82,7 +82,7 @@ import Data.Array | |||
82 | import Numeric.Container | 82 | import Numeric.Container |
83 | 83 | ||
84 | -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. | 84 | -- | Auxiliary typeclass used to define generic computations for both real and complex matrices. |
85 | class (Product t, Container Vector t, Container Matrix t) => Field t where | 85 | class (Product t, Convert t, Container Vector t, Container Matrix t) => Field t where |
86 | svd' :: Matrix t -> (Matrix t, Vector Double, Matrix t) | 86 | svd' :: Matrix t -> (Matrix t, Vector Double, Matrix t) |
87 | thinSVD' :: Matrix t -> (Matrix t, Vector Double, Matrix t) | 87 | thinSVD' :: Matrix t -> (Matrix t, Vector Double, Matrix t) |
88 | sv' :: Matrix t -> Vector Double | 88 | sv' :: Matrix t -> Vector Double |
diff --git a/lib/Numeric/LinearAlgebra/LAPACK.hs b/lib/Numeric/LinearAlgebra/LAPACK.hs index cb48571..fbc5460 100644 --- a/lib/Numeric/LinearAlgebra/LAPACK.hs +++ b/lib/Numeric/LinearAlgebra/LAPACK.hs | |||
@@ -259,14 +259,14 @@ eigRaux m = unsafePerformIO $ do | |||
259 | where r = rows m | 259 | where r = rows m |
260 | g ra ca pa = dgeev ra ca pa 0 0 nullPtr | 260 | g ra ca pa = dgeev ra ca pa 0 0 nullPtr |
261 | 261 | ||
262 | fixeig1 s = toComplex (subVector 0 r (asReal s), subVector r r (asReal s)) | 262 | fixeig1 s = toComplex' (subVector 0 r (asReal s), subVector r r (asReal s)) |
263 | where r = dim s | 263 | where r = dim s |
264 | 264 | ||
265 | fixeig [] _ = [] | 265 | fixeig [] _ = [] |
266 | fixeig [_] [v] = [comp v] | 266 | fixeig [_] [v] = [comp' v] |
267 | fixeig ((r1:+i1):(r2:+i2):r) (v1:v2:vs) | 267 | fixeig ((r1:+i1):(r2:+i2):r) (v1:v2:vs) |
268 | | r1 == r2 && i1 == (-i2) = toComplex (v1,v2) : toComplex (v1,scale (-1) v2) : fixeig r vs | 268 | | r1 == r2 && i1 == (-i2) = toComplex' (v1,v2) : toComplex' (v1,scale (-1) v2) : fixeig r vs |
269 | | otherwise = comp v1 : fixeig ((r2:+i2):r) (v2:vs) | 269 | | otherwise = comp' v1 : fixeig ((r2:+i2):r) (v2:vs) |
270 | where scale = vectorMapValR Scale | 270 | where scale = vectorMapValR Scale |
271 | fixeig _ _ = error "fixeig with impossible inputs" | 271 | fixeig _ _ = error "fixeig with impossible inputs" |
272 | 272 | ||
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs index aa7b01c..0df29a8 100644 --- a/lib/Numeric/LinearAlgebra/Tests.hs +++ b/lib/Numeric/LinearAlgebra/Tests.hs | |||
@@ -453,7 +453,7 @@ runTests n = do | |||
453 | , utest "randomGaussian" randomTestGaussian | 453 | , utest "randomGaussian" randomTestGaussian |
454 | , utest "randomUniform" randomTestUniform | 454 | , utest "randomUniform" randomTestUniform |
455 | , utest "buildVector/Matrix" $ | 455 | , utest "buildVector/Matrix" $ |
456 | comp (10 |> [0::Double ..]) == buildVector 10 fromIntegral | 456 | complex (10 |> [0::Double ..]) == buildVector 10 fromIntegral |
457 | && ident 5 == buildMatrix 5 5 (\(r,c) -> if r==c then 1::Double else 0) | 457 | && ident 5 == buildMatrix 5 5 (\(r,c) -> if r==c then 1::Double else 0) |
458 | , utest "rank" $ rank ((2><3)[1,0,0,1,6*eps,0]) == 1 | 458 | , utest "rank" $ rank ((2><3)[1,0,0,1,6*eps,0]) == 1 |
459 | && rank ((2><3)[1,0,0,1,7*eps,0]) == 2 | 459 | && rank ((2><3)[1,0,0,1,7*eps,0]) == 2 |
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs index 6046ccb..804c481 100644 --- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs +++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs | |||
@@ -1,4 +1,4 @@ | |||
1 | {-# LANGUAGE FlexibleContexts, UndecidableInstances, CPP #-} | 1 | {-# LANGUAGE FlexibleContexts, UndecidableInstances, CPP, FlexibleInstances #-} |
2 | {-# OPTIONS_GHC -fno-warn-unused-imports #-} | 2 | {-# OPTIONS_GHC -fno-warn-unused-imports #-} |
3 | ----------------------------------------------------------------------------- | 3 | ----------------------------------------------------------------------------- |
4 | {- | | 4 | {- | |
@@ -135,10 +135,14 @@ instance (Field a, Arbitrary a, Num (Vector a)) => Arbitrary (Her a) where | |||
135 | coarbitrary = undefined | 135 | coarbitrary = undefined |
136 | #endif | 136 | #endif |
137 | 137 | ||
138 | class (Field a, Arbitrary a, Element (RealOf a), Random (RealOf a)) => ArbitraryField a | ||
139 | instance ArbitraryField Double | ||
140 | instance ArbitraryField (Complex Double) | ||
141 | |||
138 | 142 | ||
139 | -- a well-conditioned general matrix (the singular values are between 1 and 100) | 143 | -- a well-conditioned general matrix (the singular values are between 1 and 100) |
140 | newtype (WC a) = WC (Matrix a) deriving Show | 144 | newtype (WC a) = WC (Matrix a) deriving Show |
141 | instance (Convert a, Field a, Arbitrary a, Random (RealOf a)) => Arbitrary (WC a) where | 145 | instance (ArbitraryField a) => Arbitrary (WC a) where |
142 | arbitrary = do | 146 | arbitrary = do |
143 | m <- arbitrary | 147 | m <- arbitrary |
144 | let (u,_,v) = svd m | 148 | let (u,_,v) = svd m |
@@ -157,7 +161,7 @@ instance (Convert a, Field a, Arbitrary a, Random (RealOf a)) => Arbitrary (WC a | |||
157 | 161 | ||
158 | -- a well-conditioned square matrix (the singular values are between 1 and 100) | 162 | -- a well-conditioned square matrix (the singular values are between 1 and 100) |
159 | newtype (SqWC a) = SqWC (Matrix a) deriving Show | 163 | newtype (SqWC a) = SqWC (Matrix a) deriving Show |
160 | instance (Convert a, Field a, Arbitrary a, Random (RealOf a)) => Arbitrary (SqWC a) where | 164 | instance (ArbitraryField a) => Arbitrary (SqWC a) where |
161 | arbitrary = do | 165 | arbitrary = do |
162 | Sq m <- arbitrary | 166 | Sq m <- arbitrary |
163 | let (u,_,v) = svd m | 167 | let (u,_,v) = svd m |
@@ -174,7 +178,7 @@ instance (Convert a, Field a, Arbitrary a, Random (RealOf a)) => Arbitrary (SqWC | |||
174 | 178 | ||
175 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) | 179 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) |
176 | newtype (PosDef a) = PosDef (Matrix a) deriving Show | 180 | newtype (PosDef a) = PosDef (Matrix a) deriving Show |
177 | instance (Convert a, Field a, Arbitrary a, Num (Vector a), Random (RealOf a)) | 181 | instance (ArbitraryField a, Num (Vector a)) |
178 | => Arbitrary (PosDef a) where | 182 | => Arbitrary (PosDef a) where |
179 | arbitrary = do | 183 | arbitrary = do |
180 | Her m <- arbitrary | 184 | Her m <- arbitrary |