2009-07-27 17:42:54 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
// for linear algebra.
|
|
|
|
//
|
2010-06-25 05:21:58 +08:00
|
|
|
// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-07-27 17:42:54 +08:00
|
|
|
//
|
2012-07-14 02:42:47 +08:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2009-07-27 17:42:54 +08:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
template<typename Scalar, int Mode, int TriOrder, int OtherOrder, int ResOrder, int OtherCols>
|
2011-07-12 20:41:00 +08:00
|
|
|
void trmm(int rows=internal::random<int>(1,EIGEN_TEST_MAX_SIZE),
|
|
|
|
int cols=internal::random<int>(1,EIGEN_TEST_MAX_SIZE),
|
|
|
|
int otherCols = OtherCols==Dynamic?internal::random<int>(1,EIGEN_TEST_MAX_SIZE):OtherCols)
|
2009-07-27 17:42:54 +08:00
|
|
|
{
|
|
|
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
typedef Matrix<Scalar,Dynamic,Dynamic,TriOrder> TriMatrix;
|
|
|
|
typedef Matrix<Scalar,Dynamic,OtherCols,OtherCols==1?ColMajor:OtherOrder> OnTheRight;
|
|
|
|
typedef Matrix<Scalar,OtherCols,Dynamic,OtherCols==1?RowMajor:OtherOrder> OnTheLeft;
|
|
|
|
|
|
|
|
typedef Matrix<Scalar,Dynamic,OtherCols,OtherCols==1?ColMajor:ResOrder> ResXS;
|
|
|
|
typedef Matrix<Scalar,OtherCols,Dynamic,OtherCols==1?RowMajor:ResOrder> ResSX;
|
2010-06-16 04:00:34 +08:00
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
TriMatrix mat(rows,cols), tri(rows,cols), triTr(cols,rows);
|
|
|
|
|
|
|
|
OnTheRight ge_right(cols,otherCols);
|
|
|
|
OnTheLeft ge_left(otherCols,rows);
|
2011-03-31 21:32:21 +08:00
|
|
|
ResSX ge_sx, ge_sx_save;
|
|
|
|
ResXS ge_xs, ge_xs_save;
|
2009-07-27 17:42:54 +08:00
|
|
|
|
2010-10-25 22:15:22 +08:00
|
|
|
Scalar s1 = internal::random<Scalar>(),
|
|
|
|
s2 = internal::random<Scalar>();
|
2009-07-27 17:42:54 +08:00
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
mat.setRandom();
|
|
|
|
tri = mat.template triangularView<Mode>();
|
|
|
|
triTr = mat.transpose().template triangularView<Mode>();
|
|
|
|
ge_right.setRandom();
|
|
|
|
ge_left.setRandom();
|
2009-07-27 17:42:54 +08:00
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
VERIFY_IS_APPROX( ge_xs = mat.template triangularView<Mode>() * ge_right, tri * ge_right);
|
|
|
|
VERIFY_IS_APPROX( ge_sx = ge_left * mat.template triangularView<Mode>(), ge_left * tri);
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( ge_xs.noalias() = mat.template triangularView<Mode>() * ge_right, tri * ge_right);
|
|
|
|
VERIFY_IS_APPROX( ge_sx.noalias() = ge_left * mat.template triangularView<Mode>(), ge_left * tri);
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( ge_xs.noalias() = (s1*mat.adjoint()).template triangularView<Mode>() * (s2*ge_left.transpose()), s1*triTr.conjugate() * (s2*ge_left.transpose()));
|
|
|
|
VERIFY_IS_APPROX( ge_sx.noalias() = ge_right.transpose() * mat.adjoint().template triangularView<Mode>(), ge_right.transpose() * triTr.conjugate());
|
|
|
|
|
|
|
|
VERIFY_IS_APPROX( ge_xs.noalias() = (s1*mat.adjoint()).template triangularView<Mode>() * (s2*ge_left.adjoint()), s1*triTr.conjugate() * (s2*ge_left.adjoint()));
|
|
|
|
VERIFY_IS_APPROX( ge_sx.noalias() = ge_right.adjoint() * mat.adjoint().template triangularView<Mode>(), ge_right.adjoint() * triTr.conjugate());
|
|
|
|
|
2011-03-31 21:32:21 +08:00
|
|
|
ge_xs_save = ge_xs;
|
|
|
|
VERIFY_IS_APPROX( (ge_xs_save + s1*triTr.conjugate() * (s2*ge_left.adjoint())).eval(), ge_xs.noalias() += (s1*mat.adjoint()).template triangularView<Mode>() * (s2*ge_left.adjoint()) );
|
|
|
|
ge_sx_save = ge_sx;
|
|
|
|
VERIFY_IS_APPROX( ge_sx_save - (ge_right.adjoint() * (-s1 * triTr).conjugate()).eval(), ge_sx.noalias() -= (ge_right.adjoint() * (-s1 * mat).adjoint().template triangularView<Mode>()).eval());
|
2011-03-28 23:45:16 +08:00
|
|
|
|
|
|
|
VERIFY_IS_APPROX( ge_xs = (s1*mat).adjoint().template triangularView<Mode>() * ge_left.adjoint(), internal::conj(s1) * triTr.conjugate() * ge_left.adjoint());
|
|
|
|
|
|
|
|
// TODO check with sub-matrix expressions ?
|
|
|
|
}
|
2010-06-16 04:00:34 +08:00
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
template<typename Scalar, int Mode, int TriOrder>
|
2011-07-12 20:41:00 +08:00
|
|
|
void trmv(int rows=internal::random<int>(1,EIGEN_TEST_MAX_SIZE), int cols=internal::random<int>(1,EIGEN_TEST_MAX_SIZE))
|
2011-03-28 23:45:16 +08:00
|
|
|
{
|
|
|
|
trmm<Scalar,Mode,TriOrder,ColMajor,ColMajor,1>(rows,cols,1);
|
|
|
|
}
|
2010-07-16 02:39:20 +08:00
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
template<typename Scalar, int Mode, int TriOrder, int OtherOrder, int ResOrder>
|
2011-07-12 20:41:00 +08:00
|
|
|
void trmm(int rows=internal::random<int>(1,EIGEN_TEST_MAX_SIZE), int cols=internal::random<int>(1,EIGEN_TEST_MAX_SIZE), int otherCols = internal::random<int>(1,EIGEN_TEST_MAX_SIZE))
|
2011-03-28 23:45:16 +08:00
|
|
|
{
|
|
|
|
trmm<Scalar,Mode,TriOrder,OtherOrder,ResOrder,Dynamic>(rows,cols,otherCols);
|
2009-07-27 17:42:54 +08:00
|
|
|
}
|
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
#define CALL_ALL_ORDERS(NB,SCALAR,MODE) \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,ColMajor,ColMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,ColMajor,RowMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,RowMajor,ColMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,RowMajor,RowMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,ColMajor,ColMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,ColMajor,RowMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,RowMajor,ColMajor>())); \
|
|
|
|
EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,RowMajor,RowMajor>())); \
|
|
|
|
\
|
2011-07-12 20:41:00 +08:00
|
|
|
EIGEN_CAT(CALL_SUBTEST_1,NB)((trmv<SCALAR, MODE, ColMajor>())); \
|
2011-03-28 23:45:16 +08:00
|
|
|
EIGEN_CAT(CALL_SUBTEST_1,NB)((trmv<SCALAR, MODE, RowMajor>()));
|
|
|
|
|
|
|
|
|
|
|
|
#define CALL_ALL(NB,SCALAR) \
|
|
|
|
CALL_ALL_ORDERS(EIGEN_CAT(1,NB),SCALAR,Upper) \
|
|
|
|
CALL_ALL_ORDERS(EIGEN_CAT(2,NB),SCALAR,UnitUpper) \
|
|
|
|
CALL_ALL_ORDERS(EIGEN_CAT(3,NB),SCALAR,StrictlyUpper) \
|
|
|
|
CALL_ALL_ORDERS(EIGEN_CAT(1,NB),SCALAR,Lower) \
|
|
|
|
CALL_ALL_ORDERS(EIGEN_CAT(2,NB),SCALAR,UnitLower) \
|
|
|
|
CALL_ALL_ORDERS(EIGEN_CAT(3,NB),SCALAR,StrictlyLower)
|
|
|
|
|
|
|
|
|
2009-07-27 17:42:54 +08:00
|
|
|
void test_product_trmm()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < g_repeat ; i++)
|
|
|
|
{
|
2011-03-28 23:45:16 +08:00
|
|
|
CALL_ALL(1,float); // EIGEN_SUFFIXES;11;111;21;121;31;131
|
|
|
|
CALL_ALL(2,double); // EIGEN_SUFFIXES;12;112;22;122;32;132
|
|
|
|
CALL_ALL(3,std::complex<float>); // EIGEN_SUFFIXES;13;113;23;123;33;133
|
|
|
|
CALL_ALL(4,std::complex<double>); // EIGEN_SUFFIXES;14;114;24;124;34;134
|
2009-07-27 17:42:54 +08:00
|
|
|
}
|
|
|
|
}
|