diff options
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 49 |
1 files changed, 48 insertions, 1 deletions
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 | ||
15 | module Data.Packed.Matrix ( | 16 | module 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 | ||
429 | class (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 | |||
437 | instance 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 | |||
445 | instance 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 | |||
453 | instance 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 | |||
463 | instance Container Matrix (Complex Double) where | ||
464 | toComplex = undefined | ||
465 | fromComplex = undefined | ||
466 | comp = undefined | ||
467 | conj = undefined | ||
468 | real = comp | ||
469 | complex = id | ||
470 | |||