diff --git a/Numeric/fullMatrix.h b/Numeric/fullMatrix.h index d6b65e37db61b3b8d860c2de9a90dc5795edde83..6d3f28b87605db3ca4174b0c189414544a198994 100644 --- a/Numeric/fullMatrix.h +++ b/Numeric/fullMatrix.h @@ -32,17 +32,32 @@ class fullVector scalar *_data; friend class fullMatrix<scalar>; public: + fullVector(int r) : _r(r) { _data = new scalar[_r]; scale(0.); } + fullVector(void) : _r(0),_data(0) {} fullVector(const fullVector<scalar> &other) : _r(other._r) { _data = new scalar[_r]; for(int i = 0; i < _r; ++i) _data[i] = other._data[i]; } ~fullVector() { if(_data) delete [] _data; } + + bool resize(int r) + { + if ((_r<r)) + { + if (_data) delete[] _data; + _r=r; + _data = new scalar[_r]; + return true; + } + return false; + } + inline scalar operator () (int i) const { return _data[i]; @@ -177,7 +192,7 @@ class fullMatrix bool resize(int r, int c) // data will be owned (same as constructor) { - if ((r!=_r||c!=_c)||(!_own_data)) + if ((r*c>_r*_c)||(!_own_data)) { _r=r;_c=c; if ((_own_data)&&(_data)) delete[] _data; @@ -185,6 +200,10 @@ class fullMatrix _own_data = true; return true; } + else + { + _r=r;_c=c; + } return false; // no reallocation }