1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2006-2008 Benoit Jacob <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li
10*bf2c3715SXin Li #include "main.h"
11*bf2c3715SXin Li
miscMatrices(const MatrixType & m)12*bf2c3715SXin Li template<typename MatrixType> void miscMatrices(const MatrixType& m)
13*bf2c3715SXin Li {
14*bf2c3715SXin Li /* this test covers the following files:
15*bf2c3715SXin Li DiagonalMatrix.h Ones.h
16*bf2c3715SXin Li */
17*bf2c3715SXin Li typedef typename MatrixType::Scalar Scalar;
18*bf2c3715SXin Li typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
19*bf2c3715SXin Li Index rows = m.rows();
20*bf2c3715SXin Li Index cols = m.cols();
21*bf2c3715SXin Li
22*bf2c3715SXin Li Index r = internal::random<Index>(0, rows-1), r2 = internal::random<Index>(0, rows-1), c = internal::random<Index>(0, cols-1);
23*bf2c3715SXin Li VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1));
24*bf2c3715SXin Li MatrixType m1 = MatrixType::Ones(rows,cols);
25*bf2c3715SXin Li VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
26*bf2c3715SXin Li VectorType v1 = VectorType::Random(rows);
27*bf2c3715SXin Li v1[0];
28*bf2c3715SXin Li Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
29*bf2c3715SXin Li square(v1.asDiagonal());
30*bf2c3715SXin Li if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]);
31*bf2c3715SXin Li else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1));
32*bf2c3715SXin Li square = MatrixType::Zero(rows, rows);
33*bf2c3715SXin Li square.diagonal() = VectorType::Ones(rows);
34*bf2c3715SXin Li VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows));
35*bf2c3715SXin Li }
36*bf2c3715SXin Li
EIGEN_DECLARE_TEST(miscmatrices)37*bf2c3715SXin Li EIGEN_DECLARE_TEST(miscmatrices)
38*bf2c3715SXin Li {
39*bf2c3715SXin Li for(int i = 0; i < g_repeat; i++) {
40*bf2c3715SXin Li CALL_SUBTEST_1( miscMatrices(Matrix<float, 1, 1>()) );
41*bf2c3715SXin Li CALL_SUBTEST_2( miscMatrices(Matrix4d()) );
42*bf2c3715SXin Li CALL_SUBTEST_3( miscMatrices(MatrixXcf(3, 3)) );
43*bf2c3715SXin Li CALL_SUBTEST_4( miscMatrices(MatrixXi(8, 12)) );
44*bf2c3715SXin Li CALL_SUBTEST_5( miscMatrices(MatrixXcd(20, 20)) );
45*bf2c3715SXin Li }
46*bf2c3715SXin Li }
47