Go to the documentation of this file.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 #define EIGEN_NO_STATIC_ASSERT
00026 #include "main.h"
00027
00028 template<typename T>
00029 struct other_matrix_type
00030 {
00031 typedef int type;
00032 };
00033
00034 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00035 struct other_matrix_type<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
00036 {
00037 typedef Matrix<_Scalar, _Rows, _Cols, _Options^RowMajor, _MaxRows, _MaxCols> type;
00038 };
00039
00040 template<typename MatrixType> void swap(const MatrixType& m)
00041 {
00042 typedef typename other_matrix_type<MatrixType>::type OtherMatrixType;
00043 typedef typename MatrixType::Scalar Scalar;
00044
00045 eigen_assert((!internal::is_same<MatrixType,OtherMatrixType>::value));
00046 typename MatrixType::Index rows = m.rows();
00047 typename MatrixType::Index cols = m.cols();
00048
00049
00050 MatrixType m1 = MatrixType::Random(rows,cols);
00051 MatrixType m2 = MatrixType::Random(rows,cols) + Scalar(100) * MatrixType::Identity(rows,cols);
00052 OtherMatrixType m3 = OtherMatrixType::Random(rows,cols) + Scalar(200) * OtherMatrixType::Identity(rows,cols);
00053
00054 MatrixType m1_copy = m1;
00055 MatrixType m2_copy = m2;
00056 OtherMatrixType m3_copy = m3;
00057
00058
00059 m1.swap(m2);
00060 VERIFY_IS_APPROX(m1,m2_copy);
00061 VERIFY_IS_APPROX(m2,m1_copy);
00062 m1 = m1_copy;
00063 m2 = m2_copy;
00064
00065
00066 m1.swap(m3);
00067 VERIFY_IS_APPROX(m1,m3_copy);
00068 VERIFY_IS_APPROX(m3,m1_copy);
00069 m1 = m1_copy;
00070 m3 = m3_copy;
00071
00072
00073 m1.swap(m2.block(0,0,rows,cols));
00074 VERIFY_IS_APPROX(m1,m2_copy);
00075 VERIFY_IS_APPROX(m2,m1_copy);
00076 m1 = m1_copy;
00077 m2 = m2_copy;
00078
00079
00080 m1.transpose().swap(m3.transpose());
00081 VERIFY_IS_APPROX(m1,m3_copy);
00082 VERIFY_IS_APPROX(m3,m1_copy);
00083 m1 = m1_copy;
00084 m3 = m3_copy;
00085
00086
00087 VERIFY_RAISES_ASSERT(m1.swap(m1.row(0)));
00088
00089 VERIFY_RAISES_ASSERT(m1.row(0).swap(m1));
00090 }
00091
00092 void test_swap()
00093 {
00094 CALL_SUBTEST_1( swap(Matrix3f()) );
00095 CALL_SUBTEST_2( swap(Matrix4d()) );
00096 CALL_SUBTEST_3( swap(MatrixXd(3,3)) );
00097 CALL_SUBTEST_4( swap(MatrixXf(30,30)) );
00098 }