diff --git a/libsrc/GetOpt.cc b/libsrc/GetOpt.cc index e13a6c0..2ee1007 100644 --- a/libsrc/GetOpt.cc +++ b/libsrc/GetOpt.cc @@ -19,17 +19,17 @@ Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef __GNUG__ #pragma implementation #endif -/* AIX requires the alloca decl to be the first thing in the file. */ -#ifdef __GNUC__ -#define alloca __builtin_alloca -#elif defined(sparc) -#include -extern "C" void *__builtin_alloca(...); -#elif defined(_AIX) -#pragma alloca -#else -char *alloca (); -#endif +// /* AIX requires the alloca decl to be the first thing in the file. */ +// #ifdef __GNUC__ +// #define alloca __builtin_alloca +// #elif defined(sparc) +// #include +// extern "C" void *__builtin_alloca(...); +// #elif defined(_AIX) +// #pragma alloca +// #else +// char *alloca (); +// #endif #include char* GetOpt::nextchar = 0; @@ -62,7 +62,8 @@ GetOpt::exchange (char **argv) const { int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *); - char **temp = (char **) alloca (nonopts_size); + char **temp = new char*[nonopts_size]; + // char **temp = (char **) alloca (nonopts_size); /* Interchange the two blocks of data in argv. */ @@ -76,6 +77,7 @@ GetOpt::exchange (char **argv) const first_nonopt += (optind - last_nonopt); last_nonopt = optind; + delete[] temp; } /* Scan elements of ARGV (whose length is ARGC) for option characters diff --git a/libsrc/eclib/transform.h b/libsrc/eclib/transform.h index 3df3ef9..c04876a 100644 --- a/libsrc/eclib/transform.h +++ b/libsrc/eclib/transform.h @@ -49,11 +49,11 @@ int check_transform(const bigint& a, const bigint& b, const bigint& c, const bigint& xd, const bigint& xe); void xshift(const bigint& alpha, - bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, + const bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, unimod& m); void zshift(const bigint& gamma, - bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, + bigint& a, bigint& b, bigint& c, bigint& d, const bigint& e, unimod& m); void m_invert(bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, diff --git a/libsrc/eclib/vec.h b/libsrc/eclib/vec.h index 1fe209a..fc0c7c8 100644 --- a/libsrc/eclib/vec.h +++ b/libsrc/eclib/vec.h @@ -106,7 +106,7 @@ void makeprimitive(vec& v); void elim(const vec& a, vec& b, long pos); void elim1(const vec& a, vec& b, long pos); void elim2(const vec& a, vec& b, long pos, scalar lastpivot); -vec reverse(vec& order); +vec reverse(const vec& order); vec express(const vec& v, const vec& v1, const vec& v2); int lift(const vec& v, scalar pr, vec& ans); //lifts a mod-p vector to a rational //and scales to a primitive vec in Z. Returns success flag diff --git a/libsrc/ffmod.cc b/libsrc/ffmod.cc index c273fb0..a2ba6cd 100644 --- a/libsrc/ffmod.cc +++ b/libsrc/ffmod.cc @@ -36,7 +36,6 @@ FqPoly ffmodq::f2; ffmodq::ffmodq(const curvemodq& EE) { E=EE; Fq=get_field(EE); - // cout<<"In ffmodq constructor"<0; j--) + mat basis(m.ncols(),nullity); + for(int j=nullity; j>0; j--) { - jj = npcols[j]; + int jj = npcols[j]; basis(jj,j) = 1; - for(i=rank; i>0; i--) + for(int i=rank; i>0; i--) { scalar temp = -m(i,jj); - for(t=rank; t>i; t--) + for(int t=rank; t>i; t--) { - tt=pcols[t]; + int tt=pcols[t]; temp -= xmodmul(m(i,tt),basis(tt,j),pr); temp = xmod(temp,pr); } @@ -249,7 +258,7 @@ subspace pkernel(const mat& m1, scalar pr) subspace ans(basis, npcols, 1); return ans; } - + subspace pimage(const mat& m, scalar pr) { vec p,np; @@ -258,7 +267,7 @@ subspace pimage(const mat& m, scalar pr) subspace ans(b,p,1); return ans; } - + subspace peigenspace(const mat& m1, scalar lambda, scalar pr) { const mat& m = addscalar(m1,-lambda); diff --git a/libsrc/svec.cc b/libsrc/svec.cc index e68c3c1..7b45c1b 100644 --- a/libsrc/svec.cc +++ b/libsrc/svec.cc @@ -26,20 +26,23 @@ // Definitions of member operators and functions: svec::svec(const vec& v) + :d(dim(v)) { - d = dim(v); scalar vi; for(int i = 1; i <= d; i++ ) - if((vi=v[i])) // assignment not equality! - entries[i]=vi; + { + scalar vi = v[i]; + if(vi) // assignment not equality! + entries[i]=vi; + } } svec::svec (int dim, scalar* a) // conversion constructor :d(dim) { - int i=0; scalar* ai=a; - for( ; isecond,p); + scalar a = mod(vi->second,p); if(a) { (vi->second)=a; @@ -480,11 +482,13 @@ svec& svec::operator/=(scalar scal) int eqmodp(const svec& v1, const svec& v2, const scalar& p) { if(v1.d!=v2.d) return 0; - for( const auto& vi : v1.entries) - if(xmod((vi.second)-(v2.elem(vi.first)),p)!=0) return 0; - for( const auto& vi : v2.entries) - if(xmod((vi.second)-(v1.elem(vi.first)),p)!=0) return 0; - return true; + if (std::any_of(v1.entries.begin(), v1.entries.end(), + [v2,p] (const pair& vi) {return xmod((vi.second)-(v2.elem(vi.first)),p)!=0;})) + return 0; + if (std::any_of(v2.entries.begin(), v2.entries.end(), + [v1,p] (const pair& vi) {return xmod((vi.second)-(v1.elem(vi.first)),p)!=0;})) + return 0; + return 1; } int operator==(const svec& v1, const vec& v2) diff --git a/libsrc/timer.cc b/libsrc/timer.cc index 68ef5b0..d649211 100644 --- a/libsrc/timer.cc +++ b/libsrc/timer.cc @@ -276,10 +276,11 @@ int timer::count( string name ) { * Return total time of a given timer. */ double timer::total( string name ) { - double total = 0; - for ( const auto& t : times_[name]) - total += t; - return total; + return std::accumulate(times_[name].begin(), times_[name].end(), 0); + // double total = 0; + // for ( const auto& t : times_[name]) + // total += t; + // return total; } /** diff --git a/libsrc/transform.cc b/libsrc/transform.cc index 2071293..af91c4b 100644 --- a/libsrc/transform.cc +++ b/libsrc/transform.cc @@ -90,26 +90,24 @@ void apply_transform(bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, } void xshift(const bigint& alpha, - bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, + const bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, unimod& m) { - e = e+alpha*(d+alpha*( c+alpha*( b+ alpha*a))); - d = d+alpha*(2*c+alpha*(3*b+4*alpha*a)); - c = c+alpha*(3*b+6*alpha*a); - b = b+4*alpha*a; -//a = a; + e += alpha*(d+alpha*( c+alpha*( b+ alpha*a))); + d += alpha*(2*c+alpha*(3*b+4*alpha*a)); + c += alpha*(3*b+6*alpha*a); + b += 4*alpha*a; m.x_shift(alpha); } void zshift(const bigint& gamma, - bigint& a, bigint& b, bigint& c, bigint& d, bigint& e, + bigint& a, bigint& b, bigint& c, bigint& d, const bigint& e, unimod& m) { - a = a+gamma*(b+gamma*( c+gamma*( d+ gamma*e))); - b = b+gamma*(2*c+gamma*(3*d+4*gamma*e)); - c = c+gamma*(3*d+6*gamma*e); - d = d+4*gamma*e; -//e = e; + a += gamma*(b+gamma*( c+gamma*( d+ gamma*e))); + b += gamma*(2*c+gamma*(3*d+4*gamma*e)); + c += gamma*(3*d+6*gamma*e); + d += 4*gamma*e; m.y_shift(gamma); } diff --git a/libsrc/vec.cc b/libsrc/vec.cc index e034469..6195c79 100644 --- a/libsrc/vec.cc +++ b/libsrc/vec.cc @@ -194,10 +194,11 @@ void vec::add_modp(long i, scalar x, scalar p) scalar operator*(const vec& v, const vec& w) { - long dim=v.d; scalar dot=0; + scalar dot=0; scalar* vi=v.entries, *wi=w.entries; - if (dim==w.d) - while (dim--) dot+= (*vi++)*(*wi++); + long d = v.d; + if (d==w.d) + while (d--) dot+= (*vi++)*(*wi++); else { cerr << "Unequal dimensions in dot product"<