12 #include <gtest/gtest.h> 18 using namespace Eigen;
22 Eigen::Matrix3f matrix(Eigen::Matrix3f::Ones());
25 EXPECT_EQ(7, matrix.numberOfFinites());
27 Matrix<double, 13, 10> matrix2;
29 EXPECT_EQ(matrix2.rows() * matrix2.cols(), matrix2.numberOfFinites());
31 Matrix<double, 13, 10> matrix3;
32 matrix3.setConstant(NAN);
33 matrix3.col(3).setConstant(0.0);
34 EXPECT_EQ(matrix3.rows(), matrix3.numberOfFinites());
39 Matrix<double, 7, 18> matrix;
41 EXPECT_NEAR(matrix.sum(), matrix.sumOfFinites(), 1e-10);
42 double finiteSum = matrix.sum() - matrix(0, 0) - matrix(1, 2) - matrix(3, 6) - matrix(6, 12);
47 EXPECT_NEAR(finiteSum, matrix.sumOfFinites(), 1e-10);
48 matrix.setConstant(NAN);
49 EXPECT_TRUE(std::isnan(matrix.sumOfFinites()));
51 EXPECT_NEAR(1.0, matrix.sumOfFinites(), 1e-10);
56 Eigen::Matrix3f matrix(Eigen::Matrix3f::Ones());
59 EXPECT_DOUBLE_EQ(1.0, matrix.meanOfFinites());
61 Matrix<double, 13, 10> matrix2;
63 EXPECT_NEAR(matrix2.mean(), matrix2.meanOfFinites(), 1e-10);
68 Matrix<double, 7, 18> matrix;
70 double min = matrix.minCoeff();
71 EXPECT_NEAR(min, matrix.minCoeffOfFinites(), 1e-10);
74 matrix.maxCoeff(&i, &j);
76 EXPECT_NEAR(min, matrix.minCoeffOfFinites(), 1e-10);
78 matrix.setConstant(NAN);
79 EXPECT_TRUE(std::isnan(matrix.minCoeffOfFinites()));
81 EXPECT_NEAR(-1.0, matrix.minCoeffOfFinites(), 1e-10);
86 Matrix<double, 7, 18> matrix;
88 double max = matrix.maxCoeff();
89 EXPECT_NEAR(max, matrix.maxCoeffOfFinites(), 1e-10);
92 matrix.minCoeff(&i, &j);
94 EXPECT_NEAR(max, matrix.maxCoeffOfFinites(), 1e-10);
96 matrix.setConstant(NAN);
97 EXPECT_TRUE(std::isnan(matrix.maxCoeffOfFinites()));
99 EXPECT_NEAR(-1.0, matrix.maxCoeffOfFinites(), 1e-10);
102 TEST(EigenMatrixBaseAddons, clamp)
104 Eigen::VectorXf vector(Eigen::VectorXf::LinSpaced(9, 1.0, 9.0));
105 Eigen::Matrix3f matrix;
106 matrix << vector.segment(0, 3), vector.segment(3, 3), vector.segment(6, 3);
109 EXPECT_NEAR(2.1, matrix(0, 0), 1e-7);
110 EXPECT_NEAR(2.1, matrix(1, 0), 1e-7);
111 EXPECT_NEAR(3.0, matrix(2, 0), 1e-7);
112 EXPECT_TRUE(std::isnan(matrix(1, 1)));
113 EXPECT_NEAR(7.0, matrix(2, 2), 1e-7);
Scalar meanOfFinites() const
Scalar sumOfFinites() const
Scalar maxCoeffOfFinites() const
Scalar numberOfFinites() const
TEST(EigenMatrixBaseAddons, numberOfFinites)
Scalar minCoeffOfFinites() const