예제 #1
0
파일: poly.c 프로젝트: enascimento/supercop
poly_t * poly_sqrtmod_init(poly_t g) {
    int i, t;
    poly_t * sqrt, aux, p, q, * sq_aux;

    t = poly_deg(g);

    sq_aux = malloc(t * sizeof (poly_t));
    for (i = 0; i < t; ++i)
        sq_aux[i] = poly_alloc(t - 1);
    poly_sqmod_init(g, sq_aux);

    q = poly_alloc(t - 1);
    p = poly_alloc(t - 1);
    poly_set_deg(p, 1);
    poly_set_coeff(p, 1, gf_unit());
    // q(z) = 0, p(z) = z
    for (i = 0; i < t * gf_extd() - 1; ++i) {
        // q(z) <- p(z)^2 mod g(z)
        poly_sqmod(q, p, sq_aux, t);
        // q(z) <-> p(z)
        aux = q;
        q = p;
        p = aux;
    }
    // p(z) = z^(2^(tm-1)) mod g(z) = sqrt(z) mod g(z)

    sqrt = malloc(t * sizeof (poly_t));
    for (i = 0; i < t; ++i)
        sqrt[i] = poly_alloc(t - 1);

    poly_set(sqrt[1], p);
    poly_calcule_deg(sqrt[1]);
    for(i = 3; i < t; i += 2) {
        poly_set(sqrt[i], sqrt[i - 2]);
        poly_shiftmod(sqrt[i], g);
        poly_calcule_deg(sqrt[i]);
    }

    for (i = 0; i < t; i += 2) {
        poly_set_to_zero(sqrt[i]);
        sqrt[i]->coeff[i / 2] = gf_unit();
        sqrt[i]->deg = i / 2;
    }

    for (i = 0; i < t; ++i)
        poly_free(sq_aux[i]);
    free(sq_aux);
    poly_free(p);
    poly_free(q);

    return sqrt;
}
예제 #2
0
파일: poly.c 프로젝트: enascimento/supercop
poly_t * poly_syndrome_init(poly_t generator, gf_t *support, int n)
{
    int i,j,t;
    gf_t a;
    poly_t * F;

    F = malloc(n * sizeof (poly_t));
    t = poly_deg(generator);

    //g(z)=g_t+g_(t-1).z^(t-1)+......+g_1.z+g_0
    //f(z)=f_(t-1).z^(t-1)+......+f_1.z+f_0

    for(j=0; j<n; j++)
    {
        F[j] = poly_alloc(t-1);
        poly_set_coeff(F[j],t-1,gf_unit());
        for(i=t-2; i>=0; i--)
        {
            poly_set_coeff(F[j],i,gf_add(poly_coeff(generator,i+1),
                                         gf_mul(support[j],poly_coeff(F[j],i+1))));
        }
        a = gf_add(poly_coeff(generator,0),gf_mul(support[j],poly_coeff(F[j],0)));
        for(i=0; i<t; i++)
        {
            poly_set_coeff(F[j],i, gf_div(poly_coeff(F[j],i),a));
        }
    }

    return F;
}
예제 #3
0
파일: main.c 프로젝트: mattjakob/s3d
int main(int argc, char **argv)
{
  Poly *l, *p, *q = poly_alloc(3);
  Hpoly *t = hpoly_alloc(3);
  Item *i;

  init_sdl();
  s = scene_read();
  init_render();

  for (o = s->objs; o != NULL; o = o->next) {
    for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) {
      p = poly_transform(prim_polys(o->u.prim, l), mclip);
      if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p)))))
	hither_clip(0, p, z_store, plist_free);
    }
  }
  z = z_sort(z);

  for (i = z->head; i != NULL; i = i->next) {
    t = hpoly_polyxform(t, S(i), mdpy);
    q = poly_wz_hpoly(q, W(i), t);
    texture_wscale(W(i), T(i));
    scan_spoly3(q, 2, texture_shadepaint,
             texture_set(td,W(i),T(i),P(i),N(i),DU(i),DV(i),rc,M(i)));
  }
  img_write(s->img, "stdout", 0);
  exit(0);
}
예제 #4
0
파일: main.c 프로젝트: mattjakob/s3d
int main(int argc, char **argv)
{
  Poly *l, *p, *c = poly_alloc(3);
  Item *i;

  init_sdl();
  s = scene_read();
  init_render();

  for (o = s->objs; o != NULL; o = o->next) {
    for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) {
      p = poly_transform(prim_polys(o->u.prim, l), mclip);
      if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p)))))
	hither_clip(VIEW_ZMIN(s->view), p, z_store, plist_free);
    }
  }
  z = z_sort(z);

  for (i = z->head; i != NULL; i = i->next) { 
    gouraud_shade(c, P(i), N(i), s->view->center, rc, M(i));
    p = poly_homoxform(S(i),mdpy);
    scan_poly(p, gouraud_paint, gouraud_set(g,c,s->img));
  }
  img_write(s->img, "stdout", 0);
  exit(0);
}
예제 #5
0
// Returns the degree of the smallest factor
int poly_degppf(poly_t g) {
  int i, d, res;
  poly_t *u, p, r, s;

  d = poly_deg(g);
  u = malloc(d * sizeof (poly_t *));
  for (i = 0; i < d; ++i)
    u[i] = poly_alloc(d + 1);
  poly_sqmod_init(g, u);

  p = poly_alloc(d - 1);
  poly_set_deg(p, 1);
  poly_set_coeff(p, 1, gf_unit());
  r = poly_alloc(d - 1);
  res = d;
  for (i = 1; i <= (d / 2) * gf_extd(); ++i) {
    poly_sqmod(r, p, u, d);
    // r = x^(2^i) mod g
    if ((i % gf_extd()) == 0) { // so 2^i = (2^m)^j (m ext. degree)
      poly_addto_coeff(r, 1, gf_unit());
      poly_calcule_deg(r); // The degree may change
      s = poly_gcd(g, r);
      if (poly_deg(s) > 0) {
	poly_free(s);
	res = i / gf_extd();
	break;
      }
      poly_free(s);
      poly_addto_coeff(r, 1, gf_unit());
      poly_calcule_deg(r); // The degree may change
    }
    // No need for the exchange s
    s = p;
    p = r;
    r = s;
  }

  poly_free(p);
  poly_free(r);
  for (i = 0; i < d; ++i) {
    poly_free(u[i]);
  }
  free(u);

  return res;
}
예제 #6
0
파일: poly.c 프로젝트: enascimento/supercop
// retourne le degré du plus petit facteur
int poly_degppf(poly_t g) {
    int i, d, res;
    poly_t *u, p, r, s;

    d = poly_deg(g);
    u = malloc(d * sizeof (poly_t *));
    for (i = 0; i < d; ++i)
        u[i] = poly_alloc(d + 1);
    poly_sqmod_init(g, u);

    p = poly_alloc(d - 1);
    poly_set_deg(p, 1);
    poly_set_coeff(p, 1, gf_unit());
    r = poly_alloc(d - 1);
    res = d;
    for (i = 1; i <= (d / 2) * gf_extd(); ++i) {
        poly_sqmod(r, p, u, d);
        // r = x^(2^i) mod g
        if ((i % gf_extd()) == 0) { // donc 2^i = (2^m)^j (m deg d'extension)
            poly_addto_coeff(r, 1, gf_unit());
            poly_calcule_deg(r); // le degré peut changer
            s = poly_gcd(g, r);
            if (poly_deg(s) > 0) {
                poly_free(s);
                res = i / gf_extd();
                break;
            }
            poly_free(s);
            poly_addto_coeff(r, 1, gf_unit());
            poly_calcule_deg(r); // le degré peut changer
        }
        // on se sert de s pour l'échange
        s = p;
        p = r;
        r = s;
    }

    poly_free(p);
    poly_free(r);
    for (i = 0; i < d; ++i) {
        poly_free(u[i]);
    }
    free(u);

    return res;
}
예제 #7
0
pk_t* pk_bottom(ap_manager_t* man, size_t intdim, size_t realdim)
{
  pk_t* po = poly_alloc(intdim,realdim);
  pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_BOTTOM);
  pk_internal_realloc_lazy(pk,intdim+realdim);
  po->status = pk_status_conseps | pk_status_minimaleps;
  man->result.flag_exact = man->result.flag_best = true;
  return po;
}
예제 #8
0
pk_t* pk_forget_array(ap_manager_t* man, 
		      bool destructive, pk_t* pa, 
		      ap_dim_t* tdim, size_t size,
		      bool project)
{
  pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_FORGET_ARRAY);
  pk_t* po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim);
  poly_projectforget_array(project,
			   pk->funopt->algorithm<=0,
			   man,po,pa,tdim,size);
  assert(poly_check(pk,po));
  return po;
}
예제 #9
0
파일: bls.c 프로젝트: malisal/libfinite
int bls_verify(bls_ctxt_t *ctxt, ec_pqr_point_t *sig, bn_t *m)
{
	int res = 0;

	poly_t *a = poly_alloc(ctxt->ecg->p->degree - 1, ctxt->p, 1);
	poly_t *b = poly_alloc(ctxt->ecg->p->degree - 1, ctxt->p, 1);
	ec_pqr_point_t *P = ec_pqr_point_alloc(ctxt->ecg);

	//e(H(m), P)
	ec_pqr_point_mul(P, m, ctxt->G1, ctxt->ecg);
	pairing_weil(a, P, ctxt->P, ctxt->r, ctxt->ecg);
	//e(S, G)
	pairing_weil(b, sig, ctxt->G2, ctxt->r, ctxt->ecg);

	res = (poly_cmp(a, b) == POLY_CMP_E ? 1 : 0);

	ec_pqr_point_free(P);
	poly_free(b, 1);
	poly_free(a, 1);

	return res;
}
예제 #10
0
파일: poly.c 프로젝트: enascimento/supercop
poly_t poly_mul(poly_t p, poly_t q) {
    int i,j,dp,dq;
    poly_t r;

    poly_calcule_deg(p);
    poly_calcule_deg(q);
    dp = poly_deg(p);
    dq = poly_deg(q);
    r=poly_alloc(dp+dq);
    for (i = 0; i <= dp; ++i)
        for (j = 0; j <= dq; ++j)
            poly_addto_coeff(r,i+j,gf_mul(poly_coeff(p,i),poly_coeff(q,j)));
    poly_calcule_deg(r);

    return(r);
}
예제 #11
0
파일: poly.c 프로젝트: enascimento/supercop
// le corps est déjà défini
// retourne un polynôme unitaire de degré t irreductible dans le corps
poly_t poly_randgen_irred(int t, int (*u8rnd)()) {
    int i;
    poly_t g;

    g = poly_alloc(t);
    poly_set_deg(g, t);
    poly_set_coeff(g, t, gf_unit());

    i = 0;
    do
        for (i = 0; i < t; ++i)
            poly_set_coeff(g, i, gf_rand(u8rnd));
    while (poly_degppf(g) < t);

    return g;
}
예제 #12
0
poly_t poly_quo(poly_t p, poly_t d) {
  int i, j, dd, dp;
  gf_t a, b;
  poly_t quo, rem;

  dd = poly_calcule_deg(d);
  dp = poly_calcule_deg(p);
  rem = poly_copy(p);
  quo = poly_alloc(dp - dd);
  poly_set_deg(quo, dp - dd);
  a = gf_inv(poly_coeff(d, dd));
  for (i = dp; i >= dd; --i) {
    b = gf_mul_fast(a, poly_coeff(rem, i));
    poly_set_coeff(quo, i - dd, b);
    if (b != gf_zero()) {
      poly_set_coeff(rem, i, gf_zero());
      for (j = i - 1; j >= i - dd; --j)
	poly_addto_coeff(rem, j, gf_mul_fast(b, poly_coeff(d, dd - i + j)));
    }
  }
  poly_free(rem);

  return quo;
}
예제 #13
0
파일: atarisy4.c 프로젝트: ef1105/mameplus
void atarisy4_state::video_start()
{
	m_poly = poly_alloc(machine(), 1024, sizeof(poly_extra_data), POLYFLAG_NO_WORK_QUEUE);
}
예제 #14
0
파일: poly.c 프로젝트: enascimento/supercop
// On suppose deg(g) >= deg(p)
void poly_eeaux(poly_t * u, poly_t * v, poly_t p, poly_t g, int t) {
    int i, j, dr, du, delta;
    gf_t a;
    poly_t aux, r0, r1, u0, u1;

    // initialisation des variables locales
    // r0 <- g, r1 <- p, u0 <- 0, u1 <- 1
    dr = poly_deg(g);

    r0 = poly_alloc(dr);
    r1 = poly_alloc(dr - 1);
    u0 = poly_alloc(dr - 1);
    u1 = poly_alloc(dr - 1);
    poly_set(r0, g);
    poly_set(r1, p);
    poly_set_to_zero(u0);
    poly_set_to_zero(u1);
    poly_set_coeff(u1, 0, gf_unit());
    poly_set_deg(u1, 0);

    // invariants:
    // r1 = u1 * p + v1 * g
    // r0 = u0 * p + v0 * g
    // et deg(u1) = deg(g) - deg(r0)
    // on s'arrête lorsque deg(r1) < t (et deg(r0) >= t)
    // et donc deg(u1) = deg(g) - deg(r0) < deg(g) - t
    du = 0;
    dr = poly_deg(r1);
    delta = poly_deg(r0) - dr;

    while (dr >= t) {
        for (j = delta; j >= 0; --j) {
            a = gf_div(poly_coeff(r0, dr + j), poly_coeff(r1, dr));
            if (a != gf_zero()) {
                // u0(z) <- u0(z) + a * u1(z) * z^j
                for (i = 0; i <= du; ++i) {
                    poly_addto_coeff(u0, i + j, gf_mul_fast(a, poly_coeff(u1, i)));
                }
                // r0(z) <- r0(z) + a * r1(z) * z^j
                for (i = 0; i <= dr; ++i)
                    poly_addto_coeff(r0, i + j, gf_mul_fast(a, poly_coeff(r1, i)));
            }
        }
        // échanges
        aux = r0;
        r0 = r1;
        r1 = aux;
        aux = u0;
        u0 = u1;
        u1 = aux;

        du = du + delta;
        delta = 1;
        while (poly_coeff(r1, dr - delta) == gf_zero())
            delta++;
        dr -= delta;
    }

    poly_set_deg(u1, du);
    poly_set_deg(r1, dr);
    //return u1 and r1;
    *u=u1;
    *v=r1;

    poly_free(r0);
    poly_free(u0);
}
예제 #15
0
파일: galastrm.c 프로젝트: dinkc64/mame
/******************************************************************/

