Skip to content
Snippets Groups Projects
Commit 3538cbaf authored by Tuomas Karna's avatar Tuomas Karna
Browse files

fullMatrix::copy and setAll updated to avoid bugs. copy may reallocate the...

fullMatrix::copy and setAll updated to avoid bugs. copy may reallocate the matrix so it is prohibited for proxies.
parent 1f2893ac
No related branches found
No related tags found
No related merge requests found
...@@ -297,7 +297,7 @@ bool fullMatrix<double>::invert(fullMatrix<double> &result) const ...@@ -297,7 +297,7 @@ bool fullMatrix<double>::invert(fullMatrix<double> &result) const
{ {
int M = size1(), N = size2(), lda = size1(), info; int M = size1(), N = size2(), lda = size1(), info;
int *ipiv = new int[std::min(M, N)]; int *ipiv = new int[std::min(M, N)];
result = *this; result.setAll(*this);
F77NAME(dgetrf)(&M, &N, result._data, &lda, ipiv, &info); F77NAME(dgetrf)(&M, &N, result._data, &lda, ipiv, &info);
if(info == 0){ if(info == 0){
int lwork = M * 4; int lwork = M * 4;
......
...@@ -251,20 +251,7 @@ class fullMatrix ...@@ -251,20 +251,7 @@ class fullMatrix
} }
fullMatrix<scalar> & operator = (const fullMatrix<scalar> &other) fullMatrix<scalar> & operator = (const fullMatrix<scalar> &other)
{ {
if(this != &other){ copy(other);
if (_r != other._r || _c != other._c) {
_r = other._r;
_c = other._c;
if (_data && _own_data) delete[] _data;
if ((_r == 0) || (_c == 0))
_data=0;
else{
_data = new scalar[_r * _c];
_own_data=true;
}
}
for(int i = 0; i < _r * _c; ++i) _data[i] = other._data[i];
}
return *this; return *this;
} }
void operator += (const fullMatrix<scalar> &other) void operator += (const fullMatrix<scalar> &other)
...@@ -300,6 +287,8 @@ class fullMatrix ...@@ -300,6 +287,8 @@ class fullMatrix
} }
void copy(const fullMatrix<scalar> &a) void copy(const fullMatrix<scalar> &a)
{ {
if (_data && !_own_data)
Msg::Fatal("fullMatrix::copy operation is prohibited for proxies, use setAll instead");
if (_r != a._r || _c != a._c) { if (_r != a._r || _c != a._c) {
if(_data && _own_data) if(_data && _own_data)
delete [] _data; delete [] _data;
...@@ -360,6 +349,8 @@ class fullMatrix ...@@ -360,6 +349,8 @@ class fullMatrix
} }
inline void setAll(const fullMatrix<scalar> &m) inline void setAll(const fullMatrix<scalar> &m)
{ {
if (_r != m._r || _c != m._c )
Msg::Fatal("fullMatrix size does not match");
for(int i = 0; i < _r * _c; i++) _data[i] = m._data[i]; for(int i = 0; i < _r * _c; i++) _data[i] = m._data[i];
} }
void scale(const double s) void scale(const double s)
......
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