summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs114
1 files changed, 63 insertions, 51 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs
index 8694249..9059723 100644
--- a/lib/Data/Packed/Matrix.hs
+++ b/lib/Data/Packed/Matrix.hs
@@ -4,7 +4,6 @@
4{-# LANGUAGE MultiParamTypeClasses #-} 4{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE FunctionalDependencies #-} 5{-# LANGUAGE FunctionalDependencies #-}
6 6
7
8----------------------------------------------------------------------------- 7-----------------------------------------------------------------------------
9-- | 8-- |
10-- Module : Data.Packed.Matrix 9-- Module : Data.Packed.Matrix
@@ -22,6 +21,7 @@
22module Data.Packed.Matrix ( 21module Data.Packed.Matrix (
23 Element, RealElement, Container(..), 22 Element, RealElement, Container(..),
24 Convert(..), RealOf, ComplexOf, SingleOf, DoubleOf, ElementOf, 23 Convert(..), RealOf, ComplexOf, SingleOf, DoubleOf, ElementOf,
24 Precision(..), comp, real'', complex'',
25 AutoReal(..), 25 AutoReal(..),
26 Matrix,rows,cols, 26 Matrix,rows,cols,
27 (><), 27 (><),
@@ -471,53 +471,54 @@ toBlocksEvery r c m = toBlocks rs cs m where
471 471
472------------------------------------------------------------------- 472-------------------------------------------------------------------
473 473
474-- | conversion utilities 474-- | Supported single-double precision type pairs
475 475class (Element s, Element d) => Precision s d | s -> d, d -> s where
476class (Element t, Element (Complex t), RealFloat t) => RealElement t
477
478instance RealElement Double
479instance RealElement Float
480
481class (Element s, Element d) => Prec s d | s -> d, d -> s where
482 double2FloatG :: Vector d -> Vector s 476 double2FloatG :: Vector d -> Vector s
483 float2DoubleG :: Vector s -> Vector d 477 float2DoubleG :: Vector s -> Vector d
484 478
485instance Prec Float Double where 479instance Precision Float Double where
486 double2FloatG = double2FloatV 480 double2FloatG = double2FloatV
487 float2DoubleG = float2DoubleV 481 float2DoubleG = float2DoubleV
488 482
489instance Prec (Complex Float) (Complex Double) where 483instance Precision (Complex Float) (Complex Double) where
490 double2FloatG = asComplex . double2FloatV . asReal 484 double2FloatG = asComplex . double2FloatV . asReal
491 float2DoubleG = asComplex . float2DoubleV . asReal 485 float2DoubleG = asComplex . float2DoubleV . asReal
492 486
487-- | Supported real types
488class (Element t, Element (Complex t), RealFloat t) => RealElement t
489
490instance RealElement Double
491
492instance RealElement Float
493 493
494-- | Conversion utilities
494class Container c where 495class Container c where
495 toComplex :: (RealElement e) => (c e, c e) -> c (Complex e) 496 toComplex :: (RealElement e) => (c e, c e) -> c (Complex e)
496 fromComplex :: (RealElement e) => c (Complex e) -> (c e, c e) 497 fromComplex :: (RealElement e) => c (Complex e) -> (c e, c e)
497 comp :: (RealElement e) => c e -> c (Complex e) 498 complex' :: (RealElement e) => c e -> c (Complex e)
498 conj :: (RealElement e) => c (Complex e) -> c (Complex e) 499 conj :: (RealElement e) => c (Complex e) -> c (Complex e)
499 cmap :: (Element a, Element b) => (a -> b) -> c a -> c b 500 cmap :: (Element a, Element b) => (a -> b) -> c a -> c b
500 single :: Prec a b => c b -> c a 501 single' :: Precision a b => c b -> c a
501 double :: Prec a b => c a -> c b 502 double' :: Precision a b => c a -> c b
502 503
503instance Container Vector where 504instance Container Vector where
504 toComplex = toComplexV 505 toComplex = toComplexV
505 fromComplex = fromComplexV 506 fromComplex = fromComplexV
506 comp v = toComplex (v,constantD 0 (dim v)) 507 complex' v = toComplex (v,constantD 0 (dim v))
507 conj = conjV 508 conj = conjV
508 cmap = mapVector 509 cmap = mapVector
509 single = double2FloatG 510 single' = double2FloatG
510 double = float2DoubleG 511 double' = float2DoubleG
511 512
512instance Container Matrix where 513instance Container Matrix where
513 toComplex = uncurry $ liftMatrix2 $ curry toComplex 514 toComplex = uncurry $ liftMatrix2 $ curry toComplex
514 fromComplex z = (reshape c *** reshape c) . fromComplex . flatten $ z 515 fromComplex z = (reshape c *** reshape c) . fromComplex . flatten $ z
515 where c = cols z 516 where c = cols z
516 comp = liftMatrix comp 517 complex' = liftMatrix complex'
517 conj = liftMatrix conj 518 conj = liftMatrix conj
518 cmap f = liftMatrix (cmap f) 519 cmap f = liftMatrix (cmap f)
519 single = liftMatrix single 520 single' = liftMatrix single'
520 double = liftMatrix double 521 double' = liftMatrix double'
521 522
522------------------------------------------------------------------- 523-------------------------------------------------------------------
523 524
@@ -560,54 +561,65 @@ type instance ElementOf (Matrix a) = a
560 561
561-- | generic conversion functions 562-- | generic conversion functions
562class Convert t where 563class Convert t where
563 real' :: Container c => c (RealOf t) -> c t 564 real :: Container c => c (RealOf t) -> c t
564 complex' :: Container c => c t -> c (ComplexOf t) 565 complex :: Container c => c t -> c (ComplexOf t)
565 single' :: Container c => c t -> c (SingleOf t) 566 single :: Container c => c t -> c (SingleOf t)
566 double' :: Container c => c t -> c (DoubleOf t) 567 double :: Container c => c t -> c (DoubleOf t)
567 568
568instance Convert Double where 569instance Convert Double where
569 real' = id 570 real = id
570 complex' = comp 571 complex = complex'
571 single' = single 572 single = single'
572 double' = id 573 double = id
573 574
574instance Convert Float where 575instance Convert Float where
575 real' = id 576 real = id
576 complex' = comp 577 complex = complex'
577 single' = id 578 single = id
578 double' = double 579 double = double'
579 580
580instance Convert (Complex Double) where 581instance Convert (Complex Double) where
581 real' = comp 582 real = complex'
582 complex' = id 583 complex = id
583 single' = single 584 single = single'
584 double' = id 585 double = id
585 586
586instance Convert (Complex Float) where 587instance Convert (Complex Float) where
587 real' = comp 588 real = complex'
588 complex' = id 589 complex = id
589 single' = id 590 single = id
590 double' = double 591 double = double'
591 592
592------------------------------------------------------------------- 593-------------------------------------------------------------------
593 594
595
594-- | to be replaced by Convert 596-- | to be replaced by Convert
595class AutoReal t where 597class Convert t => AutoReal t where
596 real :: Container c => c Double -> c t 598 real''' :: Container c => c Double -> c t
597 complex :: Container c => c t -> c (Complex Double) 599 complex''' :: Container c => c t -> c (Complex Double)
598 600
599instance AutoReal Double where 601instance AutoReal Double where
600 real = real' 602 real''' = real
601 complex = complex' 603 complex''' = complex
602 604
603instance AutoReal (Complex Double) where 605instance AutoReal (Complex Double) where
604 real = real' 606 real''' = real
605 complex = complex' 607 complex''' = complex
606 608
607instance AutoReal Float where 609instance AutoReal Float where
608 real = real' . single 610 real''' = real . single
609 complex = double . complex' 611 complex''' = double . complex
610 612
611instance AutoReal (Complex Float) where 613instance AutoReal (Complex Float) where
612 real = real' . single 614 real''' = real . single
613 complex = double . complex' 615 complex''' = double . complex
616
617
618comp x = complex' x
619
620-- complex'' x = double (complex x)
621-- real'' x = real (single x)
622
623real'' x = real''' x
624complex'' x = complex''' x
625