Example #1
0
File: ap.c Project: KoyoA/patterns
T AP_mod(T x, T y) {
    T q, r;
    assert(x);
    assert(y);
    assert(!iszero(y));
    q = mk(x->ndigits);
    r = mk(y->ndigits);
    {
        XP_T tmp = ALLOC(x->ndigits + y->ndigits + 2);
        XP_div(x->ndigits, q->digits, x->digits,
               y->ndigits, y->digits, r->digits, tmp);
        FREE(tmp);
    }
    normalize(q, q->size);
    normalize(r, r->size);
    q->sign = iszero(q)
              || ((x->sign^y->sign) == 0) ? 1 : -1;
    if (!((x->sign^y->sign) == 0) && !iszero(r)) {
        int borrow = XP_sub(r->size, r->digits,
                            y->digits, r->digits, 0);
        assert(borrow == 0);
        normalize(r, r->size);
    }
    AP_free(&q);
    return r;
}
Example #2
0
File: ap.c Project: KoyoA/patterns
T AP_div(T x, T y) {
    T q, r;
    assert(x);
    assert(y);
    assert(!iszero(y));
    q = mk(x->ndigits);
    r = mk(y->ndigits);
    {
        XP_T tmp = ALLOC(x->ndigits + y->ndigits + 2);
        XP_div(x->ndigits, q->digits, x->digits,
               y->ndigits, y->digits, r->digits, tmp);
        FREE(tmp);
    }
    normalize(q, q->size);
    normalize(r, r->size);
    q->sign = iszero(q)
              || ((x->sign^y->sign) == 0) ? 1 : -1;
    if (!((x->sign^y->sign) == 0) && !iszero(r)) {
        int carry = XP_sum(q->size, q->digits,
                           q->digits, 1);
        assert(carry == 0);
        normalize(q, q->size);
    }
    AP_free(&r);
    return q;
}
pair<Node*, Node*> split(Node* n, int val) { // returns subtrees (< val, >= val)
	if (!n) return {0,0};
	Node*& c = n->child[val > n->val];
	auto sub = split(c, val);
	if (val > n->val) { c = sub.fst; n->maintain(); return mk(n, sub.snd); }
	else              { c = sub.snd; n->maintain(); return mk(sub.fst, n); }
}
Example #4
0
static struct n *mkcycle()
{
	register struct n *a, *b, *c;

	a = mk(0,0);
	b = mk(a,0);
	c = mk(b,0);
	a->l = c;

