Пример #1
0
M2_arrayint stdvector_to_M2_arrayint(std::vector<size_t> &v)
{
  M2_arrayint result = M2_makearrayint(static_cast<int>(v.size()));
  for (size_t i = 0; i < v.size(); i++)
    result->array[i] = static_cast<int>(v[i]);
  return result;
}
Пример #2
0
M2_arrayint varpower::to_arrayint(const int *vp)
{
  int len = *vp;
  M2_arrayint result = M2_makearrayint(len);
  for (int i = 0; i < len; i++) result->array[i] = *vp++;
  return result;
}
Пример #3
0
M2_arrayint ARingGF::representationToM2Array(UTT representation,  long coeffNum, UTT charac ) 
{
    std::cerr << "representationToM2Array:\n";
    M2_arrayint     polynomialCoeffs = M2_makearrayint(coeffNum);
    std::cerr << "coeffNum" << coeffNum << std::endl;
    std::cerr << "charac" << charac << std::endl;
    std::cerr << "representation" << representation << std::endl;
    long exp = 0;
    assert( representation !=0 );
    

    while ( representation !=0 )
    {
        assert(exp < coeffNum);
        UTT  remainder = representation%charac;
        representation = representation/charac;
        polynomialCoeffs->array[ exp ]= remainder;
        
        //debug:
        if (exp >0 )
             std::cerr << " + ";
         std::cerr << remainder <<"*" << "X^" << exp;
        // end debug
        exp++;
    }
    assert( representation ==0 );
    for ( ;exp < coeffNum ;exp ++)
    {
         assert(exp < coeffNum);
         polynomialCoeffs->array[ exp ] = 0;
    }
    std::cerr << "\n";
    return polynomialCoeffs;
}
Пример #4
0
M2_arrayintOrNull rankProfile(const DMatZZpFFPACK& mat, bool row_profile)

