Skip to content
Snippets Groups Projects
Commit 49faa182 authored by Jesper Andersson's avatar Jesper Andersson
Browse files

Added copy-constructor and assignment operator to SpMat

parent cb9e0a76
No related branches found
No related tags found
No related merge requests found
......@@ -94,6 +94,7 @@ public:
SpMat(unsigned int m, unsigned int n, const unsigned int *irp, const unsigned int *jcp, const double *sp);
SpMat(const NEWMAT::GeneralMatrix& M);
SpMat(const std::string& fname);
SpMat(const SpMat<T>& s) : _m(s._m), _n(s._n), _nz(s._nz), _ri(s._ri), _val(s._val), _pw(s._pw), _ei(*this,true) {}
~SpMat() {}
unsigned int Nrows() const {return(_m);}
......@@ -121,6 +122,12 @@ public:
void SetColumn(unsigned int c, const NEWMAT::ColumnVector& col, double eps=0.0); // Set a whole column (obliterating what was there before)
void AddTo(unsigned int r, unsigned int c, const T& v) {here(r,c) += v;} // Add value to a single (possibly existing) value
SpMat<T>& operator=(const SpMat& M)
{
if (this == &M) return(*this);
_m=M._m; _n=M._n; _nz=M._nz; _ri=M._ri; _val=M._val; _pw=M._pw; _ei=M._ei;
return(*this);
}
SpMat<T>& operator+=(const SpMat& M)
{
if (same_sparsity(M)) return(add_same_sparsity_mat_to_me(M,1));
......@@ -182,10 +189,11 @@ public:
if (_j == _mat._n) _oob = true;
}
~Iterator() {}
Iterator& operator=(const Iterator& I) { _i=I._i; _j=I._j; _oob=I._oob; return(*this); } // _mat deliberately not assigned
bool operator==(const Iterator& other) { return(&_mat==&other._mat && ((_oob && other._oob) || (_i==other._i && _j==other._j))); }
bool operator!=(const Iterator& other) { return(!(*this==other)); }
T& operator*() { return((_mat._val[_j])[_i]); }
Iterator& operator++()
Iterator& operator++() // Prefix operator
{
if (++_i < _mat._ri[_j].size()) return(*this);
else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment