mapstaticmethods.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 #include "main.h"
00026 
00027 float *ptr;
00028 const float *const_ptr;
00029 
00030 template<typename PlainObjectType,
00031          bool IsDynamicSize = PlainObjectType::SizeAtCompileTime == Dynamic,
00032          bool IsVector = PlainObjectType::IsVectorAtCompileTime
00033 >
00034 struct mapstaticmethods_impl {};
00035 
00036 template<typename PlainObjectType, bool IsVector>
00037 struct mapstaticmethods_impl<PlainObjectType, false, IsVector>
00038 {
00039   static void run(const PlainObjectType& m)
00040   {
00041     mapstaticmethods_impl<PlainObjectType, true, IsVector>::run(m);
00042 
00043     int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
00044 
00045     PlainObjectType::Map(ptr).setZero();
00046     PlainObjectType::MapAligned(ptr).setZero();
00047     PlainObjectType::Map(const_ptr).sum();
00048     PlainObjectType::MapAligned(const_ptr).sum();
00049 
00050     PlainObjectType::Map(ptr, InnerStride<>(i)).setZero();
00051     PlainObjectType::MapAligned(ptr, InnerStride<>(i)).setZero();
00052     PlainObjectType::Map(const_ptr, InnerStride<>(i)).sum();
00053     PlainObjectType::MapAligned(const_ptr, InnerStride<>(i)).sum();
00054 
00055     PlainObjectType::Map(ptr, InnerStride<2>()).setZero();
00056     PlainObjectType::MapAligned(ptr, InnerStride<3>()).setZero();
00057     PlainObjectType::Map(const_ptr, InnerStride<4>()).sum();
00058     PlainObjectType::MapAligned(const_ptr, InnerStride<5>()).sum();
00059 
00060     PlainObjectType::Map(ptr, OuterStride<>(i)).setZero();
00061     PlainObjectType::MapAligned(ptr, OuterStride<>(i)).setZero();
00062     PlainObjectType::Map(const_ptr, OuterStride<>(i)).sum();
00063     PlainObjectType::MapAligned(const_ptr, OuterStride<>(i)).sum();
00064 
00065     PlainObjectType::Map(ptr, OuterStride<2>()).setZero();
00066     PlainObjectType::MapAligned(ptr, OuterStride<3>()).setZero();
00067     PlainObjectType::Map(const_ptr, OuterStride<4>()).sum();
00068     PlainObjectType::MapAligned(const_ptr, OuterStride<5>()).sum();
00069 
00070     PlainObjectType::Map(ptr, Stride<Dynamic, Dynamic>(i,j)).setZero();
00071     PlainObjectType::MapAligned(ptr, Stride<2,Dynamic>(2,i)).setZero();
00072     PlainObjectType::Map(const_ptr, Stride<Dynamic,3>(i,3)).sum();
00073     PlainObjectType::MapAligned(const_ptr, Stride<Dynamic, Dynamic>(i,j)).sum();
00074 
00075     PlainObjectType::Map(ptr, Stride<2,3>()).setZero();
00076     PlainObjectType::MapAligned(ptr, Stride<3,4>()).setZero();
00077     PlainObjectType::Map(const_ptr, Stride<2,4>()).sum();
00078     PlainObjectType::MapAligned(const_ptr, Stride<5,3>()).sum();
00079   }
00080 };
00081 
00082 template<typename PlainObjectType>
00083 struct mapstaticmethods_impl<PlainObjectType, true, false>
00084 {
00085   static void run(const PlainObjectType& m)
00086   {
00087     int rows = m.rows(), cols = m.cols();
00088 
00089     int i = internal::random<int>(2,5), j = internal::random<int>(2,5);
00090 
00091     PlainObjectType::Map(ptr, rows, cols).setZero();
00092     PlainObjectType::MapAligned(ptr, rows, cols).setZero();
00093     PlainObjectType::Map(const_ptr, rows, cols).sum();
00094     PlainObjectType::MapAligned(const_ptr, rows, cols).sum();
00095 
00096     PlainObjectType::Map(ptr, rows, cols, InnerStride<>(i)).setZero();
00097     PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<>(i)).setZero();
00098     PlainObjectType::Map(const_ptr, rows, cols, InnerStride<>(i)).sum();
00099     PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<>(i)).sum();
00100 
00101     PlainObjectType::Map(ptr, rows, cols, InnerStride<2>()).setZero();
00102     PlainObjectType::MapAligned(ptr, rows, cols, InnerStride<3>()).setZero();
00103     PlainObjectType::Map(const_ptr, rows, cols, InnerStride<4>()).sum();
00104     PlainObjectType::MapAligned(const_ptr, rows, cols, InnerStride<5>()).sum();
00105 
00106     PlainObjectType::Map(ptr, rows, cols, OuterStride<>(i)).setZero();
00107     PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<>(i)).setZero();
00108     PlainObjectType::Map(const_ptr, rows, cols, OuterStride<>(i)).sum();
00109     PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<>(i)).sum();
00110 
00111     PlainObjectType::Map(ptr, rows, cols, OuterStride<2>()).setZero();
00112     PlainObjectType::MapAligned(ptr, rows, cols, OuterStride<3>()).setZero();
00113     PlainObjectType::Map(const_ptr, rows, cols, OuterStride<4>()).sum();
00114     PlainObjectType::MapAligned(const_ptr, rows, cols, OuterStride<5>()).sum();
00115 
00116     PlainObjectType::Map(ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).setZero();
00117     PlainObjectType::MapAligned(ptr, rows, cols, Stride<2,Dynamic>(2,i)).setZero();
00118     PlainObjectType::Map(const_ptr, rows, cols, Stride<Dynamic,3>(i,3)).sum();
00119     PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<Dynamic, Dynamic>(i,j)).sum();
00120 
00121     PlainObjectType::Map(ptr, rows, cols, Stride<2,3>()).setZero();
00122     PlainObjectType::MapAligned(ptr, rows, cols, Stride<3,4>()).setZero();
00123     PlainObjectType::Map(const_ptr, rows, cols, Stride<2,4>()).sum();
00124     PlainObjectType::MapAligned(const_ptr, rows, cols, Stride<5,3>()).sum();
00125   }
00126 };
00127 
00128 template<typename PlainObjectType>
00129 struct mapstaticmethods_impl<PlainObjectType, true, true>
00130 {
00131   static void run(const PlainObjectType& v)
00132   {
00133     int size = v.size();
00134 
00135     int i = internal::random<int>(2,5);
00136 
00137     PlainObjectType::Map(ptr, size).setZero();
00138     PlainObjectType::MapAligned(ptr, size).setZero();
00139     PlainObjectType::Map(const_ptr, size).sum();
00140     PlainObjectType::MapAligned(const_ptr, size).sum();
00141 
00142     PlainObjectType::Map(ptr, size, InnerStride<>(i)).setZero();
00143     PlainObjectType::MapAligned(ptr, size, InnerStride<>(i)).setZero();
00144     PlainObjectType::Map(const_ptr, size, InnerStride<>(i)).sum();
00145     PlainObjectType::MapAligned(const_ptr, size, InnerStride<>(i)).sum();
00146 
00147     PlainObjectType::Map(ptr, size, InnerStride<2>()).setZero();
00148     PlainObjectType::MapAligned(ptr, size, InnerStride<3>()).setZero();
00149     PlainObjectType::Map(const_ptr, size, InnerStride<4>()).sum();
00150     PlainObjectType::MapAligned(const_ptr, size, InnerStride<5>()).sum();
00151   }
00152 };
00153 
00154 template<typename PlainObjectType>
00155 void mapstaticmethods(const PlainObjectType& m)
00156 {
00157   mapstaticmethods_impl<PlainObjectType>::run(m);
00158   VERIFY(true); // just to avoid 'unused function' warning
00159 }
00160 
00161 void test_mapstaticmethods()
00162 {
00163   ptr = internal::aligned_new<float>(1000);
00164   for(int i = 0; i < 1000; i++) ptr[i] = float(i);
00165 
00166   const_ptr = ptr;
00167 
00168   CALL_SUBTEST_1(( mapstaticmethods(Matrix<float, 1, 1>()) ));
00169   CALL_SUBTEST_1(( mapstaticmethods(Vector2f()) ));
00170   CALL_SUBTEST_2(( mapstaticmethods(Vector3f()) ));
00171   CALL_SUBTEST_2(( mapstaticmethods(Matrix2f()) ));
00172   CALL_SUBTEST_3(( mapstaticmethods(Matrix4f()) ));
00173   CALL_SUBTEST_3(( mapstaticmethods(Array4f()) ));
00174   CALL_SUBTEST_4(( mapstaticmethods(Array3f()) ));
00175   CALL_SUBTEST_4(( mapstaticmethods(Array33f()) ));
00176   CALL_SUBTEST_5(( mapstaticmethods(Array44f()) ));
00177   CALL_SUBTEST_5(( mapstaticmethods(VectorXf(1)) ));
00178   CALL_SUBTEST_5(( mapstaticmethods(VectorXf(8)) ));
00179   CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(1,1)) ));
00180   CALL_SUBTEST_6(( mapstaticmethods(MatrixXf(5,7)) ));
00181   CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(1)) ));
00182   CALL_SUBTEST_7(( mapstaticmethods(ArrayXf(5)) ));
00183   CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(1,1)) ));
00184   CALL_SUBTEST_8(( mapstaticmethods(ArrayXXf(8,6)) ));
00185 
00186   internal::aligned_delete(ptr, 1000);
00187 }
00188 


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