Skip to content

Commit

Permalink
fixed run time errors (mostly in test.cpp) introduced by the recent c…
Browse files Browse the repository at this point in the history
…hanges in the Jacobi API (adding a ConstMatrix template argument)
  • Loading branch information
jewettaij committed Jan 30, 2020
1 parent 678cb68 commit 6a69c33
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/jacobi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ template<typename Scalar,typename Vector,typename Matrix,typename ConstMatrix>
void Jacobi<Scalar, Vector, Matrix, ConstMatrix>::
Init() {
n = 0;
M = nullptr;
max_idx_row = nullptr;
}

Expand Down
23 changes: 21 additions & 2 deletions include/matrix_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ void Dealloc2D(Entry ***paaX); //!< pointer to 2-D multidimensional array

// --- IMPLEMENTATION ---

/// @brief
/// Allocate a 2-dimensional table row-major order.
/// In this version, the the size of the array specified by 2 integer arguments.
template<typename Entry, typename Integer>
void Alloc2D(Integer const size[2], //!< size of the array in x,y directions
Entry ***paaX) //!< pointer to 2-D multidimensional array
{
assert(paaX);
// Allocate a conventional 2-dimensional
// pointer-to-a-pointer data structure.
*paaX = new Entry* [size[0]];
(*paaX)[0] = new Entry [size[0] * size[1]];
for(Integer iy=0; iy<size[0]; iy++)
(*paaX)[iy] = (*paaX)[0] + iy*size[1];
// The caller can access the contents of *paX using (*paaX)[i][j] notation.
}


template<typename Entry>
void Alloc2D(int nrows, //!< size of the array (outer)
int ncolumns, //!< size of the array (inner)
Expand All @@ -47,10 +65,11 @@ void Alloc2D(int nrows, //!< size of the array (outer)
template<typename Entry>
void Dealloc2D(Entry ***paaX) //!< pointer to 2-D multidimensional array
{
//*paaX = new Entry* [size[0]];
//(*paaX)[0] = new Entry [size[0] * size[1]];
if (paaX && *paaX) {
Entry *aX = &((*paaX)[0][0]);
delete [] (*paaX)[0];
delete [] (*paaX);
delete [] aX;
*paaX = nullptr;
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ void GenRandSymm(Matrix M, //<! store the matrix here
GenRandOrth<Scalar, Matrix>(evects, n, generator);

// Construct the test matrix, M, where M = Rt * D * R
mmult(evects, D, tmp, n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
evects[i][j] = evects[j][i]; //transpose "evects"
mmult(evects, D, tmp, n); //tmp = Rt * D
for (int i = 0; i < n-1; i++)
for (int j = i+1; j < n; j++)
std::swap(evects[i][j], evects[j][i]); //transpose "evects"
mmult(tmp, evects, M, n); //at this point M = Rt * D * R (where "R"="evects")
Dealloc2D(&D);
Dealloc2D(&tmp);
Expand Down Expand Up @@ -304,7 +304,7 @@ void TestJacobi(int n, //<! matrix size
//Check each eigenvector
for (int i = 0; i < n; i++) {
for (int a = 0; a < n; a++) {
test_evec[i] = 0.0;
test_evec[a] = 0.0;
for (int b = 0; b < n; b++)
test_evec[a] += M[a][b] * evects[i][b];
assert(Similar(test_evec[a], evals[i] * evects[i][a], 1.0e-06));
Expand Down

0 comments on commit 6a69c33

Please sign in to comment.