29 inline double combinedSum(
30 const int* conf,
const std::vector<double>** valuesContainer,
int dimNumber
33 for(
int i=0; i<dimNumber;i++)
34 res += (*(valuesContainer[i]))[conf[i]];
38 inline int* getConf(
void* conf)
40 return reinterpret_cast<int*
>(
41 reinterpret_cast<char*
>(conf) +
sizeof(
double)
45 inline double getLProb(
void* conf)
47 double ret = *
reinterpret_cast<double*
>(conf);
52 inline double unnormalized_logProb(
const int* conf,
const double* logProbs,
int dim)
56 int curr_method = fegetround();
58 fesetround(FE_TOWARDZERO);
60 for(
int i=0; i < dim; i++)
61 res += minuslogFactorial(conf[i]);
63 fesetround(FE_UPWARD);
65 for(
int i=0; i < dim; i++)
66 res += conf[i] * logProbs[i];
68 fesetround(curr_method);
73 inline double mass(
const int* conf,
const double* masses,
int dim)
77 for(
int i=0; i < dim; i++)
79 res += conf[i] * masses[i];
87 std::tuple<double,double,int*> t1,
88 std::tuple<double,double,int*> t2
90 return std::get<1>(t1) > std::get<1>(t2);
93 template<
typename T>
void printArray(
const T* array,
int size,
const char* prefix =
"")
95 if (strlen(prefix) > 0)
96 std::cout << prefix <<
" ";
97 for (
int i=0; i<size; i++)
98 std::cout << array[i] <<
" ";
99 std::cout << std::endl;
102 template<
typename T>
void printVector(
const std::vector<T>& vec)
104 printArray<T>(vec.data(), vec.size());
107 template<
typename T>
void printOffsets(
const T** array,
int size,
const T* offset,
const char* prefix =
"")
109 if (strlen(prefix) > 0)
110 std::cout << prefix <<
" ";
111 for (
int i=0; i<size; i++)
112 std::cout << array[i] - offset <<
" ";
113 std::cout << std::endl;
116 template<
typename T>
void printNestedArray(
const T** array,
const int* shape,
int size)
118 for (
int i=0; i<size; i++)
119 printArray(array[i], shape[i]);
120 std::cout << std::endl;
123 #define mswap(x, y) swapspace = x; x = y; y=swapspace;
127 void*
quickselect(
void** array,
int n,
int start,
int end);
130 template <
typename T>
inline static T* array_copy(
const T* A,
int size)
132 T* ret =
new T[size];
133 memcpy(ret, A, size*
sizeof(T));
137 template<
typename T>
void dealloc_table(T* tbl,
int dim)
139 for(
int i=0; i<dim; i++)
146 template<
typename T>
void realloc_append(T** array, T what,
size_t old_array_size)
148 T* newT =
new T[old_array_size+1];
149 memcpy(newT, *array, old_array_size*
sizeof(T));
150 newT[old_array_size] = what;