summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Instances.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Instances.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs
index 147537d..334ccff 100644
--- a/lib/Numeric/LinearAlgebra/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Instances.hs
@@ -83,18 +83,26 @@ compat' m1 m2 = rows m1 == 1 && cols m1 == 1
83instance (Eq a, Element a) => Eq (Vector a) where 83instance (Eq a, Element a) => Eq (Vector a) where
84 a == b = dim a == dim b && toList a == toList b 84 a == b = dim a == dim b && toList a == toList b
85 85
86instance (Linear Vector a) => Num (Vector a) where 86instance Num (Vector Double) where
87 (+) = adaptScalar addConstant add (flip addConstant) 87 (+) = adaptScalar addConstant add (flip addConstant)
88 negate = scale (-1) 88 negate = scale (-1)
89 (*) = adaptScalar scale mul (flip scale) 89 (*) = adaptScalar scale mul (flip scale)
90 signum = liftVector signum 90 signum = vectorMapR Sign
91 abs = liftVector abs 91 abs = vectorMapR Abs
92 fromInteger = fromList . return . fromInteger
93
94instance Num (Vector (Complex Double)) where
95 (+) = adaptScalar addConstant add (flip addConstant)
96 negate = scale (-1)
97 (*) = adaptScalar scale mul (flip scale)
98 signum = vectorMapC Sign
99 abs = vectorMapC Abs
92 fromInteger = fromList . return . fromInteger 100 fromInteger = fromList . return . fromInteger
93 101
94instance (Eq a, Element a) => Eq (Matrix a) where 102instance (Eq a, Element a) => Eq (Matrix a) where
95 a == b = cols a == cols b && flatten a == flatten b 103 a == b = cols a == cols b && flatten a == flatten b
96 104
97instance (Linear Vector a) => Num (Matrix a) where 105instance (Linear Matrix a, Num (Vector a)) => Num (Matrix a) where
98 (+) = liftMatrix2' (+) 106 (+) = liftMatrix2' (+)
99 (-) = liftMatrix2' (-) 107 (-) = liftMatrix2' (-)
100 negate = liftMatrix negate 108 negate = liftMatrix negate
@@ -105,7 +113,7 @@ instance (Linear Vector a) => Num (Matrix a) where
105 113
106--------------------------------------------------- 114---------------------------------------------------
107 115
108instance (Linear Vector a) => Fractional (Vector a) where 116instance (Linear Vector a, Num (Vector a)) => Fractional (Vector a) where
109 fromRational n = fromList [fromRational n] 117 fromRational n = fromList [fromRational n]
110 (/) = adaptScalar f divide g where 118 (/) = adaptScalar f divide g where
111 r `f` v = scaleRecip r v 119 r `f` v = scaleRecip r v
@@ -113,7 +121,7 @@ instance (Linear Vector a) => Fractional (Vector a) where
113 121
114------------------------------------------------------- 122-------------------------------------------------------
115 123
116instance (Linear Vector a, Fractional (Vector a)) => Fractional (Matrix a) where 124instance (Linear Vector a, Fractional (Vector a), Num (Matrix a)) => Fractional (Matrix a) where
117 fromRational n = (1><1) [fromRational n] 125 fromRational n = (1><1) [fromRational n]
118 (/) = liftMatrix2' (/) 126 (/) = liftMatrix2' (/)
119 127
@@ -161,7 +169,7 @@ instance Floating (Vector (Complex Double)) where
161 169
162----------------------------------------------------------- 170-----------------------------------------------------------
163 171
164instance (Linear Vector a, Floating (Vector a)) => Floating (Matrix a) where 172instance (Linear Vector a, Floating (Vector a), Fractional (Matrix a)) => Floating (Matrix a) where
165 sin = liftMatrix sin 173 sin = liftMatrix sin
166 cos = liftMatrix cos 174 cos = liftMatrix cos
167 tan = liftMatrix tan 175 tan = liftMatrix tan