blkdiag.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include <test_common.h>
  9. #include <igl/blkdiag.h>
  10. TEST_CASE("blkdiag: 3-matrices", "[igl]")
  11. {
  12. const Eigen::MatrixXd Ygt=
  13. (Eigen::MatrixXd(3+0+2,3+2+5)<<
  14. 1,2,3,0,0,0,0,0,0,0,
  15. 4,5,6,0,0,0,0,0,0,0,
  16. 7,8,9,0,0,0,0,0,0,0,
  17. 0,0,0,0,0,0,1,2,3,4,
  18. 0,0,0,0,0,5,6,7,8,9).finished();
  19. Eigen::MatrixXd A(3,3);
  20. A<<1,2,3,4,5,6,7,8,9;
  21. // This is the correct behavior for a 0×n matrix
  22. Eigen::MatrixXd B(0,2);
  23. Eigen::MatrixXd C(2,5);
  24. C<<0,1,2,3,4,5,6,7,8,9;
  25. Eigen::MatrixXd Y;
  26. igl::blkdiag({A,B,C},Y);
  27. test_common::assert_eq(Y,Ygt);
  28. {
  29. Eigen::SparseMatrix<double> sA = A.sparseView();
  30. Eigen::SparseMatrix<double> sB = B.sparseView();
  31. Eigen::SparseMatrix<double> sC = C.sparseView();
  32. Eigen::SparseMatrix<double> sY;
  33. igl::blkdiag({sA,sB,sC},sY);
  34. Y = sY;
  35. test_common::assert_eq(Y,Ygt);
  36. }
  37. }