summaryrefslogtreecommitdiff
path: root/packages/base/src/Numeric/LinearAlgebra/Static.hs
diff options
context:
space:
mode:
authorJustin Le <justin@jle.im>2016-01-07 00:09:52 -0800
committerJustin Le <justin@jle.im>2016-01-07 00:09:52 -0800
commitcc18707dc26ae27b338bc7ff033921b7e4946294 (patch)
treec82de5201eb04fb7dc6594b6fa718d954d1882c4 /packages/base/src/Numeric/LinearAlgebra/Static.hs
parente97a22d5bbdde5b96d9401a7abb25534a2d45bd1 (diff)
parent0fc937994fb46bd3c4f2679165e414a89746cea6 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'packages/base/src/Numeric/LinearAlgebra/Static.hs')
-rw-r--r--packages/base/src/Numeric/LinearAlgebra/Static.hs27
1 files changed, 22 insertions, 5 deletions
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
424instance Domain ℝ R L 426instance 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
484outerR :: R n -> R m -> L n m 486outerR :: (KnownNat m, KnownNat n) => R n -> R m -> L n m
485outerR (R (Dim x)) (R (Dim y)) = mkL (LA.outer x y) 487outerR (extract -> x) (extract -> y) = mkL (LA.outer x y)
486 488
487mapR :: (ℝ -> ℝ) -> R n -> R n 489mapR :: (ℝ -> ℝ) -> R n -> R n
488mapR f (R (Dim v)) = R (Dim (LA.cmap f v)) 490mapR 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
531outerC :: C n -> C m -> M n m 533outerC :: (KnownNat m, KnownNat n) => C n -> C m -> M n m
532outerC (C (Dim x)) (C (Dim y)) = mkM (LA.outer x y) 534outerC (extract -> x) (extract -> y) = mkM (LA.outer x y)
533 535
534mapC :: (ℂ -> ℂ) -> C n -> C n 536mapC :: (ℂ -> ℂ) -> C n -> C n
535mapC f (C (Dim v)) = C (Dim (LA.cmap f v)) 537mapC 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
650instance 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
657instance (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)