summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs15
1 files changed, 12 insertions, 3 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