Beispiel #1
0
FreeModule *FreeModule::exterior(int pp) const
// p th exterior power
{
    FreeModule *result;
    if (pp == 0)
        return get_ring()->make_FreeModule(1);
    else
        result = new_free();

    int rk = rank();
    if (pp > rk || pp < 0) return result;

    size_t p = static_cast<size_t>(pp);

    Subset a(p, 0);
    for (size_t i=0; i<p; i++) a[i] = i;

    int *deg = degree_monoid()->make_one();
    do
    {
        degree_monoid()->one(deg);

        for (size_t r=0; r<p; r++)
            degree_monoid()->mult(deg, degree(static_cast<int>(a[r])), deg);

        result->append(deg);
    }
    while (Subsets::increment(rk, a));

    degree_monoid()->remove(deg);

    if (schreyer != NULL)
        result->schreyer = schreyer->exterior(pp);
    return result;
}
Beispiel #2
0
M2_arrayintOrNull FreeModule::select_by_degrees(M2_arrayintOrNull lo, M2_arrayintOrNull hi) const
{
    const Ring *R = get_ring();
    const Monoid *D = R->degree_monoid();
    std::vector<size_t> result;
    int ndegrees = D->n_vars();
    int *exp = newarray_atomic(int,ndegrees);
    for (int i=0; i<rank(); i++)
    {
        D->to_expvector(degree(i), exp);
#if 0
        for (int i=0; i<ndegrees; i++)
            printf("%d ", exp[i]);
        if (degree_in_box(ndegrees, exp, lo, hi))
            printf("yes\n");
        else
            printf("no\n");
#endif
        if (degree_in_box(ndegrees, exp, lo, hi))
            result.push_back(i);
    }
    M2_arrayint selection = stdvector_to_M2_arrayint(result);
    deletearray(exp);
    return selection;
}
Beispiel #3
0
// color_map must point to an array of COLOR_MAP_SIZE color_t structs
void draw_circles (coordinates_t *center_pos, color_t *my_color_map)
{
	uint8_t r_index, rb_index;
	uint16_t dist;
	ring_t *r;
	beam_t *b;
	coordinates_t *pos;
//	fprintf (stderr, "Inside draw_circles\n");
	for (r_index = 0; r_index < NUM_RINGS; ++r_index) {
		r = get_ring (r_index);
//		fprintf (stderr, "Num beams %d for ring %d\n", r->num_beams, r_index);
		for (rb_index = 0; rb_index < r->num_beams; ++rb_index) {
			b = r->beams[rb_index];
			pos = &(b->position);

			dist = calc_degree_distance (pos, center_pos);

/*			if (r_index == 0) {
			fprintf (stderr, "Ring %d Beam %d, elevation %d, azimuth %d colors %d, %d, %d\n",
				r_index, rb_index, (int)(pos->elevation * 180 / PI), (int)(pos->azimuth * 180 / PI), my_color_map[dist].red, my_color_map[dist].green, my_color_map[dist].blue);
			}
*/

			*(b->red) = atten[my_color_map[dist].red];
			*(b->green) = atten[my_color_map[dist].green];
			*(b->blue) = atten[my_color_map[dist].blue];

			// possibly optimize to only set dirty if changed?
			*(b->dirty) = 1;
		}
	}

	draw();
}
Beispiel #4
0
void MutableMatrix::text_out(buffer &o) const
{
  const Ring *R = get_ring();
  size_t nrows = n_rows();
  size_t ncols = n_cols();
  buffer *p = new buffer[nrows];
  size_t r;
  for (size_t c=0; c<ncols; c++)
    {
      size_t maxcount = 0;
      for (r=0; r<nrows; r++)
        {
          ring_elem f;
          get_entry(r,c,f);
          if (!R->is_zero(f))
            R->elem_text_out(p[r], f);
          else
            p[r] << ".";
          if (p[r].size() > maxcount)
            maxcount = p[r].size();
        }
      for (r=0; r<nrows; r++)
        for (size_t k=maxcount+1-p[r].size(); k > 0; k--)
          p[r] << ' ';
    }
  for (r=0; r<nrows; r++)
    {
      p[r] << '\0';
      char *s = p[r].str();
      o << s << newline;
    }
  delete[] p;
}
Beispiel #5
0
Matrix /* or null */ *Matrix::minors(int p,
                       int strategy,
                       int n_to_compute, // -1 means all
                       M2_arrayintOrNull first_row, // possibly NULL
                       M2_arrayintOrNull first_col // possibly NULL
                       ) const
{
  if (strategy == DET_BAREISS && get_ring()->get_precision() > 0)
    {
      ERROR("determinant computations over RR or CC requires Strategy=>Cofactor");
      return 0;
    }
  if (first_row != 0 || first_col != 0)
    {
      // Make sure these are the correct size, and both are given
      if (first_row == 0 || first_row->len != p)
        {
          ERROR("row index set inappropriate");
          return 0;
        }
      if (first_col == 0 || first_col->len != p)
        {
          ERROR("column index set inappropriate");
          return 0;
        }
    }
  DetComputation *d = new DetComputation(this,p,0,strategy);
  if (first_row != 0 && first_col != 0)
    d->set_next_minor(first_row->array, first_col->array);
  d->calc(n_to_compute);
  Matrix *result = d->determinants();
  deleteitem(d);
  return result;
}
Beispiel #6
0
void
do_buf()
{
	struct netmap_ring *ring;
	long int buf_idx, len;
	char *buf, *arg;

	/* defaults */
	buf_idx = 2;
	len = 64;

	arg = nextarg();
	if (!arg)
		goto doit;
	buf_idx = strtoll(arg, NULL, 0);
	
	arg = nextarg();
	if (!arg)
		goto doit;
	len = strtoll(arg, NULL, 0);
doit:
	ring = get_ring();
	buf = NETMAP_BUF(ring, buf_idx);
	dump_payload(buf, len);
}
Beispiel #7
0
Matrix *Matrix::pfaffians(int p) const
{
  if (get_ring()->get_precision() > 0)
    {
      ERROR("pfaffian computations over RR or CC not yet implemented");
      return 0;
    }
  PfaffianComputation d = PfaffianComputation(this,p);
  d.calc();
  return d.pfaffians();
}
Beispiel #8
0
Matrix /* or null */ *Matrix::minors(int p,int strategy) const
{
  if (strategy == DET_BAREISS && get_ring()->get_precision() > 0)
    {
      ERROR("determinant computations over RR or CC requires Strategy=>Cofactor");
      return 0;
    }
  DetComputation *d = new DetComputation(this,p,0,strategy);
  d->calc(-1);
  Matrix *result = d->determinants();
  deleteitem(d);
  return result;
}
Beispiel #9
0
  virtual MutableMat * mult(const RingElement *f) const
  // return f*this.  return NULL of sizes or types do not match.
  {
    if (f->get_ring() != get_ring())
      {
        ERROR("expected same ring");
        return 0;
      }
    elem a;
    mat.ring().from_ring_elem(a, f->get_value());

    MutableMat *result = clone();
    result->mat.scalarMultInPlace(a);

    return result;
  }
