summaryrefslogtreecommitdiff
path: root/packages/hmatrix
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-14 20:17:24 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-14 20:17:24 +0200
commitce03cbdf416db2af2830b4b3b7d1722bb26f6546 (patch)
tree870e6256e6a660fdec01e7a87666bfbdc3ae2068 /packages/hmatrix
parent0f9575462eb37a7c9985583ca33ae315f6e6431d (diff)
moved sum
Diffstat (limited to 'packages/hmatrix')
-rw-r--r--packages/hmatrix/src/Numeric/GSL/Vector.hs83
-rw-r--r--packages/hmatrix/src/Numeric/GSL/gsl-vector.c50
2 files changed, 7 insertions, 126 deletions
diff --git a/packages/hmatrix/src/Numeric/GSL/Vector.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs
index 3591289..33bd778 100644
--- a/packages/hmatrix/src/Numeric/GSL/Vector.hs
+++ b/packages/hmatrix/src/Numeric/GSL/Vector.hs
@@ -24,6 +24,13 @@ 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(
28 sumF, sumR, sumQ, sumC,
29 FunCodeS(..),
30 FunCodeV(..),
31 FunCodeSV(..),
32 FunCodeVV(..)
33 )
27 34
28import Data.Complex 35import Data.Complex
29import Foreign.Marshal.Alloc(free) 36import Foreign.Marshal.Alloc(free)
@@ -36,84 +43,8 @@ import Control.Monad(when)
36 43
37fromei x = fromIntegral (fromEnum x) :: CInt 44fromei x = fromIntegral (fromEnum x) :: CInt
38 45
39data FunCodeV = Sin
40 | Cos
41 | Tan
42 | Abs
43 | ASin
44 | ACos
45 | ATan
46 | Sinh
47 | Cosh
48 | Tanh
49 | ASinh
50 | ACosh
51 | ATanh
52 | Exp
53 | Log
54 | Sign
55 | Sqrt
56 deriving Enum
57
58data FunCodeSV = Scale
59 | Recip
60 | AddConstant
61 | Negate
62 | PowSV
63 | PowVS
64 deriving Enum
65
66data FunCodeVV = Add
67 | Sub
68 | Mul
69 | Div
70 | Pow
71 | ATan2
72 deriving Enum
73
74data FunCodeS = Norm2
75 | AbsSum
76 | MaxIdx
77 | Max
78 | MinIdx
79 | Min
80 deriving Enum
81
82------------------------------------------------------------------ 46------------------------------------------------------------------
83 47
84-- | sum of elements
85sumF :: Vector Float -> Float
86sumF x = unsafePerformIO $ do
87 r <- createVector 1
88 app2 c_sumF vec x vec r "sumF"
89 return $ r @> 0
90
91-- | sum of elements
92sumR :: Vector Double -> Double
93sumR x = unsafePerformIO $ do
94 r <- createVector 1
95 app2 c_sumR vec x vec r "sumR"
96 return $ r @> 0
97
98-- | sum of elements
99sumQ :: Vector (Complex Float) -> Complex Float
100sumQ x = unsafePerformIO $ do
101 r <- createVector 1
102 app2 c_sumQ vec x vec r "sumQ"
103 return $ r @> 0
104
105-- | sum of elements
106sumC :: Vector (Complex Double) -> Complex Double
107sumC x = unsafePerformIO $ do
108 r <- createVector 1
109 app2 c_sumC vec x vec r "sumC"
110 return $ r @> 0
111
112foreign import ccall unsafe "gsl-aux.h sumF" c_sumF :: TFF
113foreign import ccall unsafe "gsl-aux.h sumR" c_sumR :: TVV
114foreign import ccall unsafe "gsl-aux.h sumQ" c_sumQ :: TQVQV
115foreign import ccall unsafe "gsl-aux.h sumC" c_sumC :: TCVCV
116
117-- | product of elements 48-- | product of elements
118prodF :: Vector Float -> Float 49prodF :: Vector Float -> Float
119prodF x = unsafePerformIO $ do 50prodF x = unsafePerformIO $ do
diff --git a/packages/hmatrix/src/Numeric/GSL/gsl-vector.c b/packages/hmatrix/src/Numeric/GSL/gsl-vector.c
index 40a086a..3c2db4d 100644
--- a/packages/hmatrix/src/Numeric/GSL/gsl-vector.c
+++ b/packages/hmatrix/src/Numeric/GSL/gsl-vector.c
@@ -88,56 +88,6 @@
88#define BAD_FILE 2003 88#define BAD_FILE 2003
89 89
90 90
91int sumF(KFVEC(x),FVEC(r)) {
92 DEBUGMSG("sumF");
93 REQUIRES(rn==1,BAD_SIZE);
94 int i;
95 float res = 0;
96 for (i = 0; i < xn; i++) res += xp[i];
97 rp[0] = res;
98 OK
99}
100
101int sumR(KRVEC(x),RVEC(r)) {
102 DEBUGMSG("sumR");
103 REQUIRES(rn==1,BAD_SIZE);
104 int i;
105 double res = 0;
106 for (i = 0; i < xn; i++) res += xp[i];
107 rp[0] = res;
108 OK
109}
110
111int sumQ(KQVEC(x),QVEC(r)) {
112 DEBUGMSG("sumQ");
113 REQUIRES(rn==1,BAD_SIZE);
114 int i;
115 gsl_complex_float res;
116 res.dat[0] = 0;
117 res.dat[1] = 0;
118 for (i = 0; i < xn; i++) {
119 res.dat[0] += xp[i].dat[0];
120 res.dat[1] += xp[i].dat[1];
121 }
122 rp[0] = res;
123 OK
124}
125
126int sumC(KCVEC(x),CVEC(r)) {
127 DEBUGMSG("sumC");
128 REQUIRES(rn==1,BAD_SIZE);
129 int i;
130 gsl_complex res;
131 res.dat[0] = 0;
132 res.dat[1] = 0;
133 for (i = 0; i < xn; i++) {
134 res.dat[0] += xp[i].dat[0];
135 res.dat[1] += xp[i].dat[1];
136 }
137 rp[0] = res;
138 OK
139}
140
141int prodF(KFVEC(x),FVEC(r)) { 91int prodF(KFVEC(x),FVEC(r)) {
142 DEBUGMSG("prodF"); 92 DEBUGMSG("prodF");
143 REQUIRES(rn==1,BAD_SIZE); 93 REQUIRES(rn==1,BAD_SIZE);