summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r--lib/Data/Packed/Internal/Vector.hs6
1 files changed, 2 insertions, 4 deletions
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 =
71 , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block 71 , fptr :: {-# UNPACK #-} !(ForeignPtr t) -- ^ foreign pointer to the memory block
72 } 72 }
73 73
74unsafeToForeignPtr :: Vector a -> (ForeignPtr a, Int, Int) 74unsafeToForeignPtr :: Storable a => Vector a -> (ForeignPtr a, Int, Int)
75unsafeToForeignPtr v = (fptr v, ioff v, idim v) 75unsafeToForeignPtr v = (fptr v, ioff v, idim v)
76 76
77-- | Same convention as in Roman Leshchinskiy's vector package. 77-- | Same convention as in Roman Leshchinskiy's vector package.
78unsafeFromForeignPtr :: ForeignPtr a -> Int -> Int -> Vector a 78unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Int -> Int -> Vector a
79unsafeFromForeignPtr fp i n | n > 0 = V {ioff = i, idim = n, fptr = fp} 79unsafeFromForeignPtr fp i n | n > 0 = V {ioff = i, idim = n, fptr = fp}
80 | otherwise = error "unsafeFromForeignPtr with dim < 1" 80 | otherwise = error "unsafeFromForeignPtr with dim < 1"
81 81
@@ -266,13 +266,11 @@ takesV ms w | sum ms > dim w = error $ "takesV " ++ show ms ++ " on dim = " ++ (
266 266
267-- | transforms a complex vector into a real vector with alternating real and imaginary parts 267-- | transforms a complex vector into a real vector with alternating real and imaginary parts
268asReal :: (RealFloat a, Storable a) => Vector (Complex a) -> Vector a 268asReal :: (RealFloat a, Storable a) => Vector (Complex a) -> Vector a
269--asReal v = V { ioff = 2*ioff v, idim = 2*dim v, fptr = castForeignPtr (fptr v) }
270asReal v = unsafeFromForeignPtr (castForeignPtr fp) (2*i) (2*n) 269asReal v = unsafeFromForeignPtr (castForeignPtr fp) (2*i) (2*n)
271 where (fp,i,n) = unsafeToForeignPtr v 270 where (fp,i,n) = unsafeToForeignPtr v
272 271
273-- | transforms a real vector into a complex vector with alternating real and imaginary parts 272-- | transforms a real vector into a complex vector with alternating real and imaginary parts
274asComplex :: (RealFloat a, Storable a) => Vector a -> Vector (Complex a) 273asComplex :: (RealFloat a, Storable a) => Vector a -> Vector (Complex a)
275--asComplex v = V { ioff = ioff v `div` 2, idim = dim v `div` 2, fptr = castForeignPtr (fptr v) }
276asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2) 274asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2)
277 where (fp,i,n) = unsafeToForeignPtr v 275 where (fp,i,n) = unsafeToForeignPtr v
278 276