mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -10,105 +10,95 @@
|
||||
#include "main.h"
|
||||
#include <Eigen/SVD>
|
||||
|
||||
template <typename MatrixType>
|
||||
void check_generateRandomUnitaryMatrix(const Index dim) {
|
||||
const MatrixType Q = generateRandomUnitaryMatrix<MatrixType>(dim);
|
||||
|
||||
template<typename MatrixType>
|
||||
void check_generateRandomUnitaryMatrix(const Index dim)
|
||||
{
|
||||
const MatrixType Q = generateRandomUnitaryMatrix<MatrixType>(dim);
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(Q.rows(), dim);
|
||||
VERIFY_IS_EQUAL(Q.cols(), dim);
|
||||
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(Q.rows(), dim);
|
||||
VERIFY_IS_EQUAL(Q.cols(), dim);
|
||||
|
||||
VERIFY_IS_UNITARY(Q);
|
||||
VERIFY_IS_UNITARY(Q);
|
||||
}
|
||||
|
||||
template<typename VectorType, typename RealScalarType>
|
||||
void check_setupRandomSvs(const Index dim, const RealScalarType max)
|
||||
{
|
||||
const VectorType v = setupRandomSvs<VectorType, RealScalarType>(dim, max);
|
||||
template <typename VectorType, typename RealScalarType>
|
||||
void check_setupRandomSvs(const Index dim, const RealScalarType max) {
|
||||
const VectorType v = setupRandomSvs<VectorType, RealScalarType>(dim, max);
|
||||
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(v.size(), dim);
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(v.size(), dim);
|
||||
|
||||
// check entries
|
||||
for(Index i = 0; i < v.size(); ++i)
|
||||
VERIFY_GE(v(i), 0);
|
||||
for(Index i = 0; i < v.size()-1; ++i)
|
||||
VERIFY_GE(v(i), v(i+1));
|
||||
// check entries
|
||||
for (Index i = 0; i < v.size(); ++i) VERIFY_GE(v(i), 0);
|
||||
for (Index i = 0; i < v.size() - 1; ++i) VERIFY_GE(v(i), v(i + 1));
|
||||
}
|
||||
|
||||
template<typename VectorType, typename RealScalarType>
|
||||
void check_setupRangeSvs(const Index dim, const RealScalarType min, const RealScalarType max)
|
||||
{
|
||||
const VectorType v = setupRangeSvs<VectorType, RealScalarType>(dim, min, max);
|
||||
template <typename VectorType, typename RealScalarType>
|
||||
void check_setupRangeSvs(const Index dim, const RealScalarType min, const RealScalarType max) {
|
||||
const VectorType v = setupRangeSvs<VectorType, RealScalarType>(dim, min, max);
|
||||
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(v.size(), dim);
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(v.size(), dim);
|
||||
|
||||
// check entries
|
||||
if(dim == 1) {
|
||||
VERIFY_IS_APPROX(v(0), min);
|
||||
} else {
|
||||
VERIFY_IS_APPROX(v(0), max);
|
||||
VERIFY_IS_APPROX(v(dim-1), min);
|
||||
}
|
||||
for(Index i = 0; i < v.size()-1; ++i)
|
||||
VERIFY_GE(v(i), v(i+1));
|
||||
// check entries
|
||||
if (dim == 1) {
|
||||
VERIFY_IS_APPROX(v(0), min);
|
||||
} else {
|
||||
VERIFY_IS_APPROX(v(0), max);
|
||||
VERIFY_IS_APPROX(v(dim - 1), min);
|
||||
}
|
||||
for (Index i = 0; i < v.size() - 1; ++i) VERIFY_GE(v(i), v(i + 1));
|
||||
}
|
||||
|
||||
template<typename MatrixType, typename RealScalar, typename RealVectorType>
|
||||
void check_generateRandomMatrixSvs(const Index rows, const Index cols, const Index diag_size,
|
||||
const RealScalar min_svs, const RealScalar max_svs)
|
||||
{
|
||||
RealVectorType svs = setupRangeSvs<RealVectorType, RealScalar>(diag_size, min_svs, max_svs);
|
||||
template <typename MatrixType, typename RealScalar, typename RealVectorType>
|
||||
void check_generateRandomMatrixSvs(const Index rows, const Index cols, const Index diag_size, const RealScalar min_svs,
|
||||
const RealScalar max_svs) {
|
||||
RealVectorType svs = setupRangeSvs<RealVectorType, RealScalar>(diag_size, min_svs, max_svs);
|
||||
|
||||
MatrixType M = MatrixType::Zero(rows, cols);
|
||||
generateRandomMatrixSvs(svs, rows, cols, M);
|
||||
MatrixType M = MatrixType::Zero(rows, cols);
|
||||
generateRandomMatrixSvs(svs, rows, cols, M);
|
||||
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(M.rows(), rows);
|
||||
VERIFY_IS_EQUAL(M.cols(), cols);
|
||||
VERIFY_IS_EQUAL(svs.size(), diag_size);
|
||||
// validate dimensions
|
||||
VERIFY_IS_EQUAL(M.rows(), rows);
|
||||
VERIFY_IS_EQUAL(M.cols(), cols);
|
||||
VERIFY_IS_EQUAL(svs.size(), diag_size);
|
||||
|
||||
// validate singular values
|
||||
Eigen::JacobiSVD<MatrixType> SVD(M);
|
||||
VERIFY_IS_APPROX(svs, SVD.singularValues());
|
||||
// validate singular values
|
||||
Eigen::JacobiSVD<MatrixType> SVD(M);
|
||||
VERIFY_IS_APPROX(svs, SVD.singularValues());
|
||||
}
|
||||
|
||||
template<typename MatrixType>
|
||||
void check_random_matrix(const MatrixType &m)
|
||||
{
|
||||
enum {
|
||||
Rows = MatrixType::RowsAtCompileTime,
|
||||
Cols = MatrixType::ColsAtCompileTime,
|
||||
DiagSize = internal::min_size_prefer_dynamic(Rows, Cols)
|
||||
};
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
typedef Matrix<RealScalar, DiagSize, 1> RealVectorType;
|
||||
template <typename MatrixType>
|
||||
void check_random_matrix(const MatrixType &m) {
|
||||
enum {
|
||||
Rows = MatrixType::RowsAtCompileTime,
|
||||
Cols = MatrixType::ColsAtCompileTime,
|
||||
DiagSize = internal::min_size_prefer_dynamic(Rows, Cols)
|
||||
};
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
typedef Matrix<RealScalar, DiagSize, 1> RealVectorType;
|
||||
|
||||
const Index rows = m.rows(), cols = m.cols();
|
||||
const Index diag_size = (std::min)(rows, cols);
|
||||
const RealScalar min_svs = 1.0, max_svs = 1000.0;
|
||||
const Index rows = m.rows(), cols = m.cols();
|
||||
const Index diag_size = (std::min)(rows, cols);
|
||||
const RealScalar min_svs = 1.0, max_svs = 1000.0;
|
||||
|
||||
// check generation of unitary random matrices
|
||||
typedef Matrix<Scalar, Rows, Rows> MatrixAType;
|
||||
typedef Matrix<Scalar, Cols, Cols> MatrixBType;
|
||||
check_generateRandomUnitaryMatrix<MatrixAType>(rows);
|
||||
check_generateRandomUnitaryMatrix<MatrixBType>(cols);
|
||||
// check generation of unitary random matrices
|
||||
typedef Matrix<Scalar, Rows, Rows> MatrixAType;
|
||||
typedef Matrix<Scalar, Cols, Cols> MatrixBType;
|
||||
check_generateRandomUnitaryMatrix<MatrixAType>(rows);
|
||||
check_generateRandomUnitaryMatrix<MatrixBType>(cols);
|
||||
|
||||
// test generators for singular values
|
||||
check_setupRandomSvs<RealVectorType, RealScalar>(diag_size, max_svs);
|
||||
check_setupRangeSvs<RealVectorType, RealScalar>(diag_size, min_svs, max_svs);
|
||||
// test generators for singular values
|
||||
check_setupRandomSvs<RealVectorType, RealScalar>(diag_size, max_svs);
|
||||
check_setupRangeSvs<RealVectorType, RealScalar>(diag_size, min_svs, max_svs);
|
||||
|
||||
// check generation of random matrices
|
||||
check_generateRandomMatrixSvs<MatrixType, RealScalar, RealVectorType>(rows, cols, diag_size, min_svs, max_svs);
|
||||
// check generation of random matrices
|
||||
check_generateRandomMatrixSvs<MatrixType, RealScalar, RealVectorType>(rows, cols, diag_size, min_svs, max_svs);
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(random_matrix)
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
EIGEN_DECLARE_TEST(random_matrix) {
|
||||
for (int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST_1(check_random_matrix(Matrix<float, 1, 1>()));
|
||||
CALL_SUBTEST_2(check_random_matrix(Matrix<float, 4, 4>()));
|
||||
CALL_SUBTEST_3(check_random_matrix(Matrix<float, 2, 3>()));
|
||||
|
||||
Reference in New Issue
Block a user