diff options
Diffstat (limited to 'lib/LinearAlgebra/Linear.hs')
-rw-r--r-- | lib/LinearAlgebra/Linear.hs | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/LinearAlgebra/Linear.hs b/lib/LinearAlgebra/Linear.hs index 53e011f..a2071ed 100644 --- a/lib/LinearAlgebra/Linear.hs +++ b/lib/LinearAlgebra/Linear.hs | |||
@@ -15,8 +15,6 @@ Portability : uses ffi | |||
15 | 15 | ||
16 | module LinearAlgebra.Linear ( | 16 | module LinearAlgebra.Linear ( |
17 | Linear(..), | 17 | Linear(..), |
18 | toComplex, comp, | ||
19 | conj, | ||
20 | multiply, dot, outer | 18 | multiply, dot, outer |
21 | ) where | 19 | ) where |
22 | 20 | ||
@@ -33,6 +31,10 @@ class (Field e) => Linear c e where | |||
33 | add :: c e -> c e -> c e | 31 | add :: c e -> c e -> c e |
34 | sub :: c e -> c e -> c e | 32 | sub :: c e -> c e -> c e |
35 | mul :: c e -> c e -> c e | 33 | mul :: c e -> c e -> c e |
34 | toComplex :: RealFloat e => (c e, c e) -> c (Complex e) | ||
35 | fromComplex :: RealFloat e => c (Complex e) -> (c e, c e) | ||
36 | comp :: RealFloat e => c e -> c (Complex e) | ||
37 | conj :: RealFloat e => c (Complex e) -> c (Complex e) | ||
36 | 38 | ||
37 | instance Linear Vector Double where | 39 | instance Linear Vector Double where |
38 | scale = vectorMapValR Scale | 40 | scale = vectorMapValR Scale |
@@ -40,6 +42,10 @@ instance Linear Vector Double where | |||
40 | add = vectorZipR Add | 42 | add = vectorZipR Add |
41 | sub = vectorZipR Sub | 43 | sub = vectorZipR Sub |
42 | mul = vectorZipR Mul | 44 | mul = vectorZipR Mul |
45 | toComplex = Data.Packed.Internal.toComplex | ||
46 | fromComplex = Data.Packed.Internal.fromComplex | ||
47 | comp = Data.Packed.Internal.comp | ||
48 | conj = Data.Packed.Internal.conj | ||
43 | 49 | ||
44 | instance Linear Vector (Complex Double) where | 50 | instance Linear Vector (Complex Double) where |
45 | scale = vectorMapValC Scale | 51 | scale = vectorMapValC Scale |
@@ -47,6 +53,34 @@ instance Linear Vector (Complex Double) where | |||
47 | add = vectorZipC Add | 53 | add = vectorZipC Add |
48 | sub = vectorZipC Sub | 54 | sub = vectorZipC Sub |
49 | mul = vectorZipC Mul | 55 | mul = vectorZipC Mul |
56 | toComplex = undefined -- can't match | ||
57 | fromComplex = undefined | ||
58 | comp = undefined | ||
59 | conj = undefined | ||
60 | |||
61 | instance Linear Matrix Double where | ||
62 | scale x = liftMatrix (scale x) | ||
63 | addConstant x = liftMatrix (addConstant x) | ||
64 | add = liftMatrix2 add | ||
65 | sub = liftMatrix2 sub | ||
66 | mul = liftMatrix2 mul | ||
67 | toComplex = uncurry $ liftMatrix2 $ curry LinearAlgebra.Linear.toComplex | ||
68 | fromComplex z = (reshape c r, reshape c i) | ||
69 | where (r,i) = LinearAlgebra.Linear.fromComplex (cdat z) | ||
70 | c = cols z | ||
71 | comp = liftMatrix Data.Packed.Internal.comp | ||
72 | conj = liftMatrix Data.Packed.Internal.conj | ||
73 | |||
74 | instance Linear Matrix (Complex Double) where | ||
75 | scale x = liftMatrix (scale x) | ||
76 | addConstant x = liftMatrix (addConstant x) | ||
77 | add = liftMatrix2 add | ||
78 | sub = liftMatrix2 sub | ||
79 | mul = liftMatrix2 mul | ||
80 | toComplex = undefined | ||
81 | fromComplex = undefined | ||
82 | comp = undefined | ||
83 | conj = undefined | ||
50 | 84 | ||
51 | -------------------------------------------------- | 85 | -------------------------------------------------- |
52 | 86 | ||
@@ -58,8 +92,6 @@ dot u v = dat (multiply r c) `at` 0 | |||
58 | c = asColumn v | 92 | c = asColumn v |
59 | 93 | ||
60 | 94 | ||
61 | |||
62 | |||
63 | {- | Outer product of two vectors. | 95 | {- | Outer product of two vectors. |
64 | 96 | ||
65 | @\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3] | 97 | @\> 'fromList' [1,2,3] \`outer\` 'fromList' [5,2,3] |