Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 1 | // This file is part of Eigen, a lightweight C++ template library |
| 2 | // for linear algebra. Eigen itself is part of the KDE project. |
| 3 | // |
| 4 | // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr> |
| 5 | // |
| 6 | // Eigen is free software; you can redistribute it and/or |
| 7 | // modify it under the terms of the GNU Lesser General Public |
| 8 | // License as published by the Free Software Foundation; either |
| 9 | // version 3 of the License, or (at your option) any later version. |
| 10 | // |
| 11 | // Alternatively, you can redistribute it and/or |
| 12 | // modify it under the terms of the GNU General Public License as |
| 13 | // published by the Free Software Foundation; either version 2 of |
| 14 | // the License, or (at your option) any later version. |
| 15 | // |
| 16 | // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY |
| 17 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the |
| 19 | // GNU General Public License for more details. |
| 20 | // |
| 21 | // You should have received a copy of the GNU Lesser General Public |
| 22 | // License and a copy of the GNU General Public License along with |
| 23 | // Eigen. If not, see <http://www.gnu.org/licenses/>. |
| 24 | |
| 25 | #include "main.h" |
| 26 | #include <typeinfo> |
| 27 | |
| 28 | template<typename Dst, typename Src> |
| 29 | bool test_assign(const Dst&, const Src&, int vectorization, int unrolling) |
| 30 | { |
| 31 | return ei_assign_traits<Dst,Src>::Vectorization==vectorization |
| 32 | && ei_assign_traits<Dst,Src>::Unrolling==unrolling; |
| 33 | } |
| 34 | |
| 35 | template<typename Xpr> |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 36 | bool test_redux(const Xpr&, int vectorization, int unrolling) |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 37 | { |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 38 | typedef ei_redux_traits<ei_scalar_sum_op<typename Xpr::Scalar>,Xpr> traits; |
| 39 | return traits::Vectorization==vectorization && traits::Unrolling==unrolling; |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void test_vectorization_logic() |
| 43 | { |
| 44 | |
| 45 | #ifdef EIGEN_VECTORIZE |
| 46 | |
| 47 | VERIFY(test_assign(Vector4f(),Vector4f(), |
| 48 | InnerVectorization,CompleteUnrolling)); |
| 49 | VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(), |
| 50 | InnerVectorization,CompleteUnrolling)); |
| 51 | VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(), |
| 52 | InnerVectorization,CompleteUnrolling)); |
| 53 | |
| 54 | VERIFY(test_assign(Matrix4f(),Matrix4f(), |
| 55 | InnerVectorization,CompleteUnrolling)); |
| 56 | VERIFY(test_assign(Matrix4f(),Matrix4f()+Matrix4f(), |
| 57 | InnerVectorization,CompleteUnrolling)); |
| 58 | VERIFY(test_assign(Matrix4f(),Matrix4f().cwise() * Matrix4f(), |
| 59 | InnerVectorization,CompleteUnrolling)); |
| 60 | |
| 61 | VERIFY(test_assign(Matrix<float,16,16>(),Matrix<float,16,16>()+Matrix<float,16,16>(), |
| 62 | InnerVectorization,InnerUnrolling)); |
| 63 | |
| 64 | VERIFY(test_assign(Matrix<float,16,16,DontAlign>(),Matrix<float,16,16>()+Matrix<float,16,16>(), |
| 65 | NoVectorization,InnerUnrolling)); |
| 66 | |
| 67 | VERIFY(test_assign(Matrix<float,6,2>(),Matrix<float,6,2>().cwise() / Matrix<float,6,2>(), |
| 68 | LinearVectorization,CompleteUnrolling)); |
| 69 | |
| 70 | VERIFY(test_assign(Matrix<float,17,17>(),Matrix<float,17,17>()+Matrix<float,17,17>(), |
| 71 | NoVectorization,InnerUnrolling)); |
| 72 | |
| 73 | VERIFY(test_assign(Matrix<float,4,4>(),Matrix<float,17,17>().block<4,4>(2,3)+Matrix<float,17,17>().block<4,4>(10,4), |
| 74 | NoVectorization,CompleteUnrolling)); |
| 75 | |
| 76 | VERIFY(test_assign(MatrixXf(10,10),MatrixXf(20,20).block(10,10,2,3), |
| 77 | SliceVectorization,NoUnrolling)); |
| 78 | |
| 79 | |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 80 | VERIFY(test_redux(VectorXf(10), |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 81 | LinearVectorization,NoUnrolling)); |
| 82 | |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 83 | VERIFY(test_redux(Matrix<float,5,2>(), |
Gael Guennebaud | af27fb7 | 2009-01-08 11:53:21 +0000 | [diff] [blame] | 84 | NoVectorization,CompleteUnrolling)); |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 85 | |
| 86 | VERIFY(test_redux(Matrix<float,6,2>(), |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 87 | LinearVectorization,CompleteUnrolling)); |
| 88 | |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 89 | VERIFY(test_redux(Matrix<float,16,16>(), |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 90 | LinearVectorization,NoUnrolling)); |
| 91 | |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 92 | VERIFY(test_redux(Matrix<float,16,16>().block<4,4>(1,2), |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 93 | NoVectorization,CompleteUnrolling)); |
| 94 | |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 95 | VERIFY(test_redux(Matrix<float,16,16>().block<8,1>(1,2), |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 96 | LinearVectorization,CompleteUnrolling)); |
| 97 | |
Gael Guennebaud | c5245a3 | 2009-02-13 08:45:19 +0000 | [diff] [blame] | 98 | VERIFY(test_redux(Matrix<double,7,3>(), |
Gael Guennebaud | cb71dc4 | 2009-01-07 22:20:03 +0000 | [diff] [blame] | 99 | NoVectorization,CompleteUnrolling)); |
| 100 | |
| 101 | #endif // EIGEN_VECTORIZE |
| 102 | |
| 103 | } |