You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.2 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_4
  10. #define EIGEN_DONT_ALIGN
  11. #elif defined EIGEN_TEST_PART_5 || defined EIGEN_TEST_PART_6 || defined EIGEN_TEST_PART_7 || defined EIGEN_TEST_PART_8
  12. #define EIGEN_DONT_ALIGN_STATICALLY
  13. #endif
  14. #include "main.h"
  15. #include <Eigen/Dense>
  16. template<typename MatrixType>
  17. void dontalign(const MatrixType& m)
  18. {
  19. typedef typename MatrixType::Index Index;
  20. typedef typename MatrixType::Scalar Scalar;
  21. typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  22. typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
  23. Index rows = m.rows();
  24. Index cols = m.cols();
  25. MatrixType a = MatrixType::Random(rows,cols);
  26. SquareMatrixType square = SquareMatrixType::Random(rows,rows);
  27. VectorType v = VectorType::Random(rows);
  28. VERIFY_IS_APPROX(v, square * square.colPivHouseholderQr().solve(v));
  29. square = square.inverse().eval();
  30. a = square * a;
  31. square = square*square;
  32. v = square * v;
  33. v = a.adjoint() * v;
  34. VERIFY(square.determinant() != Scalar(0));
  35. // bug 219: MapAligned() was giving an assert with EIGEN_DONT_ALIGN, because Map Flags were miscomputed
  36. Scalar* array = internal::aligned_new<Scalar>(rows);
  37. v = VectorType::MapAligned(array, rows);
  38. internal::aligned_delete(array, rows);
  39. }
  40. void test_dontalign()
  41. {
  42. #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_5
  43. dontalign(Matrix3d());
  44. dontalign(Matrix4f());
  45. #elif defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_6
  46. dontalign(Matrix3cd());
  47. dontalign(Matrix4cf());
  48. #elif defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_7
  49. dontalign(Matrix<float, 32, 32>());
  50. dontalign(Matrix<std::complex<float>, 32, 32>());
  51. #elif defined EIGEN_TEST_PART_4 || defined EIGEN_TEST_PART_8
  52. dontalign(MatrixXd(32, 32));
  53. dontalign(MatrixXcf(32, 32));
  54. #endif
  55. }