From 07bd78f10f2bcce8a5e9838d73754ab4d27f6d1c Mon Sep 17 00:00:00 2001 From: Vivian McPhail Date: Fri, 9 Jul 2010 20:12:19 +0000 Subject: type signatures for use with vector package --- lib/Data/Packed/Internal/Matrix.hs | 4 ++-- lib/Data/Packed/Internal/Vector.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs index 861c72a..100b8ea 100644 --- a/lib/Data/Packed/Internal/Matrix.hs +++ b/lib/Data/Packed/Internal/Matrix.hs @@ -391,11 +391,11 @@ conjV :: (Storable a, RealFloat a) => Vector (Complex a) -> Vector (Complex a) conjV = mapVector conjugate -- | creates a complex vector from vectors with real and imaginary parts -toComplexV :: Element a => (Vector a, Vector a) -> Vector (Complex a) +toComplexV :: (RealFloat a, Element a) => (Vector a, Vector a) -> Vector (Complex a) toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i] -- | the inverse of 'toComplex' -fromComplexV :: Element a => Vector (Complex a) -> (Vector a, Vector a) +fromComplexV :: (RealFloat a, Element a) => Vector (Complex a) -> (Vector a, Vector a) fromComplexV z = (r,i) where [r,i] = toColumns $ reshape 2 $ asReal z diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 6d39c6e..dfa2e86 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs @@ -266,13 +266,13 @@ takesV ms w | sum ms > dim w = error $ "takesV " ++ show ms ++ " on dim = " ++ ( --------------------------------------------------------------- -- | transforms a complex vector into a real vector with alternating real and imaginary parts -asReal :: Vector (Complex a) -> Vector a +asReal :: (RealFloat a, Storable a) => Vector (Complex a) -> Vector a --asReal v = V { ioff = 2*ioff v, idim = 2*dim v, fptr = castForeignPtr (fptr v) } asReal v = unsafeFromForeignPtr (castForeignPtr fp) (2*i) (2*n) where (fp,i,n) = unsafeToForeignPtr v -- | transforms a real vector into a complex vector with alternating real and imaginary parts -asComplex :: Vector a -> Vector (Complex a) +asComplex :: (RealFloat a, Storable a) => Vector a -> Vector (Complex a) --asComplex v = V { ioff = ioff v `div` 2, idim = dim v `div` 2, fptr = castForeignPtr (fptr v) } asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2) where (fp,i,n) = unsafeToForeignPtr v -- cgit v1.2.3