From 66db67b299bd91f3cf35f93500e05eaf6c8085d3 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 6 Jun 2015 14:09:21 +0200 Subject: int64_t C funs --- packages/base/src/Internal/C/lapack-aux.c | 101 ++++------ packages/base/src/Internal/C/lapack-aux.h | 6 + packages/base/src/Internal/C/vector-aux.c | 300 +++++++++++++++++++++++------- 3 files changed, 276 insertions(+), 131 deletions(-) (limited to 'packages/base/src') diff --git a/packages/base/src/Internal/C/lapack-aux.c b/packages/base/src/Internal/C/lapack-aux.c index 063e601..7da6f6a 100644 --- a/packages/base/src/Internal/C/lapack-aux.c +++ b/packages/base/src/Internal/C/lapack-aux.c @@ -3,6 +3,8 @@ #include #include #include +#include + #include "lapack-aux.h" #define MACRO(B) do {B} while (0) @@ -1300,6 +1302,18 @@ int multiplyI(KOIMAT(a), KOIMAT(b), OIMAT(r)) { OK } +int multiplyL(KOLMAT(a), KOLMAT(b), OLMAT(r)) { + { TRAV(r,i,j) { + int k; + AT(r,i,j) = 0; + for (k=0;k +#include typedef double complex TCD; typedef float complex TCF; @@ -66,6 +67,14 @@ int sumI(KIVEC(x),IVEC(r)) { OK } +int sumL(KLVEC(x),LVEC(r)) { + REQUIRES(rn==1,BAD_SIZE); + int i; + int res = 0; + for (i = 0; i < xn; i++) res += xp[i]; + rp[0] = res; + OK +} int sumQ(KQVEC(x),QVEC(r)) { DEBUGMSG("sumQ"); @@ -127,7 +136,14 @@ int prodI(KIVEC(x),IVEC(r)) { OK } - +int prodL(KLVEC(x),LVEC(r)) { + REQUIRES(rn==1,BAD_SIZE); + int i; + int res = 1; + for (i = 0; i < xn; i++) res *= xp[i]; + rp[0] = res; + OK +} int prodQ(KQVEC(x),QVEC(r)) { DEBUGMSG("prodQ"); @@ -189,7 +205,7 @@ double vector_min(KDVEC(x)) { return r; } -double vector_max_index(KDVEC(x)) { +int vector_max_index(KDVEC(x)) { int k, r = 0; for (k = 1; kxp[r]) { @@ -199,7 +215,7 @@ double vector_max_index(KDVEC(x)) { return r; } -double vector_min_index(KDVEC(x)) { +int vector_min_index(KDVEC(x)) { int k, r = 0; for (k = 1; kxp[r]) { @@ -264,7 +280,7 @@ float vector_max_index_f(KFVEC(x)) { return r; } -float vector_min_index_f(KFVEC(x)) { +int vector_min_index_f(KFVEC(x)) { int k, r = 0; for (k = 1; kr) { + r = xp[k]; + } + } + return r; +} + +int64_t vector_min_l(KLVEC(x)) { + int64_t r = xp[0]; + int k; + for (k = 1; kxp[r]) { + r = k; + } + } + return r; +} + +int vector_min_index_l(KLVEC(x)) { + int k, r = 0; + for (k = 1; k0) { + return m >=0 ? m : m+b; + } else { + return m <=0 ? m : m+b; + } +} + +int mapValL(int code, int64_t* pval, KLVEC(x), LVEC(r)) { + int k; + int64_t val = *pval; + REQUIRES(xn == rn,BAD_SIZE); + DEBUGMSG("mapValL"); + switch (code) { + OPV(0,val*xp[k]) + OPV(1,val/xp[k]) + OPV(2,val+xp[k]) + OPV(3,val-xp[k]) + OPV(6,mod(val,xp[k])) + OPV(7,mod(xp[k],val)) + default: ERROR(BAD_CODE); + } +} + + inline doublecomplex complex_add(doublecomplex a, doublecomplex b) { doublecomplex r; @@ -736,6 +847,19 @@ REQUIRES(an == bn && an == rn, BAD_SIZE); } +int zipL(int code, KLVEC(a), KLVEC(b), LVEC(r)) { +REQUIRES(an == bn && an == rn, BAD_SIZE); + int k; + switch(code) { + OPZO(0,"zipI Add",+) + OPZO(1,"zipI Sub",-) + OPZO(2,"zipI Mul",*) + OPZO(3,"zipI Div",/) + OPZO(6,"zipI Mod",%) + default: ERROR(BAD_CODE); + } +} + #define OPZOb(C,msg,O) case C: {DEBUGMSG(msg) for(k=0;k *(int64_t*)b; +} + +int sort_valuesL(KLVEC(v),LVEC(r)) { + memcpy(rp,vp,vn*sizeof(int64_t)); + qsort(rp,rn,sizeof(int64_t),compare_ints); + OK +} + + //////////////////////////////////////// @@ -1010,7 +1146,7 @@ int sort_valuesI(KIVEC(v),IVEC(r)) { OK -typedef struct SDI { int pos; double val;} DI; +typedef struct DI { int pos; double val;} DI; int compare_doubles_i (const void *a, const void *b) { return ((DI*)a)->val > ((DI*)b)->val; @@ -1043,6 +1179,17 @@ int sort_indexI(KIVEC(v),IVEC(r)) { } +typedef struct LI { int pos; int64_t val;} LI; + +int compare_longs_i (const void *a, const void *b) { + return ((II*)a)->val > ((II*)b)->val; +} + +int sort_indexL(KLVEC(v),LVEC(r)) { + SORTIDX_IMP(II,compare_longs_i) +} + + //////////////////////////////////////////////////////////////////////////////// int round_vector(KDVEC(v),DVEC(r)) { @@ -1088,6 +1235,44 @@ int range_vector(IVEC(r)) { OK } +/////////////////////////// + + +int round_vector_l(KDVEC(v),LVEC(r)) { + int k; + for(k=0; kyp[k]?gtp[k]:eqp[k]); \ - } \ - OK - -int condF(FVEC(x),FVEC(y),FVEC(lt),FVEC(eq),FVEC(gt),FVEC(r)) { - COND_IMP -} - -int condD(DVEC(x),DVEC(y),DVEC(lt),DVEC(eq),DVEC(gt),DVEC(r)) { - COND_IMP +int compareL(KLVEC(x),KLVEC(y),IVEC(r)) { + COMPARE_IMP } -int condI(KIVEC(x),KIVEC(y),KIVEC(lt),KIVEC(eq),KIVEC(gt),IVEC(r)) { - COND_IMP -} #define CHOOSE_IMP \ @@ -1314,6 +1469,11 @@ int chooseI(KIVEC(cond),KIVEC(lt),KIVEC(eq),KIVEC(gt),IVEC(r)) { CHOOSE_IMP } +int chooseL(KIVEC(cond),KLVEC(lt),KLVEC(eq),KLVEC(gt),LVEC(r)) { + CHOOSE_IMP +} + + int chooseC(KIVEC(cond),KCVEC(lt),KCVEC(eq),KCVEC(gt),CVEC(r)) { CHOOSE_IMP } -- cgit v1.2.3