diff options
Diffstat (limited to 'packages/base/src/Internal/Numeric.hs')
-rw-r--r-- | packages/base/src/Internal/Numeric.hs | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/packages/base/src/Internal/Numeric.hs b/packages/base/src/Internal/Numeric.hs index a8ae2bb..e8c7440 100644 --- a/packages/base/src/Internal/Numeric.hs +++ b/packages/base/src/Internal/Numeric.hs | |||
@@ -49,7 +49,7 @@ class Element e => Container c e | |||
49 | scalar' :: e -> c e | 49 | scalar' :: e -> c e |
50 | scale' :: e -> c e -> c e | 50 | scale' :: e -> c e -> c e |
51 | addConstant :: e -> c e -> c e | 51 | addConstant :: e -> c e -> c e |
52 | add :: c e -> c e -> c e | 52 | add' :: c e -> c e -> c e |
53 | sub :: c e -> c e -> c e | 53 | sub :: c e -> c e -> c e |
54 | -- | element by element multiplication | 54 | -- | element by element multiplication |
55 | mul :: c e -> c e -> c e | 55 | mul :: c e -> c e -> c e |
@@ -100,7 +100,7 @@ instance Container Vector I | |||
100 | size' = dim | 100 | size' = dim |
101 | scale' = vectorMapValI Scale | 101 | scale' = vectorMapValI Scale |
102 | addConstant = vectorMapValI AddConstant | 102 | addConstant = vectorMapValI AddConstant |
103 | add = vectorZipI Add | 103 | add' = vectorZipI Add |
104 | sub = vectorZipI Sub | 104 | sub = vectorZipI Sub |
105 | mul = vectorZipI Mul | 105 | mul = vectorZipI Mul |
106 | equal u v = dim u == dim v && maxElement' (vectorMapI Abs (sub u v)) == 0 | 106 | equal u v = dim u == dim v && maxElement' (vectorMapI Abs (sub u v)) == 0 |
@@ -139,7 +139,7 @@ instance Container Vector Z | |||
139 | size' = dim | 139 | size' = dim |
140 | scale' = vectorMapValL Scale | 140 | scale' = vectorMapValL Scale |
141 | addConstant = vectorMapValL AddConstant | 141 | addConstant = vectorMapValL AddConstant |
142 | add = vectorZipL Add | 142 | add' = vectorZipL Add |
143 | sub = vectorZipL Sub | 143 | sub = vectorZipL Sub |
144 | mul = vectorZipL Mul | 144 | mul = vectorZipL Mul |
145 | equal u v = dim u == dim v && maxElement' (vectorMapL Abs (sub u v)) == 0 | 145 | equal u v = dim u == dim v && maxElement' (vectorMapL Abs (sub u v)) == 0 |
@@ -179,7 +179,7 @@ instance Container Vector Float | |||
179 | size' = dim | 179 | size' = dim |
180 | scale' = vectorMapValF Scale | 180 | scale' = vectorMapValF Scale |
181 | addConstant = vectorMapValF AddConstant | 181 | addConstant = vectorMapValF AddConstant |
182 | add = vectorZipF Add | 182 | add' = vectorZipF Add |
183 | sub = vectorZipF Sub | 183 | sub = vectorZipF Sub |
184 | mul = vectorZipF Mul | 184 | mul = vectorZipF Mul |
185 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 | 185 | equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 |
@@ -216,7 +216,7 @@ instance Container Vector Double | |||
216 | size' = dim | 216 | size' = dim |
217 | scale' = vectorMapValR Scale | 217 | scale' = vectorMapValR Scale |
218 | addConstant = vectorMapValR AddConstant | 218 | addConstant = vectorMapValR AddConstant |
219 | add = vectorZipR Add | 219 | add' = vectorZipR Add |
220 | sub = vectorZipR Sub | 220 | sub = vectorZipR Sub |
221 | mul = vectorZipR Mul | 221 | mul = vectorZipR Mul |
222 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 | 222 | equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 |
@@ -253,7 +253,7 @@ instance Container Vector (Complex Double) | |||
253 | size' = dim | 253 | size' = dim |
254 | scale' = vectorMapValC Scale | 254 | scale' = vectorMapValC Scale |
255 | addConstant = vectorMapValC AddConstant | 255 | addConstant = vectorMapValC AddConstant |
256 | add = vectorZipC Add | 256 | add' = vectorZipC Add |
257 | sub = vectorZipC Sub | 257 | sub = vectorZipC Sub |
258 | mul = vectorZipC Mul | 258 | mul = vectorZipC Mul |
259 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 259 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
@@ -289,7 +289,7 @@ instance Container Vector (Complex Float) | |||
289 | size' = dim | 289 | size' = dim |
290 | scale' = vectorMapValQ Scale | 290 | scale' = vectorMapValQ Scale |
291 | addConstant = vectorMapValQ AddConstant | 291 | addConstant = vectorMapValQ AddConstant |
292 | add = vectorZipQ Add | 292 | add' = vectorZipQ Add |
293 | sub = vectorZipQ Sub | 293 | sub = vectorZipQ Sub |
294 | mul = vectorZipQ Mul | 294 | mul = vectorZipQ Mul |
295 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 | 295 | equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 |
@@ -327,7 +327,7 @@ instance (Num a, Element a, Container Vector a) => Container Matrix a | |||
327 | size' = size | 327 | size' = size |
328 | scale' x = liftMatrix (scale' x) | 328 | scale' x = liftMatrix (scale' x) |
329 | addConstant x = liftMatrix (addConstant x) | 329 | addConstant x = liftMatrix (addConstant x) |
330 | add = liftMatrix2 add | 330 | add' = liftMatrix2 add' |
331 | sub = liftMatrix2 sub | 331 | sub = liftMatrix2 sub |
332 | mul = liftMatrix2 mul | 332 | mul = liftMatrix2 mul |
333 | equal a b = cols a == cols b && flatten a `equal` flatten b | 333 | equal a b = cols a == cols b && flatten a `equal` flatten b |
@@ -387,9 +387,6 @@ scalar = scalar' | |||
387 | conj :: Container c e => c e -> c e | 387 | conj :: Container c e => c e -> c e |
388 | conj = conj' | 388 | conj = conj' |
389 | 389 | ||
390 | -- | multiplication by scalar | ||
391 | scale :: Container c e => e -> c e -> c e | ||
392 | scale = scale' | ||
393 | 390 | ||
394 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e | 391 | arctan2 :: (Fractional e, Container c e) => c e -> c e -> c e |
395 | arctan2 = arctan2' | 392 | arctan2 = arctan2' |
@@ -581,6 +578,10 @@ class ( Container Vector t | |||
581 | , Konst t (Int,Int) Matrix | 578 | , Konst t (Int,Int) Matrix |
582 | , CTrans t | 579 | , CTrans t |
583 | , Product t | 580 | , Product t |
581 | , Additive (Vector t) | ||
582 | , Additive (Matrix t) | ||
583 | , Linear t Vector | ||
584 | , Linear t Matrix | ||
584 | ) => Numeric t | 585 | ) => Numeric t |
585 | 586 | ||
586 | instance Numeric Double | 587 | instance Numeric Double |
@@ -912,11 +913,30 @@ instance (CTrans t, Container Vector t) => Transposable (Matrix t) (Matrix t) | |||
912 | tr = ctrans | 913 | tr = ctrans |
913 | tr' = trans | 914 | tr' = trans |
914 | 915 | ||
915 | class Linear t v | 916 | class Additive c |
916 | where | 917 | where |
917 | scalarL :: t -> v | 918 | add :: c -> c -> c |
918 | addL :: v -> v -> v | 919 | |
919 | scaleL :: t -> v -> v | 920 | class Linear t c |
921 | where | ||
922 | scale :: t -> c t -> c t | ||
923 | |||
924 | |||
925 | instance Container Vector t => Linear t Vector | ||
926 | where | ||
927 | scale = scale' | ||
928 | |||
929 | instance Container Matrix t => Linear t Matrix | ||
930 | where | ||
931 | scale = scale' | ||
932 | |||
933 | instance Container Vector t => Additive (Vector t) | ||
934 | where | ||
935 | add = add' | ||
936 | |||
937 | instance Container Matrix t => Additive (Matrix t) | ||
938 | where | ||
939 | add = add' | ||
920 | 940 | ||
921 | 941 | ||
922 | class Testable t | 942 | class Testable t |