source: pacpussensors/trunk/Vislab/lib3dv/eigen/test/dontalign.cpp@ 138

Last change on this file since 138 was 136, checked in by ldecherf, 8 years ago

Doc

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