summaryrefslogtreecommitdiff
path: root/lib/Numeric
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-09-20 17:08:34 +0000
committerAlberto Ruiz <aruiz@um.es>2010-09-20 17:08:34 +0000
commit05908719a7323110ba1955038d8341a8b7483351 (patch)
treef1f1fe28a8db64675dacc7eb4ec79d36e8174588 /lib/Numeric
parent482b533c3fbfcd75d6c5c1d3ce32585bf9fc2ad7 (diff)
generalized diagRect
Diffstat (limited to 'lib/Numeric')
-rw-r--r--lib/Numeric/Container.hs15
-rw-r--r--lib/Numeric/LinearAlgebra/Algorithms.hs8
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Instances.hs2
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Properties.hs2
-rw-r--r--lib/Numeric/Matrix.hs1
5 files changed, 21 insertions, 7 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index 83bf44e..1afc5a1 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -22,6 +22,7 @@
22module Numeric.Container ( 22module Numeric.Container (
23 -- * Generic operations 23 -- * Generic operations
24 Container(..), 24 Container(..),
25 ctrans, diag, ident,
25 -- * Matrix product and related functions 26 -- * Matrix product and related functions
26 Product(..), 27 Product(..),
27 mXm,mXv,vXm, 28 mXm,mXv,vXm,
@@ -221,6 +222,20 @@ instance (Container Vector a) => Container Matrix a where
221 222
222---------------------------------------------------- 223----------------------------------------------------
223 224
225-- | conjugate transpose
226ctrans :: Element e => Matrix e -> Matrix e
227ctrans = liftMatrix conjugateD . trans
228
229-- | Creates a square matrix with a given diagonal.
230diag :: (Num a, Element a) => Vector a -> Matrix a
231diag v = diagRect 0 v n n where n = dim v
232
233-- | creates the identity matrix of given dimension
234ident :: (Num a, Element a) => Int -> Matrix a
235ident n = diag (constantD 1 n)
236
237----------------------------------------------------
238
224 239
225-- | Matrix product and related functions 240-- | Matrix product and related functions
226class Element e => Product e where 241class Element e => Product e where
diff --git a/lib/Numeric/LinearAlgebra/Algorithms.hs b/lib/Numeric/LinearAlgebra/Algorithms.hs
index 4f6f54d..394a1d7 100644
--- a/lib/Numeric/LinearAlgebra/Algorithms.hs
+++ b/lib/Numeric/LinearAlgebra/Algorithms.hs
@@ -183,7 +183,7 @@ singularValues = {-# SCC "singularValues" #-} sv'
183fullSVD :: Field t => Matrix t -> (Matrix t, Matrix Double, Matrix t) 183fullSVD :: Field t => Matrix t -> (Matrix t, Matrix Double, Matrix t)
184fullSVD m = (u,d,v) where 184fullSVD m = (u,d,v) where
185 (u,s,v) = svd m 185 (u,s,v) = svd m
186 d = diagRect s r c 186 d = diagRect 0 s r c
187 r = rows m 187 r = rows m
188 c = cols m 188 c = cols m
189 189
@@ -210,7 +210,7 @@ leftSV m | vertical m = let (u,s,_) = svd m in (u,s)
210{-# DEPRECATED full "use fullSVD instead" #-} 210{-# DEPRECATED full "use fullSVD instead" #-}
211full svdFun m = (u, d ,v) where 211full svdFun m = (u, d ,v) where
212 (u,s,v) = svdFun m 212 (u,s,v) = svdFun m
213 d = diagRect s r c 213 d = diagRect 0 s r c
214 r = rows m 214 r = rows m
215 c = cols m 215 c = cols m
216 216
@@ -624,10 +624,10 @@ luFact (l_u,perm) | r <= c = (l ,u ,p, s)
624 c = cols l_u 624 c = cols l_u
625 tu = triang r c 0 1 625 tu = triang r c 0 1
626 tl = triang r c 0 0 626 tl = triang r c 0 0
627 l = takeColumns r (l_u |*| tl) |+| diagRect (konst 1 r) r r 627 l = takeColumns r (l_u |*| tl) |+| diagRect 0 (konst 1 r) r r
628 u = l_u |*| tu 628 u = l_u |*| tu
629 (p,s) = fixPerm r perm 629 (p,s) = fixPerm r perm
630 l' = (l_u |*| tl) |+| diagRect (konst 1 c) r c 630 l' = (l_u |*| tl) |+| diagRect 0 (konst 1 c) r c
631 u' = takeRows c (l_u |*| tu) 631 u' = takeRows c (l_u |*| tu)
632 (|+|) = add 632 (|+|) = add
633 (|*|) = mul 633 (|*|) = mul
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
index 804c481..771739a 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
@@ -150,7 +150,7 @@ instance (ArbitraryField a) => Arbitrary (WC a) where
150 c = cols m 150 c = cols m
151 n = min r c 151 n = min r c
152 sv' <- replicateM n (choose (1,100)) 152 sv' <- replicateM n (choose (1,100))
153 let s = diagRect (fromList sv') r c 153 let s = diagRect 0 (fromList sv') r c
154 return $ WC (u <> real s <> trans v) 154 return $ WC (u <> real s <> trans v)
155 155
156#if MIN_VERSION_QuickCheck(2,0,0) 156#if MIN_VERSION_QuickCheck(2,0,0)
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/lib/Numeric/LinearAlgebra/Tests/Properties.hs
index 623b78c..a35f591 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Properties.hs
@@ -138,7 +138,7 @@ svdProp1 m = m |~| u <> real d <> trans v && unitary u && unitary v
138 138
139svdProp1a svdfun m = m |~| u <> real d <> trans v && unitary u && unitary v where 139svdProp1a svdfun m = m |~| u <> real d <> trans v && unitary u && unitary v where
140 (u,s,v) = svdfun m 140 (u,s,v) = svdfun m
141 d = diagRect s (rows m) (cols m) 141 d = diagRect 0 s (rows m) (cols m)
142 142
143svdProp1b svdfun m = unitary u && unitary v where 143svdProp1b svdfun m = unitary u && unitary v where
144 (u,_,v) = svdfun m 144 (u,_,v) = svdfun m
diff --git a/lib/Numeric/Matrix.hs b/lib/Numeric/Matrix.hs
index d5c6f44..9260bd5 100644
--- a/lib/Numeric/Matrix.hs
+++ b/lib/Numeric/Matrix.hs
@@ -28,7 +28,6 @@ module Numeric.Matrix (
28 -- * Basic functions 28 -- * Basic functions
29 module Data.Packed.Matrix, 29 module Data.Packed.Matrix,
30 module Numeric.Vector, 30 module Numeric.Vector,
31 --module Numeric.Container,
32 optimiseMult, 31 optimiseMult,
33 -- * Operators 32 -- * Operators
34 (<>), (<\>) 33 (<>), (<\>)