xref: /aosp_15_r20/external/eigen/test/dontalign.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2011 Benoit Jacob <[email protected]>
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 
10 #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_4
11 #define EIGEN_DONT_ALIGN
12 #elif defined EIGEN_TEST_PART_5 || defined EIGEN_TEST_PART_6 || defined EIGEN_TEST_PART_7 || defined EIGEN_TEST_PART_8
13 #define EIGEN_DONT_ALIGN_STATICALLY
14 #endif
15 
16 #include "main.h"
17 #include <Eigen/Dense>
18 
19 template<typename MatrixType>
dontalign(const MatrixType & m)20 void dontalign(const MatrixType& m)
21 {
22   typedef typename MatrixType::Scalar Scalar;
23   typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
24   typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
25 
26   Index rows = m.rows();
27   Index cols = m.cols();
28 
29   MatrixType a = MatrixType::Random(rows,cols);
30   SquareMatrixType square = SquareMatrixType::Random(rows,rows);
31   VectorType v = VectorType::Random(rows);
32 
33   VERIFY_IS_APPROX(v, square * square.colPivHouseholderQr().solve(v));
34   square = square.inverse().eval();
35   a = square * a;
36   square = square*square;
37   v = square * v;
38   v = a.adjoint() * v;
39   VERIFY(square.determinant() != Scalar(0));
40 
41   // bug 219: MapAligned() was giving an assert with EIGEN_DONT_ALIGN, because Map Flags were miscomputed
42   Scalar* array = internal::aligned_new<Scalar>(rows);
43   v = VectorType::MapAligned(array, rows);
44   internal::aligned_delete(array, rows);
45 }
46 
EIGEN_DECLARE_TEST(dontalign)47 EIGEN_DECLARE_TEST(dontalign)
48 {
49 #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_5
50   dontalign(Matrix3d());
51   dontalign(Matrix4f());
52 #elif defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_6
53   dontalign(Matrix3cd());
54   dontalign(Matrix4cf());
55 #elif defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_7
56   dontalign(Matrix<float, 32, 32>());
57   dontalign(Matrix<std::complex<float>, 32, 32>());
58 #elif defined EIGEN_TEST_PART_4 || defined EIGEN_TEST_PART_8
59   dontalign(MatrixXd(32, 32));
60   dontalign(MatrixXcf(32, 32));
61 #endif
62 }
63