Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/potentials/Tables/divide_by_table.c @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 /* divide_by_table.c ../potential/tables */ | |
2 | |
3 | |
4 /******************************************/ | |
5 /* 6 input & 1 output */ | |
6 /* Big table [0] */ | |
7 /* Big domain [1] */ | |
8 /* big sizes [2] */ | |
9 /* Small table [3] */ | |
10 /* small domain [4] */ | |
11 /* small sizes [5] */ | |
12 /* */ | |
13 /* New big table[0] */ | |
14 /******************************************/ | |
15 | |
16 #include "mex.h" | |
17 | |
18 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ | |
19 int i, j, count, NB, NS, siz_b, siz_s, ndim, temp; | |
20 int *mask, *sx, *sy, *cpsy, *subs, *s, *cpsy2; | |
21 double *pbDomain, *psDomain, *sp, *zp, *bs, value; | |
22 | |
23 plhs[0] = mxDuplicateArray(prhs[0]); | |
24 zp = mxGetPr(plhs[0]); | |
25 | |
26 siz_b = mxGetNumberOfElements(prhs[1]); | |
27 siz_s = mxGetNumberOfElements(prhs[4]); | |
28 pbDomain = mxGetPr(prhs[1]); | |
29 psDomain = mxGetPr(prhs[4]); | |
30 | |
31 NB = mxGetNumberOfElements(prhs[0]); | |
32 NS = mxGetNumberOfElements(prhs[3]); | |
33 sp = mxGetPr(prhs[3]); | |
34 | |
35 bs = mxGetPr(prhs[2]); | |
36 | |
37 if(NS == 1){ | |
38 value = *sp; | |
39 if(value == 0) value = 1; | |
40 for(i=0; i<NB; i++){ | |
41 zp[i] /= value; | |
42 } | |
43 return; | |
44 } | |
45 | |
46 if(NS == NB){ | |
47 for(i=0; i<NB; i++){ | |
48 value = sp[i]; | |
49 if(value == 0) value = 1; | |
50 zp[i] /= value; | |
51 } | |
52 return; | |
53 } | |
54 | |
55 mask = malloc(siz_s * sizeof(int)); | |
56 count = 0; | |
57 for(i=0; i<siz_s; i++){ | |
58 for(j=0; j<siz_b; j++){ | |
59 if(psDomain[i] == pbDomain[j]){ | |
60 mask[count] = j; | |
61 count++; | |
62 break; | |
63 } | |
64 } | |
65 } | |
66 | |
67 ndim = siz_b; | |
68 sx = (int *)malloc(sizeof(int)*ndim); | |
69 sy = (int *)malloc(sizeof(int)*ndim); | |
70 for(i=0; i<ndim; i++){ | |
71 sx[i] = (int)bs[i]; | |
72 sy[i] = 1; | |
73 } | |
74 for(i=0; i<count; i++){ | |
75 temp = mask[i]; | |
76 sy[temp] = sx[temp]; | |
77 } | |
78 | |
79 s = (int *)malloc(sizeof(int)*ndim); | |
80 *(cpsy = (int *)malloc(sizeof(int)*ndim)) = 1; | |
81 subs = (int *)malloc(sizeof(int)*ndim); | |
82 cpsy2 = (int *)malloc(sizeof(int)*ndim); | |
83 for(i = 0; i < ndim; i++){ | |
84 subs[i] = 0; | |
85 s[i] = sx[i] - 1; | |
86 } | |
87 | |
88 for(i = 0; i < ndim-1; i++){ | |
89 cpsy[i+1] = cpsy[i]*sy[i]--; | |
90 cpsy2[i] = cpsy[i]*sy[i]; | |
91 } | |
92 cpsy2[ndim-1] = cpsy[ndim-1]*(--sy[ndim-1]); | |
93 | |
94 for(j=0; j<NB; j++){ | |
95 value = *sp; | |
96 if(value == 0) value = 1; | |
97 *zp++ /= value; | |
98 for(i = 0; i < ndim; i++){ | |
99 if(subs[i] == s[i]){ | |
100 subs[i] = 0; | |
101 if(sy[i]) | |
102 sp -= cpsy2[i]; | |
103 } | |
104 else{ | |
105 subs[i]++; | |
106 if(sy[i]) | |
107 sp += cpsy[i]; | |
108 break; | |
109 } | |
110 } | |
111 } | |
112 free(sx); | |
113 free(sy); | |
114 free(s); | |
115 free(cpsy); | |
116 free(subs); | |
117 free(cpsy2); | |
118 free(mask); | |
119 } | |
120 |