ind_t VarSizeList_get(const PVarSizeList pset, uint32 i, ind_t* data, ind_t max_dim){ assert(i < pset->count()); auto cur = pset->get(i); for (int i=0;i<max_dim;i++) data[i] = cur[i]; return cur.size(); }
PVarSizeList GetIndexSet(PVarSizeList pRet, const PProfitCalculator profCalc, double max_prof, double **p_profits) { ind_t max_d = profCalc->max_dim(); ind_mul_ind_t ind_set; ind_set.push_back(setprof_t(mul_ind_t(), profCalc->calc_log_prof(mul_ind_t()))); double cur_prof; ind_mul_ind_t::iterator itrCur = ind_set.begin(); while (itrCur != ind_set.end()) { if (itrCur->size < max_d) { mul_ind_t cur_ind = itrCur->ind; ind_set.push_back(setprof_t(cur_ind, -1, itrCur->size+1)); ind_t cur_size = itrCur->size; cur_ind.step(cur_size); while ((cur_prof=profCalc->calc_log_prof(cur_ind)) <= max_prof){ ind_set.push_back(setprof_t(cur_ind, cur_prof)); cur_ind.step(cur_size); } // if (added > 0) // This assumes that dimensions are ordered! } // If this iterator has negative profit it means it's temporary and // can be deleted safely (since all derivatives are already added) if (itrCur->profit < 0) itrCur = ind_set.erase(itrCur); // erase returns the next iterator else itrCur++; } ind_set.sort(compare_setprof); if (p_profits) *p_profits = static_cast<double*>(malloc(sizeof(double) * ind_set.size())); uint32 i=0; if (!pRet) pRet = new VarSizeList(ind_set.size()); for (auto itr=ind_set.begin();itr!=ind_set.end();itr++){ if (!pRet->has_ind(itr->ind)) pRet->push_back(itr->ind); if (p_profits) (*p_profits)[i++] = itr->profit; } return pRet; }
PVarSizeList VarSizeList_from_matrix(const ind_t *sizes, uint32 count, const ind_t *j, uint32 j_size, const ind_t *data, uint32 data_size){ PVarSizeList pset = new VarSizeList(count); uint32 total_size = 0; for (uint32 i=0;i<count;i++){ total_size += sizes[i]; assert(j_size >= total_size); assert(data_size >= total_size); pset->push_back(mul_ind_t(j, data, sizes[i])); j += sizes[i]; data += sizes[i]; } return pset; }
double VarSizeList_estimate_bias(const PVarSizeList pset, const double *err_contributions, uint32 count, const double *rates, uint32 rates_size){ return pset->estimate_bias(err_contributions, count, rates, rates_size); }
void VarSizeList_get_adaptive_order(const PVarSizeList pset, const double *error, const double *work, uint32 *adaptive_order, uint32 count, ind_t seedLookahead){ pset->get_adaptive_order(error, work, adaptive_order, count, seedLookahead); }
PVarSizeList VarSizeList_expand_set(const PVarSizeList pset, const double* error, const double* work, uint32 count, ind_t dimLookahead){ PVarSizeList result = new VarSizeList(); *result = pset->expand_set(error, work, count, dimLookahead); return result; }
ind_t VarSizeList_get(const PVarSizeList pset, uint32 i, ind_t* data, ind_t* j, ind_t size){ const mul_ind_t& cur = pset->get(i); i=0; assert(cur.active() <= size); for (auto itr=cur.begin();itr!=cur.end();itr++, i++) { data[i] = itr->value; j[i] = itr->ind; } return cur.active(); }
PVarSizeList VarSizeList_from_matrix(PVarSizeList pset, const ind_t *sizes, uint32 count, const ind_t *j, uint32 j_size, const ind_t *data, uint32 data_size){ if (!pset) pset = new VarSizeList(count); uint32 total_size = 0; for (uint32 i=0;i<count;i++){ total_size += sizes[i]; assert(j_size >= total_size); assert(data_size >= total_size); //std::cout << "adding: " << mul_ind_t(j, data, sizes[i]) << "of size" << sizes[i] << std::endl; pset->push_back(mul_ind_t(j, data, sizes[i])); j += sizes[i]; data += sizes[i]; } return pset; }
void VarSizeList_to_matrix(const PVarSizeList pset, ind_t *ij, uint32 ij_size, ind_t *data, uint32 data_size){ pset->to_matrix(ij, ij_size, data, data_size); }
void VarSizeList_all_active_dim(const PVarSizeList pset, uint32 *active_dim, uint32 size){ pset->all_active_dim(active_dim, size); }
void VarSizeList_all_dim(const PVarSizeList pset, uint32 *dim, uint32 size){ pset->all_dim(dim, size); }
ind_t VarSizeList_get_active_dim(const PVarSizeList pset, uint32 i){ return pset->get(i).active(); }
ind_t VarSizeList_get_dim(const PVarSizeList pset, uint32 i){ return pset->get(i).size(); }
void CalculateSetProfit(const PVarSizeList pset, const PProfitCalculator profCalc, double *log_prof, uint32 size){ pset->calc_set_profit(profCalc, log_prof, size); }
void VarSizeList_is_parent_of_admissible(const PVarSizeList pset, unsigned char *out, uint32 count){ pset->is_parent_of_admissible(out, count); }
void VarSizeList_check_errors(const PVarSizeList pset, const double *errors, unsigned char* strange, uint32 count){ pset->check_errors(errors, strange, count); }
PVarSizeList VarSizeList_set_union(const PVarSizeList lhs, const PVarSizeList rhs){ PVarSizeList result = new VarSizeList(); *result = lhs->set_union(*rhs); return result; }
void MakeProfitsAdmissible(const PVarSizeList pset, ind_t d_start, ind_t d_end, double *pProfits){ pset->make_profits_admissible(d_start, d_end, pProfits, pset->count()); }
void CheckAdmissibility(const PVarSizeList pset, ind_t d_start, ind_t d_end, unsigned char *admissible){ pset->check_admissibility(d_start, d_end, admissible, pset->count()); }
int VarSizeList_find(const PVarSizeList pset, ind_t *j, ind_t *data, ind_t size){ uint32 index; bool bfound = pset->find_ind(SparseMIndex(j, data, size), index); return bfound ? index:-1; }
void CheckAdmissibility(const PVarSizeList pset, ind_t d_start, ind_t d_end, bool *admissible){ pset->CheckAdmissibility(d_start, d_end, admissible, pset->count()); }
//////// ------------------------------------------------ /// C-Accessors to C++ methods double GetMinOuterProfit(const PVarSizeList pset, const PProfitCalculator profCalc){ return pset->get_min_outer_profit(profCalc); }
void VarSizeList_count_neighbors(const PVarSizeList pset, ind_t *out_neighbors, uint32 count){ pset->count_neighbors(out_neighbors, count); }
uint32 VarSizeList_count(const PVarSizeList pset){ return pset->count(); }
ind_t VarSizeList_max_dim(const PVarSizeList pset){ return pset->max_dim(); }
void CalculateSetProfit(const PVarSizeList pset, const PProfitCalculator profCalc, double *log_error, double *log_work){ pset->CalculateSetProfit(profCalc, log_error, log_work, pset->count()); }