summaryrefslogtreecommitdiff
path: root/lib/Numeric/Container.hs
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-09-21 03:05:52 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-09-21 03:05:52 +0000
commit7b8680256893a8624fab8d1d256773919df70068 (patch)
treeb5efd7cec14fc0cb0c8843dd5f998de64d8eebb1 /lib/Numeric/Container.hs
parent44d228ad83e876d45d1511761d7cd61bb2cd5c79 (diff)
move conjugate* to Container
The benefit of this patch is that Data.Packed.Internal.Matrix now has no numeric dependency. There is no 'optimisation' class for conjugateD, instead, different instances are directly specified in each Container instance. Unfortunately, an unsafeIO call now exists in Numeric.Container.
Diffstat (limited to 'lib/Numeric/Container.hs')
-rw-r--r--lib/Numeric/Container.hs25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs
index 09f8002..3b590de 100644
--- a/lib/Numeric/Container.hs
+++ b/lib/Numeric/Container.hs
@@ -52,6 +52,8 @@ import Control.Monad(ap)
52 52
53import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ) 53import Numeric.LinearAlgebra.LAPACK(multiplyR,multiplyC,multiplyF,multiplyQ)
54 54
55import System.IO.Unsafe
56
55------------------------------------------------------------------- 57-------------------------------------------------------------------
56 58
57type family IndexOf c 59type family IndexOf c
@@ -119,7 +121,7 @@ instance Container Vector Float where
119 equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 121 equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0
120 scalar x = fromList [x] 122 scalar x = fromList [x]
121 konst = constantD 123 konst = constantD
122 conj = conjugateD 124 conj = id
123 cmap = mapVector 125 cmap = mapVector
124 atIndex = (@>) 126 atIndex = (@>)
125 minIndex = round . toScalarF MinIdx 127 minIndex = round . toScalarF MinIdx
@@ -140,7 +142,7 @@ instance Container Vector Double where
140 equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0 142 equal u v = dim u == dim v && maxElement (vectorMapR Abs (sub u v)) == 0.0
141 scalar x = fromList [x] 143 scalar x = fromList [x]
142 konst = constantD 144 konst = constantD
143 conj = conjugateD 145 conj = id
144 cmap = mapVector 146 cmap = mapVector
145 atIndex = (@>) 147 atIndex = (@>)
146 minIndex = round . toScalarR MinIdx 148 minIndex = round . toScalarR MinIdx
@@ -161,7 +163,7 @@ instance Container Vector (Complex Double) where
161 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 163 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0
162 scalar x = fromList [x] 164 scalar x = fromList [x]
163 konst = constantD 165 konst = constantD
164 conj = conjugateD 166 conj = conjugateC
165 cmap = mapVector 167 cmap = mapVector
166 atIndex = (@>) 168 atIndex = (@>)
167 minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) 169 minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate)
@@ -182,7 +184,7 @@ instance Container Vector (Complex Float) where
182 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0 184 equal u v = dim u == dim v && maxElement (mapVector magnitude (sub u v)) == 0.0
183 scalar x = fromList [x] 185 scalar x = fromList [x]
184 konst = constantD 186 konst = constantD
185 conj = conjugateD 187 conj = conjugateQ
186 cmap = mapVector 188 cmap = mapVector
187 atIndex = (@>) 189 atIndex = (@>)
188 minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate) 190 minIndex = minIndex . fst . fromComplex . (zipVectorWith (*) `ap` mapVector conjugate)
@@ -205,7 +207,7 @@ instance (Container Vector a) => Container Matrix a where
205 equal a b = cols a == cols b && flatten a `equal` flatten b 207 equal a b = cols a == cols b && flatten a `equal` flatten b
206 scalar x = (1><1) [x] 208 scalar x = (1><1) [x]
207 konst v (r,c) = reshape c (konst v (r*c)) 209 konst v (r,c) = reshape c (konst v (r*c))
208 conj = liftMatrix conjugateD 210 conj = liftMatrix conj
209 cmap f = liftMatrix (mapVector f) 211 cmap f = liftMatrix (mapVector f)
210 atIndex = (@@>) 212 atIndex = (@@>)
211 minIndex m = let (r,c) = (rows m,cols m) 213 minIndex m = let (r,c) = (rows m,cols m)
@@ -405,6 +407,19 @@ type instance ElementOf (Matrix a) = a
405 407
406------------------------------------------------------------ 408------------------------------------------------------------
407 409
410conjugateAux fun x = unsafePerformIO $ do
411 v <- createVector (dim x)
412 app2 fun vec x vec v "conjugateAux"
413 return v
414
415conjugateQ :: Vector (Complex Float) -> Vector (Complex Float)
416conjugateQ = conjugateAux c_conjugateQ
417foreign import ccall "conjugateQ" c_conjugateQ :: TQVQV
418
419conjugateC :: Vector (Complex Double) -> Vector (Complex Double)
420conjugateC = conjugateAux c_conjugateC
421foreign import ccall "conjugateC" c_conjugateC :: TCVCV
422
408---------------------------------------------------- 423----------------------------------------------------
409 424
410{-# DEPRECATED (.*) "use scale a x or scalar a * x" #-} 425{-# DEPRECATED (.*) "use scale a x or scalar a * x" #-}