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 #define VERIFY_TRSM(TRI,XB) { \
00028 (XB).setRandom(); ref = (XB); \
00029 (TRI).solveInPlace(XB); \
00030 VERIFY_IS_APPROX((TRI).toDenseMatrix() * (XB), ref); \
00031 (XB).setRandom(); ref = (XB); \
00032 (XB) = (TRI).solve(XB); \
00033 VERIFY_IS_APPROX((TRI).toDenseMatrix() * (XB), ref); \
00034 }
00035
00036 #define VERIFY_TRSM_ONTHERIGHT(TRI,XB) { \
00037 (XB).setRandom(); ref = (XB); \
00038 (TRI).transpose().template solveInPlace<OnTheRight>(XB.transpose()); \
00039 VERIFY_IS_APPROX((XB).transpose() * (TRI).transpose().toDenseMatrix(), ref.transpose()); \
00040 (XB).setRandom(); ref = (XB); \
00041 (XB).transpose() = (TRI).transpose().template solve<OnTheRight>(XB.transpose()); \
00042 VERIFY_IS_APPROX((XB).transpose() * (TRI).transpose().toDenseMatrix(), ref.transpose()); \
00043 }
00044
00045 template<typename Scalar,int Size, int Cols> void trsolve(int size=Size,int cols=Cols)
00046 {
00047 typedef typename NumTraits<Scalar>::Real RealScalar;
00048
00049 Matrix<Scalar,Size,Size,ColMajor> cmLhs(size,size);
00050 Matrix<Scalar,Size,Size,RowMajor> rmLhs(size,size);
00051
00052 enum { colmajor = Size==1 ? RowMajor : ColMajor,
00053 rowmajor = Cols==1 ? ColMajor : RowMajor };
00054 Matrix<Scalar,Size,Cols,colmajor> cmRhs(size,cols);
00055 Matrix<Scalar,Size,Cols,rowmajor> rmRhs(size,cols);
00056 Matrix<Scalar,Dynamic,Dynamic,colmajor> ref(size,cols);
00057
00058 cmLhs.setRandom(); cmLhs *= static_cast<RealScalar>(0.1); cmLhs.diagonal().array() += static_cast<RealScalar>(1);
00059 rmLhs.setRandom(); rmLhs *= static_cast<RealScalar>(0.1); rmLhs.diagonal().array() += static_cast<RealScalar>(1);
00060
00061 VERIFY_TRSM(cmLhs.conjugate().template triangularView<Lower>(), cmRhs);
00062 VERIFY_TRSM(cmLhs.adjoint() .template triangularView<Lower>(), cmRhs);
00063 VERIFY_TRSM(cmLhs .template triangularView<Upper>(), cmRhs);
00064 VERIFY_TRSM(cmLhs .template triangularView<Lower>(), rmRhs);
00065 VERIFY_TRSM(cmLhs.conjugate().template triangularView<Upper>(), rmRhs);
00066 VERIFY_TRSM(cmLhs.adjoint() .template triangularView<Upper>(), rmRhs);
00067
00068 VERIFY_TRSM(cmLhs.conjugate().template triangularView<UnitLower>(), cmRhs);
00069 VERIFY_TRSM(cmLhs .template triangularView<UnitUpper>(), rmRhs);
00070
00071 VERIFY_TRSM(rmLhs .template triangularView<Lower>(), cmRhs);
00072 VERIFY_TRSM(rmLhs.conjugate().template triangularView<UnitUpper>(), rmRhs);
00073
00074
00075 VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView<Lower>(), cmRhs);
00076 VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView<Upper>(), cmRhs);
00077 VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView<Lower>(), rmRhs);
00078 VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView<Upper>(), rmRhs);
00079
00080 VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView<UnitLower>(), cmRhs);
00081 VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView<UnitUpper>(), rmRhs);
00082
00083 VERIFY_TRSM_ONTHERIGHT(rmLhs .template triangularView<Lower>(), cmRhs);
00084 VERIFY_TRSM_ONTHERIGHT(rmLhs.conjugate().template triangularView<UnitUpper>(), rmRhs);
00085
00086 int c = internal::random<int>(0,cols-1);
00087 VERIFY_TRSM(rmLhs.template triangularView<Lower>(), rmRhs.col(c));
00088 VERIFY_TRSM(cmLhs.template triangularView<Lower>(), rmRhs.col(c));
00089 }
00090
00091 void test_product_trsolve()
00092 {
00093 for(int i = 0; i < g_repeat ; i++)
00094 {
00095
00096 CALL_SUBTEST_1((trsolve<float,Dynamic,Dynamic>(internal::random<int>(1,320),internal::random<int>(1,320))));
00097 CALL_SUBTEST_2((trsolve<double,Dynamic,Dynamic>(internal::random<int>(1,320),internal::random<int>(1,320))));
00098 CALL_SUBTEST_3((trsolve<std::complex<float>,Dynamic,Dynamic>(internal::random<int>(1,200),internal::random<int>(1,200))));
00099 CALL_SUBTEST_4((trsolve<std::complex<double>,Dynamic,Dynamic>(internal::random<int>(1,200),internal::random<int>(1,200))));
00100
00101
00102 CALL_SUBTEST_1((trsolve<float,Dynamic,1>(internal::random<int>(1,320))));
00103 CALL_SUBTEST_5((trsolve<std::complex<double>,Dynamic,1>(internal::random<int>(1,320))));
00104 CALL_SUBTEST_6((trsolve<float,1,1>()));
00105 CALL_SUBTEST_7((trsolve<float,1,2>()));
00106 CALL_SUBTEST_8((trsolve<std::complex<float>,4,1>()));
00107 }
00108 }