summaryrefslogtreecommitdiff
path: root/packages/hmatrix/src/Numeric/GSL/Vector.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-15 18:51:03 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-15 18:51:03 +0200
commit69d1fc1588532b48a946c1501f92ed56600baf4d (patch)
tree783de9d3dc07a5d1915b044a38982952125faf2e /packages/hmatrix/src/Numeric/GSL/Vector.hs
parentf34e120d08154dc97130eca2bc569d3cdd199270 (diff)
moved complex mapVal and zip
Diffstat (limited to 'packages/hmatrix/src/Numeric/GSL/Vector.hs')
-rw-r--r--packages/hmatrix/src/Numeric/GSL/Vector.hs58
1 files changed, 1 insertions, 57 deletions
diff --git a/packages/hmatrix/src/Numeric/GSL/Vector.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs
index 5c34f70..e133c2c 100644
--- a/packages/hmatrix/src/Numeric/GSL/Vector.hs
+++ b/packages/hmatrix/src/Numeric/GSL/Vector.hs
@@ -24,73 +24,17 @@ module Numeric.GSL.Vector (
24 24
25import Data.Packed 25import Data.Packed
26import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) 26import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM)
27import Numeric.Vectorized( 27import Numeric.Vectorized
28 sumF, sumR, sumQ, sumC,
29 prodF, prodR, prodQ, prodC,
30 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ,
31 FunCodeV(..), vectorMapR, vectorMapF, vectorMapC, vectorMapQ,
32 FunCodeSV(..), vectorMapValR, vectorMapValF,
33 FunCodeVV(..), vectorZipR, vectorZipF
34 )
35 28
36import Data.Complex 29import Data.Complex
37import Foreign.Marshal.Alloc(free) 30import Foreign.Marshal.Alloc(free)
38import Foreign.Marshal.Array(newArray)
39import Foreign.Ptr(Ptr) 31import Foreign.Ptr(Ptr)
40import Foreign.C.Types 32import Foreign.C.Types
41import Foreign.C.String(newCString) 33import Foreign.C.String(newCString)
42import System.IO.Unsafe(unsafePerformIO) 34import System.IO.Unsafe(unsafePerformIO)
43import Control.Monad(when)
44 35
45fromei x = fromIntegral (fromEnum x) :: CInt 36fromei x = fromIntegral (fromEnum x) :: CInt
46 37
47------------------------------------------------------------------
48
49vectorMapAux fun code v = unsafePerformIO $ do
50 r <- createVector (dim v)
51 app2 (fun (fromei code)) vec v vec r "vectorMapAux"
52 return r
53
54vectorMapValAux fun code val v = unsafePerformIO $ do
55 r <- createVector (dim v)
56 pval <- newArray [val]
57 app2 (fun (fromei code) pval) vec v vec r "vectorMapValAux"
58 free pval
59 return r
60
61vectorZipAux fun code u v = unsafePerformIO $ do
62 r <- createVector (dim u)
63 when (dim u > 0) $ app3 (fun (fromei code)) vec u vec v vec r "vectorZipAux"
64 return r
65
66---------------------------------------------------------------------
67
68-- | map of complex vectors with given function
69vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double)
70vectorMapValC = vectorMapValAux c_vectorMapValC
71
72foreign import ccall unsafe "gsl-aux.h mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TCVCV
73
74-- | map of complex vectors with given function
75vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float)
76vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper)
77
78foreign import ccall unsafe "gsl-aux.h mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV
79
80-------------------------------------------------------------------
81
82-- | elementwise operation on complex vectors
83vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double)
84vectorZipC = vectorZipAux c_vectorZipC
85
86foreign import ccall unsafe "gsl-aux.h zipC" c_vectorZipC :: CInt -> TCVCVCV
87
88-- | elementwise operation on complex vectors
89vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float)
90vectorZipQ = vectorZipAux c_vectorZipQ
91
92foreign import ccall unsafe "gsl-aux.h zipQ" c_vectorZipQ :: CInt -> TQVQVQV
93
94----------------------------------------------------------------------- 38-----------------------------------------------------------------------
95 39
96data RandDist = Uniform -- ^ uniform distribution in [0,1) 40data RandDist = Uniform -- ^ uniform distribution in [0,1)