Skip to content

Commit

Permalink
Added test where we use a CSR matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed May 14, 2020
1 parent 7f3ec5f commit 4c5ea47
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/SparseMatrixTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,29 @@
template<typename T, int n, int m>
bool computeTest(const Eigen::Matrix<T, n, m> &mEigen)
{
Eigen::SparseMatrix<T> matrix, newMatrix;
Eigen::SparseMatrix<T, Eigen::ColMajor> matrix, newMatrix, newMatrixFromCSR;
matrix = mEigen.sparseView();

csc* osqpSparseMatrix = nullptr;
//NOTE: Dynamic memory allocation
if(!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(matrix, osqpSparseMatrix))
return false;

Eigen::SparseMatrix<T, Eigen::RowMajor> csrMatrix;
csrMatrix = matrix;
csc* otherOsqpSparseMatrix = nullptr;
if(!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(csrMatrix, otherOsqpSparseMatrix))
return false;

if(!OsqpEigen::SparseMatrixHelper::osqpSparseMatrixToEigenSparseMatrix(osqpSparseMatrix, newMatrix))
return false;

if(!OsqpEigen::SparseMatrixHelper::osqpSparseMatrixToEigenSparseMatrix(otherOsqpSparseMatrix, newMatrixFromCSR))
return false;

if (!newMatrixFromCSR.isApprox(newMatrix))
return false;

std::vector<Eigen::Triplet<T>> tripletListCsc;
if(!OsqpEigen::SparseMatrixHelper::osqpSparseMatrixToTriplets(osqpSparseMatrix, tripletListCsc))
return false;
Expand All @@ -41,6 +54,8 @@ bool computeTest(const Eigen::Matrix<T, n, m> &mEigen)
bool outcome = matrix.isApprox(newMatrix);

csc_spfree(osqpSparseMatrix);
csc_spfree(otherOsqpSparseMatrix);


return outcome;
}
Expand Down

0 comments on commit 4c5ea47

Please sign in to comment.