dontalign.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_4
00026 #define EIGEN_DONT_ALIGN
00027 #elif defined EIGEN_TEST_PART_5 || defined EIGEN_TEST_PART_6 || defined EIGEN_TEST_PART_7 || defined EIGEN_TEST_PART_8
00028 #define EIGEN_DONT_ALIGN_STATICALLY
00029 #endif
00030 
00031 #include "main.h"
00032 #include <Eigen/Dense>
00033 
00034 template<typename MatrixType>
00035 void dontalign(const MatrixType& m)
00036 {
00037   typedef typename MatrixType::Index Index;
00038   typedef typename MatrixType::Scalar Scalar;
00039   typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
00040   typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType;
00041 
00042   Index rows = m.rows();
00043   Index cols = m.cols();
00044 
00045   MatrixType a = MatrixType::Random(rows,cols);
00046   SquareMatrixType square = SquareMatrixType::Random(rows,rows);
00047   VectorType v = VectorType::Random(rows);
00048 
00049   VERIFY_IS_APPROX(v, square * square.colPivHouseholderQr().solve(v));
00050   square = square.inverse().eval();
00051   a = square * a;
00052   square = square*square;
00053   v = square * v;
00054   v = a.adjoint() * v;
00055   VERIFY(square.determinant() != Scalar(0));
00056 
00057   // bug 219: MapAligned() was giving an assert with EIGEN_DONT_ALIGN, because Map Flags were miscomputed
00058   Scalar* array = internal::aligned_new<Scalar>(rows);
00059   v = VectorType::MapAligned(array, rows);
00060   internal::aligned_delete(array, rows);
00061 }
00062 
00063 void test_dontalign()
00064 {
00065 #if defined EIGEN_TEST_PART_1 || defined EIGEN_TEST_PART_5
00066   dontalign(Matrix3d());
00067   dontalign(Matrix4f());
00068 #elif defined EIGEN_TEST_PART_2 || defined EIGEN_TEST_PART_6
00069   dontalign(Matrix3cd());
00070   dontalign(Matrix4cf());
00071 #elif defined EIGEN_TEST_PART_3 || defined EIGEN_TEST_PART_7
00072   dontalign(Matrix<float, 32, 32>());
00073   dontalign(Matrix<std::complex<float>, 32, 32>());
00074 #elif defined EIGEN_TEST_PART_4 || defined EIGEN_TEST_PART_8
00075   dontalign(MatrixXd(32, 32));
00076   dontalign(MatrixXcf(32, 32));
00077 #endif
00078 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:02