From 4c5ea472a8d300d7ecd728af36f9df20463a115a Mon Sep 17 00:00:00 2001 From: Stefano Date: Thu, 14 May 2020 16:11:48 +0200 Subject: [PATCH] Added test where we use a CSR matrix. --- tests/SparseMatrixTest.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/SparseMatrixTest.cpp b/tests/SparseMatrixTest.cpp index 2a5ce9d..e14bf87 100644 --- a/tests/SparseMatrixTest.cpp +++ b/tests/SparseMatrixTest.cpp @@ -14,7 +14,7 @@ template bool computeTest(const Eigen::Matrix &mEigen) { - Eigen::SparseMatrix matrix, newMatrix; + Eigen::SparseMatrix matrix, newMatrix, newMatrixFromCSR; matrix = mEigen.sparseView(); csc* osqpSparseMatrix = nullptr; @@ -22,8 +22,21 @@ bool computeTest(const Eigen::Matrix &mEigen) if(!OsqpEigen::SparseMatrixHelper::createOsqpSparseMatrix(matrix, osqpSparseMatrix)) return false; + Eigen::SparseMatrix 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> tripletListCsc; if(!OsqpEigen::SparseMatrixHelper::osqpSparseMatrixToTriplets(osqpSparseMatrix, tripletListCsc)) return false; @@ -41,6 +54,8 @@ bool computeTest(const Eigen::Matrix &mEigen) bool outcome = matrix.isApprox(newMatrix); csc_spfree(osqpSparseMatrix); + csc_spfree(otherOsqpSparseMatrix); + return outcome; }