diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-08-25 16:29:37 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-08-25 16:29:37 +0000 |
commit | f541d7dbdc8338b1dd1c0538751d837a16740bd8 (patch) | |
tree | 02b3383ed3ffdb3f3f5c0f61ce0243c73e160a24 /lib/Data/Packed/Internal/Vector.hs | |
parent | 2b5b266bb02c7205262bc8a0b584477b6043a112 (diff) |
simpler Container typeclass
Diffstat (limited to 'lib/Data/Packed/Internal/Vector.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Vector.hs | 6 |
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 | ||
74 | unsafeToForeignPtr :: Vector a -> (ForeignPtr a, Int, Int) | 74 | unsafeToForeignPtr :: Storable a => Vector a -> (ForeignPtr a, Int, Int) |
75 | unsafeToForeignPtr v = (fptr v, ioff v, idim v) | 75 | unsafeToForeignPtr 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. |
78 | unsafeFromForeignPtr :: ForeignPtr a -> Int -> Int -> Vector a | 78 | unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Int -> Int -> Vector a |
79 | unsafeFromForeignPtr fp i n | n > 0 = V {ioff = i, idim = n, fptr = fp} | 79 | unsafeFromForeignPtr 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 |
268 | asReal :: (RealFloat a, Storable a) => Vector (Complex a) -> Vector a | 268 | asReal :: (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) } | ||
270 | asReal v = unsafeFromForeignPtr (castForeignPtr fp) (2*i) (2*n) | 269 | asReal 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 |
274 | asComplex :: (RealFloat a, Storable a) => Vector a -> Vector (Complex a) | 273 | asComplex :: (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) } | ||
276 | asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2) | 274 | asComplex 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 | ||