product_syrk.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #include "main.h"
00026 
00027 template<typename MatrixType> void syrk(const MatrixType& m)
00028 {
00029   typedef typename MatrixType::Index Index;
00030   typedef typename MatrixType::Scalar Scalar;
00031   typedef typename NumTraits<Scalar>::Real RealScalar;
00032   typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, Dynamic> Rhs1;
00033   typedef Matrix<Scalar, Dynamic, MatrixType::RowsAtCompileTime> Rhs2;
00034   typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, Dynamic,RowMajor> Rhs3;
00035 
00036   Index rows = m.rows();
00037   Index cols = m.cols();
00038 
00039   MatrixType m1 = MatrixType::Random(rows, cols),
00040              m2 = MatrixType::Random(rows, cols);
00041 
00042   Rhs1 rhs1 = Rhs1::Random(internal::random<int>(1,320), cols);
00043   Rhs2 rhs2 = Rhs2::Random(rows, internal::random<int>(1,320));
00044   Rhs3 rhs3 = Rhs3::Random(internal::random<int>(1,320), rows);
00045 
00046   Scalar s1 = internal::random<Scalar>();
00047   
00048   Index c = internal::random<Index>(0,cols-1);
00049 
00050   m2.setZero();
00051   VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(rhs2,s1)._expression()),
00052                    ((s1 * rhs2 * rhs2.adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00053 
00054   m2.setZero();
00055   VERIFY_IS_APPROX(m2.template selfadjointView<Upper>().rankUpdate(rhs2,s1)._expression(),
00056                    (s1 * rhs2 * rhs2.adjoint()).eval().template triangularView<Upper>().toDenseMatrix());
00057 
00058   m2.setZero();
00059   VERIFY_IS_APPROX(m2.template selfadjointView<Lower>().rankUpdate(rhs1.adjoint(),s1)._expression(),
00060                    (s1 * rhs1.adjoint() * rhs1).eval().template triangularView<Lower>().toDenseMatrix());
00061 
00062   m2.setZero();
00063   VERIFY_IS_APPROX(m2.template selfadjointView<Upper>().rankUpdate(rhs1.adjoint(),s1)._expression(),
00064                    (s1 * rhs1.adjoint() * rhs1).eval().template triangularView<Upper>().toDenseMatrix());
00065 
00066   m2.setZero();
00067   VERIFY_IS_APPROX(m2.template selfadjointView<Lower>().rankUpdate(rhs3.adjoint(),s1)._expression(),
00068                    (s1 * rhs3.adjoint() * rhs3).eval().template triangularView<Lower>().toDenseMatrix());
00069 
00070   m2.setZero();
00071   VERIFY_IS_APPROX(m2.template selfadjointView<Upper>().rankUpdate(rhs3.adjoint(),s1)._expression(),
00072                    (s1 * rhs3.adjoint() * rhs3).eval().template triangularView<Upper>().toDenseMatrix());
00073                    
00074   m2.setZero();
00075   VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(m1.col(c),s1)._expression()),
00076                    ((s1 * m1.col(c) * m1.col(c).adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00077                    
00078   m2.setZero();
00079   VERIFY_IS_APPROX((m2.template selfadjointView<Upper>().rankUpdate(m1.col(c),s1)._expression()),
00080                    ((s1 * m1.col(c) * m1.col(c).adjoint()).eval().template triangularView<Upper>().toDenseMatrix()));
00081   
00082   m2.setZero();
00083   VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(m1.col(c).conjugate(),s1)._expression()),
00084                    ((s1 * m1.col(c).conjugate() * m1.col(c).conjugate().adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00085                    
00086   m2.setZero();
00087   VERIFY_IS_APPROX((m2.template selfadjointView<Upper>().rankUpdate(m1.col(c).conjugate(),s1)._expression()),
00088                    ((s1 * m1.col(c).conjugate() * m1.col(c).conjugate().adjoint()).eval().template triangularView<Upper>().toDenseMatrix()));
00089   
00090   m2.setZero();
00091   VERIFY_IS_APPROX((m2.template selfadjointView<Lower>().rankUpdate(m1.row(c),s1)._expression()),
00092                    ((s1 * m1.row(c).transpose() * m1.row(c).transpose().adjoint()).eval().template triangularView<Lower>().toDenseMatrix()));
00093   
00094   m2.setZero();
00095   VERIFY_IS_APPROX((m2.template selfadjointView<Upper>().rankUpdate(m1.row(c).adjoint(),s1)._expression()),
00096                    ((s1 * m1.row(c).adjoint() * m1.row(c).adjoint().adjoint()).eval().template triangularView<Upper>().toDenseMatrix()));
00097 }
00098 
00099 void test_product_syrk()
00100 {
00101   for(int i = 0; i < g_repeat ; i++)
00102   {
00103     int s;
00104     s = internal::random<int>(1,320);
00105     CALL_SUBTEST_1( syrk(MatrixXf(s, s)) );
00106     s = internal::random<int>(1,320);
00107     CALL_SUBTEST_2( syrk(MatrixXd(s, s)) );
00108     s = internal::random<int>(1,200);
00109     CALL_SUBTEST_3( syrk(MatrixXcf(s, s)) );
00110     s = internal::random<int>(1,200);
00111     CALL_SUBTEST_4( syrk(MatrixXcd(s, s)) );
00112   }
00113 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:11