1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This file is part of Eigen, a lightweight C++ template library
2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// for linear algebra.
3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This Source Code Form is subject to the terms of the Mozilla
7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Public License v. 2.0. If a copy of the MPL was not distributed
8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#include "main.h"
11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar, int Mode, int TriOrder, int OtherOrder, int ResOrder, int OtherCols>
13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid trmm(int rows=internal::random<int>(1,EIGEN_TEST_MAX_SIZE),
14c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          int cols=internal::random<int>(1,EIGEN_TEST_MAX_SIZE),
15c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath          int otherCols = OtherCols==Dynamic?internal::random<int>(1,EIGEN_TEST_MAX_SIZE):OtherCols)
16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef Matrix<Scalar,Dynamic,Dynamic,TriOrder> TriMatrix;
18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef Matrix<Scalar,Dynamic,OtherCols,OtherCols==1?ColMajor:OtherOrder> OnTheRight;
19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef Matrix<Scalar,OtherCols,Dynamic,OtherCols==1?RowMajor:OtherOrder> OnTheLeft;
20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
21c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef Matrix<Scalar,Dynamic,OtherCols,OtherCols==1?ColMajor:ResOrder> ResXS;
22c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef Matrix<Scalar,OtherCols,Dynamic,OtherCols==1?RowMajor:ResOrder> ResSX;
23c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
24c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  TriMatrix  mat(rows,cols), tri(rows,cols), triTr(cols,rows);
25c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
26c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  OnTheRight  ge_right(cols,otherCols);
27c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  OnTheLeft   ge_left(otherCols,rows);
28c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  ResSX       ge_sx, ge_sx_save;
29c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  ResXS       ge_xs, ge_xs_save;
30c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
31c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  Scalar s1 = internal::random<Scalar>(),
32c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath         s2 = internal::random<Scalar>();
33c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
34c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  mat.setRandom();
35c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  tri = mat.template triangularView<Mode>();
36c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  triTr = mat.transpose().template triangularView<Mode>();
37c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  ge_right.setRandom();
38c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  ge_left.setRandom();
39c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
40c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_xs = mat.template triangularView<Mode>() * ge_right, tri * ge_right);
41c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_sx = ge_left * mat.template triangularView<Mode>(), ge_left * tri);
42c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
43c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_xs.noalias() = mat.template triangularView<Mode>() * ge_right, tri * ge_right);
44c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_sx.noalias() = ge_left * mat.template triangularView<Mode>(), ge_left * tri);
45c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
46c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_xs.noalias() = (s1*mat.adjoint()).template triangularView<Mode>() * (s2*ge_left.transpose()), s1*triTr.conjugate() * (s2*ge_left.transpose()));
47c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_sx.noalias() = ge_right.transpose() * mat.adjoint().template triangularView<Mode>(), ge_right.transpose() * triTr.conjugate());
48c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
49c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_xs.noalias() = (s1*mat.adjoint()).template triangularView<Mode>() * (s2*ge_left.adjoint()), s1*triTr.conjugate() * (s2*ge_left.adjoint()));
50c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  VERIFY_IS_APPROX( ge_sx.noalias() = ge_right.adjoint() * mat.adjoint().template triangularView<Mode>(), ge_right.adjoint() * triTr.conjugate());
51c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
52c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  ge_xs_save = ge_xs;
53c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  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()) );
547faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  ge_sx.setRandom();
55c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  ge_sx_save = ge_sx;
56c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  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());
57c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
587faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  VERIFY_IS_APPROX( ge_xs = (s1*mat).adjoint().template triangularView<Mode>() * ge_left.adjoint(), numext::conj(s1) * triTr.conjugate() * ge_left.adjoint());
59c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
60c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  // TODO check with sub-matrix expressions ?
61c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
62c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
63c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar, int Mode, int TriOrder>
64c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid trmv(int rows=internal::random<int>(1,EIGEN_TEST_MAX_SIZE), int cols=internal::random<int>(1,EIGEN_TEST_MAX_SIZE))
65c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
66c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  trmm<Scalar,Mode,TriOrder,ColMajor,ColMajor,1>(rows,cols,1);
67c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
68c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
69c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar, int Mode, int TriOrder, int OtherOrder, int ResOrder>
70c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid 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))
71c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
72c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  trmm<Scalar,Mode,TriOrder,OtherOrder,ResOrder,Dynamic>(rows,cols,otherCols);
73c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
74c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
75c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#define CALL_ALL_ORDERS(NB,SCALAR,MODE)                                             \
76c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,ColMajor,ColMajor>()));  \
77c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,ColMajor,RowMajor>()));  \
78c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,RowMajor,ColMajor>()));  \
79c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, ColMajor,RowMajor,RowMajor>()));  \
80c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,ColMajor,ColMajor>()));  \
81c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,ColMajor,RowMajor>()));  \
82c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,RowMajor,ColMajor>()));  \
83c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_,NB)((trmm<SCALAR, MODE, RowMajor,RowMajor,RowMajor>()));  \
84c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  \
85c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_1,NB)((trmv<SCALAR, MODE, ColMajor>()));                   \
86c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_CAT(CALL_SUBTEST_1,NB)((trmv<SCALAR, MODE, RowMajor>()));
87c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
88c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
89c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#define CALL_ALL(NB,SCALAR)                 \
90c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  CALL_ALL_ORDERS(EIGEN_CAT(1,NB),SCALAR,Upper)          \
91c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  CALL_ALL_ORDERS(EIGEN_CAT(2,NB),SCALAR,UnitUpper)      \
92c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  CALL_ALL_ORDERS(EIGEN_CAT(3,NB),SCALAR,StrictlyUpper)  \
93c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  CALL_ALL_ORDERS(EIGEN_CAT(1,NB),SCALAR,Lower)          \
94c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  CALL_ALL_ORDERS(EIGEN_CAT(2,NB),SCALAR,UnitLower)      \
95c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  CALL_ALL_ORDERS(EIGEN_CAT(3,NB),SCALAR,StrictlyLower)
96c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
97c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
98c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid test_product_trmm()
99c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
100c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  for(int i = 0; i < g_repeat ; i++)
101c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
102c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CALL_ALL(1,float);                //  EIGEN_SUFFIXES;11;111;21;121;31;131
103c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CALL_ALL(2,double);               //  EIGEN_SUFFIXES;12;112;22;122;32;132
104c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CALL_ALL(3,std::complex<float>);  //  EIGEN_SUFFIXES;13;113;23;123;33;133
105c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    CALL_ALL(4,std::complex<double>); //  EIGEN_SUFFIXES;14;114;24;124;34;134
106c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
107c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
108