From f9816fa69a0babca4f1d71a578df89146aab2774 Mon Sep 17 00:00:00 2001 From: Eric Bechet <eric.bechet@ulg.ac.be> Date: Sat, 12 Dec 2009 08:20:02 +0000 Subject: [PATCH] Added functionality / fullVector --- Numeric/fullMatrix.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Numeric/fullMatrix.h b/Numeric/fullMatrix.h index d6b65e37db..6d3f28b876 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 } -- GitLab