diff options
Diffstat (limited to 'packages/base')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Static.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index 8019558..2e7c462 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs | |||
@@ -79,6 +79,7 @@ import Internal.Static | |||
79 | import Control.Arrow((***)) | 79 | import Control.Arrow((***)) |
80 | import Text.Printf | 80 | import Text.Printf |
81 | import Data.Type.Equality ((:~:)(Refl)) | 81 | import Data.Type.Equality ((:~:)(Refl)) |
82 | import Data.Bifunctor (first) | ||
82 | 83 | ||
83 | ud1 :: R n -> Vector ℝ | 84 | ud1 :: R n -> Vector ℝ |
84 | ud1 (R (Dim v)) = v | 85 | ud1 (R (Dim v)) = v |
@@ -534,6 +535,8 @@ class Domain field vec mat | mat -> vec field, vec -> mat field, field -> mat ve | |||
534 | dmmap :: forall n m. (KnownNat m, KnownNat n) => (field -> field) -> mat n m -> mat n m | 535 | dmmap :: forall n m. (KnownNat m, KnownNat n) => (field -> field) -> mat n m -> mat n m |
535 | outer :: forall n m. (KnownNat m, KnownNat n) => vec n -> vec m -> mat n m | 536 | outer :: forall n m. (KnownNat m, KnownNat n) => vec n -> vec m -> mat n m |
536 | zipWithVector :: forall n. KnownNat n => (field -> field -> field) -> vec n -> vec n -> vec n | 537 | zipWithVector :: forall n. KnownNat n => (field -> field -> field) -> vec n -> vec n -> vec n |
538 | det :: forall n. KnownNat n => mat n n -> field | ||
539 | invlndet :: forall n. KnownNat n => mat n n -> (mat n n, (field, field)) | ||
537 | 540 | ||
538 | 541 | ||
539 | instance Domain ℝ R L | 542 | instance Domain ℝ R L |
@@ -547,6 +550,8 @@ instance Domain ℝ R L | |||
547 | dmmap = mapL | 550 | dmmap = mapL |
548 | outer = outerR | 551 | outer = outerR |
549 | zipWithVector = zipWithR | 552 | zipWithVector = zipWithR |
553 | det = detL | ||
554 | invlndet = invlndetL | ||
550 | 555 | ||
551 | instance Domain ℂ C M | 556 | instance Domain ℂ C M |
552 | where | 557 | where |
@@ -559,6 +564,8 @@ instance Domain ℂ C M | |||
559 | dmmap = mapM' | 564 | dmmap = mapM' |
560 | outer = outerC | 565 | outer = outerC |
561 | zipWithVector = zipWithC | 566 | zipWithVector = zipWithC |
567 | det = detM | ||
568 | invlndet = invlndetM | ||
562 | 569 | ||
563 | -------------------------------------------------------------------------------- | 570 | -------------------------------------------------------------------------------- |
564 | 571 | ||
@@ -610,6 +617,11 @@ zipWithR f (extract -> x) (extract -> y) = mkR (LA.zipVectorWith f x y) | |||
610 | mapL :: (KnownNat n, KnownNat m) => (ℝ -> ℝ) -> L n m -> L n m | 617 | mapL :: (KnownNat n, KnownNat m) => (ℝ -> ℝ) -> L n m -> L n m |
611 | mapL f (unwrap -> m) = mkL (LA.cmap f m) | 618 | mapL f (unwrap -> m) = mkL (LA.cmap f m) |
612 | 619 | ||
620 | detL :: KnownNat n => Sq n -> ℝ | ||
621 | detL = LA.det . unwrap | ||
622 | |||
623 | invlndetL :: KnownNat n => Sq n -> (L n n, (ℝ, ℝ)) | ||
624 | invlndetL = first mkL . LA.invlndet . unwrap | ||
613 | 625 | ||
614 | -------------------------------------------------------------------------------- | 626 | -------------------------------------------------------------------------------- |
615 | 627 | ||
@@ -661,6 +673,12 @@ zipWithC f (extract -> x) (extract -> y) = mkC (LA.zipVectorWith f x y) | |||
661 | mapM' :: (KnownNat n, KnownNat m) => (ℂ -> ℂ) -> M n m -> M n m | 673 | mapM' :: (KnownNat n, KnownNat m) => (ℂ -> ℂ) -> M n m -> M n m |
662 | mapM' f (unwrap -> m) = mkM (LA.cmap f m) | 674 | mapM' f (unwrap -> m) = mkM (LA.cmap f m) |
663 | 675 | ||
676 | detM :: KnownNat n => M n n -> ℂ | ||
677 | detM = LA.det . unwrap | ||
678 | |||
679 | invlndetM :: KnownNat n => M n n -> (M n n, (ℂ, ℂ)) | ||
680 | invlndetM = first mkM . LA.invlndet . unwrap | ||
681 | |||
664 | 682 | ||
665 | -------------------------------------------------------------------------------- | 683 | -------------------------------------------------------------------------------- |
666 | 684 | ||