Daniel@0: /* convert_to_sparse_table.c convert a sparse discrete CPD with evidence into sparse table */ Daniel@0: /* convert_to_pot.m located in ../CPDs/discrete_CPD call it */ Daniel@0: /* 3 input */ Daniel@0: /* CPD prhs[0] with 1D sparse CPT */ Daniel@0: /* domain prhs[1] */ Daniel@0: /* evidence prhs[2] */ Daniel@0: /* 1 output */ Daniel@0: /* T plhs[0] sparse table */ Daniel@0: Daniel@0: #include Daniel@0: #include "mex.h" Daniel@0: Daniel@0: void ind_subv(int index, const int *cumprod, const int n, int *bsubv){ Daniel@0: int i; Daniel@0: Daniel@0: for (i = n-1; i >= 0; i--) { Daniel@0: bsubv[i] = ((int)floor(index / cumprod[i])); Daniel@0: index = index % cumprod[i]; Daniel@0: } Daniel@0: } Daniel@0: Daniel@0: int subv_ind(const int n, const int *cumprod, const int *subv){ Daniel@0: int i, index=0; Daniel@0: Daniel@0: for(i=0; i