summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/GSL/Vector.hs')
-rw-r--r--lib/Numeric/GSL/Vector.hs70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs
index d09323b..97a0f9c 100644
--- a/lib/Numeric/GSL/Vector.hs
+++ b/lib/Numeric/GSL/Vector.hs
@@ -14,6 +14,8 @@
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15 15
16module Numeric.GSL.Vector ( 16module Numeric.GSL.Vector (
17 sumF, sumR, sumQ, sumC,
18 dotF, dotR, dotQ, dotC,
17 FunCodeS(..), toScalarR, toScalarF, 19 FunCodeS(..), toScalarR, toScalarF,
18 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, 20 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF,
19 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, 21 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF,
@@ -76,6 +78,74 @@ data FunCodeS = Norm2
76 78
77------------------------------------------------------------------ 79------------------------------------------------------------------
78 80
81-- | sum of elements
82sumF :: Vector Float -> Float
83sumF x = unsafePerformIO $ do
84 r <- createVector 1
85 app2 c_sumF vec x vec r "sumF"
86 return $ r @> 0
87
88-- | sum of elements
89sumR :: Vector Double -> Double
90sumR x = unsafePerformIO $ do
91 r <- createVector 1
92 app2 c_sumR vec x vec r "sumR"
93 return $ r @> 0
94
95-- | sum of elements
96sumQ :: Vector (Complex Float) -> Complex Float
97sumQ x = unsafePerformIO $ do
98 r <- createVector 1
99 app2 c_sumQ vec x vec r "sumQ"
100 return $ r @> 0
101
102-- | sum of elements
103sumC :: Vector (Complex Double) -> Complex Double
104sumC x = unsafePerformIO $ do
105 r <- createVector 1
106 app2 c_sumC vec x vec r "sumC"
107 return $ r @> 0
108
109foreign import ccall safe "gsl-aux.h sumF" c_sumF :: TFF
110foreign import ccall safe "gsl-aux.h sumR" c_sumR :: TVV
111foreign import ccall safe "gsl-aux.h sumQ" c_sumQ :: TQVQV
112foreign import ccall safe "gsl-aux.h sumC" c_sumC :: TCVCV
113
114-- | dot product
115dotF :: Vector Float -> Vector Float -> Float
116dotF x y = unsafePerformIO $ do
117 r <- createVector 1
118 app3 c_dotF vec x vec y vec r "dotF"
119 return $ r @> 0
120
121-- | dot product
122dotR :: Vector Double -> Vector Double -> Double
123dotR x y = unsafePerformIO $ do
124 r <- createVector 1
125 app3 c_dotR vec x vec y vec r "dotR"
126 return $ r @> 0
127
128-- | dot product
129dotQ :: Vector (Complex Float) -> Vector (Complex Float) -> Complex Float
130dotQ x y = unsafePerformIO $ do
131 r <- createVector 1
132 app3 c_dotQ vec x vec y vec r "dotQ"
133 return $ r @> 0
134
135-- | dot product
136dotC :: Vector (Complex Double) -> Vector (Complex Double) -> Complex Double
137dotC x y = unsafePerformIO $ do
138 r <- createVector 1
139 app3 c_dotC vec x vec y vec r "dotC"
140 return $ r @> 0
141
142foreign import ccall safe "gsl-aux.h dotF" c_dotF :: TFFF
143foreign import ccall safe "gsl-aux.h dotR" c_dotR :: TVVV
144foreign import ccall safe "gsl-aux.h dotQ" c_dotQ :: TQVQVQV
145foreign import ccall safe "gsl-aux.h dotC" c_dotC :: TCVCVCV
146
147------------------------------------------------------------------
148
79toScalarAux fun code v = unsafePerformIO $ do 149toScalarAux fun code v = unsafePerformIO $ do
80 r <- createVector 1 150 r <- createVector 1
81 app2 (fun (fromei code)) vec v vec r "toScalarAux" 151 app2 (fun (fromei code)) vec v vec r "toScalarAux"