Skip to content

Commit

Permalink
Improve equality check for COO and CSR
Browse files Browse the repository at this point in the history
  • Loading branch information
francois141 committed Oct 23, 2023
1 parent a499e9e commit 106b7d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/matrices/COO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,26 @@ class COO {
}

friend bool operator==(const COO &lhs, const COO &rhs) {
return lhs.colPositions == rhs.colPositions &&
bool posMatch = lhs.colPositions == rhs.colPositions &&
lhs.rowPositions == rhs.rowPositions &&
lhs.values == rhs.values &&
lhs.rows == rhs.rows &&
lhs.cols == rhs.cols;

bool valMatch = true;

if(std::is_integral<T>::value) {
valMatch = (lhs.values == rhs.values);
} else {
if(lhs.values.size() != rhs.values.size()) {
return false;
}

for(int i = 0; i < lhs.values.size();i++) {
valMatch &= abs(rhs.values[i] - lhs.values[i]) <= 1e-6;
}
}

return posMatch && valMatch;
}

int getRows() const {
Expand Down
19 changes: 17 additions & 2 deletions src/matrices/CSR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,26 @@ class CSR {
}

friend bool operator==(const CSR &lhs, const CSR &rhs) {
return lhs.colPositions == rhs.colPositions &&
bool posMatch = lhs.colPositions == rhs.colPositions &&
lhs.rowPositions == rhs.rowPositions &&
lhs.values == rhs.values &&
lhs.rows == rhs.rows &&
lhs.cols == rhs.cols;

bool valMatch = true;

if(std::is_integral<T>::value) {
valMatch = (lhs.values == rhs.values);
} else {
if(lhs.values.size() != rhs.values.size()) {
return false;
}

for(int i = 0; i < lhs.values.size();i++) {
valMatch &= abs(rhs.values[i] - lhs.values[i]) <= 1e-6;
}
}

return posMatch && valMatch;
}

int getRows() const {
Expand Down

0 comments on commit 106b7d1

Please sign in to comment.