dontalign.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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::Scalar Scalar;
  20. typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
  21. typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
  22. Index rows = m.rows();
  23. Index cols = m.cols();
  24. MatrixType a = MatrixType::Random(rows,cols);
  25. SquareMatrixType square = SquareMatrixType::Random(rows,rows);
  26. VectorType v = VectorType::Random(rows);
  27. VERIFY_IS_APPROX(v, square * square.colPivHouseholderQr().solve(v));
  28. square = square.inverse().eval();
  29. a = square * a;
  30. square = square*square;
  31. v = square * v;
  32. v = a.adjoint() * v;
  33. VERIFY(square.determinant() != Scalar(0));
  34. // bug 219: MapAligned() was giving an assert with EIGEN_DONT_ALIGN, because Map Flags were miscomputed
  35. Scalar* array = internal::aligned_new<Scalar>(rows);
  36. v = VectorType::MapAligned(array, rows);
  37. internal::aligned_delete(array, rows);
  38. }
  39. void test_dontalign()
  40. {
  41. #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_5
  42. dontalign(Matrix3d());
  43. dontalign(Matrix4f());
  44. #elif defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_6
  45. dontalign(Matrix3cd());
  46. dontalign(Matrix4cf());
  47. #elif defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_7
  48. dontalign(Matrix<float, 32, 32>());
  49. dontalign(Matrix<std::complex<float>, 32, 32>());
  50. #elif defined EIGEN_TEST_PART_4 || defined EIGEN_TEST_PART_8
  51. dontalign(MatrixXd(32, 32));
  52. dontalign(MatrixXcf(32, 32));
  53. #endif
  54. }