Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve unit-testing for sparse-matrix values. #544

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions unit_tests/UnitTestTpetraHelperObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@

namespace unit_test_utils {

inline
bool find_col(int col,
const std::vector<int>& cols,
int begin, int end)
{
for(int i=begin; i<end; ++i) {
if (cols[i] == col) {
return true;
}
}
return false;
}

struct TpetraHelperObjectsBase {
TpetraHelperObjectsBase(stk::mesh::BulkData& bulk, int numDof)
: yamlNode(unit_test_utils::get_default_inputs()),
Expand Down Expand Up @@ -109,10 +122,21 @@ struct TpetraHelperObjectsBase {

for(int i=0; i<localMatrix.numRows(); ++i) {
KokkosSparse::SparseRowViewConst<MatrixType> constRowView = localMatrix.rowConst(i);

for(int j=0; j<constRowView.length; ++j) {
EXPECT_EQ(cols[rowOffsets[i]+j], constRowView.colidx(j));
EXPECT_NEAR(vals[rowOffsets[i]+j], constRowView.value(j), 1.e-14)<<"i: "<<i<<", j: "<<j;
for(int offset=rowOffsets[i]; offset<rowOffsets[i+1]; ++offset) {
int goldCol = cols[offset];
bool foundGoldCol = false;
for(int j=0; j<constRowView.length; ++j) {
if (constRowView.colidx(j) == goldCol) {
foundGoldCol = true;
EXPECT_NEAR(vals[offset], constRowView.value(j), 1.e-14)<<"i: "<<i<<", j: "<<j;
}
else if (!find_col(constRowView.colidx(j),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alanw0 Shouldn't this be if (find_col(...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's checking the case where the column from the matrix is not found in the "gold" cols. In other words the column from the matrix is one of the "extra" graph columns which should correspond to a zero coefficient value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, got it. cols are the "gold" columns.

cols, rowOffsets[i], rowOffsets[i+1]))
{
EXPECT_NEAR(0.0, constRowView.value(j), 1.e-14);
}
}
EXPECT_TRUE(foundGoldCol);
}

EXPECT_NEAR(rhs[i], localRhs(i,0), 1.e-14)<<"i: "<<i;
Expand Down