summaryrefslogtreecommitdiff
path: root/lib/LinearAlgebra
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LinearAlgebra')
-rw-r--r--lib/LinearAlgebra/Algorithms.hs4
-rw-r--r--lib/LinearAlgebra/Linear.hs29
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/LinearAlgebra/Algorithms.hs b/lib/LinearAlgebra/Algorithms.hs
index 4ac6dde..192c0d6 100644
--- a/lib/LinearAlgebra/Algorithms.hs
+++ b/lib/LinearAlgebra/Algorithms.hs
@@ -14,7 +14,7 @@ Portability : uses ffi
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15 15
16module LinearAlgebra.Algorithms ( 16module LinearAlgebra.Algorithms (
17 mXm, mXv, vXm, 17 mXv, vXm,
18 inv, 18 inv,
19 pinv, 19 pinv,
20 pinvTol, 20 pinvTol,
@@ -59,7 +59,7 @@ i = 0:+1
59 59
60-- | matrix product 60-- | matrix product
61mXm :: (Num t, Field t) => Matrix t -> Matrix t -> Matrix t 61mXm :: (Num t, Field t) => Matrix t -> Matrix t -> Matrix t
62mXm = multiply RowMajor 62mXm = multiply
63 63
64-- | matrix - vector product 64-- | matrix - vector product
65mXv :: (Num t, Field t) => Matrix t -> Vector t -> Vector t 65mXv :: (Num t, Field t) => Matrix t -> Vector t -> Vector t
diff --git a/lib/LinearAlgebra/Linear.hs b/lib/LinearAlgebra/Linear.hs
index 5c5bf0d..51b32f5 100644
--- a/lib/LinearAlgebra/Linear.hs
+++ b/lib/LinearAlgebra/Linear.hs
@@ -14,11 +14,15 @@ Portability : uses ffi
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15 15
16module LinearAlgebra.Linear ( 16module LinearAlgebra.Linear (
17 Linear(..) 17 Linear(..),
18 toComplex, comp,
19 conj,
20 multiply, dot, outer
18) where 21) where
19 22
20 23
21import Data.Packed.Internal 24import Data.Packed.Internal
25import Data.Packed.Matrix
22import GSL.Vector 26import GSL.Vector
23import Complex 27import Complex
24 28
@@ -43,3 +47,26 @@ instance Linear Vector (Complex Double) where
43 add = vectorZipC Add 47 add = vectorZipC Add
44 sub = vectorZipC Sub 48 sub = vectorZipC Sub
45 mul = vectorZipC Mul 49 mul = vectorZipC Mul
50
51--------------------------------------------------
52
53
54-- | euclidean inner product
55dot :: (Field t) => Vector t -> Vector t -> t
56dot u v = dat (multiply r c) `at` 0
57 where r = asRow u
58 c = asColumn v
59
60
61
62
63{- | Outer product of two vectors.
64
65@\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3]
66(3><3)
67 [ 5.0, 2.0, 3.0
68 , 10.0, 4.0, 6.0
69 , 15.0, 6.0, 9.0 ]@
70-}
71outer :: (Num t, Field t) => Vector t -> Vector t -> Matrix t
72outer u v = asColumn u `multiply` asRow v