	return a;
}
Example #5
0
/* getherevar -- read a variable from a here doc */
extern Tree *getherevar(void) {
	int c;
	char *s;
	Buffer *buf = openbuffer(0);
	while (!dnw[c = GETC()])
		buf = bufputc(buf, c);
	s = sealcountedbuffer(buf);
	if (buf->len == 0) {
		yyerror("null variable name in here document");
		return NULL;
	}
	if (c != '^')
		UNGETC(c);
	return flatten(mk(nVar, mk(nWord, s)), " ");
}
Example #6
0
File: ap.c Project: KoyoA/patterns
T AP_sub(T x, T y) {
    T z;
    assert(x);
    assert(y);
    if (!((x->sign^y->sign) == 0)) {
        z = add(mk(maxdigits(x,y) + 1), x, y);
        z->sign = iszero(z) ? 1 : x->sign;
    } else if (cmp(x, y) > 0) {
        z = sub(mk(x->ndigits), x, y);
        z->sign = iszero(z) ? 1 : x->sign;
    } else {
        z = sub(mk(y->ndigits), y, x);
        z->sign = iszero(z) ? 1 : -x->sign;
    }
    return z;
}
Example #7
0
bool MComponent::makeMakeFile( bool long_lines )
{
    bool ok = true;
    WFileName mk( _filename );
    mk.setExt( makeExt );

    updateItemList();

    if( needsMake() || !mk.attribs() ) {
        ContFile        tmak;
        if( long_lines )
            tmak.long_lines();
        if( !tmak.open( mk, OStyleWrite ) ) {
            ok = false;
        } else {
            tmak.puts( "!define BLANK \"\"\n" );
            initWorkFiles( _workFiles );
//          for( int i=0; i<_workFiles.count(); i++ ) {
//              ((MWorkFile*)_workFiles[i])->dump( tmak );
//          }
            writeRule( tmak );
            finiWorkFiles();
            tmak.close();
            ok = tmak.ok();
            setNeedsMake( false );
        }
    }
    return( ok );
}
Example #8
0
void ANNbruteForce::annkSearch( // approx k near neighbor search
    ANNpoint q,                 // query point
    int k,                      // number of near neighbors to return
    ANNidxArray nn_idx,         // nearest neighbor indices (returned)
    ANNdistArray dd,            // dist to near neighbors (returned)
    double eps)                 // error bound (ignored)
{
    ANNmin_k mk(k); // construct a k-limited priority queue
    int i;

    if (k > n_pts) { // too many near neighbors?
        annError("Requesting more near neighbors than data points", ANNabort);
    }
    // run every point through queue
    for (i = 0; i < n_pts; i++) {
        // compute distance to point
        ANNdist sqDist = annDist(dim, pts[i], q);
        if (ANN_ALLOW_SELF_MATCH || sqDist != 0)
            mk.insert(sqDist, i);
    }
    for (i = 0; i < k; i++) { // extract the k closest points
        dd[i] = mk.ith_smallest_key(i);
        nn_idx[i] = mk.ith_smallest_info(i);
    }
}
Example #9
0
int ANNbruteForce::annkFRSearch( // approx fixed-radius kNN search
    ANNpoint q,                  // query point
    ANNdist sqRad,               // squared radius
    int k,                       // number of near neighbors to return
    ANNidxArray nn_idx,          // nearest neighbor array (returned)
    ANNdistArray dd,             // dist to near neighbors (returned)
    double eps)                  // error bound
{
    ANNmin_k mk(k); // construct a k-limited priority queue
    int i;
    int pts_in_range = 0; // number of points in query range
    // run every point through queue
    for (i = 0; i < n_pts; i++) {
        // compute distance to point
        ANNdist sqDist = annDist(dim, pts[i], q);
        if (sqDist <= sqRad &&                       // within radius bound
                (ANN_ALLOW_SELF_MATCH || sqDist != 0)) { // ...and no self match
            mk.insert(sqDist, i);
            pts_in_range++;
        }
    }
    for (i = 0; i < k; i++) { // extract the k closest points
        if (dd != nullptr)
            dd[i] = mk.ith_smallest_key(i);
        if (nn_idx != nullptr)
            nn_idx[i] = mk.ith_smallest_info(i);
    }

    return pts_in_range;
}
Example #10
0
void Contour::simplify(float tol)
{
  int n = points.size();
  int pv; // misc counters

  // STAGE 1.  Vertex Reduction within tolerance of prior vertex cluster
  int m = 1;// first point always kept
  for (int i = 1, pv = 0; i < n - 1; i++) {
    if (frsm_dist(&points[i], &points[pv]) < tol)
      continue;
    points[m] = points[i];
    pv = m++;
  }
  points[m++] = points[n - 1]; //make sure end is added
  //m vertices in vertex reduced polyline
  points.resize(m);

  // STAGE 2.  Douglas-Peucker polyline simplification
  vector<bool> mk(points.size(), false);
  mk[0] = mk.back() = 1; // mark the first and last vertices
  simplifyDP(tol, points, 0, points.size() - 1, mk);

  // copy marked vertices to the output simplified polyline
  m = 0;
  for (int i = 0; i < points.size(); i++) {
    if (mk[i])
      points[m++] = points[i]; //m<=i;
  }
  //m vertices in simplified polyline
  points.resize(m);

}
Example #11
0
YAPStringTerm::YAPStringTerm(char *s) { // build string
  BACKUP_H();

  CACHE_REGS
  Term ts = MkStringTerm(s);
  mk(ts);
  RECOVER_H();
}
Example #12
0
int main(int argc,char *argv[])
  {
  FILE *f=fopen(argv[1],"r");

  // Parse XML file
  struct foo *b=(struct foo *)xml_parse(f,"root",&myschema,metafind(&myschema, "foo"),1);
  struct item *i;

  // Access values in foo
  printf("root->val = %d\n",b->val);
  printf("root->val_name = %s\n",b->val_name);
  printf("root->items->val = %d\n",b->items->val);
  printf("root->items->next->val = %d\n",b->items->next->val);
  printf("root->items->next->next->val = %d\n",b->items->next->next->val);

  // Print in various formats
  xml_print(stdout,"root",0,(struct base *)b);

  lisp_print(stdout,"root",0,(struct base *)b);

  lisp_print_untagged(stdout,"root",0,(struct base *)b);

  indent_print(stdout,"root",0,(struct base *)b);

  indent_print_untagged(stdout,"root",0,(struct base *)b);

  json_print(stdout,NULL,0,(struct base *)b,0);

  // Create a database within C
  b=mk(&myschema, "foo");
  b->val=10;
  b->val_name=strdup("Hello");

  // Build list
  i=b->items=mk(&myschema, "item");
  i->val=7;
  i=i->next=mk(&myschema, "item");
  i->val=8;
  i=i->next=mk(&myschema, "item");
  i->val=9;

  // Print it
  xml_print(stdout,"root",0,(struct base *)b);

  return 0;
  }
