00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "main.h"
00026
00027 template<typename VectorType> void map_class_vector(const VectorType& m)
00028 {
00029 typedef typename VectorType::Scalar Scalar;
00030
00031 int size = m.size();
00032
00033
00034 Scalar* array1 = ei_aligned_new<Scalar>(size);
00035 Scalar* array2 = ei_aligned_new<Scalar>(size);
00036 Scalar* array3 = new Scalar[size+1];
00037 Scalar* array3unaligned = std::size_t(array3)%16 == 0 ? array3+1 : array3;
00038
00039 Map<VectorType, Aligned>(array1, size) = VectorType::Random(size);
00040 Map<VectorType>(array2, size) = Map<VectorType>(array1, size);
00041 Map<VectorType>(array3unaligned, size) = Map<VectorType>((const Scalar*)array1, size);
00042 VectorType ma1 = Map<VectorType>(array1, size);
00043 VectorType ma2 = Map<VectorType, Aligned>(array2, size);
00044 VectorType ma3 = Map<VectorType>(array3unaligned, size);
00045 VERIFY_IS_APPROX(ma1, ma2);
00046 VERIFY_IS_APPROX(ma1, ma3);
00047
00048 ei_aligned_delete(array1, size);
00049 ei_aligned_delete(array2, size);
00050 delete[] array3;
00051 }
00052
00053 template<typename MatrixType> void map_class_matrix(const MatrixType& m)
00054 {
00055 typedef typename MatrixType::Scalar Scalar;
00056
00057 int rows = m.rows(), cols = m.cols(), size = rows*cols;
00058
00059
00060 Scalar* array1 = ei_aligned_new<Scalar>(size);
00061 for(int i = 0; i < size; i++) array1[i] = Scalar(1);
00062 Scalar* array2 = ei_aligned_new<Scalar>(size);
00063 for(int i = 0; i < size; i++) array2[i] = Scalar(1);
00064 Scalar* array3 = new Scalar[size+1];
00065 for(int i = 0; i < size+1; i++) array3[i] = Scalar(1);
00066 Scalar* array3unaligned = std::size_t(array3)%16 == 0 ? array3+1 : array3;
00067 Map<MatrixType, Aligned>(array1, rows, cols) = MatrixType::Ones(rows,cols);
00068 Map<MatrixType>(array2, rows, cols) = Map<MatrixType>((const Scalar*)array1, rows, cols);
00069 Map<MatrixType>(array3unaligned, rows, cols) = Map<MatrixType>(array1, rows, cols);
00070 MatrixType ma1 = Map<MatrixType>(array1, rows, cols);
00071 MatrixType ma2 = Map<MatrixType, Aligned>(array2, rows, cols);
00072 VERIFY_IS_APPROX(ma1, ma2);
00073 MatrixType ma3 = Map<MatrixType>(array3unaligned, rows, cols);
00074 VERIFY_IS_APPROX(ma1, ma3);
00075
00076 ei_aligned_delete(array1, size);
00077 ei_aligned_delete(array2, size);
00078 delete[] array3;
00079 }
00080
00081 template<typename VectorType> void map_static_methods(const VectorType& m)
00082 {
00083 typedef typename VectorType::Scalar Scalar;
00084
00085 int size = m.size();
00086
00087
00088 Scalar* array1 = ei_aligned_new<Scalar>(size);
00089 Scalar* array2 = ei_aligned_new<Scalar>(size);
00090 Scalar* array3 = new Scalar[size+1];
00091 Scalar* array3unaligned = std::size_t(array3)%16 == 0 ? array3+1 : array3;
00092
00093 VectorType::MapAligned(array1, size) = VectorType::Random(size);
00094 VectorType::Map(array2, size) = VectorType::Map(array1, size);
00095 VectorType::Map(array3unaligned, size) = VectorType::Map(array1, size);
00096 VectorType ma1 = VectorType::Map(array1, size);
00097 VectorType ma2 = VectorType::MapAligned(array2, size);
00098 VectorType ma3 = VectorType::Map(array3unaligned, size);
00099 VERIFY_IS_APPROX(ma1, ma2);
00100 VERIFY_IS_APPROX(ma1, ma3);
00101
00102 ei_aligned_delete(array1, size);
00103 ei_aligned_delete(array2, size);
00104 delete[] array3;
00105 }
00106
00107
00108 void test_eigen2_map()
00109 {
00110 for(int i = 0; i < g_repeat; i++) {
00111 CALL_SUBTEST_1( map_class_vector(Matrix<float, 1, 1>()) );
00112 CALL_SUBTEST_2( map_class_vector(Vector4d()) );
00113 CALL_SUBTEST_3( map_class_vector(RowVector4f()) );
00114 CALL_SUBTEST_4( map_class_vector(VectorXcf(8)) );
00115 CALL_SUBTEST_5( map_class_vector(VectorXi(12)) );
00116
00117 CALL_SUBTEST_1( map_class_matrix(Matrix<float, 1, 1>()) );
00118 CALL_SUBTEST_2( map_class_matrix(Matrix4d()) );
00119 CALL_SUBTEST_6( map_class_matrix(Matrix<float,3,5>()) );
00120 CALL_SUBTEST_4( map_class_matrix(MatrixXcf(ei_random<int>(1,10),ei_random<int>(1,10))) );
00121 CALL_SUBTEST_5( map_class_matrix(MatrixXi(ei_random<int>(1,10),ei_random<int>(1,10))) );
00122
00123 CALL_SUBTEST_1( map_static_methods(Matrix<double, 1, 1>()) );
00124 CALL_SUBTEST_2( map_static_methods(Vector3f()) );
00125 CALL_SUBTEST_7( map_static_methods(RowVector3d()) );
00126 CALL_SUBTEST_4( map_static_methods(VectorXcd(8)) );
00127 CALL_SUBTEST_5( map_static_methods(VectorXf(12)) );
00128 }
00129 }