Skip to content

Commit

Permalink
cppcheck on libsrc *.cc: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCremona committed Apr 19, 2024
1 parent 7b0b857 commit 3970c75
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 63 deletions.
2 changes: 1 addition & 1 deletion libsrc/eclib/smat.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ friend class smat_elim;

friend inline vector<int> dim(const smat& A)
{vector<int>d; d.push_back(A.nro);d.push_back(A.nco);return d;}
friend vec operator* (smat& m, const vec& v);
friend vec operator* (const smat& m, const vec& v);
friend svec operator* ( const smat& A, const svec& v );
friend svec operator* ( const svec& v, const smat& A );
friend svec mult_mod_p( const smat& A, const svec& v, const scalar& p );
Expand Down
8 changes: 4 additions & 4 deletions libsrc/eclib/smat_elim.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class smat_elim : public smat{
}
list_array[ num++ ] = X;
}
int find( type& X, int ub, int lb = 0 );
int find( const type& X, int ub, int lb = 0 );
void grow ();
type next() {
if( index < num ) return( list_array[index++] ); else return(-1);
Expand Down Expand Up @@ -79,8 +79,8 @@ class smat_elim : public smat{
void clear_col(int,int,list&, int fr = 0, int fc = 0,int M = 0,int *li =0);
void check_col( int col, list& L );
void check_row (int d2, int row2, list& L );
int get_weight( int, int* );
int has_weight_one( int, int* );
int get_weight( int, const int* );
int has_weight_one( int, const int* );
int n_active_cols(); // number of active columns
int n_active_rows(); // number of active rows
long n_active_entries(); // number of active entries
Expand All @@ -102,7 +102,7 @@ class smat_elim : public smat{
smat new_kernel( vec&, vec& );
smat kernel( vec&, vec& );
void normalize( int, int );
void eliminate( int&, int& );
void eliminate( const int&, const int& );
void step5dense();
void free_space( int col );
void elim( int row1, int row2, scalar v2 );
Expand Down
2 changes: 1 addition & 1 deletion libsrc/eclib/symb.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ class symbdata :public moddata {
long tof(long i) const {symb s=symbol(i); long c=s.cee(), d=s.dee(); return index2(c-d, c);}
};

modsym jumpsymb(symb s1, symb s2);
modsym jumpsymb(const symb& s1, const symb& s2);

#endif
19 changes: 8 additions & 11 deletions libsrc/smat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void smat::set_row( int i, int d, int* pos, scalar* values) // i counts from 0
void smat::setrow ( int i, const vec& v) // i counts from 1
{
int j, m, n;
scalar *vi, *vali, e;
scalar *vi, *vali;
int *coli;

// count nonzero entries of v:
Expand All @@ -168,7 +168,7 @@ void smat::setrow ( int i, const vec& v) // i counts from 1
vi = v.entries;
for(m=1; m<=v.d; m++)
{
e = *vi++;
scalar e = *vi++;
if (e)
{
*coli++ = m;
Expand Down Expand Up @@ -429,15 +429,14 @@ smat& smat::operator+= (const scalar& scal) // adds scalar*identity
scalar *V = new scalar [ d + 1 ]; // new value vector
int* Pi=P+1;
scalar* Vi=V;
scalar newval;
int k = 0; // k will be # of non-zero entries of new row
while((d)&&(*pos1<(i+1))) // just copy entries
{
*Pi++ = *pos1++; *Vi++ = *val1++; k++; d--;
}
if(d&&(*pos1==(i+1))) // add the scalar, see if it's zero
{
newval = (*val1)+scal;
scalar newval = (*val1)+scal;
if( newval!=0) { *Vi++ = newval; *Pi++=*pos1; k++; }
pos1++; val1++; d--;
}
Expand Down Expand Up @@ -547,24 +546,22 @@ svec operator* ( const smat& A, const svec& v )
cerr << "Dimensions "<<dim(A)<<" and "<<dim(v)<<endl;
return svec();
}
int n = A.nro, j; scalar s;
int n = A.nro;
svec prod(n);
for(j = 1; j<=n; j++)
for(int j = 1; j<=n; j++)
{
s = (A.row(j))*v;
scalar s = (A.row(j))*v;
if(s) prod.entries[j]=s;
}
return prod;
}

vec operator* (smat& m, const vec& v)
vec operator* (const smat& m, const vec& v)
{
int r = m.nrows(), c=m.ncols();
vec w(r);
if(c!=dim(v))
{
cerr<<"Error in smat*vec: wrong dimensions ("<<r<<"x"<<c<<")*"<<dim(v)<<endl;
}
cerr<<"Error in smat*vec: wrong dimensions ("<<r<<"x"<<c<<")*"<<dim(v)<<endl;
else
for(int i=1; i<=r; i++) w.set(i,m.row(i)*v);
return w;
Expand Down
62 changes: 31 additions & 31 deletions libsrc/smat_elim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ smat_elim::list::grow()
}

int
smat_elim::list::find( type& X, int ub, int lb )
smat_elim::list::find( const type& X, int ub, int lb )
{
// returns highest number i, lb <= i <= ub, such that list_array[i] <= X
// or returns ub+1 if list_array[ub]<X
Expand Down Expand Up @@ -515,7 +515,7 @@ smat smat_elim::new_kernel( vec& pc, vec& npc)
*/

smat basis( nco, nullity );
smat bas( nco, nullity );

/* First set the identity block */

Expand All @@ -525,9 +525,9 @@ smat smat_elim::new_kernel( vec& pc, vec& npc)
for(j=1; j<=nullity; j++)
{
jj = npc[j]-1; // NB constructor gives this much
basis.col[jj][0] = 1; // 1 entry in this row
basis.col[jj][1] = j; // in column 1
basis.val[jj][0] = 1; // with value 1
bas.col[jj][0] = 1; // 1 entry in this row
bas.col[jj][1] = j; // in column 1
bas.val[jj][0] = 1; // with value 1
}

/* set the other entries in order */
Expand Down Expand Up @@ -594,15 +594,15 @@ smat smat_elim::new_kernel( vec& pc, vec& npc)
cout<<" setting row "<< position[ir]-1 <<" (from 0) of basis: "<< nv <<" non-zero entries out of "<<nullity<<endl;
#endif
ir = position[ir]-1;
co = basis.col[ir];
va = basis.val[ir];
co = bas.col[ir];
va = bas.val[ir];
if (nv > co[0]) // there are more entries in this row than the
// constructor gave us
{
delete [] co;
delete [] va;
co = basis.col[ir] = new int[nv+1];
va = basis.val[ir] = new scalar[nv];
co = bas.col[ir] = new int[nv+1];
va = bas.val[ir] = new scalar[nv];
}
*co++ = nv;
size_t nbytes = nv*sizeof(int);
Expand Down Expand Up @@ -634,10 +634,10 @@ smat smat_elim::new_kernel( vec& pc, vec& npc)
cout<<endl;

cout<<"Finished constructing basis for kernel"<<endl;
cout<<" basis = "<<basis.as_mat()<<endl;
cout<<" basis = "<<bas.as_mat()<<endl;
#endif

return basis;
return bas;
}

// old version of kernel which uses back_sub()
Expand Down Expand Up @@ -666,7 +666,7 @@ smat smat_elim::old_kernel( vec& pc, vec& npc)
#endif

}
smat basis( nco, nullity );
smat bas( nco, nullity );
pc.init( rank );
npc.init( nullity );

Expand Down Expand Up @@ -695,17 +695,17 @@ smat smat_elim::old_kernel( vec& pc, vec& npc)
#endif
for( n = 1; n <= nullity; n++ )
{
int i = npc[n]-1;
basis.col[i][0] = 1; //this much storage was granted in the
basis.col[i][1] = n; // in the constructor.
basis.val[i][0] = 1;
i = npc[n]-1;
bas.col[i][0] = 1; //this much storage was granted in the
bas.col[i][1] = n; // in the constructor.
bas.val[i][0] = 1;
}

scalar *aux_val = new scalar [nco];
int *aux_col = new int [nco];
for ( r=1; r<=rank; r++)
{
int i = pc[r]-1;
i = pc[r]-1;
int count = 0;
int *axp = aux_col; scalar *axv = aux_val;
int *posB = col[new_row[r-1]];
Expand All @@ -715,12 +715,12 @@ smat smat_elim::old_kernel( vec& pc, vec& npc)
while( *posB < npc[j] && h < d ) { posB++; h++; }
if( *posB == npc[j] ) { *axp++ = j; *axv++ = -valB[h]; count++; }
}
delete [] basis.col[i];
delete [] basis.val[i];
basis.col[i] = new int [count + 1];
basis.val[i] = new scalar [count];
int *pos = basis.col[i];
scalar *val = basis.val[i];
delete [] bas.col[i];
delete [] bas.val[i];
bas.col[i] = new int [count + 1];
bas.val[i] = new scalar [count];
int *pos = bas.col[i];
scalar *val = bas.val[i];
axp = aux_col;
axv = aux_val;
*pos++ = count;
Expand All @@ -736,9 +736,9 @@ smat smat_elim::old_kernel( vec& pc, vec& npc)
delete[]aux_col;
#if TRACE_ELIM
cout<<"Finished constructing basis for kernel"<<endl;
cout<<"Basis = "<<basis.as_mat()<<endl;
cout<<"Basis = "<<bas.as_mat()<<endl;
#endif
return basis;
return bas;
}

void smat_elim::step0()
Expand Down Expand Up @@ -1005,7 +1005,7 @@ void smat_elim::normalize( int row, int col0)
}
}

