summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs15
-rw-r--r--lib/Data/Packed/Internal/Signatures.hs6
-rw-r--r--lib/Data/Packed/Internal/Vector.hs4
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index 003e8ee..7b3b305 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -257,6 +257,10 @@ class (Storable a, Floating a) => Element a where
257 constantD :: a -> Int -> Vector a 257 constantD :: a -> Int -> Vector a
258 constantD = constant' 258 constantD = constant'
259 259
260instance Element Float where
261 transdata = transdataAux ctransF
262 constantD = constantAux cconstantF
263
260instance Element Double where 264instance Element Double where
261 transdata = transdataAux ctransR 265 transdata = transdataAux ctransR
262 constantD = constantAux cconstantR 266 constantD = constantAux cconstantR
@@ -308,6 +312,7 @@ transdataAux fun c1 d c2 =
308 r2 = dim d `div` c2 312 r2 = dim d `div` c2
309 noneed = r1 == 1 || c1 == 1 313 noneed = r1 == 1 || c1 == 1
310 314
315foreign import ccall "transF" ctransF :: TFMFM
311foreign import ccall "transR" ctransR :: TMM 316foreign import ccall "transR" ctransR :: TMM
312foreign import ccall "transC" ctransC :: TCMCM 317foreign import ccall "transC" ctransC :: TCMCM
313---------------------------------------------------------------------- 318----------------------------------------------------------------------
@@ -329,6 +334,10 @@ constantAux fun x n = unsafePerformIO $ do
329 free px 334 free px
330 return v 335 return v
331 336
337constantF :: Float -> Int -> Vector Float
338constantF = constantAux cconstantF
339foreign import ccall "constantF" cconstantF :: Ptr Float -> TF
340
332constantR :: Double -> Int -> Vector Double 341constantR :: Double -> Int -> Vector Double
333constantR = constantAux cconstantR 342constantR = constantAux cconstantR
334foreign import ccall "constantR" cconstantR :: Ptr Double -> TV 343foreign import ccall "constantR" cconstantR :: Ptr Double -> TV
@@ -368,15 +377,15 @@ subMatrix' (r0,c0) (rt,ct) m = trans $ subMatrix' (c0,r0) (ct,rt) (trans m)
368-------------------------------------------------------------------------- 377--------------------------------------------------------------------------
369 378
370-- | obtains the complex conjugate of a complex vector 379-- | obtains the complex conjugate of a complex vector
371conjV :: Vector (Complex Double) -> Vector (Complex Double) 380conjV :: (Storable a, RealFloat a) => Vector (Complex a) -> Vector (Complex a)
372conjV = mapVector conjugate 381conjV = mapVector conjugate
373 382
374-- | creates a complex vector from vectors with real and imaginary parts 383-- | creates a complex vector from vectors with real and imaginary parts
375toComplexV :: (Vector Double, Vector Double) -> Vector (Complex Double) 384toComplexV :: Element a => (Vector a, Vector a) -> Vector (Complex a)
376toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i] 385toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i]
377 386
378-- | the inverse of 'toComplex' 387-- | the inverse of 'toComplex'
379fromComplexV :: Vector (Complex Double) -> (Vector Double, Vector Double) 388fromComplexV :: Element a => Vector (Complex a) -> (Vector a, Vector a)
380fromComplexV z = (r,i) where 389fromComplexV z = (r,i) where
381 [r,i] = toColumns $ reshape 2 $ asReal z 390 [r,i] = toColumns $ reshape 2 $ asReal z
382 391
diff --git a/lib/Data/Packed/Internal/Signatures.hs b/lib/Data/Packed/Internal/Signatures.hs
index d3ce121..4d984e3 100644
--- a/lib/Data/Packed/Internal/Signatures.hs
+++ b/lib/Data/Packed/Internal/Signatures.hs
@@ -18,11 +18,17 @@ import Foreign
18import Data.Complex 18import Data.Complex
19import Foreign.C.Types 19import Foreign.C.Types
20 20
21type PF = Ptr Float --
21type PD = Ptr Double -- 22type PD = Ptr Double --
22type PC = Ptr (Complex Double) -- 23type PC = Ptr (Complex Double) --
24type TF = CInt -> PF -> IO CInt --
25type TFF = CInt -> PF -> TF --
26type TFFF = CInt -> PF -> TFF --
23type TV = CInt -> PD -> IO CInt -- 27type TV = CInt -> PD -> IO CInt --
24type TVV = CInt -> PD -> TV -- 28type TVV = CInt -> PD -> TV --
25type TVVV = CInt -> PD -> TVV -- 29type TVVV = CInt -> PD -> TVV --
30type TFM = CInt -> CInt -> PF -> IO CInt --
31type TFMFM = CInt -> CInt -> PF -> TFM --
26type TM = CInt -> CInt -> PD -> IO CInt -- 32type TM = CInt -> CInt -> PD -> IO CInt --
27type TMM = CInt -> CInt -> PD -> TM -- 33type TMM = CInt -> CInt -> PD -> TM --
28type TVMM = CInt -> PD -> TMM -- 34type TVMM = CInt -> PD -> TMM --
diff --git a/lib/Data/Packed/Internal/Vector.hs b/lib/Data/Packed/Internal/Vector.hs
index a6868d9..d97a86d 100644
--- a/lib/Data/Packed/Internal/Vector.hs
+++ b/lib/Data/Packed/Internal/Vector.hs
@@ -264,13 +264,13 @@ takesV ms w | sum ms > dim w = error $ "takesV " ++ show ms ++ " on dim = " ++ (
264--------------------------------------------------------------- 264---------------------------------------------------------------
265 265
266-- | transforms a complex vector into a real vector with alternating real and imaginary parts 266-- | transforms a complex vector into a real vector with alternating real and imaginary parts
267asReal :: Vector (Complex Double) -> Vector Double 267asReal :: Vector (Complex a) -> Vector a
268--asReal v = V { ioff = 2*ioff v, idim = 2*dim v, fptr = castForeignPtr (fptr v) } 268--asReal v = V { ioff = 2*ioff v, idim = 2*dim v, fptr = castForeignPtr (fptr v) }
269asReal v = unsafeFromForeignPtr (castForeignPtr fp) (2*i) (2*n) 269asReal v = unsafeFromForeignPtr (castForeignPtr fp) (2*i) (2*n)
270 where (fp,i,n) = unsafeToForeignPtr v 270 where (fp,i,n) = unsafeToForeignPtr v
271 271
272-- | 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
273asComplex :: Vector Double -> Vector (Complex Double) 273asComplex :: Vector a -> Vector (Complex a)
274--asComplex v = V { ioff = ioff v `div` 2, idim = dim v `div` 2, fptr = castForeignPtr (fptr v) } 274--asComplex v = V { ioff = ioff v `div` 2, idim = dim v `div` 2, fptr = castForeignPtr (fptr v) }
275asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2) 275asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2)
276 where (fp,i,n) = unsafeToForeignPtr v 276 where (fp,i,n) = unsafeToForeignPtr v