From f901d49d1392327c79f1d4c63932fa350cfb506a Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 15 Sep 2007 09:59:20 +0000 Subject: minor changes --- lib/Data/Packed/Internal/Matrix.hs | 3 ++- lib/Data/Packed/Matrix.hs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/Data') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 58b325c..8bca510 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -152,11 +152,12 @@ reshape c v = matrixFromVector RowMajor c v singleton x = reshape 1 (fromList [x]) +-- | application of a vector function on the flattened matrix elements liftMatrix :: (Field a, Field b) => (Vector a -> Vector b) -> Matrix a -> Matrix b liftMatrix f MC { cols = c, cdat = d } = matrixFromVector RowMajor c (f d) liftMatrix f MF { cols = c, fdat = d } = matrixFromVector ColumnMajor c (f d) - +-- | application of a vector function on the flattened matrices elements liftMatrix2 :: (Field t, Field a, Field b) => (Vector a -> Vector b -> Vector t) -> Matrix a -> Matrix b -> Matrix t liftMatrix2 f m1 m2 | not (compat m1 m2) = error "nonconformant matrices in liftMatrix2" diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index fc08ce4..4f2ad90 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs @@ -24,7 +24,7 @@ module Data.Packed.Matrix ( fromBlocks, joinVert, joinHoriz, flipud, fliprl, subMatrix, takeRows, dropRows, takeColumns, dropColumns, - diag, takeDiag, diagRect, ident, + ident, diag, diagRect, takeDiag, liftMatrix, liftMatrix2, ) where @@ -69,6 +69,14 @@ fliprl m = fromColumns . reverse . toColumns $ m ------------------------------------------------------------ +{- | creates a rectangular diagonal matrix + +@> diagRect (constant 5 3) 3 4 +(3><4) + [ 5.0, 0.0, 0.0, 0.0 + , 0.0, 5.0, 0.0, 0.0 + , 0.0, 0.0, 5.0, 0.0 ]@ +-} diagRect :: (Field t, Num t) => Vector t -> Int -> Int -> Matrix t diagRect s r c | dim s < min r c = error "diagRect" @@ -77,9 +85,11 @@ diagRect s r c | r > c = joinVert [diag s , zeros (r-c,c)] where zeros (r,c) = reshape c $ constantD 0 (r*c) +-- | extracts the diagonal from a rectangular matrix takeDiag :: (Field t) => Matrix t -> Vector t takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]] +-- | creates the identity matrix of given dimension ident :: Int -> Matrix Double ident n = diag (constant 1 n) @@ -138,12 +148,15 @@ flatten = cdat fromLists :: Field t => [[t]] -> Matrix t fromLists = fromRows . map fromList +-- | conjugate transpose conjTrans :: Matrix (Complex Double) -> Matrix (Complex Double) conjTrans = trans . liftMatrix conj +-- | creates a 1-row matrix from a vector asRow :: Field a => Vector a -> Matrix a asRow v = reshape (dim v) v +-- | creates a 1-column matrix from a vector asColumn :: Field a => Vector a -> Matrix a asColumn v = reshape 1 v -- cgit v1.2.3