-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[symbolic] Fix SparseMatrix<Expression> data loss (#18219)
- Loading branch information
1 parent
679ef89
commit edb3c0a
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* clang-format off to disable clang-format-includes */ | ||
#include "drake/common/symbolic/expression/all.h" | ||
/* clang-format on */ | ||
|
||
#include <vector> | ||
|
||
#include <Eigen/Sparse> | ||
#include <gtest/gtest.h> | ||
|
||
#include "drake/common/test_utilities/symbolic_test_util.h" | ||
|
||
namespace drake { | ||
namespace symbolic { | ||
namespace { | ||
|
||
using test::ExprEqual; | ||
|
||
// This is a regression test for drake#18218. | ||
GTEST_TEST(SymbolicMatricesTest, SparseMatrices) { | ||
const Variable x("x"); | ||
std::vector<Eigen::Triplet<Expression>> triplets; | ||
triplets.push_back(Eigen::Triplet<Expression>(1, 1, 1.1)); | ||
triplets.push_back(Eigen::Triplet<Expression>(2, 2, x*2.0)); | ||
Eigen::SparseMatrix<Expression> M(3, 3); | ||
M.setFromTriplets(triplets.begin(), triplets.end()); | ||
EXPECT_PRED2(ExprEqual, M.coeff(0, 0), 0.0); | ||
EXPECT_PRED2(ExprEqual, M.coeff(1, 1), 1.1); | ||
EXPECT_PRED2(ExprEqual, M.coeff(2, 2), x*2.0); | ||
} | ||
|
||
} // namespace | ||
} // namespace symbolic | ||
} // namespace drake |