summaryrefslogtreecommitdiff
path: root/lib/Data/Packed
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed')
-rw-r--r--lib/Data/Packed/Internal/Matrix.hs14
-rw-r--r--lib/Data/Packed/Matrix.hs49
2 files changed, 55 insertions, 8 deletions
diff --git a/lib/Data/Packed/Internal/Matrix.hs b/lib/Data/Packed/Internal/Matrix.hs
index d879ee6..003e8ee 100644
--- a/lib/Data/Packed/Internal/Matrix.hs
+++ b/lib/Data/Packed/Internal/Matrix.hs
@@ -29,7 +29,7 @@ module Data.Packed.Internal.Matrix(
29 liftMatrix, liftMatrix2, 29 liftMatrix, liftMatrix2,
30 (@@>), 30 (@@>),
31 saveMatrix, 31 saveMatrix,
32 fromComplex, toComplex, conj, 32 fromComplexV, toComplexV, conjV,
33 singleton 33 singleton
34) where 34) where
35 35
@@ -368,16 +368,16 @@ subMatrix' (r0,c0) (rt,ct) m = trans $ subMatrix' (c0,r0) (ct,rt) (trans m)
368-------------------------------------------------------------------------- 368--------------------------------------------------------------------------
369 369
370-- | obtains the complex conjugate of a complex vector 370-- | obtains the complex conjugate of a complex vector
371conj :: Vector (Complex Double) -> Vector (Complex Double) 371conjV :: Vector (Complex Double) -> Vector (Complex Double)
372conj = mapVector conjugate 372conjV = mapVector conjugate
373 373
374-- | creates a complex vector from vectors with real and imaginary parts 374-- | creates a complex vector from vectors with real and imaginary parts
375toComplex :: (Vector Double, Vector Double) -> Vector (Complex Double) 375toComplexV :: (Vector Double, Vector Double) -> Vector (Complex Double)
376toComplex (r,i) = asComplex $ flatten $ fromColumns [r,i] 376toComplexV (r,i) = asComplex $ flatten $ fromColumns [r,i]
377 377
378-- | the inverse of 'toComplex' 378-- | the inverse of 'toComplex'
379fromComplex :: Vector (Complex Double) -> (Vector Double, Vector Double) 379fromComplexV :: Vector (Complex Double) -> (Vector Double, Vector Double)
380fromComplex z = (r,i) where 380fromComplexV z = (r,i) where
381 [r,i] = toColumns $ reshape 2 $ asReal z 381 [r,i] = toColumns $ reshape 2 $ asReal z
382 382
383-------------------------------------------------------------------------- 383--------------------------------------------------------------------------
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 4fdd2c6..3147e13 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-}
1----------------------------------------------------------------------------- 2-----------------------------------------------------------------------------
2-- | 3-- |
3-- Module : Data.Packed.Matrix 4-- Module : Data.Packed.Matrix
@@ -13,7 +14,7 @@
13----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
14 15
15module Data.Packed.Matrix ( 16module Data.Packed.Matrix (
16 Element, 17 Element, Container(..),
17 Matrix,rows,cols, 18 Matrix,rows,cols,
18 (><), 19 (><),
19 trans, 20 trans,
@@ -421,3 +422,49 @@ toBlocksEvery r c m = toBlocks rs cs m where
421 (qc,rc) = cols m `divMod` c 422 (qc,rc) = cols m `divMod` c
422 rs = replicate qr r ++ if rr > 0 then [rr] else [] 423 rs = replicate qr r ++ if rr > 0 then [rr] else []
423 cs = replicate qc c ++ if rc > 0 then [rc] else [] 424 cs = replicate qc c ++ if rc > 0 then [rc] else []
425
426-------------------------------------------------------------------
427
428-- | conversion utilities
429class (Element e) => Container c e where
430 toComplex :: RealFloat e => (c e, c e) -> c (Complex e)
431 fromComplex :: RealFloat e => c (Complex e) -> (c e, c e)
432 comp :: RealFloat e => c e -> c (Complex e)
433 conj :: RealFloat e => c (Complex e) -> c (Complex e)
434 real :: c Double -> c e
435 complex :: c e -> c (Complex Double)
436
437instance Container Vector Double where
438 toComplex = toComplexV
439 fromComplex = fromComplexV
440 comp v = toComplex (v,constant 0 (dim v))
441 conj = conjV
442 real = id
443 complex = comp
444
445instance Container Vector (Complex Double) where
446 toComplex = undefined -- can't match
447 fromComplex = undefined
448 comp = undefined
449 conj = undefined
450 real = comp
451 complex = id
452
453instance Container Matrix Double where
454 toComplex = uncurry $ liftMatrix2 $ curry toComplex
455 fromComplex z = (reshape c r, reshape c i)
456 where (r,i) = fromComplex (flatten z)
457 c = cols z
458 comp = liftMatrix comp
459 conj = liftMatrix conj
460 real = id
461 complex = comp
462
463instance Container Matrix (Complex Double) where
464 toComplex = undefined
465 fromComplex = undefined
466 comp = undefined
467 conj = undefined
468 real = comp
469 complex = id
470