From dd7919095dc76f67ba2bf8aec506e13a55b8847d Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 6 Jun 2015 19:52:55 +0200 Subject: fromZ, toZ --- packages/base/src/Internal/Numeric.hs | 23 +++++++++++++++++++++-- packages/base/src/Internal/Vectorized.hs | 9 +++++++++ packages/base/src/Numeric/LinearAlgebra/Data.hs | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'packages') 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 cmod' :: Integral e => e -> c e -> c e fromInt' :: c I -> c e toInt' :: c e -> c I - + fromZ' :: c Z -> c e + toZ' :: c e -> c Z -------------------------------------------------------------------------- @@ -128,6 +129,8 @@ instance Container Vector I | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) fromInt' = id toInt' = id + fromZ' = long2intV + toZ' = int2longV instance Container Vector Z @@ -165,6 +168,8 @@ instance Container Vector Z | otherwise = error $ "cmod 0 on vector of size "++(show $ dim x) fromInt' = int2longV toInt' = long2intV + fromZ' = id + toZ' = id @@ -201,7 +206,8 @@ instance Container Vector Float cmod' = undefined fromInt' = int2floatV toInt' = float2IntV - + fromZ' = (single :: Vector R-> Vector Float) . fromZ' + toZ' = toZ' . double instance Container Vector Double @@ -237,6 +243,8 @@ instance Container Vector Double cmod' = undefined fromInt' = int2DoubleV toInt' = double2IntV + fromZ' = long2DoubleV + toZ' = double2longV instance Container Vector (Complex Double) @@ -272,6 +280,8 @@ instance Container Vector (Complex Double) cmod' = undefined fromInt' = complex . int2DoubleV toInt' = toInt' . fst . fromComplex + fromZ' = complex . long2DoubleV + toZ' = toZ' . fst . fromComplex instance Container Vector (Complex Float) where @@ -306,6 +316,8 @@ instance Container Vector (Complex Float) cmod' = undefined fromInt' = complex . int2floatV toInt' = toInt' . fst . fromComplex + fromZ' = complex . single . long2DoubleV + toZ' = toZ' . double . fst . fromComplex --------------------------------------------------------------- @@ -346,6 +358,8 @@ instance (Num a, Element a, Container Vector a) => Container Matrix a | otherwise = error $ "cmod 0 on matrix "++shSize x fromInt' = liftMatrix fromInt' toInt' = liftMatrix toInt' + fromZ' = liftMatrix fromZ' + toZ' = liftMatrix toZ' emptyErrorV msg f v = @@ -399,6 +413,11 @@ fromInt = fromInt' toInt :: (Container c e) => c e -> c I toInt = toInt' +fromZ :: (Container c e) => c Z -> c e +fromZ = fromZ' + +toZ :: (Container c e) => c e -> c Z +toZ = toZ' -- | like 'fmap' (cannot implement instance Functor because of Element class constraint) cmap :: (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 int2DoubleV :: Vector CInt -> Vector Double int2DoubleV = tog c_int2double +double2longV :: Vector Double -> Vector Z +double2longV = tog c_double2long + +long2DoubleV :: Vector Z -> Vector Double +long2DoubleV = tog c_long2double + + float2IntV :: Vector Float -> Vector CInt float2IntV = tog c_float2int @@ -430,6 +437,8 @@ foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :> foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok foreign import ccall unsafe "int2double" c_int2double :: CInt :> Double :> Ok foreign import ccall unsafe "double2int" c_double2int :: Double :> CInt :> Ok +foreign import ccall unsafe "long2double" c_long2double :: Z :> Double :> Ok +foreign import ccall unsafe "double2long" c_double2long :: Double :> Z :> Ok foreign import ccall unsafe "int2float" c_int2float :: CInt :> Float :> Ok foreign import ccall unsafe "float2int" c_float2int :: Float :> CInt :> Ok foreign import ccall unsafe "int2long" c_int2long :: I :> Z :> Ok diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 06485e6..c3e0c1d 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs @@ -82,7 +82,7 @@ module Numeric.LinearAlgebra.Data( -- * Element conversion Convert(..), roundVector, - fromInt,toInt, + fromInt,toInt,fromZ,toZ, -- * Misc arctan2, separable, -- cgit v1.2.3