diff options
Diffstat (limited to 'lib/LinearAlgebra')
-rw-r--r-- | lib/LinearAlgebra/Algorithms.hs | 4 | ||||
-rw-r--r-- | lib/LinearAlgebra/Linear.hs | 29 |
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 | ||
16 | module LinearAlgebra.Algorithms ( | 16 | module 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 |
61 | mXm :: (Num t, Field t) => Matrix t -> Matrix t -> Matrix t | 61 | mXm :: (Num t, Field t) => Matrix t -> Matrix t -> Matrix t |
62 | mXm = multiply RowMajor | 62 | mXm = multiply |
63 | 63 | ||
64 | -- | matrix - vector product | 64 | -- | matrix - vector product |
65 | mXv :: (Num t, Field t) => Matrix t -> Vector t -> Vector t | 65 | mXv :: (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 | ||
16 | module LinearAlgebra.Linear ( | 16 | module LinearAlgebra.Linear ( |
17 | Linear(..) | 17 | Linear(..), |
18 | toComplex, comp, | ||
19 | conj, | ||
20 | multiply, dot, outer | ||
18 | ) where | 21 | ) where |
19 | 22 | ||
20 | 23 | ||
21 | import Data.Packed.Internal | 24 | import Data.Packed.Internal |
25 | import Data.Packed.Matrix | ||
22 | import GSL.Vector | 26 | import GSL.Vector |
23 | import Complex | 27 | import 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 | ||
55 | dot :: (Field t) => Vector t -> Vector t -> t | ||
56 | dot 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 | -} | ||
71 | outer :: (Num t, Field t) => Vector t -> Vector t -> Matrix t | ||
72 | outer u v = asColumn u `multiply` asRow v | ||