summaryrefslogtreecommitdiff
path: root/packages/base/src/Internal
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2015-06-06 19:52:55 +0200
committerAlberto Ruiz <aruiz@um.es>2015-06-06 19:52:55 +0200
commitdd7919095dc76f67ba2bf8aec506e13a55b8847d (patch)
tree2739a3333843ac787ede16c22dcf3d306b329941 /packages/base/src/Internal
parentc680fbb7a743b2fc519987a4d5f24bb9b675655f (diff)
fromZ, toZ
Diffstat (limited to 'packages/base/src/Internal')
-rw-r--r--packages/base/src/Internal/Numeric.hs23
-rw-r--r--packages/base/src/Internal/Vectorized.hs9
2 files changed, 30 insertions, 2 deletions
diff --git a/packages/base/src/Internal/Numeric.hs b/packages/base/src/Internal/Numeric.hs
index 85594cc..eb744d1 100644
--- a/packages/base/src/Internal/Numeric.hs
+++ b/packages/base/src/Internal/Numeric.hs
@@ -89,7 +89,8 @@ class Element e => Container c e
89 cmod' :: Integral e => e -> c e -> c e 89 cmod' :: Integral e => e -> c e -> c e
90 fromInt' :: c I -> c e 90 fromInt' :: c I -> c e
91 toInt' :: c e -> c I 91 toInt' :: c e -> c I
92 92 fromZ' :: c Z -> c e
93 toZ' :: c e -> c Z
93 94
94-------------------------------------------------------------------------- 95--------------------------------------------------------------------------
95 96
@@ -128,6 +129,8 @@ instance Container Vector I
128 | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) 129 | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x)
129 fromInt' = id 130 fromInt' = id
130 toInt' = id 131 toInt' = id
132 fromZ' = long2intV
133 toZ' = int2longV
131 134
132 135
133instance Container Vector Z 136instance Container Vector Z
@@ -165,6 +168,8 @@ instance Container Vector Z
165 | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) 168 | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x)
166 fromInt' = int2longV 169 fromInt' = int2longV
167 toInt' = long2intV 170 toInt' = long2intV
171 fromZ' = id
172 toZ' = id
168 173
169 174
170 175
@@ -201,7 +206,8 @@ instance Container Vector Float
201 cmod' = undefined 206 cmod' = undefined
202 fromInt' = int2floatV 207 fromInt' = int2floatV
203 toInt' = float2IntV 208 toInt' = float2IntV
204 209 fromZ' = (single :: Vector R-> Vector Float) . fromZ'
210 toZ' = toZ' . double
205 211
206 212
207instance Container Vector Double 213instance Container Vector Double
@@ -237,6 +243,8 @@ instance Container Vector Double
237 cmod' = undefined 243 cmod' = undefined
238 fromInt' = int2DoubleV 244 fromInt' = int2DoubleV
239 toInt' = double2IntV 245 toInt' = double2IntV
246 fromZ' = long2DoubleV
247 toZ' = double2longV
240 248
241 249
242instance Container Vector (Complex Double) 250instance Container Vector (Complex Double)
@@ -272,6 +280,8 @@ instance Container Vector (Complex Double)
272 cmod' = undefined 280 cmod' = undefined
273 fromInt' = complex . int2DoubleV 281 fromInt' = complex . int2DoubleV
274 toInt' = toInt' . fst . fromComplex 282 toInt' = toInt' . fst . fromComplex
283 fromZ' = complex . long2DoubleV
284 toZ' = toZ' . fst . fromComplex
275 285
276instance Container Vector (Complex Float) 286instance Container Vector (Complex Float)
277 where 287 where
@@ -306,6 +316,8 @@ instance Container Vector (Complex Float)
306 cmod' = undefined 316 cmod' = undefined
307 fromInt' = complex . int2floatV 317 fromInt' = complex . int2floatV
308 toInt' = toInt' . fst . fromComplex 318 toInt' = toInt' . fst . fromComplex
319 fromZ' = complex . single . long2DoubleV
320 toZ' = toZ' . double . fst . fromComplex
309 321
310--------------------------------------------------------------- 322---------------------------------------------------------------
311 323
@@ -346,6 +358,8 @@ instance (Num a, Element a, Container Vector a) => Container Matrix a
346 | otherwise = error $ "cmod 0 on matrix "++shSize x 358 | otherwise = error $ "cmod 0 on matrix "++shSize x
347 fromInt' = liftMatrix fromInt' 359 fromInt' = liftMatrix fromInt'
348 toInt' = liftMatrix toInt' 360 toInt' = liftMatrix toInt'
361 fromZ' = liftMatrix fromZ'
362 toZ' = liftMatrix toZ'
349 363
350 364
351emptyErrorV msg f v = 365emptyErrorV msg f v =
@@ -399,6 +413,11 @@ fromInt = fromInt'
399toInt :: (Container c e) => c e -> c I 413toInt :: (Container c e) => c e -> c I
400toInt = toInt' 414toInt = toInt'
401 415
416fromZ :: (Container c e) => c Z -> c e
417fromZ = fromZ'
418
419toZ :: (Container c e) => c e -> c Z
420toZ = toZ'
402 421
403-- | like 'fmap' (cannot implement instance Functor because of Element class constraint) 422-- | like 'fmap' (cannot implement instance Functor because of Element class constraint)
404cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b 423cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b
diff --git a/packages/base/src/Internal/Vectorized.hs b/packages/base/src/Internal/Vectorized.hs
index b1ad424..ff51494 100644
--- a/packages/base/src/Internal/Vectorized.hs
+++ b/packages/base/src/Internal/Vectorized.hs
@@ -408,6 +408,13 @@ double2IntV = tog c_double2int
408int2DoubleV :: Vector CInt -> Vector Double 408int2DoubleV :: Vector CInt -> Vector Double
409int2DoubleV = tog c_int2double 409int2DoubleV = tog c_int2double
410 410
411double2longV :: Vector Double -> Vector Z
412double2longV = tog c_double2long
413
414long2DoubleV :: Vector Z -> Vector Double
415long2DoubleV = tog c_long2double
416
417
411float2IntV :: Vector Float -> Vector CInt 418float2IntV :: Vector Float -> Vector CInt
412float2IntV = tog c_float2int 419float2IntV = tog c_float2int
413 420
@@ -430,6 +437,8 @@ foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :>
430foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok 437foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok
431foreign import ccall unsafe "int2double" c_int2double :: CInt :> Double :> Ok 438foreign import ccall unsafe "int2double" c_int2double :: CInt :> Double :> Ok
432foreign import ccall unsafe "double2int" c_double2int :: Double :> CInt :> Ok 439foreign import ccall unsafe "double2int" c_double2int :: Double :> CInt :> Ok
440foreign import ccall unsafe "long2double" c_long2double :: Z :> Double :> Ok
441foreign import ccall unsafe "double2long" c_double2long :: Double :> Z :> Ok
433foreign import ccall unsafe "int2float" c_int2float :: CInt :> Float :> Ok 442foreign import ccall unsafe "int2float" c_int2float :: CInt :> Float :> Ok
434foreign import ccall unsafe "float2int" c_float2int :: Float :> CInt :> Ok 443foreign import ccall unsafe "float2int" c_float2int :: Float :> CInt :> Ok
435foreign import ccall unsafe "int2long" c_int2long :: I :> Z :> Ok 444foreign import ccall unsafe "int2long" c_int2long :: I :> Z :> Ok