コード例 #1
0
ファイル: mat.cpp プロジェクト: JosephineYu/M2
MutableMatrix *MutableMatrix::identity(const Ring *R, size_t nrows, bool dense)
{
  MutableMatrix *result = MutableMatrix::zero_matrix(R,nrows,nrows,dense);
  for (size_t i=0; i<nrows; i++)
    result->set_entry(i,i,R->from_long(1));
  return result;
}
コード例 #2
0
ファイル: res-f4-m2-interface.cpp プロジェクト: pzinn/M2
MutableMatrix* ResF4toM2Interface::to_M2_MutableMatrix(
                                                       const Ring* K,
                                                       SchreyerFrame& C,
                                                       int lev,
                                                       int degree)
{
  // Now we loop through the elements of degree 'degree' at level 'lev'
  auto& thislevel = C.level(lev);
  int n = 0;
  for (auto p=thislevel.begin(); p != thislevel.end(); ++p)
    {
      if (p->mDegree == degree) n++;
    }

  auto& prevlevel = C.level(lev-1);
  int* newcomps = new int[prevlevel.size()];
  int nextcomp = 0;
  for (int i=0; i<prevlevel.size(); i++)
    if (prevlevel[i].mDegree == degree)
      newcomps[i] = nextcomp++;
    else
      newcomps[i] = -1;

  // create the mutable matrix
  MutableMatrix* result = MutableMatrix::zero_matrix(K,
                                                     nextcomp,
                                                     n,
                                                     true);
  // Now loop through the elements at thislevel,
  // and for each, loop through the terms of mSyzygy.
  // if the component x satisfies newcomps[x] >= 0, then place
  // this coeff into the mutable matrix.
  int col = 0;
  
  for (auto p=thislevel.begin(); p != thislevel.end(); ++p)
    {
      if (p->mDegree != degree) continue;
      auto& f = p->mSyzygy;
      auto end = poly_iter(C.ring(), f, 1);
      auto i = poly_iter(C.ring(), f);
      for ( ; i != end; ++i)
        {
          long comp = C.monoid().get_component(i.monomial());
          if (newcomps[comp] >= 0)
            {
              ring_elem a;
              a = K->from_long(C.ring().resGausser().coeff_to_int(i.coefficient()));
              result->set_entry(newcomps[comp], col, a);
            }
        }
      ++col;
    }

  delete [] newcomps;
  return result;
}
コード例 #3
0
ファイル: mat.cpp プロジェクト: JosephineYu/M2
MutableMatrix *MutableMatrix::from_matrix(const Matrix *m, bool prefer_dense)
{
  MutableMatrix *result = zero_matrix(m->get_ring(),
                                         m->n_rows(),
                                         m->n_cols(),
                                         prefer_dense);
  Matrix::iterator i(m);
  for (unsigned int c=0; c<m->n_cols(); c++)
    {
      for (i.set(c); i.valid(); i.next())
        result->set_entry(i.row(), c, i.entry());
    }
  return result;
}
コード例 #4
0
ファイル: f4.cpp プロジェクト: pzinn/M2
void F4GB::show_new_rows_matrix()
{
  int ncols = INTSIZE(mat->columns);
  int nrows = 0;
  for (int nr=0; nr<mat->rows.size(); nr++)
    if (is_new_GB_row(nr)) nrows++;

  MutableMatrix *gbM = IM2_MutableMatrix_make(KK->get_ring(), nrows, ncols, false);

  int r = -1;
  for (int nr=0; nr<mat->rows.size(); nr++)
    if (is_new_GB_row(nr))
      {
        r++;
        row_elem &row = mat->rows[nr];
        ring_elem *rowelems = newarray(ring_elem, row.len);
        if (row.coeffs == 0)
          {
            if (row.monom == 0)
              KK->to_ringelem_array(row.len, gens[row.elem]->f.coeffs, rowelems);
            else
              KK->to_ringelem_array(row.len, gb[row.elem]->f.coeffs, rowelems);
          }
        else
          {
            KK->to_ringelem_array(row.len, row.coeffs, rowelems);
          }
        for (int i=0; i<row.len; i++)
          {
            int c = row.comps[i];
            gbM->set_entry(r,c,rowelems[i]);
          }
        deletearray(rowelems);
      }

  buffer o;
  gbM->text_out(o);
  emit(o.str());
}