summaryrefslogtreecommitdiff
path: root/packages/base/src
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-05-22 19:44:11 +0200
committerAlberto Ruiz <aruiz@um.es>2015-05-22 19:44:11 +0200
commit288ce45da83f2787150e00194065a0212763c902 (patch)
tree2e3e282b9eb2340346f64c2cf627d73e72933d8f /packages/base/src
parente635f3889aed9b4bf7ef02c98945e9065d114df3 (diff)
conj to SContainer, tr on CInt
Diffstat (limited to 'packages/base/src')
-rw-r--r--packages/base/src/Data/Packed/Internal/Numeric.hs35
1 files changed, 18 insertions, 17 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs
index f1b4898..354863f 100644
--- a/packages/base/src/Data/Packed/Internal/Numeric.hs
+++ b/packages/base/src/Data/Packed/Internal/Numeric.hs
@@ -117,6 +117,7 @@ m ¿¿ ec = trans (trans m ?? ec)
117-- | Basic element-by-element functions for numeric containers 117-- | Basic element-by-element functions for numeric containers
118class Element e => SContainer c e 118class Element e => SContainer c e
119 where 119 where
120 conj' :: c e -> c e
120 size' :: c e -> IndexOf c 121 size' :: c e -> IndexOf c
121 scalar' :: e -> c e 122 scalar' :: e -> c e
122 scale' :: e -> c e -> c e 123 scale' :: e -> c e -> c e
@@ -156,9 +157,8 @@ class Element e => SContainer c e
156 157
157 158
158-- | Basic element-by-element functions for numeric containers 159-- | Basic element-by-element functions for numeric containers
159class (Complexable c, Fractional e, SContainer c e) => Container c e 160class (Fractional e, SContainer c e) => Container c e
160 where 161 where
161 conj' :: c e -> c e
162 -- | scale the element by element reciprocal of the object: 162 -- | scale the element by element reciprocal of the object:
163 -- 163 --
164 -- @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@ 164 -- @scaleRecip 2 (fromList [5,i]) == 2 |> [0.4 :+ 0.0,0.0 :+ (-2.0)]@
@@ -174,6 +174,7 @@ class (Complexable c, Fractional e, SContainer c e) => Container c e
174 174
175instance SContainer Vector CInt 175instance SContainer Vector CInt
176 where 176 where
177 conj' = id
177 size' = dim 178 size' = dim
178-- scale' = vectorMapValF Scale 179-- scale' = vectorMapValF Scale
179-- addConstant = vectorMapValF AddConstant 180-- addConstant = vectorMapValF AddConstant
@@ -201,6 +202,7 @@ instance SContainer Vector CInt
201 202
202instance SContainer Vector Float 203instance SContainer Vector Float
203 where 204 where
205 conj' = id
204 size' = dim 206 size' = dim
205 scale' = vectorMapValF Scale 207 scale' = vectorMapValF Scale
206 addConstant = vectorMapValF AddConstant 208 addConstant = vectorMapValF AddConstant
@@ -230,11 +232,12 @@ instance Container Vector Float
230 scaleRecip = vectorMapValF Recip 232 scaleRecip = vectorMapValF Recip
231 divide = vectorZipF Div 233 divide = vectorZipF Div
232 arctan2' = vectorZipF ATan2 234 arctan2' = vectorZipF ATan2
233 conj' = id 235
234 236
235 237
236instance SContainer Vector Double 238instance SContainer Vector Double
237 where 239 where
240 conj' = id
238 size' = dim 241 size' = dim
239 scale' = vectorMapValR Scale 242 scale' = vectorMapValR Scale
240 addConstant = vectorMapValR AddConstant 243 addConstant = vectorMapValR AddConstant
@@ -264,10 +267,11 @@ instance Container Vector Double
264 scaleRecip = vectorMapValR Recip 267 scaleRecip = vectorMapValR Recip
265 divide = vectorZipR Div 268 divide = vectorZipR Div
266 arctan2' = vectorZipR ATan2 269 arctan2' = vectorZipR ATan2
267 conj' = id 270
268 271
269instance SContainer Vector (Complex Double) 272instance SContainer Vector (Complex Double)
270 where 273 where
274 conj' = conjugateC
271 size' = dim 275 size' = dim
272 scale' = vectorMapValC Scale 276 scale' = vectorMapValC Scale
273 addConstant = vectorMapValC AddConstant 277 addConstant = vectorMapValC AddConstant
@@ -298,11 +302,10 @@ instance Container Vector (Complex Double)
298 scaleRecip = vectorMapValC Recip 302 scaleRecip = vectorMapValC Recip
299 divide = vectorZipC Div 303 divide = vectorZipC Div
300 arctan2' = vectorZipC ATan2 304 arctan2' = vectorZipC ATan2
301 conj' = conjugateC
302
303 305
304instance SContainer Vector (Complex Float) 306instance SContainer Vector (Complex Float)
305 where 307 where
308 conj' = conjugateQ
306 size' = dim 309 size' = dim
307 scale' = vectorMapValQ Scale 310 scale' = vectorMapValQ Scale
308 addConstant = vectorMapValQ AddConstant 311 addConstant = vectorMapValQ AddConstant
@@ -332,13 +335,12 @@ instance Container Vector (Complex Float)
332 scaleRecip = vectorMapValQ Recip 335 scaleRecip = vectorMapValQ Recip
333 divide = vectorZipQ Div 336 divide = vectorZipQ Div
334 arctan2' = vectorZipQ ATan2 337 arctan2' = vectorZipQ ATan2
335 conj' = conjugateQ
336
337 338
338--------------------------------------------------------------- 339---------------------------------------------------------------
339 340
340instance (Num a, Element a, SContainer Vector a) => SContainer Matrix a 341instance (Num a, Element a, SContainer Vector a) => SContainer Matrix a
341 where 342 where
343 conj' = liftMatrix conj'
342 size' = size 344 size' = size
343 scale' x = liftMatrix (scale' x) 345 scale' x = liftMatrix (scale' x)
344 addConstant x = liftMatrix (addConstant x) 346 addConstant x = liftMatrix (addConstant x)
@@ -371,7 +373,6 @@ instance (Fractional a, Container Vector a) => Container Matrix a
371 scaleRecip x = liftMatrix (scaleRecip x) 373 scaleRecip x = liftMatrix (scaleRecip x)
372 divide = liftMatrix2 divide 374 divide = liftMatrix2 divide
373 arctan2' = liftMatrix2 arctan2' 375 arctan2' = liftMatrix2 arctan2'
374 conj' = liftMatrix conj'
375 376
376 377
377emptyErrorV msg f v = 378emptyErrorV msg f v =
@@ -655,12 +656,12 @@ kronecker a b = fromBlocks
655 656
656 657
657class Convert t where 658class Convert t where
658 real :: Container c t => c (RealOf t) -> c t 659 real :: Complexable c => c (RealOf t) -> c t
659 complex :: Container c t => c t -> c (ComplexOf t) 660 complex :: Complexable c => c t -> c (ComplexOf t)
660 single :: Container c t => c t -> c (SingleOf t) 661 single :: Complexable c => c t -> c (SingleOf t)
661 double :: Container c t => c t -> c (DoubleOf t) 662 double :: Complexable c => c t -> c (DoubleOf t)
662 toComplex :: (Container c t, RealElement t) => (c t, c t) -> c (Complex t) 663 toComplex :: (Complexable c, RealElement t) => (c t, c t) -> c (Complex t)
663 fromComplex :: (Container c t, RealElement t) => c (Complex t) -> (c t, c t) 664 fromComplex :: (Complexable c, RealElement t) => c (Complex t) -> (c t, c t)
664 665
665 666
666instance Convert Double where 667instance Convert Double where
@@ -743,7 +744,7 @@ buildV n f = fromList [f k | k <- ks]
743 744
744-------------------------------------------------------- 745--------------------------------------------------------
745-- | conjugate transpose 746-- | conjugate transpose
746ctrans :: (Container Vector e, Element e) => Matrix e -> Matrix e 747ctrans :: (SContainer Vector e, Element e) => Matrix e -> Matrix e
747ctrans = liftMatrix conj' . trans 748ctrans = liftMatrix conj' . trans
748 749
749-- | Creates a square matrix with a given diagonal. 750-- | Creates a square matrix with a given diagonal.
@@ -799,7 +800,7 @@ class Transposable m mt | m -> mt, mt -> m
799 -- | (conjugate) transpose 800 -- | (conjugate) transpose
800 tr :: m -> mt 801 tr :: m -> mt
801 802
802instance (Container Vector t) => Transposable (Matrix t) (Matrix t) 803instance (SContainer Vector t) => Transposable (Matrix t) (Matrix t)
803 where 804 where
804 tr = ctrans 805 tr = ctrans
805 806