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 #include "main.h"
00026
00027 template<typename MatrixType> void bandmatrix(const MatrixType& _m)
00028 {
00029 typedef typename MatrixType::Index Index;
00030 typedef typename MatrixType::Scalar Scalar;
00031 typedef typename NumTraits<Scalar>::Real RealScalar;
00032 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrixType;
00033
00034 Index rows = _m.rows();
00035 Index cols = _m.cols();
00036 Index supers = _m.supers();
00037 Index subs = _m.subs();
00038
00039 MatrixType m(rows,cols,supers,subs);
00040
00041 DenseMatrixType dm1(rows,cols);
00042 dm1.setZero();
00043
00044 m.diagonal().setConstant(123);
00045 dm1.diagonal().setConstant(123);
00046 for (int i=1; i<=m.supers();++i)
00047 {
00048 m.diagonal(i).setConstant(static_cast<RealScalar>(i));
00049 dm1.diagonal(i).setConstant(static_cast<RealScalar>(i));
00050 }
00051 for (int i=1; i<=m.subs();++i)
00052 {
00053 m.diagonal(-i).setConstant(-static_cast<RealScalar>(i));
00054 dm1.diagonal(-i).setConstant(-static_cast<RealScalar>(i));
00055 }
00056
00057 VERIFY_IS_APPROX(dm1,m.toDenseMatrix());
00058
00059 for (int i=0; i<cols; ++i)
00060 {
00061 m.col(i).setConstant(static_cast<RealScalar>(i+1));
00062 dm1.col(i).setConstant(static_cast<RealScalar>(i+1));
00063 }
00064 Index d = std::min(rows,cols);
00065 Index a = std::max<Index>(0,cols-d-supers);
00066 Index b = std::max<Index>(0,rows-d-subs);
00067 if(a>0) dm1.block(0,d+supers,rows,a).setZero();
00068 dm1.block(0,supers+1,cols-supers-1-a,cols-supers-1-a).template triangularView<Upper>().setZero();
00069 dm1.block(subs+1,0,rows-subs-1-b,rows-subs-1-b).template triangularView<Lower>().setZero();
00070 if(b>0) dm1.block(d+subs,0,b,cols).setZero();
00071
00072 VERIFY_IS_APPROX(dm1,m.toDenseMatrix());
00073
00074 }
00075
00076 using Eigen::internal::BandMatrix;
00077
00078 void test_bandmatrix()
00079 {
00080 typedef BandMatrix<float>::Index Index;
00081
00082 for(int i = 0; i < 10*g_repeat ; i++) {
00083 Index rows = internal::random<Index>(1,10);
00084 Index cols = internal::random<Index>(1,10);
00085 Index sups = internal::random<Index>(0,cols-1);
00086 Index subs = internal::random<Index>(0,rows-1);
00087 CALL_SUBTEST(bandmatrix(BandMatrix<float>(rows,cols,sups,subs)) );
00088 }
00089 }