// This file is triangularView of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-2009 Gael Guennebaud // // 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/. #include "main.h" template void trmv(const MatrixType& m) { typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; typedef Matrix VectorType; RealScalar largerEps = 10*test_precision(); Index rows = m.rows(); Index cols = m.cols(); MatrixType m1 = MatrixType::Random(rows, cols), m3(rows, cols); VectorType v1 = VectorType::Random(rows); Scalar s1 = internal::random(); m1 = MatrixType::Random(rows, cols); // check with a column-major matrix m3 = m1.template triangularView(); VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); // check conjugated and scalar multiple expressions (col-major) m3 = m1.template triangularView(); VERIFY(((s1*m3).conjugate() * v1).isApprox((s1*m1).conjugate().template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3.conjugate() * v1.conjugate()).isApprox(m1.conjugate().template triangularView() * v1.conjugate(), largerEps)); // check with a row-major matrix m3 = m1.template triangularView(); VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); // check conjugated and scalar multiple expressions (row-major) m3 = m1.template triangularView(); VERIFY((m3.adjoint() * v1).isApprox(m1.adjoint().template triangularView() * v1, largerEps)); m3 = m1.template triangularView(); VERIFY((m3.adjoint() * (s1*v1.conjugate())).isApprox(m1.adjoint().template triangularView() * (s1*v1.conjugate()), largerEps)); m3 = m1.template triangularView(); // check transposed cases: m3 = m1.template triangularView(); VERIFY((v1.transpose() * m3).isApprox(v1.transpose() * m1.template triangularView(), largerEps)); VERIFY((v1.adjoint() * m3).isApprox(v1.adjoint() * m1.template triangularView(), largerEps)); VERIFY((v1.adjoint() * m3.adjoint()).isApprox(v1.adjoint() * m1.template triangularView().adjoint(), largerEps)); // TODO check with sub-matrices } void test_product_trmv() { int s = 0; s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat ; i++) { CALL_SUBTEST_1( trmv(Matrix()) ); CALL_SUBTEST_2( trmv(Matrix()) ); CALL_SUBTEST_3( trmv(Matrix3d()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/2); CALL_SUBTEST_4( trmv(MatrixXcf(s,s)) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/2); CALL_SUBTEST_5( trmv(MatrixXcd(s,s)) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE); CALL_SUBTEST_6( trmv(Matrix(s, s)) ); } EIGEN_UNUSED_VARIABLE(s); }