diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-05-24 14:22:22 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-05-24 14:22:22 +0200 |
commit | 861753b66e70b4071c5434cfe210e96dc4ab0f6d (patch) | |
tree | d9fc20a625f634a58d175e965b66ad3563d3f64b /packages/base | |
parent | 250cbbff42667efeafcf704594c88a626754c1ac (diff) |
Container, Product and Num instances for CInt elements
Diffstat (limited to 'packages/base')
-rw-r--r-- | packages/base/src/C/vector-aux.c | 145 | ||||
-rw-r--r-- | packages/base/src/Data/Packed/Internal/Numeric.hs | 30 | ||||
-rw-r--r-- | packages/base/src/Numeric/Vector.hs | 8 | ||||
-rw-r--r-- | packages/base/src/Numeric/Vectorized.hs | 105 |
4 files changed, 221 insertions, 67 deletions
diff --git a/packages/base/src/C/vector-aux.c b/packages/base/src/C/vector-aux.c index 58afc49..b67275f 100644 --- a/packages/base/src/C/vector-aux.c +++ b/packages/base/src/C/vector-aux.c | |||
@@ -46,7 +46,7 @@ int sumF(KFVEC(x),FVEC(r)) { | |||
46 | rp[0] = res; | 46 | rp[0] = res; |
47 | OK | 47 | OK |
48 | } | 48 | } |
49 | 49 | ||
50 | int sumR(KDVEC(x),DVEC(r)) { | 50 | int sumR(KDVEC(x),DVEC(r)) { |
51 | DEBUGMSG("sumR"); | 51 | DEBUGMSG("sumR"); |
52 | REQUIRES(rn==1,BAD_SIZE); | 52 | REQUIRES(rn==1,BAD_SIZE); |
@@ -57,6 +57,15 @@ int sumR(KDVEC(x),DVEC(r)) { | |||
57 | OK | 57 | OK |
58 | } | 58 | } |
59 | 59 | ||
60 | int sumI(KIVEC(x),IVEC(r)) { | ||
61 | REQUIRES(rn==1,BAD_SIZE); | ||
62 | int i; | ||
63 | int res = 0; | ||
64 | for (i = 0; i < xn; i++) res += xp[i]; | ||
65 | rp[0] = res; | ||
66 | OK | ||
67 | } | ||
68 | |||
60 | 69 | ||
61 | int sumQ(KQVEC(x),QVEC(r)) { | 70 | int sumQ(KQVEC(x),QVEC(r)) { |
62 | DEBUGMSG("sumQ"); | 71 | DEBUGMSG("sumQ"); |
@@ -72,7 +81,7 @@ int sumQ(KQVEC(x),QVEC(r)) { | |||
72 | rp[0] = res; | 81 | rp[0] = res; |
73 | OK | 82 | OK |
74 | } | 83 | } |
75 | 84 | ||
76 | int sumC(KCVEC(x),CVEC(r)) { | 85 | int sumC(KCVEC(x),CVEC(r)) { |
77 | DEBUGMSG("sumC"); | 86 | DEBUGMSG("sumC"); |
78 | REQUIRES(rn==1,BAD_SIZE); | 87 | REQUIRES(rn==1,BAD_SIZE); |
@@ -98,7 +107,7 @@ int prodF(KFVEC(x),FVEC(r)) { | |||
98 | rp[0] = res; | 107 | rp[0] = res; |
99 | OK | 108 | OK |
100 | } | 109 | } |
101 | 110 | ||
102 | int prodR(KDVEC(x),DVEC(r)) { | 111 | int prodR(KDVEC(x),DVEC(r)) { |
103 | DEBUGMSG("prodR"); | 112 | DEBUGMSG("prodR"); |
104 | REQUIRES(rn==1,BAD_SIZE); | 113 | REQUIRES(rn==1,BAD_SIZE); |
@@ -109,6 +118,16 @@ int prodR(KDVEC(x),DVEC(r)) { | |||
109 | OK | 118 | OK |
110 | } | 119 | } |
111 | 120 | ||
121 | int prodI(KIVEC(x),IVEC(r)) { | ||
122 | REQUIRES(rn==1,BAD_SIZE); | ||
123 | int i; | ||
124 | int res = 1; | ||
125 | for (i = 0; i < xn; i++) res *= xp[i]; | ||
126 | rp[0] = res; | ||
127 | OK | ||
128 | } | ||
129 | |||
130 | |||
112 | 131 | ||
113 | int prodQ(KQVEC(x),QVEC(r)) { | 132 | int prodQ(KQVEC(x),QVEC(r)) { |
114 | DEBUGMSG("prodQ"); | 133 | DEBUGMSG("prodQ"); |
@@ -126,7 +145,7 @@ int prodQ(KQVEC(x),QVEC(r)) { | |||
126 | rp[0] = res; | 145 | rp[0] = res; |
127 | OK | 146 | OK |
128 | } | 147 | } |
129 | 148 | ||
130 | int prodC(KCVEC(x),CVEC(r)) { | 149 | int prodC(KCVEC(x),CVEC(r)) { |
131 | DEBUGMSG("prodC"); | 150 | DEBUGMSG("prodC"); |
132 | REQUIRES(rn==1,BAD_SIZE); | 151 | REQUIRES(rn==1,BAD_SIZE); |
@@ -144,7 +163,7 @@ int prodC(KCVEC(x),CVEC(r)) { | |||
144 | OK | 163 | OK |
145 | } | 164 | } |
146 | 165 | ||
147 | 166 | ||
148 | double dnrm2_(integer*, const double*, integer*); | 167 | double dnrm2_(integer*, const double*, integer*); |
149 | double dasum_(integer*, const double*, integer*); | 168 | double dasum_(integer*, const double*, integer*); |
150 | 169 | ||
@@ -189,8 +208,8 @@ double vector_min_index(KDVEC(x)) { | |||
189 | } | 208 | } |
190 | return r; | 209 | return r; |
191 | } | 210 | } |
192 | 211 | ||
193 | int toScalarR(int code, KDVEC(x), DVEC(r)) { | 212 | int toScalarR(int code, KDVEC(x), DVEC(r)) { |
194 | REQUIRES(rn==1,BAD_SIZE); | 213 | REQUIRES(rn==1,BAD_SIZE); |
195 | DEBUGMSG("toScalarR"); | 214 | DEBUGMSG("toScalarR"); |
196 | double res; | 215 | double res; |
@@ -256,7 +275,7 @@ float vector_min_index_f(KFVEC(x)) { | |||
256 | } | 275 | } |
257 | 276 | ||
258 | 277 | ||
259 | int toScalarF(int code, KFVEC(x), FVEC(r)) { | 278 | int toScalarF(int code, KFVEC(x), FVEC(r)) { |
260 | REQUIRES(rn==1,BAD_SIZE); | 279 | REQUIRES(rn==1,BAD_SIZE); |
261 | DEBUGMSG("toScalarF"); | 280 | DEBUGMSG("toScalarF"); |
262 | float res; | 281 | float res; |
@@ -275,10 +294,68 @@ int toScalarF(int code, KFVEC(x), FVEC(r)) { | |||
275 | OK | 294 | OK |
276 | } | 295 | } |
277 | 296 | ||
297 | int vector_max_i(KIVEC(x)) { | ||
298 | int r = xp[0]; | ||
299 | int k; | ||
300 | for (k = 1; k<xn; k++) { | ||
301 | if(xp[k]>r) { | ||
302 | r = xp[k]; | ||
303 | } | ||
304 | } | ||
305 | return r; | ||
306 | } | ||
307 | |||
308 | int vector_min_i(KIVEC(x)) { | ||
309 | float r = xp[0]; | ||
310 | int k; | ||
311 | for (k = 1; k<xn; k++) { | ||
312 | if(xp[k]<r) { | ||
313 | r = xp[k]; | ||
314 | } | ||
315 | } | ||
316 | return r; | ||
317 | } | ||
318 | |||
319 | int vector_max_index_i(KIVEC(x)) { | ||
320 | int k, r = 0; | ||
321 | for (k = 1; k<xn; k++) { | ||
322 | if(xp[k]>xp[r]) { | ||
323 | r = k; | ||
324 | } | ||
325 | } | ||
326 | return r; | ||
327 | } | ||
328 | |||
329 | int vector_min_index_i(KIVEC(x)) { | ||
330 | int k, r = 0; | ||
331 | for (k = 1; k<xn; k++) { | ||
332 | if(xp[k]<xp[r]) { | ||
333 | r = k; | ||
334 | } | ||
335 | } | ||
336 | return r; | ||
337 | } | ||
338 | |||
339 | |||
340 | int toScalarI(int code, KIVEC(x), IVEC(r)) { | ||
341 | REQUIRES(rn==1,BAD_SIZE); | ||
342 | int res; | ||
343 | switch(code) { | ||
344 | case 2: { res = vector_max_index_i(V(x)); break; } | ||
345 | case 3: { res = vector_max_i(V(x)); break; } | ||
346 | case 4: { res = vector_min_index_i(V(x)); break; } | ||
347 | case 5: { res = vector_min_i(V(x)); break; } | ||
348 | default: ERROR(BAD_CODE); | ||
349 | } | ||
350 | rp[0] = res; | ||
351 | OK | ||
352 | } | ||
353 | |||
354 | |||
278 | double dznrm2_(integer*, const doublecomplex*, integer*); | 355 | double dznrm2_(integer*, const doublecomplex*, integer*); |
279 | double dzasum_(integer*, const doublecomplex*, integer*); | 356 | double dzasum_(integer*, const doublecomplex*, integer*); |
280 | 357 | ||
281 | int toScalarC(int code, KCVEC(x), DVEC(r)) { | 358 | int toScalarC(int code, KCVEC(x), DVEC(r)) { |
282 | REQUIRES(rn==1,BAD_SIZE); | 359 | REQUIRES(rn==1,BAD_SIZE); |
283 | DEBUGMSG("toScalarC"); | 360 | DEBUGMSG("toScalarC"); |
284 | double res; | 361 | double res; |
@@ -297,7 +374,7 @@ int toScalarC(int code, KCVEC(x), DVEC(r)) { | |||
297 | double scnrm2_(integer*, const complex*, integer*); | 374 | double scnrm2_(integer*, const complex*, integer*); |
298 | double scasum_(integer*, const complex*, integer*); | 375 | double scasum_(integer*, const complex*, integer*); |
299 | 376 | ||
300 | int toScalarQ(int code, KQVEC(x), FVEC(r)) { | 377 | int toScalarQ(int code, KQVEC(x), FVEC(r)) { |
301 | REQUIRES(rn==1,BAD_SIZE); | 378 | REQUIRES(rn==1,BAD_SIZE); |
302 | DEBUGMSG("toScalarQ"); | 379 | DEBUGMSG("toScalarQ"); |
303 | float res; | 380 | float res; |
@@ -389,6 +466,18 @@ int mapF(int code, KFVEC(x), FVEC(r)) { | |||
389 | } | 466 | } |
390 | 467 | ||
391 | 468 | ||
469 | int mapI(int code, KIVEC(x), IVEC(r)) { | ||
470 | int k; | ||
471 | REQUIRES(xn == rn,BAD_SIZE); | ||
472 | switch (code) { | ||
473 | OP(3,abs) | ||
474 | OP(15,sign) | ||
475 | default: ERROR(BAD_CODE); | ||
476 | } | ||
477 | } | ||
478 | |||
479 | |||
480 | |||
392 | inline double abs_complex(doublecomplex z) { | 481 | inline double abs_complex(doublecomplex z) { |
393 | return sqrt(z.r*z.r + z.i*z.i); | 482 | return sqrt(z.r*z.r + z.i*z.i); |
394 | } | 483 | } |
@@ -526,6 +615,22 @@ int mapValF(int code, float* pval, KFVEC(x), FVEC(r)) { | |||
526 | } | 615 | } |
527 | } | 616 | } |
528 | 617 | ||
618 | int mapValI(int code, int* pval, KIVEC(x), IVEC(r)) { | ||
619 | int k; | ||
620 | int val = *pval; | ||
621 | REQUIRES(xn == rn,BAD_SIZE); | ||
622 | DEBUGMSG("mapValI"); | ||
623 | switch (code) { | ||
624 | OPV(0,val*xp[k]) | ||
625 | OPV(1,val/xp[k]) | ||
626 | OPV(2,val+xp[k]) | ||
627 | OPV(3,val-xp[k]) | ||
628 | OPV(6,val%xp[k]) | ||
629 | OPV(7,xp[k]%val) | ||
630 | default: ERROR(BAD_CODE); | ||
631 | } | ||
632 | } | ||
633 | |||
529 | 634 | ||
530 | 635 | ||
531 | inline doublecomplex complex_add(doublecomplex a, doublecomplex b) { | 636 | inline doublecomplex complex_add(doublecomplex a, doublecomplex b) { |
@@ -608,6 +713,20 @@ REQUIRES(an == bn && an == rn, BAD_SIZE); | |||
608 | } | 713 | } |
609 | 714 | ||
610 | 715 | ||
716 | int zipI(int code, KIVEC(a), KIVEC(b), IVEC(r)) { | ||
717 | REQUIRES(an == bn && an == rn, BAD_SIZE); | ||
718 | int k; | ||
719 | switch(code) { | ||
720 | OPZO(0,"zipI Add",+) | ||
721 | OPZO(1,"zipI Sub",-) | ||
722 | OPZO(2,"zipI Mul",*) | ||
723 | OPZO(3,"zipI Div",/) | ||
724 | OPZO(6,"zipI Mod",%) | ||
725 | default: ERROR(BAD_CODE); | ||
726 | } | ||
727 | } | ||
728 | |||
729 | |||
611 | 730 | ||
612 | #define OPZOb(C,msg,O) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) r2p[k] = a2p[k] O b2p[k]; OK } | 731 | #define OPZOb(C,msg,O) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) r2p[k] = a2p[k] O b2p[k]; OK } |
613 | #define OPZEb(C,msg,E) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) r2p[k] = E(a2p[k],b2p[k]); OK } | 732 | #define OPZEb(C,msg,E) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) r2p[k] = E(a2p[k],b2p[k]); OK } |
@@ -679,7 +798,7 @@ int vectorScan(char * file, int* n, double**pp){ | |||
679 | *pp = p; | 798 | *pp = p; |
680 | fclose(fp); | 799 | fclose(fp); |
681 | OK | 800 | OK |
682 | } | 801 | } |
683 | 802 | ||
684 | int saveMatrix(char * file, char * format, KDMAT(a)){ | 803 | int saveMatrix(char * file, char * format, KDMAT(a)){ |
685 | FILE * fp; | 804 | FILE * fp; |
@@ -754,7 +873,7 @@ int random_vector(unsigned int seed, int code, DVEC(r)) { | |||
754 | double V1,V2,S; | 873 | double V1,V2,S; |
755 | 874 | ||
756 | srandom(seed); | 875 | srandom(seed); |
757 | 876 | ||
758 | int k; | 877 | int k; |
759 | switch (code) { | 878 | switch (code) { |
760 | case 0: { // uniform | 879 | case 0: { // uniform |
@@ -816,7 +935,7 @@ int random_vector(unsigned int seed, int code, DVEC(r)) { | |||
816 | char random_state[128]; | 935 | char random_state[128]; |
817 | memset(&buffer, 0, sizeof(struct random_data)); | 936 | memset(&buffer, 0, sizeof(struct random_data)); |
818 | memset(random_state, 0, sizeof(random_state)); | 937 | memset(random_state, 0, sizeof(random_state)); |
819 | 938 | ||
820 | initstate_r(seed,random_state,sizeof(random_state),&buffer); | 939 | initstate_r(seed,random_state,sizeof(random_state),&buffer); |
821 | // setstate_r(random_state,&buffer); | 940 | // setstate_r(random_state,&buffer); |
822 | // srandom_r(seed,&buffer); | 941 | // srandom_r(seed,&buffer); |
diff --git a/packages/base/src/Data/Packed/Internal/Numeric.hs b/packages/base/src/Data/Packed/Internal/Numeric.hs index e6fcd31..6c30a72 100644 --- a/packages/base/src/Data/Packed/Internal/Numeric.hs +++ b/packages/base/src/Data/Packed/Internal/Numeric.hs | |||
@@ -186,23 +186,23 @@ instance Container Vector CInt | |||
186 | where | 186 | where |
187 | conj' = id | 187 | conj' = id |
188 | size' = dim | 188 | size' = dim |
189 | -- scale' = vectorMapValF Scale | 189 | scale' = vectorMapValI Scale |
190 | -- addConstant = vectorMapValF AddConstant | 190 | addConstant = vectorMapValI AddConstant |
191 | -- add = vectorZipF Add | 191 | add = vectorZipI Add |
192 | -- sub = vectorZipF Sub | 192 | sub = vectorZipI Sub |
193 | -- mul = vectorZipF Mul | 193 | mul = vectorZipI Mul |
194 | -- equal u v = dim u == dim v && maxElement (vectorMapF Abs (sub u v)) == 0.0 | 194 | equal u v = dim u == dim v && maxElement' (vectorMapI Abs (sub u v)) == 0 |
195 | scalar' x = fromList [x] | 195 | scalar' x = fromList [x] |
196 | konst' = constantD | 196 | konst' = constantD |
197 | build' = buildV | 197 | build' = buildV |
198 | cmap' = mapVector | 198 | cmap' = mapVector |
199 | atIndex' = (@>) | 199 | atIndex' = (@>) |
200 | -- minIndex' = emptyErrorV "minIndex" (round . toScalarF MinIdx) | 200 | minIndex' = emptyErrorV "minIndex" (fromIntegral . toScalarI MinIdx) |
201 | -- maxIndex' = emptyErrorV "maxIndex" (round . toScalarF MaxIdx) | 201 | maxIndex' = emptyErrorV "maxIndex" (fromIntegral . toScalarI MaxIdx) |
202 | -- minElement' = emptyErrorV "minElement" (toScalarF Min) | 202 | minElement' = emptyErrorV "minElement" (toScalarI Min) |
203 | -- maxElement' = emptyErrorV "maxElement" (toScalarF Max) | 203 | maxElement' = emptyErrorV "maxElement" (toScalarI Max) |
204 | -- sumElements' = sumF | 204 | sumElements' = sumI |
205 | -- prodElements' = prodF | 205 | prodElements' = prodI |
206 | step' = stepI | 206 | step' = stepI |
207 | find' = findV | 207 | find' = findV |
208 | assoc' = assocV | 208 | assoc' = assocV |
@@ -569,9 +569,9 @@ instance Product (Complex Double) where | |||
569 | 569 | ||
570 | instance Product CInt where | 570 | instance Product CInt where |
571 | norm2 = undefined | 571 | norm2 = undefined |
572 | -- absSum = emptyVal (toScalarF AbsSum) | 572 | absSum = emptyVal (sumElements . vectorMapI Abs) |
573 | -- norm1 = emptyVal (toScalarF AbsSum) | 573 | norm1 = absSum |
574 | -- normInf = emptyVal (maxElement . vectorMapF Abs) | 574 | normInf = emptyVal (maxElement . vectorMapI Abs) |
575 | multiply = emptyMul multiplyI | 575 | multiply = emptyMul multiplyI |
576 | 576 | ||
577 | 577 | ||
diff --git a/packages/base/src/Numeric/Vector.hs b/packages/base/src/Numeric/Vector.hs index 1c16871..6cac5dc 100644 --- a/packages/base/src/Numeric/Vector.hs +++ b/packages/base/src/Numeric/Vector.hs | |||
@@ -32,6 +32,14 @@ adaptScalar f1 f2 f3 x y | |||
32 | 32 | ||
33 | ------------------------------------------------------------------ | 33 | ------------------------------------------------------------------ |
34 | 34 | ||
35 | instance Num (Vector CInt) where | ||
36 | (+) = adaptScalar addConstant add (flip addConstant) | ||
37 | negate = scale (-1) | ||
38 | (*) = adaptScalar scale mul (flip scale) | ||
39 | signum = vectorMapI Sign | ||
40 | abs = vectorMapI Abs | ||
41 | fromInteger = fromList . return . fromInteger | ||
42 | |||
35 | instance Num (Vector Float) where | 43 | instance Num (Vector Float) where |
36 | (+) = adaptScalar addConstant add (flip addConstant) | 44 | (+) = adaptScalar addConstant add (flip addConstant) |
37 | negate = scale (-1) | 45 | negate = scale (-1) |
diff --git a/packages/base/src/Numeric/Vectorized.hs b/packages/base/src/Numeric/Vectorized.hs index 405ae01..70bd48b 100644 --- a/packages/base/src/Numeric/Vectorized.hs +++ b/packages/base/src/Numeric/Vectorized.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.Vectorized | 3 | -- Module : Numeric.Vectorized |
4 | -- Copyright : (c) Alberto Ruiz 2007-14 | 4 | -- Copyright : (c) Alberto Ruiz 2007-15 |
5 | -- License : BSD3 | 5 | -- License : BSD3 |
6 | -- Maintainer : Alberto Ruiz | 6 | -- Maintainer : Alberto Ruiz |
7 | -- Stability : provisional | 7 | -- Stability : provisional |
@@ -11,12 +11,12 @@ | |||
11 | ----------------------------------------------------------------------------- | 11 | ----------------------------------------------------------------------------- |
12 | 12 | ||
13 | module Numeric.Vectorized ( | 13 | module Numeric.Vectorized ( |
14 | sumF, sumR, sumQ, sumC, | 14 | sumF, sumR, sumQ, sumC, sumI, |
15 | prodF, prodR, prodQ, prodC, | 15 | prodF, prodR, prodQ, prodC, prodI, |
16 | FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, | 16 | FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, toScalarI, |
17 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, | 17 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, vectorMapI, |
18 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, | 18 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, vectorMapValI, |
19 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, | 19 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, vectorZipI, |
20 | vectorScan, saveMatrix, | 20 | vectorScan, saveMatrix, |
21 | Seed, RandDist(..), randomVector, | 21 | Seed, RandDist(..), randomVector, |
22 | sortVector, roundVector | 22 | sortVector, roundVector |
@@ -67,6 +67,8 @@ data FunCodeSV = Scale | |||
67 | | Negate | 67 | | Negate |
68 | | PowSV | 68 | | PowSV |
69 | | PowVS | 69 | | PowVS |
70 | | ModSV | ||
71 | | ModVS | ||
70 | deriving Enum | 72 | deriving Enum |
71 | 73 | ||
72 | data FunCodeVV = Add | 74 | data FunCodeVV = Add |
@@ -75,6 +77,7 @@ data FunCodeVV = Add | |||
75 | | Div | 77 | | Div |
76 | | Pow | 78 | | Pow |
77 | | ATan2 | 79 | | ATan2 |
80 | | Mod | ||
78 | deriving Enum | 81 | deriving Enum |
79 | 82 | ||
80 | data FunCodeS = Norm2 | 83 | data FunCodeS = Norm2 |
@@ -89,69 +92,67 @@ data FunCodeS = Norm2 | |||
89 | 92 | ||
90 | -- | sum of elements | 93 | -- | sum of elements |
91 | sumF :: Vector Float -> Float | 94 | sumF :: Vector Float -> Float |
92 | sumF x = unsafePerformIO $ do | 95 | sumF = sumg c_sumF |
93 | r <- createVector 1 | ||
94 | app2 c_sumF vec x vec r "sumF" | ||
95 | return $ r @> 0 | ||
96 | 96 | ||
97 | -- | sum of elements | 97 | -- | sum of elements |
98 | sumR :: Vector Double -> Double | 98 | sumR :: Vector Double -> Double |
99 | sumR x = unsafePerformIO $ do | 99 | sumR = sumg c_sumR |
100 | r <- createVector 1 | ||
101 | app2 c_sumR vec x vec r "sumR" | ||
102 | return $ r @> 0 | ||
103 | 100 | ||
104 | -- | sum of elements | 101 | -- | sum of elements |
105 | sumQ :: Vector (Complex Float) -> Complex Float | 102 | sumQ :: Vector (Complex Float) -> Complex Float |
106 | sumQ x = unsafePerformIO $ do | 103 | sumQ = sumg c_sumQ |
107 | r <- createVector 1 | ||
108 | app2 c_sumQ vec x vec r "sumQ" | ||
109 | return $ r @> 0 | ||
110 | 104 | ||
111 | -- | sum of elements | 105 | -- | sum of elements |
112 | sumC :: Vector (Complex Double) -> Complex Double | 106 | sumC :: Vector (Complex Double) -> Complex Double |
113 | sumC x = unsafePerformIO $ do | 107 | sumC = sumg c_sumC |
114 | r <- createVector 1 | 108 | |
115 | app2 c_sumC vec x vec r "sumC" | 109 | -- | sum of elements |
116 | return $ r @> 0 | 110 | sumI :: Vector CInt -> CInt |
111 | sumI = sumg c_sumI | ||
112 | |||
113 | sumg f x = unsafePerformIO $ do | ||
114 | r <- createVector 1 | ||
115 | app2 f vec x vec r "sum" | ||
116 | return $ r @> 0 | ||
117 | 117 | ||
118 | foreign import ccall unsafe "sumF" c_sumF :: TFF | 118 | foreign import ccall unsafe "sumF" c_sumF :: TFF |
119 | foreign import ccall unsafe "sumR" c_sumR :: TVV | 119 | foreign import ccall unsafe "sumR" c_sumR :: TVV |
120 | foreign import ccall unsafe "sumQ" c_sumQ :: TQVQV | 120 | foreign import ccall unsafe "sumQ" c_sumQ :: TQVQV |
121 | foreign import ccall unsafe "sumC" c_sumC :: TCVCV | 121 | foreign import ccall unsafe "sumC" c_sumC :: TCVCV |
122 | foreign import ccall unsafe "sumC" c_sumI :: CV CInt (CV CInt (IO CInt)) | ||
122 | 123 | ||
123 | -- | product of elements | 124 | -- | product of elements |
124 | prodF :: Vector Float -> Float | 125 | prodF :: Vector Float -> Float |
125 | prodF x = unsafePerformIO $ do | 126 | prodF = prodg c_prodF |
126 | r <- createVector 1 | ||
127 | app2 c_prodF vec x vec r "prodF" | ||
128 | return $ r @> 0 | ||
129 | 127 | ||
130 | -- | product of elements | 128 | -- | product of elements |
131 | prodR :: Vector Double -> Double | 129 | prodR :: Vector Double -> Double |
132 | prodR x = unsafePerformIO $ do | 130 | prodR = prodg c_prodR |
133 | r <- createVector 1 | ||
134 | app2 c_prodR vec x vec r "prodR" | ||
135 | return $ r @> 0 | ||
136 | 131 | ||
137 | -- | product of elements | 132 | -- | product of elements |
138 | prodQ :: Vector (Complex Float) -> Complex Float | 133 | prodQ :: Vector (Complex Float) -> Complex Float |
139 | prodQ x = unsafePerformIO $ do | 134 | prodQ = prodg c_prodQ |
140 | r <- createVector 1 | ||
141 | app2 c_prodQ vec x vec r "prodQ" | ||
142 | return $ r @> 0 | ||
143 | 135 | ||
144 | -- | product of elements | 136 | -- | product of elements |
145 | prodC :: Vector (Complex Double) -> Complex Double | 137 | prodC :: Vector (Complex Double) -> Complex Double |
146 | prodC x = unsafePerformIO $ do | 138 | prodC = prodg c_prodC |
147 | r <- createVector 1 | 139 | |
148 | app2 c_prodC vec x vec r "prodC" | 140 | -- | product of elements |
149 | return $ r @> 0 | 141 | prodI :: Vector CInt -> CInt |
142 | prodI = prodg c_prodI | ||
143 | |||
144 | |||
145 | prodg f x = unsafePerformIO $ do | ||
146 | r <- createVector 1 | ||
147 | app2 f vec x vec r "prod" | ||
148 | return $ r @> 0 | ||
149 | |||
150 | 150 | ||
151 | foreign import ccall unsafe "prodF" c_prodF :: TFF | 151 | foreign import ccall unsafe "prodF" c_prodF :: TFF |
152 | foreign import ccall unsafe "prodR" c_prodR :: TVV | 152 | foreign import ccall unsafe "prodR" c_prodR :: TVV |
153 | foreign import ccall unsafe "prodQ" c_prodQ :: TQVQV | 153 | foreign import ccall unsafe "prodQ" c_prodQ :: TQVQV |
154 | foreign import ccall unsafe "prodC" c_prodC :: TCVCV | 154 | foreign import ccall unsafe "prodC" c_prodC :: TCVCV |
155 | foreign import ccall unsafe "prodI" c_prodI :: CV CInt (CV CInt (IO CInt)) | ||
155 | 156 | ||
156 | ------------------------------------------------------------------ | 157 | ------------------------------------------------------------------ |
157 | 158 | ||
@@ -203,6 +204,12 @@ toScalarQ oper = toScalarAux c_toScalarQ (fromei oper) | |||
203 | 204 | ||
204 | foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> TQVF | 205 | foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> TQVF |
205 | 206 | ||
207 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | ||
208 | toScalarI :: FunCodeS -> Vector CInt -> CInt | ||
209 | toScalarI oper = toScalarAux c_toScalarI (fromei oper) | ||
210 | |||
211 | foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> CV CInt (CV CInt (IO CInt)) | ||
212 | |||
206 | ------------------------------------------------------------------ | 213 | ------------------------------------------------------------------ |
207 | 214 | ||
208 | -- | map of real vectors with given function | 215 | -- | map of real vectors with given function |
@@ -229,6 +236,12 @@ vectorMapQ = vectorMapAux c_vectorMapQ | |||
229 | 236 | ||
230 | foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TQVQV | 237 | foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TQVQV |
231 | 238 | ||
239 | -- | map of real vectors with given function | ||
240 | vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt | ||
241 | vectorMapI = vectorMapAux c_vectorMapI | ||
242 | |||
243 | foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> CV CInt (CV CInt (IO CInt)) | ||
244 | |||
232 | ------------------------------------------------------------------- | 245 | ------------------------------------------------------------------- |
233 | 246 | ||
234 | -- | map of real vectors with given function | 247 | -- | map of real vectors with given function |
@@ -255,6 +268,13 @@ vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) | |||
255 | 268 | ||
256 | foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV | 269 | foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV |
257 | 270 | ||
271 | -- | map of real vectors with given function | ||
272 | vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt | ||
273 | vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper) | ||
274 | |||
275 | foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> CV CInt (CV CInt (IO CInt)) | ||
276 | |||
277 | |||
258 | ------------------------------------------------------------------- | 278 | ------------------------------------------------------------------- |
259 | 279 | ||
260 | -- | elementwise operation on real vectors | 280 | -- | elementwise operation on real vectors |
@@ -281,6 +301,13 @@ vectorZipQ = vectorZipAux c_vectorZipQ | |||
281 | 301 | ||
282 | foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TQVQVQV | 302 | foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TQVQVQV |
283 | 303 | ||
304 | -- | elementwise operation on CInt vectors | ||
305 | vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt | ||
306 | vectorZipI = vectorZipAux c_vectorZipI | ||
307 | |||
308 | foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> CV CInt (CV CInt (CV CInt (IO CInt))) | ||
309 | |||
310 | |||
284 | -------------------------------------------------------------------------------- | 311 | -------------------------------------------------------------------------------- |
285 | 312 | ||
286 | foreign import ccall unsafe "vectorScan" c_vectorScan | 313 | foreign import ccall unsafe "vectorScan" c_vectorScan |