// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #define EIGEN_DEBUG_ASSIGN #include "main.h" #include std::string demangle_traversal(int t) { if(t==DefaultTraversal) return "DefaultTraversal"; if(t==LinearTraversal) return "LinearTraversal"; if(t==InnerVectorizedTraversal) return "InnerVectorizedTraversal"; if(t==LinearVectorizedTraversal) return "LinearVectorizedTraversal"; if(t==SliceVectorizedTraversal) return "SliceVectorizedTraversal"; return "?"; } std::string demangle_unrolling(int t) { if(t==NoUnrolling) return "NoUnrolling"; if(t==InnerUnrolling) return "InnerUnrolling"; if(t==CompleteUnrolling) return "CompleteUnrolling"; return "?"; } template bool test_assign(const Dst&, const Src&, int traversal, int unrolling) { ei_assign_traits::debug(); bool res = ei_assign_traits::Traversal==traversal && ei_assign_traits::Unrolling==unrolling; if(!res) { std::cerr << " Expected Traversal == " << demangle_traversal(traversal) << " got " << demangle_traversal(ei_assign_traits::Traversal) << "\n"; std::cerr << " Expected Unrolling == " << demangle_unrolling(unrolling) << " got " << demangle_unrolling(ei_assign_traits::Unrolling) << "\n"; } return res; } template bool test_assign(int traversal, int unrolling) { ei_assign_traits::debug(); bool res = ei_assign_traits::Traversal==traversal && ei_assign_traits::Unrolling==unrolling; if(!res) { std::cerr << " Expected Traversal == " << demangle_traversal(traversal) << " got " << demangle_traversal(ei_assign_traits::Traversal) << "\n"; std::cerr << " Expected Unrolling == " << demangle_unrolling(unrolling) << " got " << demangle_unrolling(ei_assign_traits::Unrolling) << "\n"; } return res; } template bool test_redux(const Xpr&, int traversal, int unrolling) { typedef ei_redux_traits,Xpr> traits; bool res = traits::Traversal==traversal && traits::Unrolling==unrolling; if(!res) { std::cerr << " Expected Traversal == " << demangle_traversal(traversal) << " got " << demangle_traversal(traits::Traversal) << "\n"; std::cerr << " Expected Unrolling == " << demangle_unrolling(unrolling) << " got " << demangle_unrolling(traits::Unrolling) << "\n"; } return res; } template::Vectorizable> struct vectorization_logic { enum { PacketSize = ei_packet_traits::size }; static void run() { typedef Matrix Vector1; typedef Matrix VectorX; typedef Matrix MatrixXX; typedef Matrix Matrix11; typedef Matrix Matrix22; typedef Matrix Matrix44; typedef Matrix Matrix44u; typedef Matrix Matrix44c; typedef Matrix Matrix44r; typedef Matrix Matrix1; typedef Matrix Matrix1u; typedef Matrix Matrix3; VERIFY(test_assign(Vector1(),Vector1(), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Vector1(),Vector1()+Vector1(), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Vector1(),Vector1().cwiseProduct(Vector1()), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Vector1(),Vector1().template cast(), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Vector1(),Vector1(), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Vector1(),Vector1()+Vector1(), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Vector1(),Vector1().cwiseProduct(Vector1()), InnerVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Matrix44(),Matrix44()+Matrix44(), InnerVectorizedTraversal,InnerUnrolling)); VERIFY(test_assign(Matrix44u(),Matrix44()+Matrix44(), LinearTraversal,NoUnrolling)); VERIFY(test_assign(Matrix1u(),Matrix1()+Matrix1(), LinearTraversal,CompleteUnrolling)); if(PacketSize>1) { VERIFY(test_assign(Matrix3(),Matrix3().cwiseQuotient(Matrix3()), LinearVectorizedTraversal,CompleteUnrolling)); VERIFY(test_assign(Matrix(),Matrix()+Matrix(), LinearTraversal,NoUnrolling)); VERIFY(test_assign(Matrix11(),Matrix().template block(2,3)+Matrix().template block(10,4), DefaultTraversal,CompleteUnrolling)); } VERIFY(test_assign(MatrixXX(10,10),MatrixXX(20,20).block(10,10,2,3), SliceVectorizedTraversal,NoUnrolling)); VERIFY((test_assign< Map >, Matrix22 >(InnerVectorizedTraversal,CompleteUnrolling))); VERIFY((test_assign< Map >, Matrix22 >(DefaultTraversal,CompleteUnrolling))); VERIFY(test_redux(VectorX(10), LinearVectorizedTraversal,NoUnrolling)); VERIFY(test_redux(Matrix3(), LinearVectorizedTraversal,CompleteUnrolling)); VERIFY(test_redux(Matrix44(), LinearVectorizedTraversal,NoUnrolling)); VERIFY(test_redux(Matrix44().template block(1,2), DefaultTraversal,CompleteUnrolling)); VERIFY(test_redux(Matrix44c().template block<2*PacketSize,1>(1,2), LinearVectorizedTraversal,CompleteUnrolling)); VERIFY(test_redux(Matrix44r().template block<1,2*PacketSize>(2,1), LinearVectorizedTraversal,CompleteUnrolling)); } }; template struct vectorization_logic { static void run() {} }; void test_vectorization_logic() { #ifdef EIGEN_VECTORIZE vectorization_logic::run(); vectorization_logic::run(); vectorization_logic >::run(); vectorization_logic >::run(); if(ei_packet_traits::Vectorizable) { VERIFY(test_assign(Matrix(),Matrix()+Matrix(), LinearTraversal,CompleteUnrolling)); VERIFY(test_redux(Matrix(), DefaultTraversal,CompleteUnrolling)); } if(ei_packet_traits::Vectorizable) { VERIFY(test_assign(Matrix(),Matrix()+Matrix(), LinearTraversal,CompleteUnrolling)); VERIFY(test_redux(Matrix(), DefaultTraversal,CompleteUnrolling)); } #endif // EIGEN_VECTORIZE }