From f541d7dbdc8338b1dd1c0538751d837a16740bd8 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 25 Aug 2010 16:29:37 +0000 Subject: simpler Container typeclass --- lib/Data/Packed/Internal/Vector.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/Data/Packed/Internal/Vector.hs') diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs index 652b980..ac2d0d7 100644 --- a/lib/Data/Packed/Internal/Vector.hs +++ b/lib/Data/Packed/Internal/Vector.hs @@ -71,11 +71,11 @@ data Vector t = , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block } -unsafeToForeignPtr :: Vector a -> (ForeignPtr a, Int, Int) +unsafeToForeignPtr :: Storable a => Vector a -> (ForeignPtr a, Int, Int) unsafeToForeignPtr v = (fptr v, ioff v, idim v) -- | Same convention as in Roman Leshchinskiy's vector package. -unsafeFromForeignPtr :: ForeignPtr a -> Int -> Int -> Vector a +unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Int -> Int -> Vector a unsafeFromForeignPtr fp i n | n > 0 = V {ioff = i, idim = n, fptr = fp} | otherwise = error "unsafeFromForeignPtr with dim < 1" @@ -266,13 +266,11 @@ 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 :: (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 :: (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