From 7931a9b18ea84ed5f49e2803ba596f190567d9d8 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 9 Jun 2007 12:10:58 +0000 Subject: more tests --- lib/Data/Packed/Internal/Matrix.hs | 17 +++++++++++++---- lib/Data/Packed/Internal/Vector.hs | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/Data') 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 joinHoriz :: Field t => [Matrix t] -> Matrix t joinHoriz ms = trans. joinVert . map trans $ ms +-- | creates a complex vector from vectors with real and imaginary parts +toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) +toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] + +-- | obtains the complex conjugate of a complex vector +conj :: Vector (Complex Double) -> Vector (Complex Double) +conj v = asComplex $ cdat $ reshape 2 (asReal v) `mulC` diag (fromList [1,-1]) + where mulC = multiply RowMajor + ------------------------------------------------------------------------------ -- | Reverse rows @@ -191,7 +200,7 @@ fliprl m = fromColumns . reverse . toColumns $ m ----------------------------------------------------------------- -liftMatrix f m = m { dat = f dat, tdat = f tdat } -- check sizes +liftMatrix f m = m { dat = f (dat m), tdat = f (tdat m) } -- check sizes ------------------------------------------------------------------ @@ -291,7 +300,7 @@ subMatrixG (r0,c0) (rt,ct) x = reshape ct $ fromList $ concat $ map (subList c0 diagAux fun msg (v@V {dim = n}) = unsafePerformIO $ do m <- createMatrix RowMajor n n fun // vec v // mat dat m // check msg [dat m] - return m + return m {tdat = dat m} -- | diagonal matrix from a real vector diagR :: Vector Double -> Matrix Double @@ -319,6 +328,6 @@ diagG v = reshape c $ fromList $ [ l!!(i-1) * delta k i | k <- [1..c], i <- [1.. diagRect s r c | dim s < min r c = error "diagRect" | r == c = diag s - | r < c = joinHoriz [diag s , zeros (r,c-r)] - | otherwise = joinVert [diag s , zeros (r-c,c)] + | r < c = trans $ diagRect s c r + | r > c = joinVert [diag s , zeros (r-c,c)] where zeros (r,c) = reshape c $ constant (r*c) 0 diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 36d5df7..8f4e6a4 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs @@ -145,6 +145,7 @@ asReal v = V { dim = 2*dim v, fptr = castForeignPtr (fptr v), ptr = castPtr (pt asComplex :: Vector Double -> Vector (Complex Double) asComplex v = V { dim = dim v `div` 2, fptr = castForeignPtr (fptr v), ptr = castPtr (ptr v) } + constantG n x = fromList (replicate n x) constantR :: Int -> Double -> Vector Double -- cgit v1.2.3