// If no args, set cursor to all zeros. Else set initial elements of cursor // to args provided, rest to zeros. NcBool NcVar::set_cur(long c0, long c1, long c2, long c3, long c4) { long t[6]; t[0] = c0; t[1] = c1; t[2] = c2; t[3] = c3; t[4] = c4; t[5] = -1; for(int j = 0; j < 6; j++) { // find how many parameters were used int i; if (t[j] == -1) { if (num_dims() < j) return FALSE; // too many for variable's dimensionality for (i = 0; i < j; i++) { if (t[i] >= get_dim(i)->size() && ! get_dim(i)->is_unlimited()) return FALSE; // too big for dimension the_cur[i] = t[i]; } for(i = j; i < num_dims(); i++) the_cur[i] = 0; return TRUE; } } return TRUE; }
NcBool NcVar::set_cur(long* cur) { for(int i = 0; i < num_dims(); i++) { if (cur[i] >= get_dim(i)->size() && ! get_dim(i)->is_unlimited()) return FALSE; the_cur[i] = cur[i]; } return TRUE; }
void NcVar::set_rec(NcDim *rdim, long slice) { int i = dim_to_index(rdim); // we should fail and gripe about it here.... if (slice >= get_dim(i)->size() && ! get_dim(i)->is_unlimited()) return; cur_rec[i] = slice; return; }
long* NcVar::edges( void ) const // edge lengths (dimension sizes) { long* evec = new long[num_dims()]; for(int i=0; i < num_dims(); i++) evec[i] = get_dim(i)->size(); return evec; }
list<MatrixXd> Covariances::marginal(const node_lists_t& node_lists) const { const SparseSystem& R = (_slam==NULL) ? _R : _slam->_R; if (_slam) { _slam->update_starts(); } vector < vector<int> > index_lists(node_lists.size()); if (R.num_rows()>1) { // skip if _R not calculated yet (eg. before batch step) int n=0; const int* trans = R.a_to_r(); for (node_lists_t::const_iterator it_list = node_lists.begin(); it_list != node_lists.end(); it_list++, n++) { // assemble list of indices vector<int> indices; for (list<Node*>::const_iterator it = it_list->begin(); it!=it_list->end(); it++) { Node* node = *it; int start = get_start(node); int dim = get_dim(node); for (int i=0; i<dim; i++) { index_lists[n].push_back(trans[start+i]); } } } return cov_marginal(R, _cache, index_lists); } list<MatrixXd> empty_list; return empty_list; }
long NcVar::num_vals( void ) const { long prod = 1; for (int d = 0; d < num_dims(); d++) prod *= get_dim(d)->size(); return prod; }
void NcVar::set_rec(long rec) { // Since we can't ask for the record dimension here // just assume [0] is it..... set_rec(get_dim(0),rec); return; }
t_wolf *init_map(char *av) { t_wolf *wolf; t_bunny_ini_scope *scope; t_bunny_ini *ini; if ((wolf = bunny_malloc(sizeof(t_wolf))) == NULL) return ((t_wolf *)-1); if ((ini = bunny_load_ini(av)) == NULL) return ((t_wolf *)-1); scope = bunny_ini_first(ini); scope = bunny_ini_next(ini, scope); wolf->s_name = bunny_ini_scope_name(ini, scope); wolf->width = 0; wolf->height = 0; wolf = get_dim(wolf, ini); if (check_air(wolf, ini) == -1) return ((t_wolf *)-1); wolf = get_map(wolf, ini); wolf = get_player(wolf, ini); if (init_error(wolf) == -1) return ((t_wolf *)-1); bunny_delete_ini(ini); return (wolf); }
LSearch::LSearch(int _dim, function_type _funct) : PSO(0.0, ///<The w parameter (influence of old vel - momentum) 0.0, ///<The minimum value for w -- decreased by time or level 0.0, ///<Influence of personal best 0.0, ///<Influence of global best 0.0, ///<vmax = vmaxRatio*xmax, with vmaxRatio=0 no vmax is enforced 0.0, ///<Constriction factor, used by #Bird 0, ///<Swarmsize _dim, ///<Dimension of the search space 0, ///<Height of the pyramid, ignored for #seqSwarm 0, ///<Branches per node of the pyramid, ignored for #seqSwarm 0, ///<Swap allowed every swapDelay steps in #PyramidSwarm, ignored for #Swarm _funct, ///<#function_type selection noNoise, ///<#noiseStyle_type selection, set in #optFunction 0.0, ///<sigma parameter for gaussian distributed noise seqSwarm) ///<#swarm_type selection { TRACE_IN("LSearch::LSearch"); DEBUG("New LSearch :"); DEBUG1("dim = ",_dim); int a=0; for (int i=0; i<get_dim(); i++) currSolution.push_back(randDoubleRange(optFunction->get_min_x(), optFunction->get_max_x())); currentVal = evalFunction(currSolution); TRACE_OUT("LSearch::LSearch",0); }
NcDim* NcFile::get_dim( NcToken name ) const { int dimid; if(NcError::set_err( nc_inq_dimid(the_id, name, &dimid) ) != NC_NOERR) return 0; return get_dim(dimid); }
template<typename T> T SegmentTree<T>::get_dim(NVector left, NVector right, int level){ T ret=zero; if(level==dim-1){ while(left[level]<=right[level]){ if(left[level]%2==1){ ret=operation(ret,(*data)[left]); left[level]++; } if(right[level]%2==0){ ret=operation(ret,(*data)[right]); right[level]--; } right[level]/=2; left[level]/=2; if(right[level]==left[level]) return operation(ret,(*data)[left]); } return ret; } while(left[level]<=right[level]){ if(left[level]%2==1){ NVector new_right=right; new_right[level]=left[level]; ret=operation(ret,get_dim(left,new_right,level+1)); left[level]++; } if(right[level]%2==0){ NVector new_left=left; new_left[level]=right[level]; ret=operation(ret,get_dim(new_left,right,level+1)); right[level]--; } right[level]/=2; left[level]/=2; if(right[level]==left[level]) return operation(ret,get_dim(left,right,level+1)); } return ret; }
NcValues* NcVar::values( void ) const { int ndims = num_dims(); size_t crnr[NC_MAX_DIMS]; size_t edgs[NC_MAX_DIMS]; for (int i = 0; i < ndims; i++) { crnr[i] = 0; edgs[i] = get_dim(i)->size(); } NcValues* valp = get_space(); int status; switch (type()) { case ncFloat: status = NcError::set_err( nc_get_vara_float(the_file->id(), the_id, crnr, edgs, (float *)valp->base()) ); break; case ncDouble: status = NcError::set_err( nc_get_vara_double(the_file->id(), the_id, crnr, edgs, (double *)valp->base()) ); break; case ncInt: status = NcError::set_err( nc_get_vara_int(the_file->id(), the_id, crnr, edgs, (int *)valp->base()) ); break; case ncShort: status = NcError::set_err( nc_get_vara_short(the_file->id(), the_id, crnr, edgs, (short *)valp->base()) ); break; case ncByte: status = NcError::set_err( nc_get_vara_schar(the_file->id(), the_id, crnr, edgs, (signed char *)valp->base()) ); break; case ncChar: status = NcError::set_err( nc_get_vara_text(the_file->id(), the_id, crnr, edgs, (char *)valp->base()) ); break; case ncNoType: default: return 0; } if (status != NC_NOERR) return 0; return valp; }
int NcVar::dim_to_index(NcDim *rdim) { for (int i=0; i < num_dims() ; i++) { if (strcmp(get_dim(i)->name(),rdim->name()) == 0) { return i; } } // we should fail and gripe about it here.... return -1; }
virtual int get_min_size() const { int dim = get_dim(); int minsz = -1; int dx; for (dx = 0; dx < dim; ++dx) { int mysz = sz(dx); if (dx == 0 || mysz < minsz) minsz = mysz; } return minsz; }
NcDim* NcFile::rec_dim( ) const { if (! is_valid()) return 0; int recdim; if(NcError::set_err( nc_inq_unlimdim(the_id, &recdim) ) != NC_NOERR) return 0; return get_dim(recdim); }
virtual int size() const { int dim = get_dim(); if (dim == 0) return 0; int region_size = 1; int dx; for (dx = 0; dx < dim; ++dx) { int mysz = sz(dx); region_size *= mysz; } return region_size; }
inline U32 get_size() const { if (data_type) { const U32 size_table[10] = { 1, 1, 2, 2, 4, 4, 8, 8, 4, 8 }; U32 type = get_type(); U32 dim = get_dim(); return size_table[type]*dim; } else { return options; } }
list<MatrixXd> Covariances::access(const node_pair_list_t& node_pair_list) const { const SparseSystem& R = (_slam==NULL) ? _R : _slam->_R; if (_slam) { _slam->update_starts(); } if (R.num_rows()>1) { // skip if _R not calculated yet (eg. before batch step) // count how many entries in requested blocks int num = 0; for (node_pair_list_t::const_iterator it = node_pair_list.begin(); it != node_pair_list.end(); it++) { num += get_dim(it->first) * get_dim(it->second); } // request individual covariance entries vector < pair<int, int> > index_list(num); const int* trans = R.a_to_r(); int n = 0; for (node_pair_list_t::const_iterator it = node_pair_list.begin(); it != node_pair_list.end(); it++) { int start_r = get_start(it->first); int start_c = get_start(it->second); int dim_r = get_dim(it->first); int dim_c = get_dim(it->second); for (int r=0; r<dim_r; r++) { for (int c=0; c<dim_c; c++) { index_list[n] = make_pair(trans[start_r + r], trans[start_c + c]); n++; } } } list<double> covs = cov_marginal(R, _cache, index_list); // assemble into block matrices list<MatrixXd> result; list<double>::iterator it_cov = covs.begin(); for (node_pair_list_t::const_iterator it = node_pair_list.begin(); it != node_pair_list.end(); it++) { int dim_r = get_dim(it->first); int dim_c = get_dim(it->second); MatrixXd matrix(dim_r, dim_c); for (int r=0; r<dim_r; r++) { for (int c=0; c<dim_c; c++) { matrix(r,c) = *it_cov; it_cov++; } } result.push_back(matrix); } return result; } list<MatrixXd> empty_list; return empty_list; }
/* update_cost() * - simple updater, uses the rolling history sum as the cost */ void ocin_router_cost_mgr_1domni::update_cost() { if (nodes==NULL) { nodes = parent_router->nodes; // cout << "nodes in csmgr "<<nodes<<endl; } string localname = name; for (int i=0; i < (_cost_regs[0].size() -1); i++) { // i is output port vector <int> costs; int cost =0; costs.push_back(_cost_regs[0][i].get_hist_sum());// first grab the // local cost vector <int> thiscoord = parent_router->node_info->coord; /* router's multi-dimensional coordinates */ ocin_router * nextnode; // then we recurse the correct direction bool done = false; while (done != true) { stringstream d; // prosepective downstream node name int dir = get_dir(i); int dim = get_dim(i); // get coordinates of downstream node if (dir ==0) { thiscoord[dim]++; } else { thiscoord[dim]--; } d << thiscoord[0] << "." << thiscoord[1]; string next = d.str(); if ((*nodes).find(next) == (*nodes).end()) { done = true; // past the end of the network // { // stringstream tmp; // tmp << "Couldn't find node:" <<thiscoord[0]<<"."<<thiscoord[1]<<endl; // ocin_name_warn(name,tmp.str()); // } } else { nextnode = &((*nodes)[next]); costs.push_back(nextnode->cost_regs[0][i].get_hist_sum()); // { // stringstream tmp; // tmp << "Getting cost from node:"<<thiscoord[0]<<"."<<thiscoord[1]<< " in dir of port " << i <<endl; // ocin_name_warn(name,tmp.str()); // } } } cost = costs.back(); // so we dont div the first one // decaying average: while(!costs.empty()) { cost = (cost + costs.back())/2; costs.pop_back(); } _cost_regs[0][i].set_cost(cost); // #ifdef DEBUG // { // stringstream tmp; // tmp << "Cost reg @ pout " << i << " = " << cost; // ocin_name_debug(name,tmp.str()); // } // #endif } }
long NcVar::rec_size(void) { return rec_size(get_dim(0)); }
NcValues* NcVar::get_rec(long rec) { return get_rec(get_dim(0), rec); }
NcValues* NcVar::get_rec(void) { return get_rec(get_dim(0), cur_rec[0]); }
void netcdf::set_unlimited_dim(dim_vector::size_type const & i, int32_t default_dim_length) { auto dim_it = get_dim(i); set_unlimited_dim(dim_it, default_dim_length); }
void netcdf::set_unlimited_dim(std::string const & name, int32_t default_dim_length) { auto dim_it = get_dim(name); set_unlimited_dim(dim_it, default_dim_length); }
template<typename T> T SegmentTree<T>::get(NVector left_bound, NVector right_bound){ NVector left=left_bound+SIZE; NVector right=right_bound+SIZE; return get_dim(left,right,0); }
board start_editor() { int h = get_dim("enter height: "); clear(); int w = get_dim("enter width: "); curs_set(1); noecho(); cbreak(); move(20,20); int x = 0; int x_1 = 0; int y = 0; board b = init_board(h, w); int key; print_board(0, 0, b); print_instructions(); move(y,x); while((key = getch()) != 113) { // wait until user hits q print_board(0, 0, b); print_instructions(); move(y,x); if(key == 10) { // enter key toggle_alive(b,y,x_1); print_board(0,0,b); print_instructions(); y++; move(y,x); refresh(); } if(key == 32) { // space bar toggle_alive(b,y,x_1); print_board(0,0,b); print_instructions(); x+=2; x_1++; move(y,x); refresh(); } if(key == 260 && x_1 > 0) { // left arrow key x-=2; x_1--; move(y,x); } if(key == 261 && x_1 < w-1) { // right arrow key x+=2; x_1++; move(y,x); } if(key == 259 && y > 0) { // up arrow key y-=1; move(y,x); } if(key == 258 && y < h-1) { // down arrow key y+=1; move(y,x); } if(key == 544) { // control left board newboard = change_board_size(b, -1, 0); free_board(b); b = newboard; w--; print_board(0,0,b); print_instructions(); move(y,x); refresh(); } if(key == 559) { board newboard = change_board_size(b, 1, 0); free_board(b); b = newboard; w++; print_board(0,0,b); print_instructions(); move(y,x); refresh(); } if(key == 565) { // control up board newboard = change_board_size(b, 0, -1); free_board(b); b = newboard; h--; print_board(0,0,b); print_instructions(); move(y,x); refresh(); } if(key == 524) { // control down board newboard = change_board_size(b, 0, 1); free_board(b); b = newboard; h++; print_board(0,0,b); print_instructions(); move(y,x); refresh(); } refresh(); } curs_set(0); clear(); return b; }
inline BOOL set_no_data(F64 no_data, I32 dim=0) { if ((9 == get_type()) && (dim < get_dim())) { this->no_data[dim].f64 = no_data; options |= 0x01; return TRUE; } return FALSE; }
inline BOOL set_min(F64 min, I32 dim=0) { if ((9 == get_type()) && (dim < get_dim())) { this->min[dim].f64 = min; options |= 0x02; return TRUE; } return FALSE; }
inline BOOL set_max(F64 max, I32 dim=0) { if ((9 == get_type()) && (dim < get_dim())) { this->max[dim].f64 = max; options |= 0x04; return TRUE; } return FALSE; }
void Game_Loop::run() { const float interval = 1.0 / target_fps; double time = SDL_GetTicks() / 1000.0; running = true; update_state_stack(); while (running) { double current_time = SDL_GetTicks() / 1000.0; // Failsafe in case updates keep taking more time than interval and the // loop keeps falling back. int max_updates = 16; if (current_time - time >= interval) { while (current_time - time >= interval) { running = update_states(interval); if (!running) break; time += interval; if (max_updates-- <= 0) { // Forget about catching up. time = current_time; break; } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); auto dim = get_dim(); glViewport(0, 0, dim[0], dim[1]); for (auto& state : states) state->draw(); SDL_GL_SwapBuffers(); } else { // Don't busy wait. SDL_Delay(10); } SDL_Event event; while (SDL_PollEvent(&event)) { Game_State *top = top_state(); switch (event.type) { case SDL_KEYDOWN: if (top) top->key_event(event.key.keysym.sym, event.key.keysym.unicode); break; case SDL_KEYUP: if (top) top->key_event(-event.key.keysym.sym, -1); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (top) top->mouse_event(event.button.x, event.button.y, mouse_button_mask()); break; case SDL_MOUSEMOTION: if (top) top->mouse_event(event.motion.x, event.motion.y, mouse_button_mask()); break; case SDL_QUIT: quit(); break; } } } SDL_Quit(); }