void smat_elim::eliminate( int& row, int& col0 ) //1<=col0<=nco;
void smat_elim::eliminate( const int& row, const int& col0 ) //1<=col0<=nco;
{
//cout<<"Eliminating (r,c)=("<<row<<","<<col0-1<<")"<<endl;
elim_col[ col0 - 1 ] = row;
Expand Down Expand Up @@ -1127,11 +1127,11 @@ void smat_elim::check_row (int d, int row2, list& L )
}
void smat_elim::check_col( int c, list& L )
{
int c1, val = (column+c)->num;
if( val == 2 || val == 1 ) {c1=c+1; L.put(c1);}
int val = (column+c)->num;
if( val == 2 || val == 1 ) {L.put(c+1);}
}

int smat_elim::get_weight( int row, int* lightness )
int smat_elim::get_weight( int row, const int* lightness )
{
int wt = 0;
int *pos = col[row];
Expand All @@ -1140,7 +1140,7 @@ int smat_elim::get_weight( int row, int* lightness )
return wt;
}

int smat_elim::has_weight_one( int row, int* lightness )
int smat_elim::has_weight_one( int row, const int* lightness )
{
int wt = 0;
int *pos = col[row];
Expand Down Expand Up @@ -1311,7 +1311,7 @@ void smat_elim::step5dense()
for(i=1; i<=nrd; i++)
{
rowi.clear();
for(int j=1; j<=nrc; j++)
for(j=1; j<=nrc; j++)
rowi.set(remaining_cols[j-1],dmat(i,j));
setrow(remaining_rows[i-1],rowi);
}
Expand Down
3 changes: 1 addition & 2 deletions libsrc/sqfdiv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
//#define DEBUG

sqfdiv::sqfdiv(const bigint& dd, int posd, vector<bigint>* plist)
:primebase(plist), np(0), positive(posd), factor(0)
:primebase(plist), d(1), np(0), positive(posd), factor(0)
{
d=1;
bigint p;
for(unsigned long i=0; i<plist->size(); i++)
if(p=(*primebase)[i],div(p,dd)) {d*=p; np++;}
Expand Down
29 changes: 16 additions & 13 deletions libsrc/symb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ symbdata::symbdata(long n) :moddata(n),specials(nsymb2)
// cout << "In constructor symbdata::symbdata.\n";
// cout << "nsymb2 = " << nsymb2 << "\n";
if (nsymb2>0)
{ long ic,id,c,d,start; symb s;
{ long ic,id,d; symb s;
//N.B. dlist include d=1 at 0 and d=mod at end, which we don't want here
for (ic=1; (ic<ndivs-1)&&(specials.count()<nsymb2); ic++)
{ c=dlist[ic];
dstarts[ic]=start=specials.count();
{ long c=dlist[ic];
long start=specials.count();
dstarts[ic]=start;
for (id=1; (id<modulus-phi)&&(specials.count()<nsymb2); id++)
{ d = noninvlist[id];
if (::gcd(d,c)==1)
Expand Down Expand Up @@ -189,20 +190,22 @@ void symbdata::display() const
}

void symbdata::check(void) const
{long i,j; int ok=1; symb s;
for (i=0; i<nsymb; i++)
{j = index(s=symbol(i));
if (i!=j)
{
int ok=1; symb s;
for (long i=0; i<nsymb; i++)
{
cout << i << "-->" << s << "-->" << j << "\n";
ok=0;
long j = index(s=symbol(i));
if (i!=j)
{
cout << i << "-->" << s << "-->" << j << "\n";
ok=0;
}
}
}
if (ok) cout << "symbols check OK!\n";
else cout << "symbols check found errors!\n";
if (ok) cout << "symbols check OK!\n";
else cout << "symbols check found errors!\n";
}

modsym jumpsymb(symb s1, symb s2)
modsym jumpsymb(const symb& s1, const symb& s2)
{
//Assuming s1==s2, returns closed modular symbol {g1(0),g2(0)} where gi<->si
long c1=s1.cee(), c2=s2.cee(), d1=s1.dee(), d2=s2.dee();
Expand Down

0 comments on commit 3970c75

Please sign in to comment.