diff options
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 12 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Vector.hs | 35 | ||||
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Data.hs | 3 |
3 files changed, 38 insertions, 12 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 | ||
219 | instance Container Vector Float | 221 | instance 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 | ||
284 | instance Container Vector (Complex Double) | 288 | instance 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 | ||
315 | instance Container Vector (Complex Float) | 320 | instance 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 | ||
384 | emptyErrorV msg f v = | 391 | emptyErrorV msg f v = |
@@ -416,6 +423,9 @@ arctan2 = arctan2' | |||
416 | cmod :: (Integral e, Container c e) => e -> c e -> c e | 423 | cmod :: (Integral e, Container c e) => e -> c e -> c e |
417 | cmod = cmod' | 424 | cmod = cmod' |
418 | 425 | ||
426 | fromInt :: (Container c e) => c CInt -> c e | ||
427 | fromInt = 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) |
421 | cmap :: (Element b, Container c e) => (e -> b) -> c e -> c b | 431 | cmap :: (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 | ||
233 | float2DoubleV :: Vector Float -> Vector Double | 233 | float2DoubleV :: Vector Float -> Vector Double |
234 | float2DoubleV v = unsafePerformIO $ do | 234 | float2DoubleV = tog c_float2double |
235 | r <- createVector (dim v) | ||
236 | app2 c_float2double vec v vec r "float2double" | ||
237 | return r | ||
238 | 235 | ||
239 | double2FloatV :: Vector Double -> Vector Float | 236 | double2FloatV :: Vector Double -> Vector Float |
240 | double2FloatV v = unsafePerformIO $ do | 237 | double2FloatV = tog c_double2float |
238 | |||
239 | double2IntV :: Vector Double -> Vector CInt | ||
240 | double2IntV = tog c_double2int | ||
241 | |||
242 | int2DoubleV :: Vector CInt -> Vector Double | ||
243 | int2DoubleV = tog c_int2double | ||
244 | |||
245 | float2IntV :: Vector Float -> Vector CInt | ||
246 | float2IntV = tog c_float2int | ||
247 | |||
248 | int2floatV :: Vector CInt -> Vector Float | ||
249 | int2floatV = tog c_int2float | ||
250 | |||
251 | |||
252 | tog 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 | 257 | foreign import ccall unsafe "float2double" c_float2double :: TFV | |
246 | foreign import ccall unsafe "float2double" c_float2double:: TFV | 258 | foreign import ccall unsafe "double2float" c_double2float :: TVF |
247 | foreign import ccall unsafe "double2float" c_double2float:: TVF | 259 | foreign import ccall unsafe "int2double" c_int2double :: CV CInt (CV Double (IO CInt)) |
260 | foreign import ccall unsafe "double2int" c_double2int :: CV Double (CV CInt (IO CInt)) | ||
261 | foreign import ccall unsafe "int2float" c_int2float :: CV CInt (CV Float (IO CInt)) | ||
262 | foreign import ccall unsafe "float2int" c_float2int :: CV Float (CV CInt (IO CInt)) | ||
248 | 263 | ||
249 | 264 | ||
250 | --------------------------------------------------------------- | 265 | --------------------------------------------------------------- |
diff --git a/packages/base/src/Numeric/LinearAlgebra/Data.hs b/packages/base/src/Numeric/LinearAlgebra/Data.hs index 80877cb..7bc0497 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Data.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Data.hs | |||
@@ -63,6 +63,7 @@ module Numeric.LinearAlgebra.Data( | |||
63 | -- * Conversion | 63 | -- * Conversion |
64 | Convert(..), | 64 | Convert(..), |
65 | roundVector, | 65 | roundVector, |
66 | fromInt, | ||
66 | -- * Misc | 67 | -- * Misc |
67 | arctan2, | 68 | arctan2, |
68 | rows, cols, | 69 | rows, cols, |
@@ -81,6 +82,6 @@ import Numeric.LinearAlgebra.Util hiding ((&),(#)) | |||
81 | import Data.Complex | 82 | import Data.Complex |
82 | import Numeric.Sparse | 83 | import Numeric.Sparse |
83 | import Data.Packed.Internal.Vector(Idxs) | 84 | import Data.Packed.Internal.Vector(Idxs) |
84 | import Data.Packed.Internal.Numeric(CInt,Extractor(..),(??)) | 85 | import Data.Packed.Internal.Numeric(CInt,Extractor(..),(??),fromInt) |
85 | 86 | ||
86 | 87 | ||