Narayan Kamath | c981c48 | 2012-11-02 10:59:05 +0000 | [diff] [blame] | 1 | // This file is triangularView of Eigen, a lightweight C++ template library |
| 2 | // for linear algebra. |
| 3 | // |
| 4 | // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr> |
| 5 | // |
| 6 | // This Source Code Form is subject to the terms of the Mozilla |
| 7 | // Public License v. 2.0. If a copy of the MPL was not distributed |
| 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | |
| 10 | #include "main.h" |
| 11 | |
| 12 | // This file tests the basic selfadjointView API, |
| 13 | // the related products and decompositions are tested in specific files. |
| 14 | |
| 15 | template<typename MatrixType> void selfadjoint(const MatrixType& m) |
| 16 | { |
| 17 | typedef typename MatrixType::Index Index; |
| 18 | typedef typename MatrixType::Scalar Scalar; |
Narayan Kamath | c981c48 | 2012-11-02 10:59:05 +0000 | [diff] [blame] | 19 | |
| 20 | Index rows = m.rows(); |
| 21 | Index cols = m.cols(); |
| 22 | |
| 23 | MatrixType m1 = MatrixType::Random(rows, cols), |
| 24 | m3(rows, cols); |
| 25 | |
| 26 | m1.diagonal() = m1.diagonal().real().template cast<Scalar>(); |
| 27 | |
| 28 | // check selfadjoint to dense |
| 29 | m3 = m1.template selfadjointView<Upper>(); |
| 30 | VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Upper>()), MatrixType(m1.template triangularView<Upper>())); |
| 31 | VERIFY_IS_APPROX(m3, m3.adjoint()); |
| 32 | |
| 33 | |
| 34 | m3 = m1.template selfadjointView<Lower>(); |
| 35 | VERIFY_IS_APPROX(MatrixType(m3.template triangularView<Lower>()), MatrixType(m1.template triangularView<Lower>())); |
| 36 | VERIFY_IS_APPROX(m3, m3.adjoint()); |
| 37 | } |
| 38 | |
| 39 | void bug_159() |
| 40 | { |
| 41 | Matrix3d m = Matrix3d::Random().selfadjointView<Lower>(); |
| 42 | EIGEN_UNUSED_VARIABLE(m) |
| 43 | } |
| 44 | |
| 45 | void test_selfadjoint() |
| 46 | { |
| 47 | for(int i = 0; i < g_repeat ; i++) |
| 48 | { |
Carlos Hernandez | 7faaa9f | 2014-08-05 17:53:32 -0700 | [diff] [blame] | 49 | int s = internal::random<int>(1,EIGEN_TEST_MAX_SIZE); |
Narayan Kamath | c981c48 | 2012-11-02 10:59:05 +0000 | [diff] [blame] | 50 | |
| 51 | CALL_SUBTEST_1( selfadjoint(Matrix<float, 1, 1>()) ); |
| 52 | CALL_SUBTEST_2( selfadjoint(Matrix<float, 2, 2>()) ); |
| 53 | CALL_SUBTEST_3( selfadjoint(Matrix3cf()) ); |
| 54 | CALL_SUBTEST_4( selfadjoint(MatrixXcd(s,s)) ); |
| 55 | CALL_SUBTEST_5( selfadjoint(Matrix<float,Dynamic,Dynamic,RowMajor>(s, s)) ); |
| 56 | |
Carlos Hernandez | 7faaa9f | 2014-08-05 17:53:32 -0700 | [diff] [blame] | 57 | TEST_SET_BUT_UNUSED_VARIABLE(s) |
Narayan Kamath | c981c48 | 2012-11-02 10:59:05 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | CALL_SUBTEST_1( bug_159() ); |
| 61 | } |