Example #13
0
File: ap.c Project: KoyoA/patterns
T AP_neg(T x) {
    T z;
    assert(x);
    z = mk(x->ndigits);
    memcpy(z->digits, x->digits, x->ndigits);
    z->ndigits = x->ndigits;
    z->sign = iszero(z) ? 1 : -x->sign;
    return z;
}
Example #14
0
void MComponent::addMakeFile( ContFile& pmak )
{
    WFileName mk( _filename );
    mk.setExt( makeExt );
    if( mk.needQuotes() ) {
        mk.addQuotes();
    }
    pmak.printf( "!include %s\n", (const char*)mk );
}
Example #15
0
File: ap.c Project: KoyoA/patterns
T AP_lshift(T x, int s) {
    T z;
    assert(x);
    assert(s >= 0);
    z = mk(x->ndigits + ((s+7)&~7)/8);
    XP_lshift(z->size, z->digits, x->ndigits,
              x->digits, s, 0);
    z->sign = x->sign;
    return normalize(z, z->size);
}
Example #16
0
YAPApplTerm::YAPApplTerm(const std::string f, YAPTerm a1) {
  BACKUP_H();
  arity_t arity = 1;
  Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity);
  Term o = Yap_MkNewApplTerm(ff, arity);
  Term *tt = RepAppl(o) + 1;
  tt[0] = a1.term();
  mk(o);
    RECOVER_H();
}
Example #17
0
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) {
  BACKUP_H();
  arity_t arity = ArityOfFunctor(f.f);
  Term o = Yap_MkNewApplTerm(f.f, arity);
  Term *tt = RepAppl(o) + 1;
  for (arity_t i = 0; i < arity; i++)
    tt[i] = ts[i].term();
  mk(o);
  RECOVER_H();
}
Example #18
0
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) : YAPTerm() {
  BACKUP_H();
  arity_t arity = ArityOfFunctor(f.f);
  Term *tt = new Term[arity];
  for (arity_t i = 0; i < arity; i++)
    tt[i] = ts[i].term();
  mk(Yap_MkApplTerm(f.f, arity, tt));
  delete[] tt;
  RECOVER_H();
}
Example #19
0
void mpz_matrix_manager::tensor_product(mpz_matrix const & A, mpz_matrix const & B, mpz_matrix & C) {
    scoped_mpz_matrix CC(*this);
    mk(A.m * B.m, A.n * B.n, CC);
    for (unsigned i = 0; i < CC.m(); i++)
        for (unsigned j = 0; j < CC.n(); j++)
            nm().mul(A(i / B.m, j / B.n), 
                     B(i % B.m, j % B.n), 
                     CC(i, j));
    C.swap(CC);
}
Example #20
0
YAPApplTerm::YAPApplTerm(const std::string f, std::vector<YAPTerm> ts) {
    BACKUP_H();
    arity_t arity = ts.size();
    Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity);
    Term o = Yap_MkNewApplTerm(ff, arity);
    Term *tt = RepAppl(o) + 1;
    for (arity_t i = 0; i < arity; i++)
        tt[i] = ts[i].term();
    mk(o);
    RECOVER_H();
}
Example #21
0
File: ap.c Project: KoyoA/patterns
T AP_mul(T x, T y) {
    T z;
    assert(x);
    assert(y);
    z = mk(x->ndigits + y->ndigits);
    XP_mul(z->digits, x->ndigits, x->digits, y->ndigits,
           y->digits);
    normalize(z, z->size);
    z->sign = iszero(z)
              || ((x->sign^y->sign) == 0) ? 1 : -1;
    return z;
}
Example #22
0
void mpz_matrix_manager::set(mpz_matrix & A, mpz_matrix const & B) {
    if (&A == &B)
        return;
    if (A.m != B.m || A.n != B.n) {
        del(A);
        mk(B.m, B.n, A);
    }
    SASSERT(A.m == B.m && A.n == B.n);
    for (unsigned i = 0; i < B.m; i++)
        for (unsigned j = 0; j < B.n; j++)
            nm().set(A(i, j), B(i, j));
}
Example #23
0
YAPAtomTerm::YAPAtomTerm(wchar_t *s): YAPTerm() { // build string
  BACKUP_H();

  CACHE_REGS
  seq_tv_t inp, out;
  inp.val.w = s;
  inp.type = YAP_STRING_WCHARS;
  out.type = YAP_STRING_ATOM;
  if (Yap_CVT_Text(&inp, &out PASS_REGS))
    mk ( MkAtomTerm(out.val.a) );
  else t = 0L;
  RECOVER_H();
}
Example #24
0
YAPStringTerm::YAPStringTerm(char *s) { // build string
  BACKUP_H();

  CACHE_REGS
  seq_tv_t inp, out;
  inp.val.c = s;
  inp.type = YAP_STRING_CHARS;
  out.type = YAP_STRING_STRING;
  if (Yap_CVT_Text(&inp, &out PASS_REGS))
    mk ( out.val.t );
  else t = 0L;
  RECOVER_H();
}
Example #25
0
File: ap.c Project: KoyoA/patterns
T AP_rshift(T x, int s) {
    assert(x);
    assert(s >= 0);
    if (s >= 8*x->ndigits)
        return AP_new(0);
    else {
        T z = mk(x->ndigits - s/8);
        XP_rshift(z->size, z->digits, x->ndigits,
                  x->digits, s, 0);
        normalize(z, z->size);
        z->sign = iszero(z) ? 1 : x->sign;
        return z;
    }
}
Example #26
0
YAPAtomTerm::YAPAtomTerm(char s[]) { // build string
  BACKUP_H();

  CACHE_REGS
  seq_tv_t inp, out;
    inp.enc = LOCAL_encoding;
  inp.val.c = s;
  inp.type = YAP_STRING_CHARS;
  out.type = YAP_STRING_ATOM;
  if (Yap_CVT_Text(&inp, &out PASS_REGS))
    mk(MkAtomTerm(out.val.a));
  else
    t = 0L;
  RECOVER_H();
}
Example #27
0
YAPAtomTerm::YAPAtomTerm(char *s, size_t len) { // build string
  BACKUP_H();

  CACHE_REGS
  seq_tv_t inp, out;
  inp.val.c = s;
  inp.type = YAP_STRING_CHARS;
  out.type = YAP_STRING_ATOM|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
  out.sz = len;
  out.max = len;
  if (Yap_CVT_Text(&inp, &out PASS_REGS))
    mk ( MkAtomTerm(out.val.a) );
  else t = 0L;
  RECOVER_H();
}
Example #28
0
void lfmxevs(lfit *lf, mxArray *mcell)
{ int d, i, j;
  double *ll, *ur, *mg, *drv;
  char evstr[16], mod[16], mdir[256];
  evstruc *evs;
  fitpt *fp;
  deriv *dv;

  evs = &lf->evs;
  fp  = &lf->fp;
  dv  = &lf->dv;
  d   = lf->lfd.d;

  if (mxIsChar(mxGetField(mcell,0,"type")))
  { mxGetString(mxGetField(mcell,0,"type"),evstr,16);
    ev(evs) = lfevstr(evstr);
  }
  else
  { ev(evs) = EPRES;
    evs->mg[0] = mxGetN(mxGetField(mcell,0,"type"));
    fp->xev = mxGetPr(mxGetField(mcell,0,"type"));
  }


  mxGetString(mxGetField(mxGetField(mcell,0,"module"),0,"name"),mod,16);
  mxGetString(mxGetField(mxGetField(mcell,0,"module"),0,"directory"),mdir,256);
  MODPARAMS(lf) = mxGetPr(mxGetField(mxGetField(mcell,0,"module"),0,"parameters"));
  MODNPARAMS(lf) = mxGetN(mxGetField(mxGetField(mcell,0,"module"),0,"parameters"));
  initmodule(&lf->mdl,mod,mdir,lf);


  ll = mxGetPr(mxGetField(mcell,0,"lower_left"));
  ur = mxGetPr(mxGetField(mcell,0,"upper_right"));
  mg = mxGetPr(mxGetField(mcell,0,"grid"));
  j =  mxGetN(mxGetField(mcell,0,"grid"));
  cut(evs) = mxGetPr(mxGetField(mcell,0,"cut"))[0];
  for (i=0; i<d; i++)
  { evs->fl[i] = ll[i];
    evs->fl[i+d] = ur[i];
    if (ev(evs) != EPRES) evs->mg[i] = (j==1) ? mg[0] : mg[i];
  }
  mk(evs) = mxGetPr(mxGetField(mcell,0,"maxk"))[0];

  drv = mxGetPr(mxGetField(mcell,0,"derivative")); 
  j = mxGetN(mxGetField(mcell,0,"derivative")); 
  for (i=0; i<j; i++) dv->deriv[i] = drv[i]-1;
  dv->nd = (drv[0]>0) ? j : 0;
}
Example #29
0
YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len) : YAPTerm() { // build string
  BACKUP_H();

  CACHE_REGS

  seq_tv_t inp, out;
  inp.val.w = s;
  inp.type = YAP_STRING_WCHARS;
  out.type = YAP_STRING_STRING|YAP_STRING_NCHARS|YAP_STRING_TRUNC;
  out.sz = len;
  out.max = len;
  if (Yap_CVT_Text(&inp, &out PASS_REGS))
    mk ( out.val.t );
  else t = 0L;
  RECOVER_H();
}
Example #30
0
void dtfit_sigmc(){
    TChain* tree = new TChain("TEvent");
    tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmc_s1.root");
    tree->Add("/home/vitaly/B0toDh0/Tuples/b2dh_sigmc_s2.root");

    RooArgSet argset;
    RooRealVar mbc("mbc","mbc",mbc_min,mbc_max,"GeV"); argset.add(mbc);
    RooRealVar de("de","#DeltaE",-0.15,0.3,"GeV"); argset.add(de);
    de.setRange("signal",de_min,de_max);
    RooRealVar md("md","md",DMass-md_cut,DMass+md_cut,"GeV"); argset.add(md);
    RooRealVar mk("mk","mk",KMass-mk_cut,KMass+mk_cut,"GeV"); argset.add(mk);
    RooRealVar mpi0("mpi0","mpi0",Pi0Mass-mpi0_cut,Pi0Mass+mpi0_cut,"GeV"); argset.add(mpi0);
    RooRealVar bdtgs("bdtgs","bdtgs",0.98,1.); argset.add(bdtgs);
    RooRealVar atckpi_max("atckpi_max","atckpi_max",0.,atckpi_cut); argset.add(atckpi_max);

    RooDataSet ds("ds","ds",tree,argset);
    ds.Print();
}