2007-12-16 02:16:30 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-23 02:25:33 +08:00
|
|
|
// for linear algebra.
|
2007-12-16 02:16:30 +08:00
|
|
|
//
|
2008-11-24 21:40:43 +08:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2007-12-16 02:16:30 +08:00
|
|
|
//
|
2012-07-14 02:42:47 +08:00
|
|
|
// 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/.
|
2007-12-16 02:16:30 +08:00
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
template<typename MatrixType> void miscMatrices(const MatrixType& m)
|
|
|
|
{
|
|
|
|
/* this test covers the following files:
|
|
|
|
DiagonalMatrix.h Ones.h
|
|
|
|
*/
|
|
|
|
typedef typename MatrixType::Scalar Scalar;
|
2008-03-13 01:17:36 +08:00
|
|
|
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
2010-06-20 23:37:56 +08:00
|
|
|
Index rows = m.rows();
|
|
|
|
Index cols = m.cols();
|
2008-05-22 20:18:55 +08:00
|
|
|
|
2010-10-25 22:15:22 +08:00
|
|
|
Index r = internal::random<Index>(0, rows-1), r2 = internal::random<Index>(0, rows-1), c = internal::random<Index>(0, cols-1);
|
2008-07-21 08:34:46 +08:00
|
|
|
VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1));
|
|
|
|
MatrixType m1 = MatrixType::Ones(rows,cols);
|
2007-12-16 02:16:30 +08:00
|
|
|
VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
|
2008-07-21 08:34:46 +08:00
|
|
|
VectorType v1 = VectorType::Random(rows);
|
2007-12-16 02:16:30 +08:00
|
|
|
v1[0];
|
2008-03-13 01:17:36 +08:00
|
|
|
Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
|
2009-06-29 03:27:37 +08:00
|
|
|
square(v1.asDiagonal());
|
2007-12-16 02:16:30 +08:00
|
|
|
if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]);
|
|
|
|
else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1));
|
2008-07-21 08:34:46 +08:00
|
|
|
square = MatrixType::Zero(rows, rows);
|
|
|
|
square.diagonal() = VectorType::Ones(rows);
|
|
|
|
VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows));
|
2007-12-16 02:16:30 +08:00
|
|
|
}
|
|
|
|
|
2018-07-17 20:46:15 +08:00
|
|
|
EIGEN_DECLARE_TEST(miscmatrices)
|
2007-12-16 02:16:30 +08:00
|
|
|
{
|
2008-05-22 20:18:55 +08:00
|
|
|
for(int i = 0; i < g_repeat; i++) {
|
2009-10-29 06:19:29 +08:00
|
|
|
CALL_SUBTEST_1( miscMatrices(Matrix<float, 1, 1>()) );
|
|
|
|
CALL_SUBTEST_2( miscMatrices(Matrix4d()) );
|
|
|
|
CALL_SUBTEST_3( miscMatrices(MatrixXcf(3, 3)) );
|
|
|
|
CALL_SUBTEST_4( miscMatrices(MatrixXi(8, 12)) );
|
|
|
|
CALL_SUBTEST_5( miscMatrices(MatrixXcd(20, 20)) );
|
2007-12-16 02:16:30 +08:00
|
|
|
}
|
|
|
|
}
|