summaryrefslogtreecommitdiff
path: root/packages/base/src
diff options
context:
space:
mode:
authorJustin Le <justin@jle.im>2016-06-01 15:54:30 -0700
committerJustin Le <justin@jle.im>2016-06-01 15:54:30 -0700
commitd1dcad5765bcb166a8890d67da9f631632f43149 (patch)
treec92a4439a18e25b90db2725ce5d3028fcaedb6b8 /packages/base/src
parent28da346162c7b7b20c4b231ee1796f164789e555 (diff)
added matrix inverse to Domain
Diffstat (limited to 'packages/base/src')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Static.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs
index fafbf81..8175ff5 100644
--- a/packages/base/src/Numeric/LinearAlgebra/Static.hs
+++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs
@@ -79,7 +79,7 @@ import Internal.Static
79import Control.Arrow((***)) 79import Control.Arrow((***))
80import Text.Printf 80import Text.Printf
81import Data.Type.Equality ((:~:)(Refl)) 81import Data.Type.Equality ((:~:)(Refl))
82import Data.Bifunctor (first) 82import qualified Data.Bifunctor as BF (first)
83 83
84ud1 :: R n -> Vector ℝ 84ud1 :: R n -> Vector ℝ
85ud1 (R (Dim v)) = v 85ud1 (R (Dim v)) = v
@@ -539,6 +539,7 @@ class Domain field vec mat | mat -> vec field, vec -> mat field, field -> mat ve
539 invlndet :: forall n. KnownNat n => mat n n -> (mat n n, (field, field)) 539 invlndet :: forall n. KnownNat n => mat n n -> (mat n n, (field, field))
540 expm :: forall n. KnownNat n => mat n n -> mat n n 540 expm :: forall n. KnownNat n => mat n n -> mat n n
541 sqrtm :: forall n. KnownNat n => mat n n -> mat n n 541 sqrtm :: forall n. KnownNat n => mat n n -> mat n n
542 inv :: forall n. KnownNat n => mat n n -> mat n n
542 543
543 544
544instance Domain ℝ R L 545instance Domain ℝ R L
@@ -556,6 +557,7 @@ instance Domain ℝ R L
556 invlndet = invlndetL 557 invlndet = invlndetL
557 expm = expmL 558 expm = expmL
558 sqrtm = sqrtmL 559 sqrtm = sqrtmL
560 inv = invL
559 561
560instance Domain ℂ C M 562instance Domain ℂ C M
561 where 563 where
@@ -572,6 +574,7 @@ instance Domain ℂ C M
572 invlndet = invlndetM 574 invlndet = invlndetM
573 expm = expmM 575 expm = expmM
574 sqrtm = sqrtmM 576 sqrtm = sqrtmM
577 inv = invM
575 578
576-------------------------------------------------------------------------------- 579--------------------------------------------------------------------------------
577 580
@@ -627,7 +630,7 @@ detL :: KnownNat n => Sq n -> ℝ
627detL = LA.det . unwrap 630detL = LA.det . unwrap
628 631
629invlndetL :: KnownNat n => Sq n -> (L n n, (ℝ, ℝ)) 632invlndetL :: KnownNat n => Sq n -> (L n n, (ℝ, ℝ))
630invlndetL = first mkL . LA.invlndet . unwrap 633invlndetL = BF.first mkL . LA.invlndet . unwrap
631 634
632expmL :: KnownNat n => Sq n -> Sq n 635expmL :: KnownNat n => Sq n -> Sq n
633expmL = overMatL' LA.expm 636expmL = overMatL' LA.expm
@@ -635,6 +638,9 @@ expmL = overMatL' LA.expm
635sqrtmL :: KnownNat n => Sq n -> Sq n 638sqrtmL :: KnownNat n => Sq n -> Sq n
636sqrtmL = overMatL' LA.sqrtm 639sqrtmL = overMatL' LA.sqrtm
637 640
641invL :: KnownNat n => Sq n -> Sq n
642invL = overMatL' LA.inv
643
638-------------------------------------------------------------------------------- 644--------------------------------------------------------------------------------
639 645
640mulC :: forall m k n. (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n 646mulC :: forall m k n. (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n
@@ -689,7 +695,7 @@ detM :: KnownNat n => M n n -> ℂ
689detM = LA.det . unwrap 695detM = LA.det . unwrap
690 696
691invlndetM :: KnownNat n => M n n -> (M n n, (ℂ, ℂ)) 697invlndetM :: KnownNat n => M n n -> (M n n, (ℂ, ℂ))
692invlndetM = first mkM . LA.invlndet . unwrap 698invlndetM = BF.first mkM . LA.invlndet . unwrap
693 699
694expmM :: KnownNat n => M n n -> M n n 700expmM :: KnownNat n => M n n -> M n n
695expmM = overMatM' LA.expm 701expmM = overMatM' LA.expm
@@ -697,6 +703,8 @@ expmM = overMatM' LA.expm
697sqrtmM :: KnownNat n => M n n -> M n n 703sqrtmM :: KnownNat n => M n n -> M n n
698sqrtmM = overMatM' LA.sqrtm 704sqrtmM = overMatM' LA.sqrtm
699 705
706invM :: KnownNat n => M n n -> M n n
707invM = overMatM' LA.inv
700 708
701-------------------------------------------------------------------------------- 709--------------------------------------------------------------------------------
702 710