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"
|
|
|
|
|
2015-10-30 22:07:50 +08:00
|
|
|
template<typename T>
|
|
|
|
int get_random_size()
|
|
|
|
{
|
|
|
|
const int factor = NumTraits<T>::ReadCost;
|
|
|
|
const int max_test_size = EIGEN_TEST_MAX_SIZE>2*factor ? EIGEN_TEST_MAX_SIZE/factor : EIGEN_TEST_MAX_SIZE;
|
|
|
|
return internal::random<int>(1,max_test_size);
|
|
|
|
}
|
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
template<typename Scalar, int Mode, int TriOrder, int OtherOrder, int ResOrder, int OtherCols>
|
2015-10-30 22:07:50 +08:00
|
|
|
void trmm(int rows=get_random_size<Scalar>(),
|
|
|
|
int cols=get_random_size<Scalar>(),
|
|
|
|
int otherCols = OtherCols==Dynamic?get_random_size<Scalar>():OtherCols)
|
2009-07-27 17:42:54 +08:00
|
|
|
{
|
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
|
|
|
|
2018-02-09 23:52:35 +08:00
|
|
|
TriMatrix mat(rows,cols), tri(rows,cols), triTr(cols,rows), s1tri(rows,cols), s1triTr(cols,rows);
|
2011-03-28 23:45:16 +08:00
|
|
|
|
|
|
|
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>();
|
2018-02-09 23:52:35 +08:00
|
|
|
s1tri = (s1*mat).template triangularView<Mode>();
|
|
|
|
s1triTr = (s1*mat).transpose().template triangularView<Mode>();
|
2011-03-28 23:45:16 +08:00
|
|
|
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);
|
2015-10-30 22:07:50 +08:00
|
|
|
|
2018-02-09 23:52:35 +08:00
|
|
|
if((Mode&UnitDiag)==0)
|
|
|
|
VERIFY_IS_APPROX( ge_xs.noalias() = (s1*mat.adjoint()).template triangularView<Mode>() * (s2*ge_left.transpose()), s1*triTr.conjugate() * (s2*ge_left.transpose()));
|
2011-03-28 23:45:16 +08:00
|
|
|
|
2018-02-09 23:52:35 +08:00
|
|
|
VERIFY_IS_APPROX( ge_xs.noalias() = (s1*mat.transpose()).template triangularView<Mode>() * (s2*ge_left.transpose()), s1triTr * (s2*ge_left.transpose()));
|
|
|
|
VERIFY_IS_APPROX( ge_sx.noalias() = (s2*ge_left) * (s1*mat).template triangularView<Mode>(), (s2*ge_left)*s1tri);
|
2015-10-30 22:07:50 +08:00
|
|
|
|
2018-02-09 23:52:35 +08:00
|
|
|
VERIFY_IS_APPROX( ge_sx.noalias() = ge_right.transpose() * mat.adjoint().template triangularView<Mode>(), ge_right.transpose() * triTr.conjugate());
|
|
|
|
VERIFY_IS_APPROX( ge_sx.noalias() = ge_right.adjoint() * mat.adjoint().template triangularView<Mode>(), ge_right.adjoint() * triTr.conjugate());
|
|
|
|
|
|
|
|
ge_xs_save = ge_xs;
|
|
|
|
if((Mode&UnitDiag)==0)
|
|
|
|
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()) );
|
2011-03-31 21:32:21 +08:00
|
|
|
ge_xs_save = ge_xs;
|
2018-02-09 23:52:35 +08:00
|
|
|
VERIFY_IS_APPROX( (ge_xs_save + s1triTr * (s2*ge_left.adjoint())).eval(), ge_xs.noalias() += (s1*mat.transpose()).template triangularView<Mode>() * (s2*ge_left.adjoint()) );
|
2013-08-02 06:36:06 +08:00
|
|
|
ge_sx.setRandom();
|
2011-03-31 21:32:21 +08:00
|
|
|
ge_sx_save = ge_sx;
|
2018-02-09 23:52:35 +08:00
|
|
|
if((Mode&UnitDiag)==0)
|
|
|
|
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
|
|
|
|
2018-02-09 23:52:35 +08:00
|
|
|
if((Mode&UnitDiag)==0)
|
|
|
|
VERIFY_IS_APPROX( ge_xs = (s1*mat).adjoint().template triangularView<Mode>() * ge_left.adjoint(), numext::conj(s1) * triTr.conjugate() * ge_left.adjoint());
|
|
|
|
VERIFY_IS_APPROX( ge_xs = (s1*mat).transpose().template triangularView<Mode>() * ge_left.adjoint(), s1triTr * ge_left.adjoint());
|
|
|
|
|
2011-03-28 23:45:16 +08:00
|
|
|
|
|
|
|
// 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>
|
2015-10-30 22:07:50 +08:00
|
|
|
void trmv(int rows=get_random_size<Scalar>(), int cols=get_random_size<Scalar>())
|
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>
|
2015-10-30 22:07:50 +08:00
|
|
|
void trmm(int rows=get_random_size<Scalar>(), int cols=get_random_size<Scalar>(), int otherCols = get_random_size<Scalar>())
|
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)
|
|
|
|
|
|
|
|
|
2018-07-17 20:46:15 +08:00
|
|
|
EIGEN_DECLARE_TEST(product_trmm)
|
2009-07-27 17:42:54 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|