diff options
Diffstat (limited to 'lib/Data/Packed/Internal/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Matrix.hs | 15 |
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 | ||
260 | instance Element Float where | ||
261 | transdata = transdataAux ctransF | ||
262 | constantD = constantAux cconstantF | ||
263 | |||
260 | instance Element Double where | 264 | instance 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 | ||
315 | foreign import ccall "transF" ctransF :: TFMFM | ||
311 | foreign import ccall "transR" ctransR :: TMM | 316 | foreign import ccall "transR" ctransR :: TMM |
312 | foreign import ccall "transC" ctransC :: TCMCM | 317 | foreign 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 | ||
337 | constantF :: Float -> Int -> Vector Float | ||
338 | constantF = constantAux cconstantF | ||
339 | foreign import ccall "constantF" cconstantF :: Ptr Float -> TF | ||
340 | |||
332 | constantR :: Double -> Int -> Vector Double | 341 | constantR :: Double -> Int -> Vector Double |
333 | constantR = constantAux cconstantR | 342 | constantR = constantAux cconstantR |
334 | foreign import ccall "constantR" cconstantR :: Ptr Double -> TV | 343 | foreign 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 |
371 | conjV :: Vector (Complex Double) -> Vector (Complex Double) | 380 | conjV :: (Storable a, RealFloat a) => Vector (Complex a) -> Vector (Complex a) |
372 | conjV = mapVector conjugate | 381 | conjV = 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 |
375 | toComplexV :: (Vector Double, Vector Double) -> Vector (Complex Double) | 384 | toComplexV :: Element a => (Vector a, Vector a) -> Vector (Complex a) |
376 | toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i] | 385 | toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i] |
377 | 386 | ||
378 | -- | the inverse of 'toComplex' | 387 | -- | the inverse of 'toComplex' |
379 | fromComplexV :: Vector (Complex Double) -> (Vector Double, Vector Double) | 388 | fromComplexV :: Element a => Vector (Complex a) -> (Vector a, Vector a) |
380 | fromComplexV z = (r,i) where | 389 | fromComplexV z = (r,i) where |
381 | [r,i] = toColumns $ reshape 2 $ asReal z | 390 | [r,i] = toColumns $ reshape 2 $ asReal z |
382 | 391 | ||