diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/THANKS.md | 2 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Static.hs | 27 |
2 files changed, 24 insertions, 5 deletions
diff --git a/packages/base/THANKS.md b/packages/base/THANKS.md index 55a428c..34675d3 100644 --- a/packages/base/THANKS.md +++ b/packages/base/THANKS.md | |||
@@ -207,3 +207,5 @@ module reorganization, monadic mapVectorM, and many other improvements. | |||
207 | 207 | ||
208 | - Patrik Jansson changed meanCov and gaussianSample to use Herm type. Fixed stack.yaml. | 208 | - Patrik Jansson changed meanCov and gaussianSample to use Herm type. Fixed stack.yaml. |
209 | 209 | ||
210 | - Justin Le added NFData instances for Static types and added mapping and outer product methods to Domain. | ||
211 | |||
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index 4de4d7a..bd0e593 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs | |||
@@ -50,6 +50,8 @@ module Numeric.LinearAlgebra.Static( | |||
50 | -- * Factorizations | 50 | -- * Factorizations |
51 | svd, withCompactSVD, svdTall, svdFlat, Eigen(..), | 51 | svd, withCompactSVD, svdTall, svdFlat, Eigen(..), |
52 | withNullspace, qr, chol, | 52 | withNullspace, qr, chol, |
53 | -- * Norms | ||
54 | Normed(..), | ||
53 | -- * Misc | 55 | -- * Misc |
54 | mean, | 56 | mean, |
55 | Disp(..), Domain(..), | 57 | Disp(..), Domain(..), |
@@ -418,7 +420,7 @@ class Domain field vec mat | mat -> vec field, vec -> mat field, field -> mat ve | |||
418 | diagR :: forall m n k . (KnownNat m, KnownNat n, KnownNat k) => field -> vec k -> mat m n | 420 | diagR :: forall m n k . (KnownNat m, KnownNat n, KnownNat k) => field -> vec k -> mat m n |
419 | dvmap :: forall n. (field -> field) -> vec n -> vec n | 421 | dvmap :: forall n. (field -> field) -> vec n -> vec n |
420 | dmmap :: forall n m. (field -> field) -> mat n m -> mat n m | 422 | dmmap :: forall n m. (field -> field) -> mat n m -> mat n m |
421 | outer :: forall n m. vec n -> vec m -> mat n m | 423 | outer :: forall n m. (KnownNat m, KnownNat n) => vec n -> vec m -> mat n m |
422 | 424 | ||
423 | 425 | ||
424 | instance Domain ℝ R L | 426 | instance Domain ℝ R L |
@@ -481,8 +483,8 @@ crossR (extract -> x) (extract -> y) = vec3 z1 z2 z3 | |||
481 | z2 = x!2*y!0-x!0*y!2 | 483 | z2 = x!2*y!0-x!0*y!2 |
482 | z3 = x!0*y!1-x!1*y!0 | 484 | z3 = x!0*y!1-x!1*y!0 |
483 | 485 | ||
484 | outerR :: R n -> R m -> L n m | 486 | outerR :: (KnownNat m, KnownNat n) => R n -> R m -> L n m |
485 | outerR (R (Dim x)) (R (Dim y)) = mkL (LA.outer x y) | 487 | outerR (extract -> x) (extract -> y) = mkL (LA.outer x y) |
486 | 488 | ||
487 | mapR :: (ℝ -> ℝ) -> R n -> R n | 489 | mapR :: (ℝ -> ℝ) -> R n -> R n |
488 | mapR f (R (Dim v)) = R (Dim (LA.cmap f v)) | 490 | mapR f (R (Dim v)) = R (Dim (LA.cmap f v)) |
@@ -528,8 +530,8 @@ crossC (extract -> x) (extract -> y) = mkC (LA.fromList [z1, z2, z3]) | |||
528 | z2 = x!2*y!0-x!0*y!2 | 530 | z2 = x!2*y!0-x!0*y!2 |
529 | z3 = x!0*y!1-x!1*y!0 | 531 | z3 = x!0*y!1-x!1*y!0 |
530 | 532 | ||
531 | outerC :: C n -> C m -> M n m | 533 | outerC :: (KnownNat m, KnownNat n) => C n -> C m -> M n m |
532 | outerC (C (Dim x)) (C (Dim y)) = mkM (LA.outer x y) | 534 | outerC (extract -> x) (extract -> y) = mkM (LA.outer x y) |
533 | 535 | ||
534 | mapC :: (ℂ -> ℂ) -> C n -> C n | 536 | mapC :: (ℂ -> ℂ) -> C n -> C n |
535 | mapC f (C (Dim v)) = C (Dim (LA.cmap f v)) | 537 | mapC f (C (Dim v)) = C (Dim (LA.cmap f v)) |
@@ -643,3 +645,18 @@ instance (KnownNat n', KnownNat m') => Testable (L n' m') | |||
643 | where | 645 | where |
644 | checkT _ = test | 646 | checkT _ = test |
645 | 647 | ||
648 | -------------------------------------------------------------------------------- | ||
649 | |||
650 | instance KnownNat n => Normed (R n) | ||
651 | where | ||
652 | norm_0 v = norm_0 (extract v) | ||
653 | norm_1 v = norm_1 (extract v) | ||
654 | norm_2 v = norm_2 (extract v) | ||
655 | norm_Inf v = norm_Inf (extract v) | ||
656 | |||
657 | instance (KnownNat m, KnownNat n) => Normed (L m n) | ||
658 | where | ||
659 | norm_0 m = norm_0 (extract m) | ||
660 | norm_1 m = norm_1 (extract m) | ||
661 | norm_2 m = norm_2 (extract m) | ||
662 | norm_Inf m = norm_Inf (extract m) | ||