summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-09 12:10:58 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-09 12:10:58 +0000
commit7931a9b18ea84ed5f49e2803ba596f190567d9d8 (patch)
tree64a08a62b2bffcf48becbab03933f3c7b4527a73 /lib/Data/Packed/Internal/Matrix.hs
parente21f42f742959ec9452add9b6c6e08d30d9584ed (diff)
more tests
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index 4383e79..0664e9b 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -179,6 +179,15 @@ joinVert ms = case common cols ms of
179joinHoriz :: Field t => [Matrix t] -> Matrix t 179joinHoriz :: Field t => [Matrix t] -> Matrix t
180joinHoriz ms = trans. joinVert . map trans $ ms 180joinHoriz ms = trans. joinVert . map trans $ ms
181 181
182-- | creates a complex vector from vectors with real and imaginary parts
183toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double)
184toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i]
185
186-- | obtains the complex conjugate of a complex vector
187conj :: Vector (Complex Double) -> Vector (Complex Double)
188conj v = asComplex $ cdat $ reshape 2 (asReal v) `mulC` diag (fromList [1,-1])
189 where mulC = multiply RowMajor
190
182------------------------------------------------------------------------------ 191------------------------------------------------------------------------------
183 192
184-- | Reverse rows 193-- | Reverse rows
@@ -191,7 +200,7 @@ fliprl m = fromColumns . reverse . toColumns $ m
191 200
192----------------------------------------------------------------- 201-----------------------------------------------------------------
193 202
194liftMatrix f m = m { dat = f dat, tdat = f tdat } -- check sizes 203liftMatrix f m = m { dat = f (dat m), tdat = f (tdat m) } -- check sizes
195 204
196------------------------------------------------------------------ 205------------------------------------------------------------------
197 206
@@ -291,7 +300,7 @@ subMatrixG (r0,c0) (rt,ct) x = reshape ct $ fromList $ concat $ map (subList c0
291diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do 300diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do
292 m <- createMatrix RowMajor n n 301 m <- createMatrix RowMajor n n
293 fun // vec v // mat dat m // check msg [dat m] 302 fun // vec v // mat dat m // check msg [dat m]
294 return m 303 return m {tdat = dat m}
295 304
296-- | diagonal matrix from a real vector 305-- | diagonal matrix from a real vector
297diagR :: Vector Double -> Matrix Double 306diagR :: Vector Double -> Matrix Double
@@ -319,6 +328,6 @@ diagG v = reshape c $ fromList $ [ l!!(i-1) * delta k i | k <- [1..c], i <- [1..
319diagRect s r c 328diagRect s r c
320 | dim s < min r c = error "diagRect" 329 | dim s < min r c = error "diagRect"
321 | r == c = diag s 330 | r == c = diag s
322 | r < c = joinHoriz [diag s , zeros (r,c-r)] 331 | r < c = trans $ diagRect s c r
323 | otherwise = joinVert [diag s , zeros (r-c,c)] 332 | r > c = joinVert [diag s , zeros (r-c,c)]
324 where zeros (r,c) = reshape c $ constant (r*c) 0 333 where zeros (r,c) = reshape c $ constant (r*c) 0