From d14515a4a50d5b5335f9c1525432b68ab67fa7c8 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Fri, 14 Sep 2007 18:23:20 +0000 Subject: more refactoring --- lib/Data/Packed/Internal/Matrix.hs | 7 ++++++- lib/Data/Packed/Matrix.hs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/Data') diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 89a162a..58b325c 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -348,7 +348,7 @@ foreign import ccall safe "aux.h constantC" @> constant 2 7 7 |> [2.0,2.0,2.0,2.0,2.0,2.0,2.0]@ -} -constant :: Field a => a -> Int -> Vector a +constant :: Double -> Int -> Vector Double constant = constantD -------------------------------------------------------------------------- @@ -361,6 +361,11 @@ conj v = asComplex $ cdat $ reshape 2 (asReal v) `multiply` diag (fromList [1,-1 toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) toComplex (r,i) = asComplex $ cdat $ fromColumns [r,i] +-- | the inverse of 'toComplex' +fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double) +fromComplex z = (r,i) where + [r,i] = toColumns $ reshape 2 $ asReal z + -- | converts a real vector into a complex representation (with zero imaginary parts) comp :: Vector Double -> Vector (Complex Double) comp v = toComplex (v,constant 0 (dim v)) diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 01e8133..fc08ce4 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs @@ -75,12 +75,12 @@ diagRect s r c | r == c = diag s | r < c = trans $ diagRect s c r | r > c = joinVert [diag s , zeros (r-c,c)] - where zeros (r,c) = reshape c $ constant 0 (r*c) + where zeros (r,c) = reshape c $ constantD 0 (r*c) 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]] -ident :: (Num t, Field t) => Int -> Matrix t +ident :: Int -> Matrix Double ident n = diag (constant 1 n) ------------------------------------------------------------ -- cgit v1.2.3