Added checks to avoid computing bogus column pointers for matrix types

This commit is contained in:
Ray Speth 2012-02-27 18:12:29 +00:00
parent 3f3df652c6
commit 8b7dab08bd
3 changed files with 36 additions and 18 deletions

View file

@ -41,8 +41,10 @@ DoubleStarStar::DoubleStarStar(const DoubleStarStar& y)
m_data.resize(m_nrows*m_ncols);
m_data = y.m_data;
m_colAddr.resize(m_ncols);
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
if (!m_data.empty()) {
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
}
}
}
@ -57,8 +59,10 @@ DoubleStarStar& DoubleStarStar::operator=(const DoubleStarStar& y)
m_data.resize(m_nrows*m_ncols);
m_data = y.m_data;
m_colAddr.resize(m_ncols);
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
if (!m_data.empty()) {
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
}
}
return *this;
}
@ -108,8 +112,10 @@ void DoubleStarStar::resize(size_t m, size_t n, double v)
m_nrows = n;
m_ncols = m;
m_colAddr.resize(m_ncols);
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
if (!m_data.empty()) {
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
}
}
}

View file

@ -28,8 +28,10 @@ IntStarStar::IntStarStar(size_t m, size_t n, int v) :
m_data.resize(n*m);
std::fill(m_data.begin(), m_data.end(), v);
m_colAddr.resize(m);
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
if (!m_data.empty()) {
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
}
}
}
@ -41,8 +43,10 @@ IntStarStar::IntStarStar(const IntStarStar& y)
m_data.resize(m_nrows*m_ncols);
m_data = y.m_data;
m_colAddr.resize(m_ncols);
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
if (!m_data.empty()) {
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
}
}
}
@ -57,8 +61,10 @@ IntStarStar& IntStarStar::operator=(const IntStarStar& y)
m_data.resize(m_nrows*m_ncols);
m_data = y.m_data;
m_colAddr.resize(m_ncols);
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
if (!m_data.empty()) {
for (size_t jcol = 0; jcol < m_ncols; jcol++) {
m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
}
}
return *this;
}

View file

@ -35,8 +35,10 @@ DenseMatrix::DenseMatrix(size_t n, size_t m, doublereal v) :
{
m_ipiv.resize(std::max(n, m));
m_colPts.resize(m);
for (size_t j = 0; j < m; j++) {
m_colPts[j] = &(m_data[m_nrows*j]);
if (!m_data.empty()) {
for (size_t j = 0; j < m; j++) {
m_colPts[j] = &(m_data[m_nrows*j]);
}
}
}
//====================================================================================================================
@ -52,8 +54,10 @@ DenseMatrix::DenseMatrix(const DenseMatrix& y) :
{
m_ipiv = y.ipiv();
m_colPts.resize(m_ncols);
for (size_t j = 0; j < m_ncols; j++) {
m_colPts[j] = &(m_data[m_nrows*j]);
if (!m_data.empty()) {
for (size_t j = 0; j < m_ncols; j++) {
m_colPts[j] = &(m_data[m_nrows*j]);
}
}
}
//====================================================================================================================
@ -84,8 +88,10 @@ void DenseMatrix::resize(size_t n, size_t m, doublereal v)
Array2D::resize(n,m,v);
m_ipiv.resize(std::max(n,m));
m_colPts.resize(m_ncols);
for (size_t j = 0; j < m_ncols; j++) {
m_colPts[j] = &(m_data[m_nrows*j]);
if (!m_data.empty()) {
for (size_t j = 0; j < m_ncols; j++) {
m_colPts[j] = &(m_data[m_nrows*j]);
}
}
}
//====================================================================================================================