forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear_solve_test.cc
440 lines (407 loc) · 19 KB
/
linear_solve_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#include "drake/math/linear_solve.h"
#include <vector>
#include <gtest/gtest.h>
#include <unsupported/Eigen/AutoDiff>
#include "drake/common/test_utilities/eigen_matrix_compare.h"
#include "drake/common/test_utilities/expect_throws_message.h"
#include "drake/common/test_utilities/symbolic_test_util.h"
namespace drake {
namespace math {
namespace {
template <template <typename, int...> typename LinearSolverType,
typename DerivedA, typename DerivedB>
typename std::enable_if<internal::is_autodiff_v<typename DerivedA::Scalar> ||
std::is_same_v<typename DerivedA::Scalar, double>>::type
TestSolveLinearSystem(const Eigen::MatrixBase<DerivedA>& A,
const Eigen::MatrixBase<DerivedB>& b) {
Eigen::Matrix<double, DerivedA::RowsAtCompileTime,
DerivedB::ColsAtCompileTime>
x_eigen_d;
// To side-step clang optimizer problem, we separate this solve result
// x_eigen_d from its eventual use.
if constexpr (std::is_same_v<typename DerivedA::Scalar, double> &&
std::is_same_v<typename DerivedB::Scalar, double>) {
x_eigen_d =
LinearSolverType<Eigen::Matrix<double, DerivedA::RowsAtCompileTime,
DerivedA::ColsAtCompileTime>>(A)
.solve(b);
}
// TODO(jwnimmer-tri) Remove this extra unnecessary level of indentation.
{
const auto x = SolveLinearSystem<LinearSolverType>(A, b);
if constexpr (std::is_same_v<typename DerivedA::Scalar, double> &&
std::is_same_v<typename DerivedB::Scalar, double>) {
static_assert(std::is_same_v<typename decltype(x)::Scalar, double>,
"The returned x should have scalar type = double.");
} else {
static_assert(
!std::is_same_v<typename decltype(x)::Scalar, double>,
"The returned x should have scalar type as AutoDiffScalar.");
}
// Now check Ax = z and A*∂x/∂z + ∂A/∂z * x = ∂b/∂z
const auto Ax = (A * x).eval();
Eigen::MatrixXd Ax_val, b_val;
std::vector<Eigen::MatrixXd> Ax_grad;
std::vector<Eigen::MatrixXd> b_grad;
if constexpr (std::is_same_v<typename decltype(Ax)::Scalar, double>) {
Ax_val = Ax;
for (int i = 0; i < Ax.cols(); ++i) {
Ax_grad.push_back(
Eigen::Matrix<double, DerivedA::RowsAtCompileTime, 0>::Zero(
Ax.rows(), 0));
}
} else {
Ax_val = ExtractValue(Ax);
for (int i = 0; i < Ax.cols(); ++i) {
Ax_grad.push_back(ExtractGradient(Ax.col(i)));
}
}
if constexpr (std::is_same_v<typename DerivedB::Scalar, double>) {
b_val = b;
for (int i = 0; i < b.cols(); ++i) {
b_grad.push_back(
Eigen::Matrix<double, DerivedB::RowsAtCompileTime, 0>::Zero(
b.rows(), 0));
}
} else {
b_val = ExtractValue(b);
for (int i = 0; i < b.cols(); ++i) {
b_grad.push_back(ExtractGradient(b.col(i)));
}
}
const double tol = 2E-12;
EXPECT_TRUE(CompareMatrices(Ax_val, b_val, tol));
EXPECT_EQ(b_grad.size(), Ax_grad.size());
for (int i = 0; i < static_cast<int>(b_grad.size()); ++i) {
if (b_grad[i].size() == 0 && Ax_grad[i].size() == 0) {
} else if (b_grad[i].size() != 0 && Ax_grad[i].size() == 0) {
EXPECT_TRUE(CompareMatrices(
b_grad[i],
Eigen::MatrixXd::Zero(b_grad[i].rows(), b_grad[i].cols()), tol));
} else if (b_grad[i].size() == 0 && Ax_grad[i].size() != 0) {
EXPECT_TRUE(CompareMatrices(
Ax_grad[i],
Eigen::MatrixXd::Zero(Ax_grad[i].rows(), Ax_grad[i].cols()), tol));
} else {
EXPECT_TRUE(CompareMatrices(Ax_grad[i], b_grad[i], tol));
}
}
// Also use LinearSolver class, make sure it gives the same result as
// SolveLinearSystem.
const LinearSolver<LinearSolverType, DerivedA> solver(A);
const auto x_result = solver.Solve(b);
static_assert(std::is_same_v<typename decltype(x_result)::Scalar,
typename decltype(x)::Scalar>);
if constexpr (std::is_same_v<typename decltype(x_result)::Scalar, double>) {
EXPECT_TRUE(CompareMatrices(x_result, x));
} else {
EXPECT_TRUE(CompareMatrices(ExtractValue(x_result), ExtractValue(x)));
EXPECT_TRUE(
CompareMatrices(ExtractGradient(x_result), ExtractGradient(x)));
}
// When T = AutoDiffScalar or double, check if we get the same result as
// calling Eigen's linear solver directly.
if constexpr (internal::is_autodiff_v<typename DerivedA::Scalar>) {
const LinearSolverType<
Eigen::Matrix<typename DerivedA::Scalar, DerivedA::RowsAtCompileTime,
DerivedA::ColsAtCompileTime>>
eigen_linear_solver(A);
Eigen::Matrix<typename DerivedA::Scalar, DerivedA::RowsAtCompileTime,
DerivedB::ColsAtCompileTime>
x_eigen;
if constexpr (internal::is_autodiff_v<typename DerivedB::Scalar>) {
x_eigen = eigen_linear_solver.solve(b);
} else {
x_eigen = eigen_linear_solver.solve(
b.template cast<typename DerivedA::Scalar>());
}
EXPECT_TRUE(CompareMatrices(ExtractValue(x_eigen), ExtractValue(x)));
for (int i = 0; i < b.cols(); ++i) {
EXPECT_TRUE(CompareMatrices(ExtractGradient(x_eigen.col(i)),
ExtractGradient(x.col(i)), tol));
}
} else if constexpr (std::is_same_v<typename DerivedA::Scalar, double> && // NOLINT
internal::is_autodiff_v<typename DerivedB::Scalar>) {
const LinearSolverType<
Eigen::Matrix<typename DerivedB::Scalar, DerivedA::RowsAtCompileTime,
DerivedA::ColsAtCompileTime>>
eigen_linear_solver(A.template cast<typename DerivedB::Scalar>());
const auto x_eigen = eigen_linear_solver.solve(b);
EXPECT_TRUE(CompareMatrices(ExtractValue(x_eigen), ExtractValue(x)));
for (int i = 0; i < b.cols(); ++i) {
EXPECT_TRUE(CompareMatrices(ExtractGradient(x_eigen.col(i)),
ExtractGradient(x.col(i)), tol));
}
} else if constexpr (std::is_same_v<typename DerivedA::Scalar, double> && // NOLINT
std::is_same_v<typename DerivedB::Scalar, double>) {
EXPECT_TRUE(CompareMatrices(x_eigen_d, x));
}
}
}
class LinearSolveTest : public ::testing::Test {
public:
LinearSolveTest() {
A_val_ << 1, 3, 3, 10;
b_vec_val_ << 3, 5;
Eigen::Matrix<double, 2, Eigen::Dynamic> b_grad(2, 3);
b_grad << 1, 2, 3, 4, 5, 6;
b_vec_ad_ = InitializeAutoDiff(b_vec_val_, b_grad);
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
A_ad_(i, j).value() = A_val_(i, j);
}
}
A_ad_(0, 0).derivatives() = Eigen::Vector3d(1, 2, 3);
A_ad_(0, 1).derivatives() = Eigen::Vector3d(4, 5, 6);
A_ad_(1, 0).derivatives() = Eigen::Vector3d(4, 5, 6);
A_ad_(1, 1).derivatives() = Eigen::Vector3d(10, 11, 12);
b_mat_val_ << 3, 5, 8, 1, -2, -3;
b_mat_ad_ = b_mat_val_.cast<AutoDiffXd>();
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 3; ++j) {
b_mat_ad_(i, j).derivatives() = Eigen::Vector3d(i, j, i * j + 1);
}
}
A_sym_ << symbolic::Expression(1), symbolic::Expression(3),
symbolic::Expression(3), symbolic::Expression(10);
const symbolic::Variable sym_u("u");
const symbolic::Variable sym_v("v");
b_sym_ << sym_u, 1, sym_v, -sym_u + sym_v, 3, 2;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
A_ad_fixed_der_size_(i, j).value() = A_ad_(i, j).value();
A_ad_fixed_der_size_(i, j).derivatives() = A_ad_(i, j).derivatives();
}
}
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 3; ++j) {
b_ad_fixed_der_size_(i, j).value() = b_mat_ad_(i, j).value();
b_ad_fixed_der_size_(i, j).derivatives() =
b_mat_ad_(i, j).derivatives();
}
}
}
protected:
Eigen::Matrix2d A_val_;
Eigen::Vector2d b_vec_val_;
Eigen::Matrix<double, 2, 3> b_mat_val_;
Eigen::Matrix<AutoDiffXd, 2, 2> A_ad_;
Eigen::Matrix<AutoDiffXd, 2, 1> b_vec_ad_;
Eigen::Matrix<AutoDiffXd, 2, 3> b_mat_ad_;
Eigen::Matrix<symbolic::Expression, 2, 2> A_sym_;
Eigen::Matrix<symbolic::Expression, 2, 3> b_sym_;
// Use fixed-sized AutoDiffScalar.
Eigen::Matrix<Eigen::AutoDiffScalar<Eigen::Vector3d>, 2, 2>
A_ad_fixed_der_size_;
Eigen::Matrix<Eigen::AutoDiffScalar<Eigen::Vector3d>, 2, 3>
b_ad_fixed_der_size_;
};
TEST_F(LinearSolveTest, TestDoubleAandb) {
// Both A and b are double matrices.
TestSolveLinearSystem<Eigen::LLT>(A_val_, b_vec_val_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_, b_vec_val_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_, b_vec_val_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_, b_vec_val_);
TestSolveLinearSystem<Eigen::LLT>(A_val_, b_mat_val_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_, b_mat_val_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_, b_mat_val_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_, b_mat_val_);
}
template <template <typename, int...> typename LinearSolverType,
typename DerivedA, typename DerivedB>
void TestSolveLinearSystemSymbolic(const Eigen::MatrixBase<DerivedA>& A,
const Eigen::MatrixBase<DerivedB>& b) {
// TODO(jwnimmer-tri) Remove this extra unnecessary level of indentation.
{
const auto x = SolveLinearSystem<LinearSolverType>(A, b);
static_assert(
std::is_same_v<typename decltype(x)::Scalar, symbolic::Expression>,
"The scalar type should be symbolic expression");
const Eigen::Matrix<symbolic::Expression, DerivedA::RowsAtCompileTime,
DerivedB::ColsAtCompileTime>
Ax = A * x;
EXPECT_EQ(Ax.rows(), b.rows());
EXPECT_EQ(Ax.cols(), b.cols());
for (int i = 0; i < b.rows(); ++i) {
for (int j = 0; j < b.cols(); ++j) {
EXPECT_PRED2(symbolic::test::ExprEqual, Ax(i, j).Expand(), b(i, j));
}
}
}
}
TEST_F(LinearSolveTest, TestSymbolicAandb) {
TestSolveLinearSystemSymbolic<Eigen::LLT>(A_sym_, b_sym_);
}
TEST_F(LinearSolveTest, TestAutoDiffAandDoubleB) {
// A contains AutoDiffXd and b contains double.
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_vec_val_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_vec_val_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_ad_, b_vec_val_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_, b_vec_val_);
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_mat_val_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_mat_val_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_ad_, b_mat_val_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_, b_mat_val_);
}
TEST_F(LinearSolveTest, TestDoubleAandAutoDiffB) {
// A contains double and b contains AutoDiffXd.
TestSolveLinearSystem<Eigen::LLT>(A_val_, b_vec_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_, b_vec_ad_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_, b_vec_ad_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_, b_vec_ad_);
TestSolveLinearSystem<Eigen::LLT>(A_val_, b_mat_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_, b_mat_ad_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_, b_mat_ad_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_, b_mat_ad_);
}
TEST_F(LinearSolveTest, TestNoGrad) {
// A and b both contain AutoDiffXd but has empty gradient.
TestSolveLinearSystem<Eigen::LLT>(A_val_.cast<AutoDiffXd>(),
b_vec_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::LLT>(A_val_.cast<AutoDiffXd>(),
b_mat_val_.cast<AutoDiffXd>());
}
TEST_F(LinearSolveTest, TestBwithGrad) {
// Test SolveLinearSystem with A containing empty gradient while b
// contains meaningful gradient.
TestSolveLinearSystem<Eigen::LLT>(A_val_.cast<AutoDiffXd>(), b_vec_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_.cast<AutoDiffXd>(), b_vec_ad_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_.cast<AutoDiffXd>(),
b_vec_ad_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_.cast<AutoDiffXd>(),
b_vec_ad_);
TestSolveLinearSystem<Eigen::LLT>(A_val_.cast<AutoDiffXd>(), b_mat_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_.cast<AutoDiffXd>(), b_mat_ad_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_.cast<AutoDiffXd>(),
b_mat_ad_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_.cast<AutoDiffXd>(),
b_mat_ad_);
}
TEST_F(LinearSolveTest, TestAwithGrad) {
// Test SolveLinearSystem with A containing gradient while b contains
// no gradient.
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_vec_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_vec_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(
A_ad_, b_vec_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_,
b_vec_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_mat_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_mat_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(
A_ad_, b_mat_val_.cast<AutoDiffXd>());
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_,
b_mat_val_.cast<AutoDiffXd>());
}
TEST_F(LinearSolveTest, TestFixedDerivativeSize) {
// Test SolveLinearSystem with either or both A and b containing
// AutoDiffScalar, The AutoDiffScalar has a fixed derivative size.
// Both A and B contain AutoDiffScalar.
TestSolveLinearSystem<Eigen::LLT>(A_ad_fixed_der_size_, b_ad_fixed_der_size_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_fixed_der_size_,
b_ad_fixed_der_size_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_ad_fixed_der_size_,
b_ad_fixed_der_size_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_fixed_der_size_,
b_ad_fixed_der_size_);
// Only b contains AutoDiffScalar, A contains double.
TestSolveLinearSystem<Eigen::LLT>(A_val_, b_ad_fixed_der_size_);
TestSolveLinearSystem<Eigen::LDLT>(A_val_, b_ad_fixed_der_size_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_val_,
b_ad_fixed_der_size_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_val_, b_ad_fixed_der_size_);
// Only A contains AutoDiffScalar, b contains double.
TestSolveLinearSystem<Eigen::LLT>(A_ad_fixed_der_size_, b_mat_val_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_fixed_der_size_, b_mat_val_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_ad_fixed_der_size_,
b_mat_val_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_fixed_der_size_, b_mat_val_);
}
TEST_F(LinearSolveTest, TestAbWithGrad) {
// Test SolveLinearSystem with both A and b containing gradient.
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_vec_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_vec_ad_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_ad_, b_vec_ad_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_, b_vec_ad_);
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_mat_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_mat_ad_);
TestSolveLinearSystem<Eigen::ColPivHouseholderQR>(A_ad_, b_mat_ad_);
TestSolveLinearSystem<Eigen::PartialPivLU>(A_ad_, b_mat_ad_);
}
TEST_F(LinearSolveTest, TestAbWithMaybeEmptyGrad) {
// Test SolveLinearSystem with both A and b containing gradient in
// some entries, and empty gradient in some other entries.
A_ad_(1, 0).derivatives() = Eigen::VectorXd(0);
A_ad_(0, 1).derivatives() = Eigen::VectorXd(0);
b_vec_ad_(1).derivatives() = Eigen::VectorXd(0);
TestSolveLinearSystem<Eigen::LLT>(A_ad_, b_vec_ad_);
TestSolveLinearSystem<Eigen::LDLT>(A_ad_, b_vec_ad_);
}
TEST_F(LinearSolveTest, TestWrongGradientSize) {
const Eigen::LLT<Eigen::Matrix2d> linear_solver(A_val_);
// A's gradient has inconsistent size.
auto A_ad_error = A_ad_;
A_ad_error(0, 1).derivatives() = Eigen::Vector2d(1, 2);
DRAKE_EXPECT_THROWS_MESSAGE(
SolveLinearSystem<Eigen::LLT>(A_ad_error, b_vec_ad_),
".* has size 2, while another entry has size 3");
// b's gradient has inconsistent size.
auto b_vec_ad_error = b_vec_ad_;
b_vec_ad_error(1).derivatives() = Eigen::Vector2d(1, 2);
DRAKE_EXPECT_THROWS_MESSAGE(
SolveLinearSystem<Eigen::LLT>(A_ad_, b_vec_ad_error),
".* has size 2, while another entry has size 3");
// A and b have different number of derivatives.
auto b_vec_ad_error2 = b_vec_ad_;
b_vec_ad_error2(0).derivatives() = Eigen::Vector4d::Ones();
b_vec_ad_error2(1).derivatives() = Eigen::Vector4d::Ones();
DRAKE_EXPECT_THROWS_MESSAGE(
SolveLinearSystem<Eigen::LLT>(A_ad_, b_vec_ad_error2),
".*A contains derivatives for 3 variables, while b contains derivatives "
"for 4 variables");
}
template <template <typename, int...> typename LinearSolverType,
typename DerivedA>
void CheckGetLinearSolver(const Eigen::MatrixBase<DerivedA>& A) {
const auto linear_solver = GetLinearSolver<LinearSolverType>(A);
if constexpr (std::is_same_v<typename DerivedA::Scalar, double> ||
std::is_same_v<typename DerivedA::Scalar,
symbolic::Expression>) {
static_assert(
std::is_same_v<typename decltype(linear_solver)::MatrixType::Scalar,
typename DerivedA::Scalar>,
"The scalar type don't match");
} else {
static_assert(
std::is_same_v<typename decltype(linear_solver)::MatrixType::Scalar,
double>,
"The scalar type should be double");
}
// Cast away the enum types of the matrix metrics so we can compare without
// compiler warnings.
constexpr int RowsSolver =
static_cast<int>(decltype(linear_solver)::MatrixType::RowsAtCompileTime);
constexpr int RowsA = static_cast<int>(DerivedA::RowsAtCompileTime);
static_assert(RowsSolver == RowsA, "The matrix rows don't match");
constexpr int ColsSolver =
static_cast<int>(decltype(linear_solver)::MatrixType::ColsAtCompileTime);
constexpr int ColsA = static_cast<int>(DerivedA::ColsAtCompileTime);
static_assert(ColsSolver == ColsA, "The matrix rows don't match");
}
TEST_F(LinearSolveTest, GetLinearSolver) {
// Check double-valued A matrix.
CheckGetLinearSolver<Eigen::LLT>(A_val_);
CheckGetLinearSolver<Eigen::LDLT>(A_val_);
CheckGetLinearSolver<Eigen::PartialPivLU>(A_val_);
CheckGetLinearSolver<Eigen::ColPivHouseholderQR>(A_val_);
// Check symbolic::Expression-valued A matrix.
CheckGetLinearSolver<Eigen::LLT>(A_sym_);
// Check AutoDiffXd-valued A matrix.
CheckGetLinearSolver<Eigen::LLT>(A_ad_);
CheckGetLinearSolver<Eigen::LDLT>(A_ad_);
CheckGetLinearSolver<Eigen::PartialPivLU>(A_ad_);
CheckGetLinearSolver<Eigen::ColPivHouseholderQR>(A_ad_);
}
} // namespace
} // namespace math
} // namespace drake