small_blas_test.cc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. // Ceres Solver - A fast non-linear least squares minimizer
  2. // Copyright 2023 Google Inc. All rights reserved.
  3. // http://ceres-solver.org/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are met:
  7. //
  8. // * Redistributions of source code must retain the above copyright notice,
  9. // this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. // * Neither the name of Google Inc. nor the names of its contributors may be
  14. // used to endorse or promote products derived from this software without
  15. // specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  25. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  27. // POSSIBILITY OF SUCH DAMAGE.
  28. //
  29. // Author: keir@google.com (Keir Mierle)
  30. #include "ceres/small_blas.h"
  31. #include <limits>
  32. #include <string>
  33. #include "ceres/internal/eigen.h"
  34. #include "gtest/gtest.h"
  35. namespace ceres {
  36. namespace internal {
  37. const double kTolerance = 5.0 * std::numeric_limits<double>::epsilon();
  38. // Static or dynamic problem types.
  39. enum class DimType { Static, Dynamic };
  40. // Constructs matrix functor type.
  41. #define MATRIX_FUN_TY(FN) \
  42. template <int kRowA, \
  43. int kColA, \
  44. int kRowB, \
  45. int kColB, \
  46. int kOperation, \
  47. DimType kDimType> \
  48. struct FN##Ty { \
  49. void operator()(const double* A, \
  50. const int num_row_a, \
  51. const int num_col_a, \
  52. const double* B, \
  53. const int num_row_b, \
  54. const int num_col_b, \
  55. double* C, \
  56. const int start_row_c, \
  57. const int start_col_c, \
  58. const int row_stride_c, \
  59. const int col_stride_c) { \
  60. if (kDimType == DimType::Static) { \
  61. FN<kRowA, kColA, kRowB, kColB, kOperation>(A, \
  62. num_row_a, \
  63. num_col_a, \
  64. B, \
  65. num_row_b, \
  66. num_col_b, \
  67. C, \
  68. start_row_c, \
  69. start_col_c, \
  70. row_stride_c, \
  71. col_stride_c); \
  72. } else { \
  73. FN<Eigen::Dynamic, \
  74. Eigen::Dynamic, \
  75. Eigen::Dynamic, \
  76. Eigen::Dynamic, \
  77. kOperation>(A, \
  78. num_row_a, \
  79. num_col_a, \
  80. B, \
  81. num_row_b, \
  82. num_col_b, \
  83. C, \
  84. start_row_c, \
  85. start_col_c, \
  86. row_stride_c, \
  87. col_stride_c); \
  88. } \
  89. } \
  90. };
  91. MATRIX_FUN_TY(MatrixMatrixMultiply)
  92. MATRIX_FUN_TY(MatrixMatrixMultiplyNaive)
  93. MATRIX_FUN_TY(MatrixTransposeMatrixMultiply)
  94. MATRIX_FUN_TY(MatrixTransposeMatrixMultiplyNaive)
  95. #undef MATRIX_FUN_TY
  96. // Initializes matrix entries.
  97. static void initMatrix(Matrix& mat) {
  98. for (int i = 0; i < mat.rows(); ++i) {
  99. for (int j = 0; j < mat.cols(); ++j) {
  100. mat(i, j) = i + j + 1;
  101. }
  102. }
  103. }
  104. template <int kRowA,
  105. int kColA,
  106. int kColB,
  107. DimType kDimType,
  108. template <int, int, int, int, int, DimType>
  109. class FunctorTy>
  110. struct TestMatrixFunctions {
  111. void operator()() {
  112. Matrix A(kRowA, kColA);
  113. initMatrix(A);
  114. const int kRowB = kColA;
  115. Matrix B(kRowB, kColB);
  116. initMatrix(B);
  117. for (int row_stride_c = kRowA; row_stride_c < 3 * kRowA; ++row_stride_c) {
  118. for (int col_stride_c = kColB; col_stride_c < 3 * kColB; ++col_stride_c) {
  119. Matrix C(row_stride_c, col_stride_c);
  120. C.setOnes();
  121. Matrix C_plus = C;
  122. Matrix C_minus = C;
  123. Matrix C_assign = C;
  124. Matrix C_plus_ref = C;
  125. Matrix C_minus_ref = C;
  126. Matrix C_assign_ref = C;
  127. for (int start_row_c = 0; start_row_c + kRowA < row_stride_c;
  128. ++start_row_c) {
  129. for (int start_col_c = 0; start_col_c + kColB < col_stride_c;
  130. ++start_col_c) {
  131. C_plus_ref.block(start_row_c, start_col_c, kRowA, kColB) += A * B;
  132. FunctorTy<kRowA, kColA, kRowB, kColB, 1, kDimType>()(A.data(),
  133. kRowA,
  134. kColA,
  135. B.data(),
  136. kRowB,
  137. kColB,
  138. C_plus.data(),
  139. start_row_c,
  140. start_col_c,
  141. row_stride_c,
  142. col_stride_c);
  143. EXPECT_NEAR((C_plus_ref - C_plus).norm(), 0.0, kTolerance)
  144. << "C += A * B \n"
  145. << "row_stride_c : " << row_stride_c << "\n"
  146. << "col_stride_c : " << col_stride_c << "\n"
  147. << "start_row_c : " << start_row_c << "\n"
  148. << "start_col_c : " << start_col_c << "\n"
  149. << "Cref : \n"
  150. << C_plus_ref << "\n"
  151. << "C: \n"
  152. << C_plus;
  153. C_minus_ref.block(start_row_c, start_col_c, kRowA, kColB) -= A * B;
  154. FunctorTy<kRowA, kColA, kRowB, kColB, -1, kDimType>()(
  155. A.data(),
  156. kRowA,
  157. kColA,
  158. B.data(),
  159. kRowB,
  160. kColB,
  161. C_minus.data(),
  162. start_row_c,
  163. start_col_c,
  164. row_stride_c,
  165. col_stride_c);
  166. EXPECT_NEAR((C_minus_ref - C_minus).norm(), 0.0, kTolerance)
  167. << "C -= A * B \n"
  168. << "row_stride_c : " << row_stride_c << "\n"
  169. << "col_stride_c : " << col_stride_c << "\n"
  170. << "start_row_c : " << start_row_c << "\n"
  171. << "start_col_c : " << start_col_c << "\n"
  172. << "Cref : \n"
  173. << C_minus_ref << "\n"
  174. << "C: \n"
  175. << C_minus;
  176. C_assign_ref.block(start_row_c, start_col_c, kRowA, kColB) = A * B;
  177. FunctorTy<kRowA, kColA, kRowB, kColB, 0, kDimType>()(
  178. A.data(),
  179. kRowA,
  180. kColA,
  181. B.data(),
  182. kRowB,
  183. kColB,
  184. C_assign.data(),
  185. start_row_c,
  186. start_col_c,
  187. row_stride_c,
  188. col_stride_c);
  189. EXPECT_NEAR((C_assign_ref - C_assign).norm(), 0.0, kTolerance)
  190. << "C = A * B \n"
  191. << "row_stride_c : " << row_stride_c << "\n"
  192. << "col_stride_c : " << col_stride_c << "\n"
  193. << "start_row_c : " << start_row_c << "\n"
  194. << "start_col_c : " << start_col_c << "\n"
  195. << "Cref : \n"
  196. << C_assign_ref << "\n"
  197. << "C: \n"
  198. << C_assign;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. };
  205. template <int kRowA,
  206. int kColA,
  207. int kColB,
  208. DimType kDimType,
  209. template <int, int, int, int, int, DimType>
  210. class FunctorTy>
  211. struct TestMatrixTransposeFunctions {
  212. void operator()() {
  213. Matrix A(kRowA, kColA);
  214. initMatrix(A);
  215. const int kRowB = kRowA;
  216. Matrix B(kRowB, kColB);
  217. initMatrix(B);
  218. for (int row_stride_c = kColA; row_stride_c < 3 * kColA; ++row_stride_c) {
  219. for (int col_stride_c = kColB; col_stride_c < 3 * kColB; ++col_stride_c) {
  220. Matrix C(row_stride_c, col_stride_c);
  221. C.setOnes();
  222. Matrix C_plus = C;
  223. Matrix C_minus = C;
  224. Matrix C_assign = C;
  225. Matrix C_plus_ref = C;
  226. Matrix C_minus_ref = C;
  227. Matrix C_assign_ref = C;
  228. for (int start_row_c = 0; start_row_c + kColA < row_stride_c;
  229. ++start_row_c) {
  230. for (int start_col_c = 0; start_col_c + kColB < col_stride_c;
  231. ++start_col_c) {
  232. C_plus_ref.block(start_row_c, start_col_c, kColA, kColB) +=
  233. A.transpose() * B;
  234. FunctorTy<kRowA, kColA, kRowB, kColB, 1, kDimType>()(A.data(),
  235. kRowA,
  236. kColA,
  237. B.data(),
  238. kRowB,
  239. kColB,
  240. C_plus.data(),
  241. start_row_c,
  242. start_col_c,
  243. row_stride_c,
  244. col_stride_c);
  245. EXPECT_NEAR((C_plus_ref - C_plus).norm(), 0.0, kTolerance)
  246. << "C += A' * B \n"
  247. << "row_stride_c : " << row_stride_c << "\n"
  248. << "col_stride_c : " << col_stride_c << "\n"
  249. << "start_row_c : " << start_row_c << "\n"
  250. << "start_col_c : " << start_col_c << "\n"
  251. << "Cref : \n"
  252. << C_plus_ref << "\n"
  253. << "C: \n"
  254. << C_plus;
  255. C_minus_ref.block(start_row_c, start_col_c, kColA, kColB) -=
  256. A.transpose() * B;
  257. FunctorTy<kRowA, kColA, kRowB, kColB, -1, kDimType>()(
  258. A.data(),
  259. kRowA,
  260. kColA,
  261. B.data(),
  262. kRowB,
  263. kColB,
  264. C_minus.data(),
  265. start_row_c,
  266. start_col_c,
  267. row_stride_c,
  268. col_stride_c);
  269. EXPECT_NEAR((C_minus_ref - C_minus).norm(), 0.0, kTolerance)
  270. << "C -= A' * B \n"
  271. << "row_stride_c : " << row_stride_c << "\n"
  272. << "col_stride_c : " << col_stride_c << "\n"
  273. << "start_row_c : " << start_row_c << "\n"
  274. << "start_col_c : " << start_col_c << "\n"
  275. << "Cref : \n"
  276. << C_minus_ref << "\n"
  277. << "C: \n"
  278. << C_minus;
  279. C_assign_ref.block(start_row_c, start_col_c, kColA, kColB) =
  280. A.transpose() * B;
  281. FunctorTy<kRowA, kColA, kRowB, kColB, 0, kDimType>()(
  282. A.data(),
  283. kRowA,
  284. kColA,
  285. B.data(),
  286. kRowB,
  287. kColB,
  288. C_assign.data(),
  289. start_row_c,
  290. start_col_c,
  291. row_stride_c,
  292. col_stride_c);
  293. EXPECT_NEAR((C_assign_ref - C_assign).norm(), 0.0, kTolerance)
  294. << "C = A' * B \n"
  295. << "row_stride_c : " << row_stride_c << "\n"
  296. << "col_stride_c : " << col_stride_c << "\n"
  297. << "start_row_c : " << start_row_c << "\n"
  298. << "start_col_c : " << start_col_c << "\n"
  299. << "Cref : \n"
  300. << C_assign_ref << "\n"
  301. << "C: \n"
  302. << C_assign;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. };
  309. TEST(BLAS, MatrixMatrixMultiply_5_3_7) {
  310. TestMatrixFunctions<5, 3, 7, DimType::Static, MatrixMatrixMultiplyTy>()();
  311. }
  312. TEST(BLAS, MatrixMatrixMultiply_5_3_7_Dynamic) {
  313. TestMatrixFunctions<5, 3, 7, DimType::Dynamic, MatrixMatrixMultiplyTy>()();
  314. }
  315. TEST(BLAS, MatrixMatrixMultiply_1_1_1) {
  316. TestMatrixFunctions<1, 1, 1, DimType::Static, MatrixMatrixMultiplyTy>()();
  317. }
  318. TEST(BLAS, MatrixMatrixMultiply_1_1_1_Dynamic) {
  319. TestMatrixFunctions<1, 1, 1, DimType::Dynamic, MatrixMatrixMultiplyTy>()();
  320. }
  321. TEST(BLAS, MatrixMatrixMultiply_9_9_9) {
  322. TestMatrixFunctions<9, 9, 9, DimType::Static, MatrixMatrixMultiplyTy>()();
  323. }
  324. TEST(BLAS, MatrixMatrixMultiply_9_9_9_Dynamic) {
  325. TestMatrixFunctions<9, 9, 9, DimType::Dynamic, MatrixMatrixMultiplyTy>()();
  326. }
  327. TEST(BLAS, MatrixMatrixMultiplyNaive_5_3_7) {
  328. TestMatrixFunctions<5,
  329. 3,
  330. 7,
  331. DimType::Static,
  332. MatrixMatrixMultiplyNaiveTy>()();
  333. }
  334. TEST(BLAS, MatrixMatrixMultiplyNaive_5_3_7_Dynamic) {
  335. TestMatrixFunctions<5,
  336. 3,
  337. 7,
  338. DimType::Dynamic,
  339. MatrixMatrixMultiplyNaiveTy>()();
  340. }
  341. TEST(BLAS, MatrixMatrixMultiplyNaive_1_1_1) {
  342. TestMatrixFunctions<1,
  343. 1,
  344. 1,
  345. DimType::Static,
  346. MatrixMatrixMultiplyNaiveTy>()();
  347. }
  348. TEST(BLAS, MatrixMatrixMultiplyNaive_1_1_1_Dynamic) {
  349. TestMatrixFunctions<1,
  350. 1,
  351. 1,
  352. DimType::Dynamic,
  353. MatrixMatrixMultiplyNaiveTy>()();
  354. }
  355. TEST(BLAS, MatrixMatrixMultiplyNaive_9_9_9) {
  356. TestMatrixFunctions<9,
  357. 9,
  358. 9,
  359. DimType::Static,
  360. MatrixMatrixMultiplyNaiveTy>()();
  361. }
  362. TEST(BLAS, MatrixMatrixMultiplyNaive_9_9_9_Dynamic) {
  363. TestMatrixFunctions<9,
  364. 9,
  365. 9,
  366. DimType::Dynamic,
  367. MatrixMatrixMultiplyNaiveTy>()();
  368. }
  369. TEST(BLAS, MatrixTransposeMatrixMultiply_5_3_7) {
  370. TestMatrixTransposeFunctions<5,
  371. 3,
  372. 7,
  373. DimType::Static,
  374. MatrixTransposeMatrixMultiplyTy>()();
  375. }
  376. TEST(BLAS, MatrixTransposeMatrixMultiply_5_3_7_Dynamic) {
  377. TestMatrixTransposeFunctions<5,
  378. 3,
  379. 7,
  380. DimType::Dynamic,
  381. MatrixTransposeMatrixMultiplyTy>()();
  382. }
  383. TEST(BLAS, MatrixTransposeMatrixMultiply_1_1_1) {
  384. TestMatrixTransposeFunctions<1,
  385. 1,
  386. 1,
  387. DimType::Static,
  388. MatrixTransposeMatrixMultiplyTy>()();
  389. }
  390. TEST(BLAS, MatrixTransposeMatrixMultiply_1_1_1_Dynamic) {
  391. TestMatrixTransposeFunctions<1,
  392. 1,
  393. 1,
  394. DimType::Dynamic,
  395. MatrixTransposeMatrixMultiplyTy>()();
  396. }
  397. TEST(BLAS, MatrixTransposeMatrixMultiply_9_9_9) {
  398. TestMatrixTransposeFunctions<9,
  399. 9,
  400. 9,
  401. DimType::Static,
  402. MatrixTransposeMatrixMultiplyTy>()();
  403. }
  404. TEST(BLAS, MatrixTransposeMatrixMultiply_9_9_9_Dynamic) {
  405. TestMatrixTransposeFunctions<9,
  406. 9,
  407. 9,
  408. DimType::Dynamic,
  409. MatrixTransposeMatrixMultiplyTy>()();
  410. }
  411. TEST(BLAS, MatrixTransposeMatrixMultiplyNaive_5_3_7) {
  412. TestMatrixTransposeFunctions<5,
  413. 3,
  414. 7,
  415. DimType::Static,
  416. MatrixTransposeMatrixMultiplyNaiveTy>()();
  417. }
  418. TEST(BLAS, MatrixTransposeMatrixMultiplyNaive_5_3_7_Dynamic) {
  419. TestMatrixTransposeFunctions<5,
  420. 3,
  421. 7,
  422. DimType::Dynamic,
  423. MatrixTransposeMatrixMultiplyNaiveTy>()();
  424. }
  425. TEST(BLAS, MatrixTransposeMatrixMultiplyNaive_1_1_1) {
  426. TestMatrixTransposeFunctions<1,
  427. 1,
  428. 1,
  429. DimType::Static,
  430. MatrixTransposeMatrixMultiplyNaiveTy>()();
  431. }
  432. TEST(BLAS, MatrixTransposeMatrixMultiplyNaive_1_1_1_Dynamic) {
  433. TestMatrixTransposeFunctions<1,
  434. 1,
  435. 1,
  436. DimType::Dynamic,
  437. MatrixTransposeMatrixMultiplyNaiveTy>()();
  438. }
  439. TEST(BLAS, MatrixTransposeMatrixMultiplyNaive_9_9_9) {
  440. TestMatrixTransposeFunctions<9,
  441. 9,
  442. 9,
  443. DimType::Static,
  444. MatrixTransposeMatrixMultiplyNaiveTy>()();
  445. }
  446. TEST(BLAS, MatrixTransposeMatrixMultiplyNaive_9_9_9_Dynamic) {
  447. TestMatrixTransposeFunctions<9,
  448. 9,
  449. 9,
  450. DimType::Dynamic,
  451. MatrixTransposeMatrixMultiplyNaiveTy>()();
  452. }
  453. TEST(BLAS, MatrixVectorMultiply) {
  454. for (int num_rows_a = 1; num_rows_a < 10; ++num_rows_a) {
  455. for (int num_cols_a = 1; num_cols_a < 10; ++num_cols_a) {
  456. Matrix A(num_rows_a, num_cols_a);
  457. A.setOnes();
  458. Vector b(num_cols_a);
  459. b.setOnes();
  460. Vector c(num_rows_a);
  461. c.setOnes();
  462. Vector c_plus = c;
  463. Vector c_minus = c;
  464. Vector c_assign = c;
  465. Vector c_plus_ref = c;
  466. Vector c_minus_ref = c;
  467. Vector c_assign_ref = c;
  468. // clang-format off
  469. c_plus_ref += A * b;
  470. MatrixVectorMultiply<Eigen::Dynamic, Eigen::Dynamic, 1>(
  471. A.data(), num_rows_a, num_cols_a,
  472. b.data(),
  473. c_plus.data());
  474. EXPECT_NEAR((c_plus_ref - c_plus).norm(), 0.0, kTolerance)
  475. << "c += A * b \n"
  476. << "c_ref : \n" << c_plus_ref << "\n"
  477. << "c: \n" << c_plus;
  478. c_minus_ref -= A * b;
  479. MatrixVectorMultiply<Eigen::Dynamic, Eigen::Dynamic, -1>(
  480. A.data(), num_rows_a, num_cols_a,
  481. b.data(),
  482. c_minus.data());
  483. EXPECT_NEAR((c_minus_ref - c_minus).norm(), 0.0, kTolerance)
  484. << "c -= A * b \n"
  485. << "c_ref : \n" << c_minus_ref << "\n"
  486. << "c: \n" << c_minus;
  487. c_assign_ref = A * b;
  488. MatrixVectorMultiply<Eigen::Dynamic, Eigen::Dynamic, 0>(
  489. A.data(), num_rows_a, num_cols_a,
  490. b.data(),
  491. c_assign.data());
  492. EXPECT_NEAR((c_assign_ref - c_assign).norm(), 0.0, kTolerance)
  493. << "c = A * b \n"
  494. << "c_ref : \n" << c_assign_ref << "\n"
  495. << "c: \n" << c_assign;
  496. // clang-format on
  497. }
  498. }
  499. }
  500. TEST(BLAS, MatrixTransposeVectorMultiply) {
  501. for (int num_rows_a = 1; num_rows_a < 10; ++num_rows_a) {
  502. for (int num_cols_a = 1; num_cols_a < 10; ++num_cols_a) {
  503. Matrix A(num_rows_a, num_cols_a);
  504. A.setRandom();
  505. Vector b(num_rows_a);
  506. b.setRandom();
  507. Vector c(num_cols_a);
  508. c.setOnes();
  509. Vector c_plus = c;
  510. Vector c_minus = c;
  511. Vector c_assign = c;
  512. Vector c_plus_ref = c;
  513. Vector c_minus_ref = c;
  514. Vector c_assign_ref = c;
  515. // clang-format off
  516. c_plus_ref += A.transpose() * b;
  517. MatrixTransposeVectorMultiply<Eigen::Dynamic, Eigen::Dynamic, 1>(
  518. A.data(), num_rows_a, num_cols_a,
  519. b.data(),
  520. c_plus.data());
  521. EXPECT_NEAR((c_plus_ref - c_plus).norm(), 0.0, kTolerance)
  522. << "c += A' * b \n"
  523. << "c_ref : \n" << c_plus_ref << "\n"
  524. << "c: \n" << c_plus;
  525. c_minus_ref -= A.transpose() * b;
  526. MatrixTransposeVectorMultiply<Eigen::Dynamic, Eigen::Dynamic, -1>(
  527. A.data(), num_rows_a, num_cols_a,
  528. b.data(),
  529. c_minus.data());
  530. EXPECT_NEAR((c_minus_ref - c_minus).norm(), 0.0, kTolerance)
  531. << "c -= A' * b \n"
  532. << "c_ref : \n" << c_minus_ref << "\n"
  533. << "c: \n" << c_minus;
  534. c_assign_ref = A.transpose() * b;
  535. MatrixTransposeVectorMultiply<Eigen::Dynamic, Eigen::Dynamic, 0>(
  536. A.data(), num_rows_a, num_cols_a,
  537. b.data(),
  538. c_assign.data());
  539. EXPECT_NEAR((c_assign_ref - c_assign).norm(), 0.0, kTolerance)
  540. << "c = A' * b \n"
  541. << "c_ref : \n" << c_assign_ref << "\n"
  542. << "c: \n" << c_assign;
  543. // clang-format on
  544. }
  545. }
  546. }
  547. } // namespace internal
  548. } // namespace ceres