void libat_load (size_t n, void *mptr, void *rptr, int smodel) { union max_size_u u; uintptr_t r, a; switch (n) { case 0: return; case 1: EXACT(1); goto L4; case 2: EXACT(2); goto L4; case 4: EXACT(4); goto L8; case 8: EXACT(8); goto L16; case 16: EXACT(16); break; case 3: L4: LARGER(4); /* FALLTHRU */ case 5 ... 7: L8: LARGER(8); /* FALLTHRU */ case 9 ... 15: L16: LARGER(16); break; Lfinish: memcpy (rptr, u.b + r, n); return; } pre_seq_barrier (smodel); libat_lock_n (mptr, n); memcpy (rptr, mptr, n); libat_unlock_n (mptr, n); post_seq_barrier (smodel); }
void libat_store (size_t n, void *mptr, void *vptr, int smodel) { switch (n) { case 0: return; case 1: EXACT(1); goto L4; case 2: EXACT(2); goto L4; case 4: EXACT(4); goto L8; case 8: EXACT(8); goto L16; case 16: EXACT(16); break; case 3: L4: LARGER(4); /* FALLTHRU */ case 5 ... 7: L8: LARGER(8); /* FALLTHRU */ case 9 ... 15: L16: LARGER(16); break; } pre_seq_barrier (smodel); libat_lock_n (mptr, n); memcpy (mptr, vptr, n); libat_unlock_n (mptr, n); post_seq_barrier (smodel); }
//selection operator chro_ptr sel_one(population pop) { float r=rand()%100000/(float)100000; if(EXACT(r)<=EXACT(pop.acu[0])) { #ifdef debug_sel_one printf("r:%f is between 0 and %f\n",r,pop.acu[0]); #endif return &(pop.m[0]); } int i=1; while(i<pop.n) { if(r<=pop.acu[i]&&r>=pop.acu[i-1]) { #ifdef debug_sel_one printf("r:%f is between acu[%d]->%f and acu[%d]->%f\n",r,i-1,pop.acu[i-1],i,pop.acu[i]); #endif return &(pop.m[i]); } else { i++; } } return NULL; }
/*find the least significant feature in Xk*/ int glsi(fl_tp Xk_plus,mic_matrix M) { int l=Xk_plus->k; int i=0; int *set=(int *)malloc(sizeof(int)*(l-1)); int atr=-1; float max=-1; for(i=0;i<l;i++) { int j=0; int k=0; for(j=0;j<l;j++) { if(j!=i) { set[k++]=Xk_plus->membs[j]; } } float merit=cal_merit(set,l-1,M); #ifdef debug_glsi printf("list without:%d\tmerit is %f\n",Xk_plus->membs[i],merit); #endif if(EXACT(merit)>=EXACT(max)) { max=merit; atr=Xk_plus->membs[i]; } } free(set); return atr; }
population *elitist_sel(population *pop,population *S) { qksort(pop); qksort(S); #ifdef debug_elt puts("The pop is:\t"); check_pop(*pop); puts("The S is :\t"); check_pop(*S); #endif int i=0; int p=0; int q=0; for(i=0;i<pop->n;i++) { if(EXACT(pop->m[p].sig)>EXACT(S->m[q].sig)) { p++; } else { chg_chro_PS(pop,i,S,q); q++; } } #ifdef debug_elt puts("After merging...\t"); check_pop(*pop); #endif return pop; }
int best() { int i,(*myab)(); uint8 *mythrcnt; int me,x,work,score; u_int poscnt; nodes = 0; if (plycnt & 1) { mythrcnt = xthrcnt; myab = abx; me = 1; } else { mythrcnt = othrcnt; myab = abo; me = 2; } for (i = 0; i = r[i]; ) { if (mythrcnt[height[i]] || colthr[columns[i]] == me) return (plycnt&1) ? WIN2 : WIN1; } if (x = transpose(columns)) { score = SCORE(x); if (EXACT(score)) return score; } for (i=0; i<64; i++) okiller[i] = xkiller[i] = 0x80; emptyht(); score = myab(alp[window], bet[window]); poscnt = posed; for (work=1; poscnt>>=1; work++) ; /* work = log of #positions stored */ return work << 3 | score; /* normally bestofall */ }
float mic_ct_mem(fct file_content,Points *D,int a ,int b,float alpha,int f) { int i=0; for(i=0;i<file_content.inst-1;i++) { D->x[i].val=file_content.ct[a][i]; D->y[i].val=file_content.ct[b][i]; D->x[i].pos=i; D->y[i].pos=i; } float result=cal_mic(D,alpha,f); if(EXACT(result)>EXACT(1.0000)) { result=0.00; } return result; }
Vector Vector::WithMagnitude(double v) { double m = Magnitude(); if(EXACT(m == 0)) { // We can do a zero vector with zero magnitude, but not any other cases. if(fabs(v) > 1e-100) { dbp("Vector::WithMagnitude(%g) of zero vector!", v); } return From(0, 0, 0); } else { return ScaledBy(v/m); } }
void libat_exchange (size_t n, void *mptr, void *vptr, void *rptr, int smodel) { union max_size_u u, v; uintptr_t r, a; switch (n) { case 0: return; case 1: EXACT(1); goto L4; case 2: EXACT(2); goto L4; case 4: EXACT(4); goto L8; case 8: EXACT(8); goto L16; case 16: EXACT(16); break; case 3: L4: LARGER(4); /* FALLTHRU */ case 5 ... 7: L8: LARGER(8); /* FALLTHRU */ case 9 ... 15: L16: LARGER(16); break; Lfinish: post_barrier (smodel); memcpy (rptr, u.b + r, n); return; } pre_seq_barrier (smodel); libat_lock_n (mptr, n); if (vptr != rptr) { memcpy (rptr, mptr, n); memcpy (mptr, vptr, n); } else libat_exchange_large_inplace (n, mptr, vptr); libat_unlock_n (mptr, n); post_seq_barrier (smodel); }
/* find most significant feature with respect to Xk */ int gmsw(fl_tp Xk,fl_tp Ym,mic_matrix M) { int *lst_Xk=(int*)malloc((Xk->k+1)*sizeof(int)); int i=0; if(Xk->k!=0) { for(i=0;i<Xk->k;i++) { lst_Xk[i]=Xk->membs[i]; } } int Xk_len=Xk->k+1; float max=-FLT_MAX; int atr=-1; fet_tp cur=Ym->header; for(i=0;i<Ym->k;i++) { lst_Xk[Xk_len-1]=cur->atr; #ifdef debug_gmsw printf("cur->atr:%d\nCheck Xk_:",cur->atr); check_arry(lst_Xk,Xk->k+1); #endif float merit=cal_merit(lst_Xk,Xk_len,M); #ifdef debug_gmsw printf("Debugging gmsw and now merit %f with atr %d.\n",merit,cur->atr); #endif if(EXACT(merit)>EXACT(max)) { max=merit; atr=cur->atr; } cur=cur->nn; } free(lst_Xk); #ifdef debug_gmsw printf("now atr:%d\n",atr); #endif return atr; }
void SBezier::MakePwlInto(List<Vector> *l, double chordTol) { if(EXACT(chordTol == 0)) { // Use the default chord tolerance. chordTol = SS.ChordTolMm(); } l->Add(&(ctrl[0])); if(deg == 1) { l->Add(&(ctrl[1])); } else { // Never do fewer than one intermediate point; people seem to get // unhappy when their circles turn into squares, but maybe less // unhappy with octagons. MakePwlWorker(l, 0.0, 0.5, chordTol); MakePwlWorker(l, 0.5, 1.0, chordTol); } }
void SolveSpace::SaveUsingTable(int type) { int i; for(i = 0; SAVED[i].type != 0; i++) { if(SAVED[i].type != type) continue; int fmt = SAVED[i].fmt; union SAVEDptr *p = (union SAVEDptr *)SAVED[i].ptr; // Any items that aren't specified are assumed to be zero if(fmt == 'N' && p->N.str[0] == '\0') continue; if(fmt == 'd' && p->d == 0) continue; if(fmt == 'f' && EXACT(p->f == 0.0)) continue; if(fmt == 'x' && p->x == 0) continue; fprintf(fh, "%s=", SAVED[i].desc); switch(fmt) { case 'N': fprintf(fh, "%s", p->N.str); break; case 'P': fprintf(fh, "%s", &(p->P)); break; case 'b': fprintf(fh, "%d", p->b ? 1 : 0); break; case 'c': fprintf(fh, "%08x", p->c.ToPackedInt()); break; case 'd': fprintf(fh, "%d", p->d); break; case 'f': fprintf(fh, "%.20f", p->f); break; case 'x': fprintf(fh, "%08x", p->x); break; case 'M': { int j; fprintf(fh, "{\n"); for(j = 0; j < p->M.n; j++) { EntityMap *em = &(p->M.elem[j]); fprintf(fh, " %d %08x %d\n", em->h.v, em->input.v, em->copyNumber); } fprintf(fh, "}"); break; } default: oops(); } fprintf(fh, "\n"); } }
void SolveSpaceUI::SaveUsingTable(int type) { int i; for(i = 0; SAVED[i].type != 0; i++) { if(SAVED[i].type != type) continue; int fmt = SAVED[i].fmt; SAVEDptr *p = (SAVEDptr *)SAVED[i].ptr; // Any items that aren't specified are assumed to be zero if(fmt == 'S' && p->S().empty()) continue; if(fmt == 'd' && p->d() == 0) continue; if(fmt == 'f' && EXACT(p->f() == 0.0)) continue; if(fmt == 'x' && p->x() == 0) continue; fprintf(fh, "%s=", SAVED[i].desc); switch(fmt) { case 'S': fprintf(fh, "%s", p->S().c_str()); break; case 'b': fprintf(fh, "%d", p->b() ? 1 : 0); break; case 'c': fprintf(fh, "%08x", p->c().ToPackedInt()); break; case 'd': fprintf(fh, "%d", p->d()); break; case 'f': fprintf(fh, "%.20f", p->f()); break; case 'x': fprintf(fh, "%08x", p->x()); break; case 'M': { int j; fprintf(fh, "{\n"); for(j = 0; j < p->M().n; j++) { EntityMap *em = &(p->M().elem[j]); fprintf(fh, " %d %08x %d\n", em->h.v, em->input.v, em->copyNumber); } fprintf(fh, "}"); break; } default: oops(); } fprintf(fh, "\n"); } }
void ssglWriteText(const char *str, double h, Vector t, Vector u, Vector v, ssglLineFn *fn, void *fndata) { if(!fn) fn = LineDrawCallback; u = u.WithMagnitude(1); v = v.WithMagnitude(1); double scale = FONT_SCALE(h)/SS.GW.scale; int xo = 5; int yo = 5; for(; *str; str++) { int c = *str; if(c < 32 || c > 126) c = 32; c -= 32; int j; Vector prevp = Vector::From(VERY_POSITIVE, 0, 0); for(j = 0; j < Font[c].points; j++) { int x = Font[c].coord[j*2]; int y = Font[c].coord[j*2+1]; if(x == PEN_UP && y == PEN_UP) { prevp.x = VERY_POSITIVE; } else { Vector p = t; p = p.Plus(u.ScaledBy((xo + x)*scale)); p = p.Plus(v.ScaledBy((yo + y)*scale)); if(EXACT(prevp.x != VERY_POSITIVE)) { fn(fndata, prevp, p); } prevp = p; } } xo += Font[c].width; } }
void GraphicsWindow::ZoomToFit(bool includingInvisibles, bool useSelection) { std::vector<Entity *> entities; std::vector<hEntity> faces; if(useSelection) { for(int i = 0; i < selection.n; i++) { Selection *s = &selection.elem[i]; if(s->entity.v == 0) continue; Entity *e = SK.entity.FindById(s->entity); if(e->IsFace()) { faces.push_back(e->h); continue; } entities.push_back(e); } } bool selectionUsed = !entities.empty() || !faces.empty(); if(!selectionUsed) { for(int i = 0; i<SK.entity.n; i++) { Entity *e = &(SK.entity.elem[i]); // we don't want to handle separate points, because we will iterate them inside entities. if(e->IsPoint()) continue; if(!includingInvisibles && !e->IsVisible()) continue; entities.push_back(e); } } // On the first run, ignore perspective. Point2d pmax = { -1e12, -1e12 }, pmin = { 1e12, 1e12 }; double wmin = 1; LoopOverPoints(entities, faces, &pmax, &pmin, &wmin, /*usePerspective=*/false, /*includeMesh=*/!selectionUsed); double xm = (pmax.x + pmin.x)/2, ym = (pmax.y + pmin.y)/2; double dx = pmax.x - pmin.x, dy = pmax.y - pmin.y; offset = offset.Plus(projRight.ScaledBy(-xm)).Plus( projUp. ScaledBy(-ym)); // And based on this, we calculate the scale and offset if(EXACT(dx == 0 && dy == 0)) { scale = 5; } else { double scalex = 1e12, scaley = 1e12; if(EXACT(dx != 0)) scalex = 0.9*width /dx; if(EXACT(dy != 0)) scaley = 0.9*height/dy; scale = min(scalex, scaley); scale = min(300.0, scale); scale = max(0.003, scale); } // Then do another run, considering the perspective. pmax.x = -1e12; pmax.y = -1e12; pmin.x = 1e12; pmin.y = 1e12; wmin = 1; LoopOverPoints(entities, faces, &pmax, &pmin, &wmin, /*usePerspective=*/true, /*includeMesh=*/!selectionUsed); // Adjust the scale so that no points are behind the camera if(wmin < 0.1) { double k = SS.CameraTangent(); // w = 1+k*scale*z double zmin = (wmin - 1)/(k*scale); // 0.1 = 1 + k*scale*zmin // (0.1 - 1)/(k*zmin) = scale scale = min(scale, (0.1 - 1)/(k*zmin)); } }
bool Vector::EqualsExactly(Vector v) { return EXACT(x == v.x && y == v.y && z == v.z); }
/* n denotes the target number of features */ fl_tp sffs(mic_matrix M,int n) { #define debug_total /* Begin to initialize list Xk and Ym */ /* Begin Xk */ fl_tp Xk=(fl_tp)malloc(sizeof(feature_list)); if(Xk==NULL) { printf("SFFS Xk initial memory error!\n"); exit(1); } Xk->k=0; Xk->sig=0; Xk->membs=NULL; Xk->header=Xk->tail=NULL; /*Begin Ym */ fl_tp Ym=(fl_tp)malloc(sizeof(feature_list)); Ym->k=M.atrn-1; Ym->membs=(int *)malloc(sizeof(int)*(Ym->k)); Ym->header=Ym->tail=NULL; int i=0; for(i=0;i<Ym->k;i++) { Ym->membs[i]=i; fet_tp cur=(fet_tp)malloc(sizeof(feature_list)); cur->atr=i; cur->pos=i; cur->mic=M.mic[M.class_idx][i]; cur->sig=0.00; cur->nn=NULL; cur->pn=NULL; if(Ym->header==NULL&&Ym->tail==NULL) { Ym->header=cur; Ym->tail=cur; cur->pn=cur->nn=NULL; } else { Ym->tail->nn=cur; cur->pn=Ym->tail; Ym->tail=cur; } } /* Begin to add first d features into Xk */ while(Xk->k < 2) { int msw=gmsw(Xk,Ym,M); add_node(msw,Xk,Ym,M); #ifdef debug_total printf("Now add msw %d to Xk which has %d members.\n",msw,Xk->k); #endif } #ifdef debug_total printf("Xk members :"); check_feature_list(Xk); #endif /* find the approriate d features */ int d=n; if(d>=M.atrn) { /*if the target number of feature*/ d=rnd(M.atrn/3.00); } #ifdef debug_total printf("sff d :%d,M.atrn:%d\n",d,M.atrn); #endif while(Xk->k <= d && Ym->k>0) { int msw=gmsw(Xk,Ym,M); fl_tp Xk_plus=plus_msw(Xk,msw); int lsi=glsi(Xk_plus,M); #ifdef debug_total printf("*****New loop,Xk has %d members.******\n The lsi is %d while the last is %d.\n",Xk->k,lsi,msw); #endif if(lsi != Xk_plus->membs[Xk_plus->k-1]) { if(Xk_plus->k-1==2) { Xk=add_node(msw,Xk,Ym,M); add_node(lsi,Ym,Xk,M); #ifdef debug_total printf("Xk'->k=2, now Xk:"); check_feature_list(Xk); #endif free(Xk_plus->membs); free(Xk_plus); } else { fl_tp Xk_chg=del_lsi(lsi,Xk_plus,M); #ifdef debug_total printf("Begin to condition exclusion,Xk->tail:%d,Xk' without lsi\t",Xk->tail->atr); check_feature_list(Xk_chg); #endif while( Xk_chg->k > 2 && Ym->k>0) { int lsi_chg=glsi(Xk_chg,M); fl_tp Xk_miu_chg=del_lsi(lsi_chg,Xk_chg,M);//Xk'-1 #ifdef debug_total printf("Xk's lsi :%d,Xk'-1 is ",lsi_chg); check_feature_list(Xk_miu_chg); printf("Sig(Xk'-1) %f and Sig(Xk-1) %d.so..\n",EXACT( Xk_miu_chg->sig), (Xk->tail->pn->atr)); #endif if(EXACT( Xk_miu_chg->sig) > EXACT(Xk->tail->pn->sig) ) { fl_tp Xk_chg=lst_rplc(Xk_chg,Xk_miu_chg); add_node(Xk->tail->atr,Ym,Xk,M); #ifdef debug_total printf("Cause Xk'-1 > Xk-1,so now Xk"); check_feature_list(Xk); #endif } else { add_node(msw,Xk,Ym,M); Xk=del_lsi(lsi,Xk,M); #ifdef debug_total printf("Cause Xk'-1 < Xk-1,So now Xk"); check_feature_list(Xk); #endif free(Xk_miu_chg->membs); free(Xk_miu_chg); break; } } } } else { Xk=add_node(msw,Xk,Ym,M); #ifdef debug_total printf("Lsi equals the last one,and now Xk "); check_feature_list(Xk); #endif } } return Xk; }