2007-12-16 02:16:30 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
// for linear algebra. Eigen itself is part of the KDE project.
|
|
|
|
//
|
2008-01-07 17:34:21 +08:00
|
|
|
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
|
2007-12-16 02:16:30 +08:00
|
|
|
//
|
2008-02-28 23:44:45 +08:00
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
2008-05-22 20:18:55 +08:00
|
|
|
// License as published by the Free Software Foundation; either
|
2008-02-28 23:44:45 +08:00
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2008-05-22 20:18:55 +08:00
|
|
|
// published by the Free Software Foundation; either version 2 of
|
2008-02-28 23:44:45 +08:00
|
|
|
// the License, or (at your option) any later version.
|
2007-12-16 02:16:30 +08:00
|
|
|
//
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-02-28 23:44:45 +08:00
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
// GNU General Public License for more details.
|
2007-12-16 02:16:30 +08:00
|
|
|
//
|
2008-05-22 20:18:55 +08:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
2008-02-28 23:44:45 +08:00
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
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;
|
|
|
|
typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime> RowVectorType;
|
2007-12-16 02:16:30 +08:00
|
|
|
int rows = m.rows();
|
|
|
|
int cols = m.cols();
|
2008-05-22 20:18:55 +08:00
|
|
|
|
2008-02-28 20:38:12 +08:00
|
|
|
int r = ei_random<int>(0, rows-1), r2 = ei_random<int>(0, rows-1), c = ei_random<int>(0, cols-1);
|
2007-12-16 02:16:30 +08:00
|
|
|
VERIFY_IS_APPROX(MatrixType::ones(rows,cols)(r,c), static_cast<Scalar>(1));
|
|
|
|
MatrixType m1 = MatrixType::ones(rows,cols);
|
|
|
|
VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
|
|
|
|
VectorType v1 = VectorType::random(rows);
|
|
|
|
v1[0];
|
2008-03-13 01:17:36 +08:00
|
|
|
Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime>
|
2008-01-05 18:57:14 +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));
|
|
|
|
square = MatrixType::zero(rows, rows);
|
|
|
|
square.diagonal() = VectorType::ones(rows);
|
2008-01-11 23:56:21 +08:00
|
|
|
VERIFY_IS_APPROX(square, MatrixType::identity(rows, rows));
|
2007-12-16 02:16:30 +08:00
|
|
|
}
|
|
|
|
|
2008-05-22 20:18:55 +08:00
|
|
|
void 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++) {
|
|
|
|
CALL_SUBTEST( miscMatrices(Matrix<float, 1, 1>()) );
|
|
|
|
CALL_SUBTEST( miscMatrices(Matrix4d()) );
|
|
|
|
CALL_SUBTEST( miscMatrices(MatrixXcf(3, 3)) );
|
|
|
|
CALL_SUBTEST( miscMatrices(MatrixXi(8, 12)) );
|
|
|
|
CALL_SUBTEST( miscMatrices(MatrixXcd(20, 20)) );
|
2007-12-16 02:16:30 +08:00
|
|
|
}
|
|
|
|
}
|