void SymbolicQr::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { LinearSolverInternal::deepCopyMembers(already_copied); fact_fcn_ = deepcopy(fact_fcn_, already_copied); solv_fcn_N_ = deepcopy(solv_fcn_N_, already_copied); solv_fcn_T_ = deepcopy(solv_fcn_T_, already_copied); }
void ImplicitFunctionInternal::deepCopyMembers(std::map<SharedObjectNode*, SharedObject>& already_copied) { FunctionInternal::deepCopyMembers(already_copied); f_ = deepcopy(f_, already_copied); jac_ = deepcopy(jac_, already_copied); linsol_ = deepcopy(linsol_, already_copied); }
struct node* deepcopy(struct node* head) { if(!head) return NULL; struct node* cpy = malloc(sizeof(struct node)); cpy->data = head->data; cpy->left = deepcopy(head->left); cpy->right = deepcopy(head->right); return cpy; }
GslInternal* GslInternal::clone() const{ // Return a deep copy Function f = deepcopy(f_); Function q = deepcopy(q_); GslInternal* node = new GslInternal(f,q); node->setOption(dictionary()); node->jac_f_ = deepcopy(jac_f_); node->dt_f_ = deepcopy(dt_f_); if(!node->is_init) node->init(); return node; }
int main() { struct node A, B, C, D, E; A.data = 128; B.data = 64; C.data = 256; D.data = 32; E.data = 48; A.left = &B; A.right = &C; B.left = &D; B.right = 0; C.left = 0; C.right = 0; D.left = 0; D.right = &E; E.left = 0; E.right = 0; struct node* cpyTree = deepcopy(&A); incTree(cpyTree); // Copy tree should be 1 larger than original in all node values printInOrder(&A); printf("\n"); printInOrder(cpyTree); }
double& Signal::operator[](const unsigned index) { assert(index < len); deepcopy(); if (type == SIG_SAMP) return sample[index]; return sample[0]; }
ExportVariable ExportVariable::operator()( const String& _name ) const { ExportVariable tmp = deepcopy( *this ); tmp.setName( _name ); return tmp; }
Benchmark::Benchmark(Benchmark& benchmark) { expected_sat = NULL; setExpectedSat(benchmark.expected_sat); this->formulae.reserve(benchmark.formulae.size()); for(int i=0 ; i<benchmark.formulae.size() ; i++) { this->formulae.push_back(deepcopy(benchmark.formulae[i])); } }
void test_copy(){ x1_len = 3; x2_len = 3; w_len = 3; float V[3][3][3] = {{{10,10,10},{20,20,20},{30,30,30}},{{40,40,40},{50,50,50},{60,60,60}},{{70,70,70},{80,80,80},{90,90,90}}}; float V_old[3][3][3] = {{{20,10,10},{20,20,20},{30,30,30}},{{40,40,40},{50,50,50},{60,60,60}},{{70,70,70},{80,80,80},{90,90,90}}}; float ans; deepcopy(V, V_old); V[0][0][0] = 10000; printf("ans %f \n ",V_old[0][0][0]); }
/* copy template from current board to some board, append it at the end * @board - the destination board * @pptemp - template array of destination board * @temp_size - array size * @pos - which template to copy, conf->pos * @return - 0 on success, -1 otherwise * * Warning: caller should check permission before this call. **/ int tmpl_copy_to_board(const char *board, struct a_template **pptemp, int *temp_size, int pos) { if (!board || !pptemp || !*pptemp || !temp_size || *temp_size < 0 || *temp_size >= MAX_TEMPLATE || pos < 1 || pos > template_num) return -1; struct a_template *f = get_slot(&ptemplate, pos); struct a_template *t = get_slot(pptemp, *temp_size + 1); if (!deepcopy(t, board, f, currboard->filename)) { if (!orig_tmpl_save(*pptemp, *temp_size + 1, (char*)board)) { (*temp_size)++; return 0; } deepfree(t, board); } return -1; }
int main() { char **p; Lexp l, newl; initpool(); for (p = testcases; *p != NULL; p++) { printf("Lambda expression string \"%s\" -> ", *p); l = str2lexp(*p); printlexp(l); newl = deepcopy(l); printf("Original Lexp: "); printlexp(l); printf("Copied Lexp: "); printlexp(newl); } return 0; }
void ParallelizerInternal::deepCopyMembers(std::map<SharedObjectNode*,SharedObject>& already_copied){ FXInternal::deepCopyMembers(already_copied); funcs_ = deepcopy(funcs_,already_copied); }
void QpToImplicit::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { ImplicitFunctionInternal::deepCopyMembers(already_copied); solver_ = deepcopy(solver_, already_copied); }
returnValue CondensingExport::setupMultiplicationRoutines( ) { ExportVariable QQ = deepcopy( Q ); QQ.setDataStruct( ACADO_LOCAL ); ExportVariable QC1( "QC1", getNX(),getNX() ); ExportVariable QE1( "QE1", getNX(),getNU()*getN() ); ExportVariable Dx1( "Dx1", getNX(),1 ); ExportVariable QDx1("QDx1", getNX(),1 ); ExportVariable Du1( "Du1", getNU(),1 ); ExportVariable RDu1("RDu1", getNU(),1 ); ExportVariable Gx ( "Gx", getNX(),getNX() ); ExportVariable Gu ( "Gu", getNX(),getNU() ); ExportVariable C1 ( "C1", getNX(),getNX() ); ExportVariable E1 ( "E1", getNX(),getNU()*getN() ); ExportVariable d1 ( "d1", getNX(),1 ); ExportVariable u1 ( "u1", getNU(),1 ); ExportVariable C ( "C", getNX()*getN(),getNX() ); ExportVariable QC ( "QC", getNX()*getN(),getNX() ); ExportVariable E ( "E", getNX()*getN(),getNU()*getN() ); ExportVariable QE ( "QE", getNX()*getN(),getNU()*getN() ); ExportVariable QDx( "QDx", getNX()*getN(),1 ); ExportVariable g0 ( "g0", getNX(),1 ); ExportVariable g1 ( "g1", getNU()*getN(),1 ); ExportVariable H00( "H00", getNX(),getNX() ); ExportVariable H01( "H01", getNX(),getNU()*getN() ); ExportVariable H11( "H11", getNU()*getN(),getNU()*getN() ); multiplyQC1.setup( "multiplyQC1", QQ,C1,QC1 ); multiplyQC1.addStatement( QC1 == QQ*C1 ); multiplyQE1.setup( "multiplyQE1", QQ,E1,QE1 ); multiplyQE1.addStatement( QE1 == QQ*E1 ); multiplyQDX1.setup( "multiplyQDX1", QQ,Dx1,QDx1 ); multiplyQDX1.addStatement( QDx1 == QQ*Dx1 ); multiplyRDU1.setup( "multiplyRDU1", R,Du1,RDu1 ); multiplyRDU1.addStatement( RDu1 == R*Du1 ); multiplyQC2.setup( "multiplyQC2", QQF,C1,QC1 ); multiplyQC2.addStatement( QC1 == QQF*C1 ); multiplyQE2.setup( "multiplyQE2", QQF,E1,QE1 ); multiplyQE2.addStatement( QE1 == QQF*E1 ); multiplyQDX2.setup( "multiplyQDX2", QQF,Dx1,QDx1 ); multiplyQDX2.addStatement( QDx1 == QQF*Dx1 ); multiplyC.setup( "multiplyC", Gx,C1,C1("C1_new") ); multiplyC.addStatement( C1("C1_new") == Gx*C1 ); multiplyE.setup( "multiplyE", Gx,E1,E1("E1_new") ); multiplyE.addStatement( E1("E1_new") == Gx*E1 ); if ( performsSingleShooting() == BT_FALSE ) { multiplyCD1.setup( "multiplyCD1", Gx,d1,d1("d1_new") ); multiplyCD1.addStatement( d1("d1_new") == Gx*d1 ); multiplyEU1.setup( "multiplyEU1", Gu,u1,d1("d1_new") ); multiplyEU1.addStatement( d1("d1_new") += Gu*u1 ); } if ( performsFullCondensing() == BT_FALSE ) { multiplyG0.setup( "multiplyG0", C,QDx,g0 ); multiplyG0.addStatement( g0 == (C^QDx) ); } multiplyG1.setup( "multiplyG1", E,QDx,g1 ); multiplyG1.addStatement( g1 == (E^QDx) ); if ( performsFullCondensing() == BT_FALSE ) { multiplyH00.setup( "multiplyH00", C,QC,H00 ); multiplyH00.addStatement( H00 == (C^QC) ); } multiplyH01.setup( "multiplyH01", C,QE,H01 ); multiplyH01.addStatement( H01 == (C^QE) ); multiplyH11.setup( "multiplyH11", E,QE,H11 ); multiplyH11.addStatement( (H11 == (E^QE)) ); return SUCCESSFUL_RETURN; }
void FixedStepIntegrator::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { IntegratorInternal::deepCopyMembers(already_copied); F_ = deepcopy(F_, already_copied); G_ = deepcopy(G_, already_copied); }
void SimulatorInternal::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { FunctionInternal::deepCopyMembers(already_copied); integrator_ = deepcopy(integrator_, already_copied); output_fcn_ = deepcopy(output_fcn_, already_copied); }
Lexp Lcopy(Lexp orig) { return deepcopy(orig); }
int value_iteration(){ //init stuff float stopping_criterion = 0.01; float *x1_space, *x2_space, ***V, ***V_old, *temp_w, *temp_u; int i,j,k; int x1_len = (x_max[0]-x_min[0])/step_size[0] + 1; int x2_len = (x_max[1]-x_min[1])/step_size[1] + 1; int w_len = sizeof(w_space)/sizeof(float); int u_len = sizeof(u_space)/sizeof(float); float x_new[] = {0,0}; float g = 1; x1_space = (float *)(malloc(x1_len*sizeof(float))); for(i=0;i<x1_len;i++){ x1_space[i] = x_min[0] + step_size[0]*i; //printf("%f ",x1_space[i]); } printf("\n"); x2_space = (float *)(malloc(x2_len*sizeof(float))); for(i=0;i<x2_len;i++){ x2_space[i] = x_min[1] + step_size[1]*i; //printf("%f ",x2_space[i]); } temp_w = (float *)(malloc(w_len*sizeof(float))); temp_u = (float *)(malloc(u_len*sizeof(float))); V = (float ***)(malloc(x1_len*sizeof(float *))); V_old = (float ***)(malloc(x1_len*sizeof(float *))); for(i=0;i<x1_len;i++){ V[i] = (float **)(malloc(x2_len*sizeof(float *))); V_old[i] = (float **)(malloc(x2_len*sizeof(float *))); for(j=0;j<x2_len;j++){ V[i][j]=(float *)(malloc(w_len*sizeof(float))); V_old[i][j]=(float *)(malloc(w_len*sizeof(float))); for(k=0;k<w_len;k++){ V[i][j][k] = 0; V_old[i][j][k] = 1; } } } float a[] = {0,0}; float x1=0.1,x2=0.1,w=0.1; pendulum_nonlinearmodel_ss(&a[0], 1, 0, del_t, &x_new[0]); printf("array gotten %f,%f\n",x_new[0],x_new[1]); float temp; temp= interpol(x1_space, x2_space, w_space, V, x1, x2, w, x1_len, x2_len, w_len); printf("d %f",temp); //V_old = memcpy(&V[0][0][0], &V_old[0][0][0], x1_len*x2_len*w_len*sizeof(float)); i = 0, j=0, k=0; int c = 0, d=0; float x_old[] = {0,0}; float max_temp_u = 0; int iteration = 0; while(max_of_V(V, V_old, x1_len, x2_len, w_len) > stopping_criterion){ deepcopy(V, V_old, x1_len, x2_len, w_len); //printf("cpy %f %f \n",V[1][1][1],V_old[1][1][1]); for(i=0;i<x1_len;i++){ for(j=0;j<x2_len;j++){ for(k=0;k<w_len;k++){ for(c=0;c<u_len;c++){ x_old[0] = x1_space[i]; x_old[1] = x2_space[j]; pendulum_nonlinearmodel_ss(&x_old[0], u_space[c], w_space[k], del_t, &x_new[0]); //printf("non linear %f %f \n",x_new[0],x_new[1]); temp_u[c] = g; for(d=0;d<w_len;d++){ temp_w[d] = interpol(x1_space, x2_space, w_space, V, x_new[0], x_new[1], w_space[d], x1_len, x2_len, w_len); temp_u[c] = temp_u[c] + temp_w[d]*prob_matrix[k][d]; //printf("temp w[d] %f\n",temp_w[d]); } if(temp_u[c]>max_temp_u){ max_temp_u = temp_u[c]; } } V[i][j][k] = max_temp_u; } } } printf("iteration %d value %f \n",iteration, max_of_V(V, V_old, x1_len, x2_len, w_len)); iteration += 1; } printf("Value iteration Done\n"); FILE *outfile; char *outfilename = "/Users/Rounak/Desktop/Summer project/DCOC/DCOC_in_C/DCOC_in_C/abc.csv"; printf("%s",outfilename); if ((outfile = fopen(outfilename,"w")) == NULL) { printf("Error opening output file.\n"); return -1; } else{ printf("file opened\n"); } for(i=0;i<x1_len;i++) { for(j=0;j<x2_len;j++) { for(k=0;k<w_len;k++){ fprintf(outfile,"%f,",V[i][j][k]); } fprintf(outfile,"::::::"); } fprintf(outfile,"\n"); } fclose(outfile); return 0; }
void ImplicitFixedStepIntegratorInternal::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { FixedStepIntegratorInternal::deepCopyMembers(already_copied); implicit_solver_ = deepcopy(implicit_solver_, already_copied); backward_implicit_solver_ = deepcopy(backward_implicit_solver_, already_copied); }
void SDPSDQPInternal::deepCopyMembers(std::map<SharedObjectNode*, SharedObject>& already_copied) { SdqpSolverInternal::deepCopyMembers(already_copied); sdpsolver_ = deepcopy(sdpsolver_, already_copied); cholesky_ = deepcopy(cholesky_, already_copied); mapping_ = deepcopy(mapping_, already_copied); }
//******************************************************* MAIN ******************************* int main(int argc, char* argv[]){ //set up sdl SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); SDL_Window *Window = SDL_CreateWindow("Handmade Hero", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE); if(Window){ SDL_Renderer *Renderer = SDL_CreateRenderer(Window, -1, 0); if(Renderer){ // VIDEO sdl_offscreen_buffer Buffer = {}; // if non-initialized, declaring variables in a loop fails on SDLResizeTexture with a pointer error - im blaming the compiler sdl_window_dimension Dimension = SDLGetWindowDimension(Window); SDLResizeTexture(&Buffer, Renderer, Dimension.Width, Dimension.Height); keystates Keys = {}; //AUDIO sdl_sound_output sound_output = sdl_sound_outputH(48000); //open audio SDLInitAudio(sound_output.SamplesPerSecond, sound_output.SamplesPerSecond * sound_output.BytesPerSample / 60); SDL_PauseAudio(0); //BW: state area allocation void *new_state_area = malloc(128*1024*1024);//need ~2 MB at least; give it 128 MiB -- 2MB for video; dont know audio void *prev_state_area = malloc(1024);// should be sizeof(state0), or sizeof(biggest statetype) later //apparently we didnt have enough memory, but only crashed sometimes? this fixed it void *state; { uint8 *next_ptr = (uint8*)prev_state_area; anim_comp *animation = (anim_comp*)next_ptr; next_ptr += sizeof(anim_comp); init_anim_comp(animation, 0,0); state0 *stateptr = (state0*)next_ptr; printf("state0 size %ld\n", sizeof(state0)); uint64 stateptrn = (uint64)stateptr; uint64 sizeptr = (uint64)&(stateptr->size); uint64 deepc_ptr = (uint64)&(stateptr->deep_count); uint64 anim_ptr = (uint64)&(stateptr->animation); uint64 tsine_ptr = (uint64)&(stateptr->tSine); uint64 tvol_ptr = (uint64)&(stateptr->ToneVolume); uint64 thz_ptr = (uint64)&(stateptr->ToneHz); uint64 pu_ptr = (uint64)&(stateptr->pitch_up_was_pressed); printf("offset begin %lu\n", sizeptr - stateptrn); printf("width of size %lu\n", deepc_ptr - sizeptr); printf("width of deepc %lu\n", anim_ptr - deepc_ptr); printf("width of animpt %lu\n", tsine_ptr - anim_ptr); printf("width of tsine %lu\n", tvol_ptr - tsine_ptr); printf("width of tvol %lu\n", thz_ptr - tvol_ptr); printf("width of thz %lu\n", pu_ptr - thz_ptr); next_ptr += sizeof(state0); init_state0(stateptr, animation, 3000, 256, 0); state = stateptr; //return 0; } uint64 LastCounter = SDL_GetPerformanceCounter(); uint64 LastCycleCount = _rdtsc(); uint64 PerfCountFrequency = SDL_GetPerformanceFrequency(); bool running = true; //main loop printf("enter main event loop\n"); while(running){ ///////NP_UPDATE///////////// //event capturing event_return events = eventHandler(&Keys); if(events.shouldQuit) running = false; //setup for p state_window_info Wi = {}; Wi.Height = Buffer.Height; Wi.Width = Buffer.Width; Wi.Pitch = Buffer.Pitch; int TargetQueueBytes = sound_output.LatencySampleCount * sound_output.BytesPerSample; state_sound_info Si = {}; Si.BytesToGet = TargetQueueBytes - SDL_GetQueuedAudioSize(1); Si.BytesPerSample = sound_output.BytesPerSample; Si.SamplesPerSecond = sound_output.SamplesPerSecond; uint64 state_size = 0; uint64 vbuffer_size = Buffer.Height * Buffer.Pitch; uint64 abuffer_size = Si.BytesToGet; state_return next; { //in case(statetype) or similar next = P_update_state0(*(state0*)state, new_state_area, Keys, Wi, Si); //p should return state_size? and also, what statetype we are in -> later state_size = sizeof(state0); } //GARBAGE COLLECTOR //move this state to previous state //fmemcpy(prev_state_area, new_state_area, state_size); //shallow copy, as supposed //printf("hi\n"); deepcopy(prev_state_area, next.state, new_state_area, (uint8*)new_state_area + 128*1024*1024); //TODO(md): DEEPCPY //queue audio if (Si.BytesToGet > 0) SDL_QueueAudio(1, next.abuffer, abuffer_size); //render SDLUpdateWindow(Window, Renderer, Buffer, next.vbuffer); uint64 EndCycleCount = _rdtsc(); uint64 EndCounter = SDL_GetPerformanceCounter(); uint64 CounterElapsed = EndCounter - LastCounter; uint64 CyclesElapsed = EndCycleCount - LastCycleCount; real64 MSPerFrame = (((1000.0f * (real64)CounterElapsed) / (real64)PerfCountFrequency)); real64 FPS = (real64)PerfCountFrequency / (real64)CounterElapsed; real64 MCPF = ((real64)CyclesElapsed / (1000.0f * 1000.0f)); printf("%.02fms/f, %.02f/s, %.02fmc/f\n", MSPerFrame, FPS, MCPF); LastCycleCount = EndCycleCount; LastCounter = EndCounter; } } } //if(Renderer, Window) SDL_Quit(); return 0; }
void StabilizedQpToQp::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { StabilizedQpSolverInternal::deepCopyMembers(already_copied); qp_solver_ = deepcopy(qp_solver_, already_copied); }
int value_iteration(){ //float lol = prob_matrix1[0][0]; //printf("%f",lol); //init stuff static int i,j,k; float V[x1_len][x2_len][w_len]; float V_old[x1_len][x2_len][w_len]; float x_new[] = {0,0}; float x_old[] = {1,0}; float g = 1; float x1_space[x1_len]; float x2_space[x2_len]; float temp_w[w_len]; float temp_u[u_len]; int c = 0, d=0; int max_temp_c = 0; int iteration = 0; for(i=0;i<x1_len;i++){ x1_space[i] = x_min[0] + step_size[0]*i; //printf("%f ",x1_space[i]); } for(i=0;i<x2_len;i++){ x2_space[i] = x_min[1] + step_size[1]*i; } for(i=0;i<x1_len;i++){ for(j=0;j<x2_len;j++){ for(k=0;k<w_len;k++){ V[i][j][k] = 1.5; V_old[i][j][k] = 1; } } } //DEBUG AREA //printf("%d x1_len \n",x1_len); //printf("%f probmatrix\n",prob_matrix[0][0]); //printf("%f sc\n",stopping_criterion); //printf("%f x\n",x_new[1]); //pendulum_nonlinearmodel_ss(x_old, u_space[c], w_space[k],x_new); //printf("%f x\n",x_new[1]); float debug; int deb; deb = find_nearest_neighbor(-0.1, 0.1, 0, 1); //printf("%d deb\n",deb); debug = interpol_3D(x1_space, x2_space, w_space, V, -0.2456,-0.8015, 0.1);//interpol might be off or V update printf("%f debug\n",debug); debug = max_of_V(V, V_old); while(max_of_V(V, V_old) > stopping_criterion){ deepcopy(V, V_old); //printf("cpy %f %f \n",V[1][1][1],V_old[1][1][1]); for(i=0;i<x1_len;i++){ for(j=0;j<x2_len;j++){ for(k=0;k<w_len;k++){ max_temp_c = 0; for(c=0;c<u_len;c++){ x_old[0] = x1_space[i]; x_old[1] = x2_space[j]; //printf("1 %f 2 %f 3 %f 4 %f\n", x1_space[i], x2_space[j],u_space[c], w_space[k]); pendulum_nonlinearmodel_ss1(x_old, u_space[c], w_space[k],x_new); //printf("non linear %f %f \n",x_new[0],x_new[1]); temp_u[c] = g; for(d=0;d<w_len;d++){ temp_w[d] = interpol_3D(x1_space, x2_space, w_space, V, x_new[0], x_new[1], w_space[d]); //printf("%f temp_w[d]\n",temp_w[d]); temp_u[c] = temp_u[c] + temp_w[d]*prob_matrix[k][d]; } //printf("temp u[c] %f\n",temp_u[c]); if(temp_u[c]>temp_u[max_temp_c]){ max_temp_c = c; } } V[i][j][k] = temp_u[max_temp_c]; //printf("V[i][j][k] %f \n",V[i][j][k]); //printf("V_old[i][j][k] %f \n",V_old[i][j][k]); //printf("================\n"); } } } printf("iteration %d value %f \n",iteration, max_of_V(V, V_old)); iteration += 1; } printf("Value iteration Done\n Writing to file...\n"); int status; status = writeToFile(V); printf("Done\n"); return(0); }
Signal& Signal::operator+=(const Signal& obj) { deepcopy(); return (*this) = (*this) + obj; }
Signal& Signal::operator*=(const double mag) { deepcopy(); return (*this) = (*this) * mag; }
void EvaluationMX::deepCopyMembers( std::map<SharedObjectNode*, SharedObject>& already_copied) { MXNode::deepCopyMembers(already_copied); fcn_ = deepcopy(fcn_, already_copied); }
void Solve<Tr>::deepCopyMembers(std::map<SharedObjectNode*, SharedObject>& already_copied) { MXNode::deepCopyMembers(already_copied); linear_solver_ = deepcopy(linear_solver_, already_copied); }