From 0590c18555bd5d195e29ee6a131285cf0f80f9d1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 27 Jul 2009 13:17:39 +0200 Subject: various compilation and bug fixes in selfadjoint stuff --- test/product_symm.cpp | 84 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 34 deletions(-) (limited to 'test/product_symm.cpp') diff --git a/test/product_symm.cpp b/test/product_symm.cpp index 3a0cd94d0..54bf91fb9 100644 --- a/test/product_symm.cpp +++ b/test/product_symm.cpp @@ -24,25 +24,43 @@ #include "main.h" -template void symm(const MatrixType& m) +template struct symm_extra { + template + static void run(M1& m1, M1& m2, M2& rhs2, M2& rhs22, M2& rhs23, Scalar s1, Scalar s2) + { + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs22 = (rhs2) * (m2).template selfadjointView(), + rhs23 = (rhs2) * (m1)); + VERIFY_IS_APPROX(rhs22 = (s2*rhs2) * (s1*m2).template selfadjointView(), + rhs23 = (s2*rhs2) * (s1*m1)); + } +}; + +template<> struct symm_extra<1> { + template + static void run(M1& m1, M1& m2, M2& rhs2, M2& rhs22, M2& rhs23, Scalar s1, Scalar s2) {} +}; + +template void symm(int size = Size, int othersize = OtherSize) { - typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; - typedef Matrix Rhs1; - typedef Matrix Rhs2; - typedef Matrix Rhs3; - int rows = m.rows(); - int cols = m.cols(); + typedef Matrix MatrixType; + typedef Matrix Rhs1; + typedef Matrix Rhs2; + typedef Matrix Rhs3; + + int rows = size; + int cols = size; MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols); m1 = (m1+m1.adjoint()).eval(); - Rhs1 rhs1 = Rhs1::Random(cols, ei_random(1,320)), rhs12, rhs13; - Rhs2 rhs2 = Rhs2::Random(ei_random(1,320), rows), rhs22, rhs23; - Rhs3 rhs3 = Rhs3::Random(cols, ei_random(1,320)), rhs32, rhs33; + Rhs1 rhs1 = Rhs1::Random(cols, othersize), rhs12(cols, othersize), rhs13(cols, othersize); + Rhs2 rhs2 = Rhs2::Random(othersize, rows), rhs22(othersize, rows), rhs23(othersize, rows); + Rhs3 rhs3 = Rhs3::Random(cols, othersize), rhs32(cols, othersize), rhs33(cols, othersize); Scalar s1 = ei_random(), s2 = ei_random(); @@ -51,46 +69,44 @@ template void symm(const MatrixType& m) VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs1), rhs13 = (s1*m1) * (s2*rhs1)); - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs1), - rhs13 = (s1*m1) * (s2*rhs1)); + m2 = m1.template triangularView(); rhs12.setRandom(); rhs13 = rhs12; + VERIFY_IS_APPROX(rhs12 += (s1*m2).template selfadjointView() * (s2*rhs1), + rhs13 += (s1*m1) * (s2*rhs1)); m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs22 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), - rhs23 = (s1*m1) * (s2*rhs2.adjoint())); + VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), + rhs13 = (s1*m1) * (s2*rhs2.adjoint())); m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs22 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), - rhs23 = (s1*m1) * (s2*rhs2.adjoint())); + VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), + rhs13 = (s1*m1) * (s2*rhs2.adjoint())); m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs22 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs2.adjoint()), - rhs23 = (s1*m1.adjoint()) * (s2*rhs2.adjoint())); + VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs2.adjoint()), + rhs13 = (s1*m1.adjoint()) * (s2*rhs2.adjoint())); // test row major = <...> - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs32 = (s1*m2).template selfadjointView() * (s2*rhs3), - rhs33 = (s1*m1) * (s2 * rhs3)); + m2 = m1.template triangularView(); rhs12.setRandom(); rhs13 = rhs12; + VERIFY_IS_APPROX(rhs12 -= (s1*m2).template selfadjointView() * (s2*rhs3), + rhs13 -= (s1*m1) * (s2 * rhs3)); m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs32 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs3).conjugate(), - rhs33 = (s1*m1.adjoint()) * (s2*rhs3).conjugate()); + VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs3).conjugate(), + rhs13 = (s1*m1.adjoint()) * (s2*rhs3).conjugate()); // test matrix * selfadjoint - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs22 = (rhs2) * (m2).template selfadjointView(), - rhs23 = (rhs2) * (m1)); - VERIFY_IS_APPROX(rhs22 = (s2*rhs2) * (s1*m2).template selfadjointView(), - rhs23 = (s2*rhs2) * (s1*m1)); + symm_extra::run(m1,m2,rhs2,rhs22,rhs23,s1,s2); + } + void test_product_symm() { for(int i = 0; i < g_repeat ; i++) { - int s; - s = ei_random(10,320); - CALL_SUBTEST( symm(MatrixXf(s, s)) ); - s = ei_random(10,320); - CALL_SUBTEST( symm(MatrixXcd(s, s)) ); + CALL_SUBTEST(( symm(ei_random(10,320),ei_random(10,320)) )); + CALL_SUBTEST(( symm,Dynamic,Dynamic>(ei_random(10,320),ei_random(10,320)) )); + + CALL_SUBTEST(( symm(ei_random(10,320)) )); + CALL_SUBTEST(( symm,Dynamic,1>(ei_random(10,320)) )); } } -- cgit v1.2.3