void galastrm_state::galastrm_exit()
{
	poly_free(m_poly);
}

void galastrm_state::video_start()
{
	m_spritelist = auto_alloc_array(machine(), struct tempsprite, 0x4000);

	m_screen->register_screen_bitmap(m_tmpbitmaps);
	m_screen->register_screen_bitmap(m_polybitmap);

	m_poly = poly_alloc(machine(), 16, sizeof(poly_extra_data), POLYFLAG_ALLOW_QUADS);
	machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(galastrm_state::galastrm_exit), this));
}

/************************************************************
            SPRITE DRAW ROUTINES

We draw a series of small tiles ("chunks") together to
create each big sprite. The spritemap rom provides the lookup
table for this. The game hardware looks up 16x16 sprite chunks
from the spritemap rom, creating a 64x64 sprite like this:

     0  1  2  3
     4  5  6  7
     8  9 10 11
    12 13 14 15
예제 #16
0
pk_t* poly_asssub_linexpr_det(bool assign,
			      ap_manager_t* man,
			      bool destructive,
			      pk_t* pa,
			      ap_dim_t dim, ap_linexpr0_t* linexpr0)
{
  int sgn;
  pk_t* po;
  pk_internal_t* pk = (pk_internal_t*)man->internal;

  po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim);

  if (!assign) poly_dual(pa);

  /* Convert linear expression */
  itv_linexpr_set_ap_linexpr0(pk->itv,
			      &pk->poly_itv_linexpr,
			      linexpr0);
  vector_set_itv_linexpr(pk,
			 pk->poly_numintp,
			 &pk->poly_itv_linexpr,
			 pa->intdim+pa->realdim,1);
  sgn = numint_sgn(pk->poly_numintp[pk->dec + dim]);

  if (!sgn){ /* Expression is not invertible */
    /* Get the needed matrix */
    poly_obtain_F_dual(man,pa,"of the argument",assign);
    if (pk->exn){
      pk->exn = AP_EXC_NONE;
      poly_set_top(pk,po);
      man->result.flag_best = man->result.flag_exact = false;
      goto  _poly_asssub_linear_linexpr_exit;
    }
    if (destructive){
      /* If side-effect, free everything but generators */
      if (po->satC){ satmat_free(po->satC); po->satC = NULL; }
      if (po->satF){ satmat_free(po->satF); po->satF = NULL; }
      if (po->C){ matrix_free(po->C); po->C = NULL; }
    }
  }
  if (pa->F){
    /* Perform assignements on generators */
    po->F =
      assign ?
      matrix_assign_variable(pk, destructive, pa->F, dim, pk->poly_numintp) :
      matrix_substitute_variable(pk, destructive, pa->F, dim, pk->poly_numintp);
  }
  if (sgn && pa->C){ /* Expression is invertible and we have constraints */
    /* Invert the expression in pk->poly_numintp2 */
    vector_invert_expr(pk,
		       pk->poly_numintp2,
		       dim, pk->poly_numintp,
		       pa->C->nbcolumns);
    /* Perform susbtitution on constraints */
    po->C =
      assign ?
      matrix_substitute_variable(pk,destructive,pa->C, dim, pk->poly_numintp2) :
      matrix_assign_variable(pk,destructive,pa->C, dim, pk->poly_numintp2);
  }
  if (po->C && po->F){
    po->nbeq = pa->nbeq;
    po->nbline = pa->nbline;
    po->satC = (destructive || pa->satC==NULL) ? pa->satC : satmat_copy(pa->satC);
    po->satF = (destructive || pa->satF==NULL) ? pa->satF : satmat_copy(pa->satF);
  } else {
    po->nbeq = 0;
    po->nbline = 0;
  }
  po->status = 0;
 _poly_asssub_linear_linexpr_exit:
  if (!assign){
    poly_dual(pa);
    if (!destructive) poly_dual(po);
  }
  assert(poly_check(pk,po));
  return po;
}
예제 #17
0
pk_t* poly_asssub_linexpr_array_det(bool assign,
				    ap_manager_t* man,
				    bool destructive,
				    pk_t* pa,
				    ap_dim_t* tdim, ap_linexpr0_t** texpr,
				    size_t size)
{
  size_t i;
  ap_dim_t* tdim2;
  numint_t** tvec;
  size_t nbcols;
  matrix_t* mat;
  pk_t* po;
  pk_internal_t* pk = (pk_internal_t*)man->internal;

  po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim);

  if (!assign) poly_dual(pa);

  /* Obtain the needed matrix */
  poly_obtain_F_dual(man,pa,"of the argument",assign);
  if (pk->exn){
    pk->exn = AP_EXC_NONE;
    man->result.flag_best = man->result.flag_exact = false;
    poly_set_top(pk,po);
    goto _poly_asssub_linexpr_array_det_exit;
  }
  /* Return empty if empty */
  if (!pa->C && !pa->F){
    man->result.flag_best = man->result.flag_exact = true;
    poly_set_bottom(pk,po);
    return po;
  }
  /* Convert linear expressions */
  nbcols = pk->dec + pa->intdim + pa->realdim;
  tvec = (numint_t**)malloc(size*sizeof(numint_t*));
  for (i=0; i<size; i++){
    tvec[i] = vector_alloc(nbcols);
    itv_linexpr_set_ap_linexpr0(pk->itv,
				&pk->poly_itv_linexpr,
				texpr[i]);
    vector_set_itv_linexpr(pk,
			   tvec[i],
			   &pk->poly_itv_linexpr,
			   pa->intdim+pa->realdim,1);
  }
  /* Copy tdim because of sorting */
  tdim2 = (ap_dim_t*)malloc(size*sizeof(ap_dim_t));
  memcpy(tdim2,tdim,size*sizeof(ap_dim_t));
  pk_asssub_isort(tdim2,tvec,size);
  /* Perform the operation */
  mat =
    assign ?
    matrix_assign_variables(pk, pa->F, tdim2, tvec, size) :
    matrix_substitute_variables(pk, pa->F, tdim2, tvec, size);
  /* Free allocated stuff */
  for (i=0; i<size; i++){
    vector_free(tvec[i],nbcols);
  }
  free(tvec);
  free(tdim2);

  /* Update polyhedra */
  if (destructive){
    poly_clear(po);
  }
  po->F = mat;
  po->status = 0;
 _poly_asssub_linexpr_array_det_exit:
  if (!assign){
    poly_dual(pa);
    if (!destructive) poly_dual(po);
  }
  assert(poly_check(pk,po));
  return po;
}
예제 #18
0
/* ---------------------------------------------------------------------- */
static
void poly_approximate_123(ap_manager_t* man, pk_t* po, int algorithm)
{
  bool change;
  pk_internal_t* pk = (pk_internal_t*)man->internal;

  if (algorithm==1){
    poly_approximate_1(man,po,po);
  }
  else {
    size_t nbrows, nbrows2;
    ap_dim_t dim;
    ap_dim_t i,j;
    int sgn, sgny;
    itv_t itv;

    pk_t* pa = poly_alloc(po->intdim,po->realdim);

    change = poly_approximate_1(man,pa,po);
    if (!change){
      pk_free(man,pa);
      return;
    }
    poly_obtain_F(man,po,NULL);
    if (!po->F){
      if (!po->C){
	pk_free(man,pa);
	poly_set_bottom(pk,po);
	man->result.flag_exact = true;
	return;
      }
      else {
	poly_clear(po);
	*po = *pa;
	free(pa);
      }
      return;
    }
    dim = pa->intdim + pa->realdim;
    nbrows = pa->C->nbrows;
    itv_init(itv);
    if (algorithm>=2){ /* Add interval constraints */
      nbrows2 = 2*dim;
      matrix_resize_rows_lazy(pa->C, nbrows + nbrows2);
      pa->C->_sorted = false;
      for (i=0; i<dim;i++){
	matrix_bound_dimension(pk,itv,i,po->F);
	if (!bound_infty(itv->inf)){
	  vector_set_dim_bound(pk,
			       pa->C->p[nbrows],
			       i, bound_numref(itv->inf),
			       -1,
			       po->intdim, po->realdim, false);
	  nbrows++;
	}
	if (!bound_infty(itv->sup)){
	  vector_set_dim_bound(pk,
			       pa->C->p[nbrows],
			       i, bound_numref(itv->sup),
			       1,
			       po->intdim, po->realdim, false);
	  nbrows++;
	}
      }
    }
    pa->C->nbrows = nbrows;
    if (algorithm>=3){ /* Add octagonal constraints */
      vector_clear(pk->poly_numintp,po->F->nbcolumns);
      numint_set_int(pk->poly_numintp[0],1);
      for (i=0; i<dim;i++){
	numint_set_int(pk->poly_numintp[pk->dec+i],1);
	nbrows2 = 4*(dim-i-1);
	matrix_resize_rows_lazy(pa->C, nbrows + nbrows2);
	for (j=i+1; j<dim;j++){
	  for (sgny=-1; sgny<=1; sgny += 2){
	    numint_set_int(pk->poly_numintp[pk->dec+j],sgny);
	    matrix_bound_vector(pk,itv,pk->poly_numintp,po->F);
	    if (!bound_infty(itv->inf)){
	      vector_set_linexpr_bound(pk,
				       pa->C->p[nbrows], pk->poly_numintp,
				       itv->inf, -1,
				       po->intdim, po->realdim, false);
	      nbrows++;
	    }
	    if (!bound_infty(itv->sup)){
	      vector_set_linexpr_bound(pk,
				       pa->C->p[nbrows], pk->poly_numintp,
				       itv->sup, 1,
				       po->intdim, po->realdim, false);
	      nbrows++;
	    }
	  }
	  numint_set_int(pk->poly_numintp[pk->dec+j],0);
	}
	numint_set_int(pk->poly_numintp[pk->dec+i],0);
      }
      pa->C->nbrows = nbrows;
    }
    itv_clear(itv);
    poly_clear(po);
    *po = *pa;
    free(pa);
    return;
  }
}
예제 #19
0
static VIDEO_START( atarisy4 )
{
	poly = poly_alloc(machine, 1024, sizeof(poly_extra_data), POLYFLAG_NO_WORK_QUEUE);
}
예제 #20
0
pk_t* pk_closure(ap_manager_t* man, bool destructive, pk_t* pa)
{
  matrix_t* C;
  bool change,positivity;
  size_t i;
  pk_t* po;

  pk_internal_t* pk = pk_init_from_manager(man,AP_FUNID_CLOSURE);
  man->result.flag_best = man->result.flag_exact = true;
  if (!pk->strict){
    return destructive ? pa : pk_copy(man,pa);
  }
  if (pk->funopt->algorithm<0)
    poly_obtain_C(man,pa,"of the argument");
  else
    poly_chernikova(man,pa,"of the argument");
  
  if (!pa->C && !pa->F){
    return destructive ? pa : pk_copy(man,pa);
  }
  po = destructive ? pa : poly_alloc(pa->intdim,pa->realdim);
  if (pk->exn){
    poly_set_top(pk,po);
    man->result.flag_best = man->result.flag_exact = false;
    return po;
  }
  if (!destructive){
    po->C = matrix_copy(pa->C);
  }
  
  C = po->C;
  change = false;
  positivity = false;
  for (i=0;i<C->nbrows; i++){
    if (numint_sgn(C->p[i][polka_eps])<0){
      if (vector_is_positivity_constraint(pk,C->p[i],
					  C->nbcolumns)){
	/* we keep the positivity constraint epsilon<=1 */
	positivity = true;
      }
      else {
	change = true;
	numint_set_int(C->p[i][polka_eps],0);
      }
    }
  }
  assert(change || positivity);
  if (change){
    if (!positivity){
      numint_t* q;
      size_t nbrows;
      /* we should add it */
      nbrows = C->nbrows;
      matrix_resize_rows_lazy(C,C->nbrows+1);
      q = C->p[nbrows];
      numint_set_int(q[0],1);
      numint_set_int(q[polka_cst],1);
      numint_set_int(q[polka_eps],-1);
      for (i=3; i<C->nbcolumns; i++) numint_set_int(q[i],0);
    }
    C->_sorted = false;
    if (destructive){
      if (po->F) matrix_free(po->F);
      if (po->satC) satmat_free(po->satC);
      if (po->satF) satmat_free(po->satF);
      po->F = NULL;
      po->satC = NULL;
      po->satF = NULL;
      po->status = pk_status_conseps;
      po->nbeq = 0;
      po->nbline = 0;
    }
  }
  assert(poly_check(pk,po));
  return po;
}