{
  DMatZZpFFPACK N(mat);

  size_t* prof;  // this is where the result will be placed
  size_t rk;
  if (row_profile)
    rk = FFPACK::RowRankProfile(mat.ring().field(),
                                mat.numRows(),
                                mat.numColumns(),
                                N.array(),
                                mat.numColumns(),
                                prof);
  else
    rk = FFPACK::ColumnRankProfile(mat.ring().field(),
                                   mat.numRows(),
                                   mat.numColumns(),
                                   N.array(),
                                   mat.numColumns(),
                                   prof);

  M2_arrayint profile = M2_makearrayint(static_cast<int>(rk));
  for (size_t i = 0; i < rk; i++) profile->array[i] = static_cast<int>(prof[i]);

  delete[] prof;
  return profile;
}
Пример #5
0
void Monoid::set_degrees()
{
  if (degree_monoid_ == NULL)
    {
      degree_of_var_.append(static_cast<const_monomial>(NULL));
      return;
    }

  // Set 'degree_of_var
  int degvars = degree_monoid_->n_vars();
  int *t = degvals_->array;

  heft_degree_of_var_ = M2_makearrayint(nvars_);
  if (heftvals_->len != degvars)
    {
      ERROR("internal error: heftvals_->len == %d != degvars == %d",
            heftvals_->len,
            degvars);
      return;
    }
  if (degvars > 0)
    for (int i = 0; i < nvars_; i++)
      {
        monomial m = degree_monoid_->make_one();
        degree_monoid_->from_expvector(t, m);
        degree_of_var_.append(m);
        heft_degree_of_var_->array[i] = ntuple::weight(degvars, t, heftvals_);
        t += degvars;
      }
  else
    {
      for (int i = 0; i < nvars_; i++) heft_degree_of_var_->array[i] = 1;
    }
  degree_of_var_.append(degree_monoid_->make_one());
}
Пример #6
0
GBComputation * GBWalker::make_gb(const Matrix *M) const
  // return the GB of g, keep = 0 or 1.
{
  M2_arrayint weights = M2_makearrayint(R->n_vars());
  for (int i=0; i<R->n_vars(); i++) weights->array[i] = 1;

  GBComputation *G0 = GBComputation::choose_gb(M,
                                              false, // collect syz
                                              -1,
                                              weights,
                                              false,
                                              -1,
                                              0,
                                              0
                                              /* , max_reduction_count */
                                              );
  G0->set_stop_conditions(false,
                         NULL,
                         -1,
                         -1, // syzygy limit
                         -1,
                         -1,
                         -1,
                         false,
                         NULL);
  return G0;
}
Пример #7
0
/// returns mod polynomial coefficients as array of integers.
/// @todo problems, if characteristic does not fit in a int.
M2_arrayint ARingGF::getModPolynomialCoeffs() const
{
    std::cerr << "getModPolynomialCoeffs\n";
    long coeffNum=this->mDimension + 1;
    M2_arrayint     modPolynomialCoeffs = M2_makearrayint(coeffNum);
    UTT             modPolynomialRepresentation = this->givaroField.irreducible();
    return modPolynomialRepresentationToM2Array( modPolynomialRepresentation );

} 
Пример #8
0
M2_arrayint FractionField::support(const ring_elem a) const
{
  const frac_elem *f = FRAC_VAL(a);
  M2_arrayint result1 = R_->support(f->numer);
  M2_arrayint result2 = R_->support(f->denom);
  M2_arrayint result = M2_makearrayint(result1->len + result2->len);
  for (int i=0; i<result1->len; i++)
    result->array[i] = result1->array[i];
  for (int i=0; i<result2->len; i++)
    result->array[result1->len+i] = result2->array[i];

  return result;
}
Пример #9
0
M2_arrayint ResolutionComputation::betti_make(int lo,
                                              int hi,
                                              int len,
                                              int *bettis)
{
  int d, lev;
  int hi1 = hi + 1;
  int len1 = len + 1;

  // Reset 'hi1' to reflect the top degree that occurs
  for (d = hi; d >= lo; d--)
    {
      for (lev = 0; lev <= len; lev++)
        if (bettis[lev + (len + 1) * (d - lo)] > 0)
          {
            hi1 = d;
            break;
          }
      if (hi1 <= hi) break;
    }
  if (hi1 > hi) hi1 = hi;

  // Reset 'len1' to reflect the top level that occurs
  for (lev = len; lev >= 0; lev--)
    {
      for (d = lo; d <= hi1; d++)
        if (bettis[lev + (len + 1) * (d - lo)] > 0)
          {
            len1 = lev;
            break;
          }
      if (len1 <= len) break;
    }
  if (len1 > len) len1 = len;

  int totallen = (hi1 - lo + 1) * (len1 + 1);
  M2_arrayint result = M2_makearrayint(3 + totallen);

  result->array[0] = lo;
  result->array[1] = hi1;
  result->array[2] = len1;

  int next = 3;
  for (d = lo; d <= hi1; d++)
    for (lev = 0; lev <= len1; lev++)
      result->array[next++] = bettis[lev + (len + 1) * (d - lo)];

  return result;
}
Пример #10
0
M2_arrayint ARingGF::getGeneratorCoeffs() const
{
    std::cerr << "getGeneratorCoeffs\n";
    long coeffNum = this->mDimension + 1;
    M2_arrayint     generatorPolynomialCoeffs = M2_makearrayint(coeffNum);
    ElementType genRep,packedGenPolynomial; ///todo: typ (gen) eigentlich UTT?
    givaroField.generator(genRep);
    packedGenPolynomial = givaroField.generator();

    std::cerr << "packedGenPolynomial " << packedGenPolynomial << std::endl;
    std::cerr << "genRep " << genRep << std::endl;
    //assert(gen==genRep);
    //UTT  generatorRepresentation;
    //generatorRepresentation = this->givaroField.convert(generatorRepresentation,gen);
    //return elementRepresentationToM2Array( generatorRepresentation ) ;
    return elementRepresentationToM2Array( packedGenPolynomial ) ;    
}
Пример #11
0
M2_arrayint rawMonomialOrderingToMatrix(const struct MonomialOrdering* mo)
{
  bool base;
  std::vector<int> mat;
  M2_arrayint result = 0;
  int component_is_before_row = 0;
  int component_direction = 0;
  if (monomialOrderingToMatrix(
          *mo, mat, base, component_direction, component_is_before_row))
    {
      int top = static_cast<int>(mat.size());
      result = M2_makearrayint(top + 3);
      for (int i = 0; i < top; i++) result->array[i] = mat[i];
      result->array[top] = (base ? 1 : 0);
      result->array[top + 1] = component_direction;
      result->array[top + 2] = component_is_before_row;
    }
  return result;
}