summaryrefslogtreecommitdiff
path: root/packages/base/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'packages/base/src/Data')
-rw-r--r--packages/base/src/Data/Packed/Internal/Numeric.hs12
-rw-r--r--packages/base/src/Data/Packed/Internal/Vector.hs35
2 files changed, 36 insertions, 11 deletions
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs
index 3e6c90c..fec8c05 100644
--- a/packages/base/src/Data/Packed/Internal/Numeric.hs
+++ b/packages/base/src/Data/Packed/Internal/Numeric.hs
@@ -36,7 +36,7 @@ module Data.Packed.Internal.Numeric (
36 Convert(..), 36 Convert(..),
37 Complexable(), 37 Complexable(),
38 RealElement(), 38 RealElement(),
39 roundVector, 39 roundVector, fromInt,
40 RealOf, ComplexOf, SingleOf, DoubleOf, 40 RealOf, ComplexOf, SingleOf, DoubleOf,
41 IndexOf, 41 IndexOf,
42 CInt, Extractor(..), (??), 42 CInt, Extractor(..), (??),
@@ -179,6 +179,7 @@ class Element e => Container c e
179 -- element by element inverse tangent 179 -- element by element inverse tangent
180 arctan2' :: Fractional e => c e -> c e -> c e 180 arctan2' :: Fractional e => c e -> c e -> c e
181 cmod' :: Integral e => e -> c e -> c e 181 cmod' :: Integral e => e -> c e -> c e
182 fromInt' :: c CInt -> c e
182 183
183 184
184-------------------------------------------------------------------------- 185--------------------------------------------------------------------------
@@ -215,6 +216,7 @@ instance Container Vector CInt
215 cmod' m x 216 cmod' m x
216 | m /= 0 = vectorMapValI ModVS m x 217 | m /= 0 = vectorMapValI ModVS m x
217 | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) 218 | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x)
219 fromInt' = id
218 220
219instance Container Vector Float 221instance Container Vector Float
220 where 222 where
@@ -246,6 +248,7 @@ instance Container Vector Float
246 divide = vectorZipF Div 248 divide = vectorZipF Div
247 arctan2' = vectorZipF ATan2 249 arctan2' = vectorZipF ATan2
248 cmod' = undefined 250 cmod' = undefined
251 fromInt' = int2floatV
249 252
250 253
251 254
@@ -279,6 +282,7 @@ instance Container Vector Double
279 divide = vectorZipR Div 282 divide = vectorZipR Div
280 arctan2' = vectorZipR ATan2 283 arctan2' = vectorZipR ATan2
281 cmod' = undefined 284 cmod' = undefined
285 fromInt' = int2DoubleV
282 286
283 287
284instance Container Vector (Complex Double) 288instance Container Vector (Complex Double)
@@ -311,6 +315,7 @@ instance Container Vector (Complex Double)
311 divide = vectorZipC Div 315 divide = vectorZipC Div
312 arctan2' = vectorZipC ATan2 316 arctan2' = vectorZipC ATan2
313 cmod' = undefined 317 cmod' = undefined
318 fromInt' = complex . int2DoubleV
314 319
315instance Container Vector (Complex Float) 320instance Container Vector (Complex Float)
316 where 321 where
@@ -342,6 +347,7 @@ instance Container Vector (Complex Float)
342 divide = vectorZipQ Div 347 divide = vectorZipQ Div
343 arctan2' = vectorZipQ ATan2 348 arctan2' = vectorZipQ ATan2
344 cmod' = undefined 349 cmod' = undefined
350 fromInt' = complex . int2floatV
345 351
346--------------------------------------------------------------- 352---------------------------------------------------------------
347 353
@@ -379,6 +385,7 @@ instance (Num a, Element a, Container Vector a) => Container Matrix a
379 cmod' m x 385 cmod' m x
380 | m /= 0 = liftMatrix (cmod' m) x 386 | m /= 0 = liftMatrix (cmod' m) x
381 | otherwise = error $ "cmod 0 on matrix "++shSize x 387 | otherwise = error $ "cmod 0 on matrix "++shSize x
388 fromInt' = liftMatrix fromInt'
382 389
383 390
384emptyErrorV msg f v = 391emptyErrorV msg f v =
@@ -416,6 +423,9 @@ arctan2 = arctan2'
416cmod :: (Integral e, Container c e) => e -> c e -> c e 423cmod :: (Integral e, Container c e) => e -> c e -> c e
417cmod = cmod' 424cmod = cmod'
418 425
426fromInt :: (Container c e) => c CInt -> c e
427fromInt = fromInt'
428
419 429
420-- | like 'fmap' (cannot implement instance Functor because of Element class constraint) 430-- | like 'fmap' (cannot implement instance Functor because of Element class constraint)
421cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b 431cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b
diff --git a/packages/base/src/Data/Packed/Internal/Vector.hs b/packages/base/src/Data/Packed/Internal/Vector.hs
index 7b0df64..ac35596 100644
--- a/packages/base/src/Data/Packed/Internal/Vector.hs
+++ b/packages/base/src/Data/Packed/Internal/Vector.hs
@@ -18,7 +18,7 @@ module Data.Packed.Internal.Vector (
18 mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_, 18 mapVectorM, mapVectorM_, mapVectorWithIndexM, mapVectorWithIndexM_,
19 foldVector, foldVectorG, foldLoop, foldVectorWithIndex, 19 foldVector, foldVectorG, foldLoop, foldVectorWithIndex,
20 createVector, vec, 20 createVector, vec,
21 asComplex, asReal, float2DoubleV, double2FloatV, 21 asComplex, asReal, float2DoubleV, double2FloatV, double2IntV, int2DoubleV, float2IntV, int2floatV,
22 stepF, stepD, stepI, condF, condD, condI, 22 stepF, stepD, stepI, condF, condD, condI,
23 conjugateQ, conjugateC, 23 conjugateQ, conjugateC,
24 cloneVector, 24 cloneVector,
@@ -231,20 +231,35 @@ asComplex v = unsafeFromForeignPtr (castForeignPtr fp) (i `div` 2) (n `div` 2)
231--------------------------------------------------------------- 231---------------------------------------------------------------
232 232
233float2DoubleV :: Vector Float -> Vector Double 233float2DoubleV :: Vector Float -> Vector Double
234float2DoubleV v = unsafePerformIO $ do 234float2DoubleV = tog c_float2double
235 r <- createVector (dim v)
236 app2 c_float2double vec v vec r "float2double"
237 return r
238 235
239double2FloatV :: Vector Double -> Vector Float 236double2FloatV :: Vector Double -> Vector Float
240double2FloatV v = unsafePerformIO $ do 237double2FloatV = tog c_double2float
238
239double2IntV :: Vector Double -> Vector CInt
240double2IntV = tog c_double2int
241
242int2DoubleV :: Vector CInt -> Vector Double
243int2DoubleV = tog c_int2double
244
245float2IntV :: Vector Float -> Vector CInt
246float2IntV = tog c_float2int
247
248int2floatV :: Vector CInt -> Vector Float
249int2floatV = tog c_int2float
250
251
252tog f v = unsafePerformIO $ do
241 r <- createVector (dim v) 253 r <- createVector (dim v)
242 app2 c_double2float vec v vec r "double2float2" 254 app2 f vec v vec r "tog"
243 return r 255 return r
244 256
245 257foreign import ccall unsafe "float2double" c_float2double :: TFV
246foreign import ccall unsafe "float2double" c_float2double:: TFV 258foreign import ccall unsafe "double2float" c_double2float :: TVF
247foreign import ccall unsafe "double2float" c_double2float:: TVF 259foreign import ccall unsafe "int2double" c_int2double :: CV CInt (CV Double (IO CInt))
260foreign import ccall unsafe "double2int" c_double2int :: CV Double (CV CInt (IO CInt))
261foreign import ccall unsafe "int2float" c_int2float :: CV CInt (CV Float (IO CInt))
262foreign import ccall unsafe "float2int" c_float2int :: CV Float (CV CInt (IO CInt))
248 263
249 264
250--------------------------------------------------------------- 265---------------------------------------------------------------