Skip to content

Commit

Permalink
switched to range-based loops for Nterms
Browse files Browse the repository at this point in the history
  • Loading branch information
mahrud authored and mikestillman committed Mar 13, 2023
1 parent 4af767c commit 59e56c5
Show file tree
Hide file tree
Showing 19 changed files with 222 additions and 193 deletions.
2 changes: 1 addition & 1 deletion M2/Macaulay2/e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ set(HPPONLYFILES
newdelete.hpp
ExponentVector.hpp
res-a0-pair.hpp
ringelem.hpp
schur-poly-heap.hpp
smat.hpp
util.hpp
Expand Down Expand Up @@ -266,6 +265,7 @@ set(SRCLIST
res-a1
res-a2
ring
ringelem
ringmap
sagbi
schorder
Expand Down
9 changes: 5 additions & 4 deletions M2/Macaulay2/e/GF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,16 @@ bool GF::promote(const Ring *Rf, const ring_elem f, ring_elem &result) const

if (Rf != _originalR) return false;

const Ring *K = _originalR->getCoefficients();

result = from_long(0);
int exp[1];
for (Nterm *t = f; t != NULL; t = t->next)
for (Nterm& t : f)
{
std::pair<bool, long> b =
_originalR->getCoefficients()->coerceToLongInteger(t->coeff);
std::pair<bool, long> b = K->coerceToLongInteger(t.coeff);
assert(b.first);
ring_elem coef = from_long(b.second);
_originalR->getMonoid()->to_expvector(t->monom, exp);
_originalR->getMonoid()->to_expvector(t.monom, exp);
// exp[0] is the variable we want. Notice that since the ring is a
// quotient,
// this degree is < n (where Q_ = P^n).
Expand Down
2 changes: 1 addition & 1 deletion M2/Macaulay2/e/Makefile.files
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ INTERFACE = \
pfaff \
relem \
ring \
ringelem \
ringmap \
schur \
skew \
Expand Down Expand Up @@ -205,7 +206,6 @@ NAMES_H = \
VectorArithmetic \
MemoryBlock \
NCAlgebras/Range \
ringelem \
style \
util \
hash \
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/e/bibasis/involutive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ namespace BIBasis

Polynom<MonomType>* currentPolynom = new Polynom<MonomType>();

for (Nterm* currentTerm = polynomVector->coeff; currentTerm; currentTerm = currentTerm->next)
for (Nterm& currentTerm : polynomVector->coeff)
{
exponents_t monomVector = newarray_atomic(int, independ);
monoid->to_expvector(currentTerm->monom, monomVector);
monoid->to_expvector(currentTerm.monom, monomVector);

//construct Monom for every term
MonomType* currentMonom = new MonomType();
Expand Down
4 changes: 2 additions & 2 deletions M2/Macaulay2/e/franzi-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ IntermediateBasis BRPSfromMatrix(const Matrix *m)
vec v = m->elem(i);
if (v == 0) continue;
BRP temp;
for (Nterm *f = v->coeff; f != 0; f = f->next)
for (Nterm& f : v->coeff)
{
M->to_expvector(f->monom, exp);
M->to_expvector(f.monom, exp);
brMonomial mono = exponentsToLong(n, exp);
temp = temp + BRP(mono);
}
Expand Down
6 changes: 3 additions & 3 deletions M2/Macaulay2/e/hilb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ int hilb_comp::coeff_of(const RingElement *h, int deg)

exponents_t exp = newarray_atomic(int, P->n_vars());
int result = 0;
for (Nterm *f = h->get_value(); f != NULL; f = f->next)
for (Nterm& f : h->get_value())
{
P->getMonoid()->to_expvector(f->monom, exp);
P->getMonoid()->to_expvector(f.monom, exp);
if (exp[0] < deg)
{
ERROR("incorrect Hilbert function given");
Expand All @@ -725,7 +725,7 @@ int hilb_comp::coeff_of(const RingElement *h, int deg)
else if (exp[0] == deg)
{
std::pair<bool, long> res =
P->getCoefficientRing()->coerceToLongInteger(f->coeff);
P->getCoefficientRing()->coerceToLongInteger(f.coeff);
assert(res.first &&
std::abs(res.second) < std::numeric_limits<int>::max());
int n = static_cast<int>(res.second);
Expand Down
8 changes: 4 additions & 4 deletions M2/Macaulay2/e/matrix-stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void matrixToStream(const Matrix* M, T& stream)
for (; i.valid(); i.next())
{
Nterm* t = i.entry();
for (Nterm* s = t; s != 0; s = s->next) nterms++;
for ([[maybe_unused]] Nterm& s : t) nterms++;
}
stream.appendPolynomialBegin(nterms);

Expand All @@ -110,13 +110,13 @@ void matrixToStream(const Matrix* M, T& stream)
for (; i.valid(); i.next())
{
Nterm* t = i.entry();
for (Nterm* s = t; s != 0; s = s->next)
for (Nterm& s : t)
{
P->getMonoid()->to_expvector(s->monom, exp);
P->getMonoid()->to_expvector(s.monom, exp);
stream.appendTermBegin(i.row());
for (size_t j = 0; j < nvars; j++)
if (exp[j] != 0) stream.appendExponent(j, exp[j]);
std::pair<bool, long> b = KK->coerceToLongInteger(s->coeff);
std::pair<bool, long> b = KK->coerceToLongInteger(s.coeff);
assert(b.first);
int a = static_cast<int>(
b.second); // This will fit, as the charac fits into an int
Expand Down
14 changes: 7 additions & 7 deletions M2/Macaulay2/e/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,9 +904,9 @@ M2_arrayintOrNull Matrix::support() const
for (int i = 0; i < R->n_vars(); i++) exp[i] = exp2[i] = 0;
for (int j = 0; j < n_cols(); j++)
for (vec v = elem(j); v != nullptr; v = v->next)
for (const Nterm *f = v->coeff; f != nullptr; f = f->next)
for (Nterm& f : v->coeff)
{
R->getMonoid()->to_expvector(f->monom, exp2);
R->getMonoid()->to_expvector(f.monom, exp2);
for (int k = 0; k < n; k++)
if (exp2[k] != 0 && exp[k] == 0)
{
Expand Down Expand Up @@ -1718,10 +1718,10 @@ Matrix /* or null */ *Matrix::monomials(M2_arrayint vars) const
vec v = elem(c);
for (; v != nullptr; v = v->next)
{
for (Nterm *t = v->coeff; t != nullptr; t = t->next)
for (Nterm& t : v->coeff)
{
exponents_t exp1 = newarray_atomic(int, vars->len + 1);
M->to_expvector(t->monom, exp);
M->to_expvector(t.monom, exp);
for (unsigned int i = 0; i < vars->len; i++)
exp1[i] = exp[vars->array[i]];
exp1[vars->len] = v->comp;
Expand Down Expand Up @@ -1798,15 +1798,15 @@ static vec coeffs_of_vec(exponent_table *E,
vec result = nullptr;
for (vec g = f; g != nullptr; g = g->next)
{
for (Nterm *h = g->coeff; h != nullptr; h = h->next)
for (Nterm& h : g->coeff)
{
M->to_expvector(h->monom, exp);
M->to_expvector(h.monom, exp);
get_part_of_expvector(vars, exp, g->comp, scratch_exp);
int val = static_cast<int>(exponent_table_get(E, scratch_exp));
if (val > 0)
{
M->from_expvector(exp, mon);
ring_elem t = P->make_flat_term(h->coeff, mon);
ring_elem t = P->make_flat_term(h.coeff, mon);
vec v = P->make_vec(val - 1, t);
v->next = result;
result = v;
Expand Down
Loading

0 comments on commit 59e56c5

Please sign in to comment.