summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs10
-rw-r--r--lib/Numeric/LinearAlgebra/Linear.hs9
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Instances.hs4
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Properties.hs5
4 files changed, 14 insertions, 14 deletions
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 8962c60..7e258de 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -82,7 +82,7 @@ import Data.List(foldl1')
82import Data.Array 82import Data.Array
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.
85class (Prod t, Normed (Matrix t), Linear Vector t, Linear Matrix t) => Field t where 85class (AutoReal t, Prod t, Linear Vector t, Linear 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
@@ -588,8 +588,8 @@ diagonalize m = if rank v == n
588-- 588--
589-- @logm = matFunc log@ 589-- @logm = matFunc log@
590-- 590--
591matFunc :: Field t => (Complex Double -> Complex Double) -> Matrix t -> Matrix (Complex Double) 591matFunc :: (Field t) => (Complex Double -> Complex Double) -> Matrix t -> Matrix (Complex Double)
592matFunc f m = case diagonalize (complex m) of 592matFunc f m = case diagonalize (complex'' m) of
593 Just (l,v) -> v `mXm` diag (mapVector f l) `mXm` inv v 593 Just (l,v) -> v `mXm` diag (mapVector f l) `mXm` inv v
594 Nothing -> error "Sorry, matFunc requires a diagonalizable matrix" 594 Nothing -> error "Sorry, matFunc requires a diagonalizable matrix"
595 595
@@ -630,7 +630,7 @@ expGolub m = iterate msq f !! j
630{- | Matrix exponential. It uses a direct translation of Algorithm 11.3.1 in Golub & Van Loan, 630{- | Matrix exponential. It uses a direct translation of Algorithm 11.3.1 in Golub & Van Loan,
631 based on a scaled Pade approximation. 631 based on a scaled Pade approximation.
632-} 632-}
633expm :: Field t => Matrix t -> Matrix t 633expm :: (Normed (Matrix t), Field t) => Matrix t -> Matrix t
634expm = expGolub 634expm = expGolub
635 635
636-------------------------------------------------------------- 636--------------------------------------------------------------
@@ -646,7 +646,7 @@ It only works with invertible matrices that have a real solution. For diagonaliz
646 [ 2.0, 2.25 646 [ 2.0, 2.25
647 , 0.0, 2.0 ]@ 647 , 0.0, 2.0 ]@
648-} 648-}
649sqrtm :: Field t => Matrix t -> Matrix t 649sqrtm :: (Normed (Matrix t), Field t) => Matrix t -> Matrix t
650sqrtm = sqrtmInv 650sqrtm = sqrtmInv
651 651
652sqrtmInv x = fst $ fixedPoint $ iterate f (x, ident (rows x)) 652sqrtmInv x = fst $ fixedPoint $ iterate f (x, ident (rows x))
diff --git a/lib/Numeric/LinearAlgebra/Linear.hs b/lib/Numeric/LinearAlgebra/Linear.hs
index 71869cb..67921d8 100644
--- a/lib/Numeric/LinearAlgebra/Linear.hs
+++ b/lib/Numeric/LinearAlgebra/Linear.hs
@@ -21,7 +21,7 @@ module Numeric.LinearAlgebra.Linear (
21 Linear(..), 21 Linear(..),
22 -- * Products 22 -- * Products
23 Prod(..), 23 Prod(..),
24 mXm,mXv,vXm, mulH, 24 mXm,mXv,vXm,
25 outer, kronecker, 25 outer, kronecker,
26 -- * Creation of numeric vectors 26 -- * Creation of numeric vectors
27 constant, linspace 27 constant, linspace
@@ -90,7 +90,7 @@ instance Vectors Vector (Complex Double) where
90---------------------------------------------------- 90----------------------------------------------------
91 91
92-- | Basic element-by-element functions. 92-- | Basic element-by-element functions.
93class (Element e, AutoReal e, Container c) => Linear c e where 93class (Element e, Container c) => Linear c e where
94 -- | create a structure with a single element 94 -- | create a structure with a single element
95 scalar :: e -> c e 95 scalar :: e -> c e
96 scale :: e -> c e -> c e 96 scale :: e -> c e -> c e
@@ -190,13 +190,8 @@ linspace n (a,b) = addConstant a $ scale s $ fromList [0 .. fromIntegral n-1]
190 190
191---------------------------------------------------- 191----------------------------------------------------
192 192
193-- reference multiply
194mulH a b = fromLists [[ doth ai bj | bj <- toColumns b] | ai <- toRows a ]
195 where doth u v = sum $ zipWith (*) (toList u) (toList v)
196
197class Element t => Prod t where 193class Element t => Prod t where
198 multiply :: Matrix t -> Matrix t -> Matrix t 194 multiply :: Matrix t -> Matrix t -> Matrix t
199 multiply = mulH
200 ctrans :: Matrix t -> Matrix t 195 ctrans :: Matrix t -> Matrix t
201 196
202instance Prod Double where 197instance Prod Double where
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
index ad59b25..aaaff28 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
@@ -27,10 +27,12 @@ module Numeric.LinearAlgebra.Tests.Instances(
27) where 27) where
28 28
29 29
30import Numeric.LinearAlgebra 30import Numeric.LinearAlgebra hiding (real,complex)
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
34 36
35#if MIN_VERSION_QuickCheck(2,0,0) 37#if MIN_VERSION_QuickCheck(2,0,0)
36shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] 38shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]]
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/lib/Numeric/LinearAlgebra/Tests/Properties.hs
index f7a948e..9891d8a 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Properties.hs
@@ -42,12 +42,15 @@ module Numeric.LinearAlgebra.Tests.Properties (
42 linearSolveProp, linearSolveProp2 42 linearSolveProp, linearSolveProp2
43) where 43) where
44 44
45import Numeric.LinearAlgebra hiding (mulH) 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
52complex x = complex'' x
53
51debug x = trace (show x) x 54debug x = trace (show x) x
52 55
53-- relative error 56-- relative error