Beispiel #10
0
void
do_slot()
{
	struct netmap_ring *ring;
	struct netmap_slot *slot;
	long int index;
	char *arg;

	/* defaults */
	index = 0;

	arg = nextarg();
	if (!arg)
		goto doit;
	index = strtoll(arg, NULL, 0);
doit:
	ring = get_ring();
	slot = ring->slot + index;
	printf("buf_idx       %u\n", slot->buf_idx);
	printf("len           %u\n", slot->len);
	printf("flags         %x", slot->flags);
	if (slot->flags) {
		printf(" [");
		if (slot->flags & NS_BUF_CHANGED) {
			printf(" BUF_CHANGED");
		}
		if (slot->flags & NS_REPORT) {
			printf(" REPORT");
		}     
		if (slot->flags & NS_FORWARD) {
			printf(" FORWARD");
		}    
		if (slot->flags & NS_NO_LEARN) {
			printf(" NO_LEARN");
		}   
		if (slot->flags & NS_INDIRECT) {
			printf(" INDIRECT");
		}   
		if (slot->flags & NS_MOREFRAG) {
			printf(" MOREFRAG");
		}   
		printf(" ]");
	}
	printf("\n");
	printf("ptr           %lx\n", (long)slot->ptr);
}
Beispiel #11
0
void
do_ring()
{
	struct netmap_ring *ring;

	ring = get_ring();

	printf("buf_ofs     %"PRId64"\n", ring->buf_ofs);
	printf("num_slots   %u\n", ring->num_slots);
	printf("nr_buf_size %u\n", ring->nr_buf_size);
	printf("ringid      %d\n", ring->ringid);
	printf("dir         %d [", ring->dir);
	switch (ring->dir) {
	case 1:
		printf("rx");
		break;
	case 0:
		printf("tx");
		break;
	default:
		printf("??");
		break;
	}
	printf("]\n");
	printf("head        %u\n", ring->head);
	printf("cur         %u\n", ring->head);
	printf("tail        %u\n", ring->head);
	printf("flags       %x", ring->flags);
	if (ring->flags) {
		printf(" [");
		if (ring->flags & NR_TIMESTAMP) {
			printf(" TIMESTAMP");
		}
		if (ring->flags & NR_FORWARD) {
			printf(" FORWARD");
		}
		printf(" ]");
	}
	printf("\n");
	printf("ts          %ld:%ld\n",
			(long int)ring->ts.tv_sec, (long int)ring->ts.tv_usec);
}
Beispiel #12
0
FreeModule *FreeModule::direct_sum(const FreeModule *G) const
// direct sum
{
    int i;
    if (get_ring() != G->get_ring())
    {
        ERROR("expected free modules over the same ring");
        return 0;
    }
    FreeModule *result = new_free();
    for (i=0; i<rank(); i++)
        result->append(degree(i));
    for (i=0; i<G->rank(); i++)
        result->append(G->degree(i));

    //  if (schreyer != NULL && G->schreyer != NULL)
    //    result->schreyer = schreyer->direct_sum(G->schreyer);

    return result;
}
Beispiel #13
0
FreeModule *FreeModule::tensor(const FreeModule *G) const
// tensor product
{
    if (get_ring() != G->get_ring())
    {
        ERROR("expected free modules over the same ring");
        return 0;
    }
    FreeModule *result = new_free();
    int *deg = degree_monoid()->make_one();

    for (int i=0; i<rank(); i++)
        for (int j=0; j<G->rank(); j++)
        {
            degree_monoid()->mult(degree(i), G->degree(j), deg);
            result->append(deg);
        }

    degree_monoid()->remove(deg);
    if (schreyer != NULL && G->schreyer != NULL)
        result->schreyer = schreyer->tensor(G->schreyer);
    return result;
}
Beispiel #14
0
FreeModule *FreeModule::exterior(int p) const
     // p th exterior power
{
  FreeModule *result;

  int rk = rank();

  if (p == 0)
    return get_ring()->make_FreeModule(1);
  else
    result = new_free();
  if (p > rk || p < 0) return result;

  int *a = newarray_atomic(int,p);
  for (int i=0; i<p; i++)
    a[i] = i;

  int *deg = degree_monoid()->make_one();
  do
    {
      degree_monoid()->one(deg);

      for (int r=0; r<p; r++)
        degree_monoid()->mult(deg, degree(a[r]), deg);

      result->append(deg);
    }
  while (comb::increment(p, rk, a));

  degree_monoid()->remove(deg);
  deletearray(a);

  if (schreyer != NULL)
    result->schreyer = schreyer->exterior(p);
  return result;
}
Beispiel #15
0
  virtual MutableMat * add(const MutableMatrix *B) const
  // return this + B.  return NULL if sizes or types do not match.
  {
    const Mat *B1 = B->coerce<Mat>();
    if (B1 == NULL) 
      {
        ERROR("expected matrices with the same ring and sparsity");
        return NULL;
      }
    if (B->get_ring() != get_ring())
      {
        ERROR("expected matrices with the same ring");
        return NULL;
      }
    if (B1->n_rows() != n_rows() || B1->n_cols() != n_cols())
      {
        ERROR("expected matrices of the same shape");
        return NULL;
      }

    MutableMat* result = clone();
    result->getMat().addInPlace(*B1);
    return result;
  }
Beispiel #16
0
int FreeModule::primary_degree(int i) const
{
    int result = degree_monoid()->degree_weights(degree(i),get_ring()->get_heft_vector());
    return result;
}