summaryrefslogtreecommitdiff
path: root/lib/LinearAlgebra/Linear.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/LinearAlgebra/Linear.hs')
-rw-r--r--lib/LinearAlgebra/Linear.hs43
1 files changed, 7 insertions, 36 deletions
diff --git a/lib/LinearAlgebra/Linear.hs b/lib/LinearAlgebra/Linear.hs
index 85daa4a..3e6c55d 100644
--- a/lib/LinearAlgebra/Linear.hs
+++ b/lib/LinearAlgebra/Linear.hs
@@ -9,10 +9,10 @@ Maintainer : Alberto Ruiz (aruiz at um dot es)
9Stability : provisional 9Stability : provisional
10Portability : uses ffi 10Portability : uses ffi
11 11
12Basic optimized operations on vectors and matrices.
12 13
13-} 14-}
14----------------------------------------------------------------------------- 15-----------------------------------------------------------------------------
15-- #hide
16 16
17module LinearAlgebra.Linear ( 17module LinearAlgebra.Linear (
18 Linear(..), 18 Linear(..),
@@ -21,25 +21,22 @@ module LinearAlgebra.Linear (
21 21
22 22
23import Data.Packed.Internal 23import Data.Packed.Internal
24import Data.Packed.Matrix 24import Data.Packed
25import GSL.Vector 25import GSL.Vector
26import Complex 26import Complex
27 27
28-- | basic optimized operations 28-- | basic optimized operations
29class (Field e) => Linear c e where 29class (Container c e) => Linear c e where
30 scale :: e -> c e -> c e 30 scale :: e -> c e -> c e
31 scaleRecip :: e -> c e -> c e
32 addConstant :: e -> c e -> c e 31 addConstant :: e -> c e -> c e
33 add :: c e -> c e -> c e 32 add :: c e -> c e -> c e
34 sub :: c e -> c e -> c e 33 sub :: c e -> c e -> c e
34 -- | element by element multiplication
35 mul :: c e -> c e -> c e 35 mul :: c e -> c e -> c e
36 -- | element by element division
36 divide :: c e -> c e -> c e 37 divide :: c e -> c e -> c e
37 toComplex :: RealFloat e => (c e, c e) -> c (Complex e) 38 -- | scale the element by element reciprocal of the object: @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@
38 fromComplex :: RealFloat e => c (Complex e) -> (c e, c e) 39 scaleRecip :: e -> c e -> c e
39 comp :: RealFloat e => c e -> c (Complex e)
40 conj :: RealFloat e => c (Complex e) -> c (Complex e)
41 real :: c Double -> c e
42 complex :: c e -> c (Complex Double)
43 40
44instance Linear Vector Double where 41instance Linear Vector Double where
45 scale = vectorMapValR Scale 42 scale = vectorMapValR Scale
@@ -49,12 +46,6 @@ instance Linear Vector Double where
49 sub = vectorZipR Sub 46 sub = vectorZipR Sub
50 mul = vectorZipR Mul 47 mul = vectorZipR Mul
51 divide = vectorZipR Div 48 divide = vectorZipR Div
52 toComplex = Data.Packed.Internal.toComplex
53 fromComplex = Data.Packed.Internal.fromComplex
54 comp = Data.Packed.Internal.comp
55 conj = Data.Packed.Internal.conj
56 real = id
57 complex = LinearAlgebra.Linear.comp
58 49
59instance Linear Vector (Complex Double) where 50instance Linear Vector (Complex Double) where
60 scale = vectorMapValC Scale 51 scale = vectorMapValC Scale
@@ -64,12 +55,6 @@ instance Linear Vector (Complex Double) where
64 sub = vectorZipC Sub 55 sub = vectorZipC Sub
65 mul = vectorZipC Mul 56 mul = vectorZipC Mul
66 divide = vectorZipC Div 57 divide = vectorZipC Div
67 toComplex = undefined -- can't match
68 fromComplex = undefined
69 comp = undefined
70 conj = undefined
71 real = LinearAlgebra.Linear.comp
72 complex = id
73 58
74instance Linear Matrix Double where 59instance Linear Matrix Double where
75 scale x = liftMatrix (scale x) 60 scale x = liftMatrix (scale x)
@@ -79,14 +64,6 @@ instance Linear Matrix Double where
79 sub = liftMatrix2 sub 64 sub = liftMatrix2 sub
80 mul = liftMatrix2 mul 65 mul = liftMatrix2 mul
81 divide = liftMatrix2 divide 66 divide = liftMatrix2 divide
82 toComplex = uncurry $ liftMatrix2 $ curry LinearAlgebra.Linear.toComplex
83 fromComplex z = (reshape c r, reshape c i)
84 where (r,i) = LinearAlgebra.Linear.fromComplex (cdat z)
85 c = cols z
86 comp = liftMatrix Data.Packed.Internal.comp
87 conj = liftMatrix Data.Packed.Internal.conj
88 real = id
89 complex = LinearAlgebra.Linear.comp
90 67
91instance Linear Matrix (Complex Double) where 68instance Linear Matrix (Complex Double) where
92 scale x = liftMatrix (scale x) 69 scale x = liftMatrix (scale x)
@@ -96,12 +73,6 @@ instance Linear Matrix (Complex Double) where
96 sub = liftMatrix2 sub 73 sub = liftMatrix2 sub
97 mul = liftMatrix2 mul 74 mul = liftMatrix2 mul
98 divide = liftMatrix2 divide 75 divide = liftMatrix2 divide
99 toComplex = undefined
100 fromComplex = undefined
101 comp = undefined
102 conj = undefined
103 real = LinearAlgebra.Linear.comp
104 complex = id
105 76
106-------------------------------------------------- 77--------------------------------------------------
107 78