mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
Fix a bunch of annoying compiler warnings in tests
This commit is contained in:
parent
e7b1ad0315
commit
b7551bff92
@ -63,10 +63,10 @@ template<> struct adjoint_specific<false> {
|
||||
};
|
||||
|
||||
template<typename MatrixType, typename Scalar = typename MatrixType::Scalar>
|
||||
MatrixType RandomMatrix(int rows, int cols, Scalar min, Scalar max) {
|
||||
MatrixType RandomMatrix(Index rows, Index cols, Scalar min, Scalar max) {
|
||||
MatrixType M = MatrixType(rows, cols);
|
||||
for (int i=0; i<rows; ++i) {
|
||||
for (int j=0; j<cols; ++j) {
|
||||
for (Index i=0; i<rows; ++i) {
|
||||
for (Index j=0; j<cols; ++j) {
|
||||
M(i, j) = Eigen::internal::random<Scalar>(min, max);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,18 @@
|
||||
#include <vector>
|
||||
#include "main.h"
|
||||
|
||||
template <typename Scalar>
|
||||
template <typename Scalar, std::enable_if_t<NumTraits<Scalar>::IsInteger,int> = 0>
|
||||
std::vector<Scalar> special_values() {
|
||||
const Scalar zero = Scalar(0);
|
||||
const Scalar one = Scalar(1);
|
||||
const Scalar two = Scalar(2);
|
||||
const Scalar three = Scalar(3);
|
||||
const Scalar min = (std::numeric_limits<Scalar>::min)();
|
||||
const Scalar max = (std::numeric_limits<Scalar>::max)();
|
||||
return { zero, min, one, two, three, max };
|
||||
}
|
||||
|
||||
template <typename Scalar, std::enable_if_t<!NumTraits<Scalar>::IsInteger, int> = 0>
|
||||
std::vector<Scalar> special_values() {
|
||||
const Scalar zero = Scalar(0);
|
||||
const Scalar eps = Eigen::NumTraits<Scalar>::epsilon();
|
||||
@ -25,30 +36,29 @@ std::vector<Scalar> special_values() {
|
||||
const Scalar min = (std::numeric_limits<Scalar>::min)();
|
||||
const Scalar max = (std::numeric_limits<Scalar>::max)();
|
||||
const Scalar max_exp = (static_cast<Scalar>(int(Eigen::NumTraits<Scalar>::max_exponent())) * Scalar(EIGEN_LN2)) / eps;
|
||||
|
||||
return {zero, denorm_min, min, eps, sqrt_half, one, sqrt2, two, three, max_exp, max, inf, nan};
|
||||
return { zero, denorm_min, min, eps, sqrt_half, one, sqrt2, two, three, max_exp, max, inf, nan };
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
void special_value_pairs(Array<Scalar, Dynamic, Dynamic>& x,
|
||||
Array<Scalar, Dynamic, Dynamic>& y) {
|
||||
std::vector<Scalar> abs_vals = special_values<Scalar>();
|
||||
const int abs_cases = abs_vals.size();
|
||||
const int num_cases = 2*abs_cases * 2*abs_cases;
|
||||
const Index abs_cases = (Index)abs_vals.size();
|
||||
const Index num_cases = 2*abs_cases * 2*abs_cases;
|
||||
// ensure both vectorized and non-vectorized paths taken
|
||||
const int num_repeats = 2 * internal::packet_traits<Scalar>::size + 1;
|
||||
const Index num_repeats = 2 * (Index)internal::packet_traits<Scalar>::size + 1;
|
||||
x.resize(num_repeats, num_cases);
|
||||
y.resize(num_repeats, num_cases);
|
||||
int count = 0;
|
||||
for (int i = 0; i < abs_cases; ++i) {
|
||||
for (Index i = 0; i < abs_cases; ++i) {
|
||||
const Scalar abs_x = abs_vals[i];
|
||||
for (int sign_x = 0; sign_x < 2; ++sign_x) {
|
||||
for (Index sign_x = 0; sign_x < 2; ++sign_x) {
|
||||
Scalar x_case = sign_x == 0 ? -abs_x : abs_x;
|
||||
for (int j = 0; j < abs_cases; ++j) {
|
||||
for (Index j = 0; j < abs_cases; ++j) {
|
||||
const Scalar abs_y = abs_vals[j];
|
||||
for (int sign_y = 0; sign_y < 2; ++sign_y) {
|
||||
for (Index sign_y = 0; sign_y < 2; ++sign_y) {
|
||||
Scalar y_case = sign_y == 0 ? -abs_y : abs_y;
|
||||
for (int repeat = 0; repeat < num_repeats; ++repeat) {
|
||||
for (Index repeat = 0; repeat < num_repeats; ++repeat) {
|
||||
x(repeat, count) = x_case;
|
||||
y(repeat, count) = y_case;
|
||||
}
|
||||
@ -68,8 +78,8 @@ void binary_op_test(std::string name, Fn fun, RefFn ref) {
|
||||
|
||||
Array<Scalar, Dynamic, Dynamic> actual = fun(x, y);
|
||||
bool all_pass = true;
|
||||
for (int i = 0; i < x.rows(); ++i) {
|
||||
for (int j = 0; j < x.cols(); ++j) {
|
||||
for (Index i = 0; i < x.rows(); ++i) {
|
||||
for (Index j = 0; j < x.cols(); ++j) {
|
||||
Scalar e = static_cast<Scalar>(ref(x(i,j), y(i,j)));
|
||||
Scalar a = actual(i, j);
|
||||
bool success = (a==e) || ((numext::isfinite)(e) && internal::isApprox(a, e, tol)) || ((numext::isnan)(a) && (numext::isnan)(e));
|
||||
@ -98,7 +108,7 @@ void pow_scalar_exponent_test() {
|
||||
const Scalar tol = test_precision<Scalar>();
|
||||
|
||||
std::vector<Scalar> abs_vals = special_values<Scalar>();
|
||||
const int num_vals = abs_vals.size();
|
||||
const Index num_vals = (Index)abs_vals.size();
|
||||
Map<Array<Scalar, Dynamic, 1>> bases(abs_vals.data(), num_vals);
|
||||
|
||||
bool all_pass = true;
|
||||
@ -110,7 +120,7 @@ void pow_scalar_exponent_test() {
|
||||
if (exponent_is_integer) {
|
||||
Int_t exponent_as_int = static_cast<Int_t>(exponent);
|
||||
Array<Scalar, Dynamic, 1> eigenPow = bases.pow(exponent_as_int);
|
||||
for (int j = 0; j < num_vals; j++) {
|
||||
for (Index j = 0; j < num_vals; j++) {
|
||||
Scalar e = static_cast<Scalar>(std::pow(bases(j), exponent));
|
||||
Scalar a = eigenPow(j);
|
||||
bool success = (a == e) || ((numext::isfinite)(e) && internal::isApprox(a, e, tol)) ||
|
||||
@ -123,7 +133,7 @@ void pow_scalar_exponent_test() {
|
||||
} else {
|
||||
// test floating point exponent code path
|
||||
Array<Scalar, Dynamic, 1> eigenPow = bases.pow(exponent);
|
||||
for (int j = 0; j < num_vals; j++) {
|
||||
for (Index j = 0; j < num_vals; j++) {
|
||||
Scalar e = static_cast<Scalar>(std::pow(bases(j), exponent));
|
||||
Scalar a = eigenPow(j);
|
||||
bool success = (a == e) || ((numext::isfinite)(e) && internal::isApprox(a, e, tol)) ||
|
||||
|
@ -207,8 +207,9 @@ void checkOptimalTraversal() {
|
||||
|
||||
// Unrolled - ColMajor.
|
||||
{
|
||||
Eigen::Matrix4f X = Eigen::Matrix4f::Random();
|
||||
TrackedVisitor<double, false> visitor;
|
||||
using MatrixType = Matrix<float, 4, 4, ColMajor>;
|
||||
MatrixType X = MatrixType::Random(4, 4);
|
||||
TrackedVisitor<MatrixType::Scalar, false> visitor;
|
||||
X.visit(visitor);
|
||||
Index count = 0;
|
||||
for (Index j=0; j<X.cols(); ++j) {
|
||||
@ -221,10 +222,10 @@ void checkOptimalTraversal() {
|
||||
}
|
||||
|
||||
// Unrolled - RowMajor.
|
||||
using Matrix4fRowMajor = Eigen::Matrix<float, 4, 4, Eigen::RowMajor>;
|
||||
{
|
||||
Matrix4fRowMajor X = Matrix4fRowMajor::Random();
|
||||
TrackedVisitor<double, false> visitor;
|
||||
using MatrixType = Matrix<float, 4, 4, RowMajor>;
|
||||
MatrixType X = MatrixType::Random(4, 4);
|
||||
TrackedVisitor<MatrixType::Scalar, false> visitor;
|
||||
X.visit(visitor);
|
||||
Index count = 0;
|
||||
for (Index i=0; i<X.rows(); ++i) {
|
||||
@ -238,8 +239,9 @@ void checkOptimalTraversal() {
|
||||
|
||||
// Not unrolled - ColMajor
|
||||
{
|
||||
Eigen::MatrixXf X = Eigen::MatrixXf::Random(4, 4);
|
||||
TrackedVisitor<double, false> visitor;
|
||||
using MatrixType = Matrix<float, Dynamic, Dynamic, ColMajor>;
|
||||
MatrixType X = MatrixType::Random(4, 4);
|
||||
TrackedVisitor<MatrixType::Scalar, false> visitor;
|
||||
X.visit(visitor);
|
||||
Index count = 0;
|
||||
for (Index j=0; j<X.cols(); ++j) {
|
||||
@ -252,10 +254,10 @@ void checkOptimalTraversal() {
|
||||
}
|
||||
|
||||
// Not unrolled - RowMajor.
|
||||
using MatrixXfRowMajor = Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
|
||||
{
|
||||
MatrixXfRowMajor X = MatrixXfRowMajor::Random(4, 4);
|
||||
TrackedVisitor<double, false> visitor;
|
||||
using MatrixType = Matrix<float, Dynamic, Dynamic, RowMajor>;
|
||||
MatrixType X = MatrixType::Random(4, 4);
|
||||
TrackedVisitor<MatrixType::Scalar, false> visitor;
|
||||
X.visit(visitor);
|
||||
Index count = 0;
|
||||
for (Index i=0; i<X.rows(); ++i) {
|
||||
@ -269,10 +271,11 @@ void checkOptimalTraversal() {
|
||||
|
||||
// Vectorized - ColMajor
|
||||
{
|
||||
using MatrixType = Matrix<float, Dynamic, Dynamic, ColMajor>;
|
||||
// Ensure rows/cols is larger than packet size.
|
||||
constexpr int PacketSize = Eigen::internal::packet_traits<float>::size;
|
||||
Eigen::MatrixXf X = Eigen::MatrixXf::Random(4 * PacketSize, 4 * PacketSize);
|
||||
TrackedVisitor<double, true> visitor;
|
||||
constexpr int PacketSize = Eigen::internal::packet_traits<MatrixType::Scalar>::size;
|
||||
MatrixType X = MatrixType::Random(4 * PacketSize, 4 * PacketSize);
|
||||
TrackedVisitor<MatrixType::Scalar, true> visitor;
|
||||
X.visit(visitor);
|
||||
Index previ = -1;
|
||||
Index prevj = 0;
|
||||
@ -287,17 +290,18 @@ void checkOptimalTraversal() {
|
||||
previ = i;
|
||||
prevj = j;
|
||||
}
|
||||
if (Eigen::internal::packet_traits<float>::Vectorizable) {
|
||||
if (Eigen::internal::packet_traits<MatrixType::Scalar>::Vectorizable) {
|
||||
VERIFY(visitor.vectorized);
|
||||
}
|
||||
}
|
||||
|
||||
// Vectorized - RowMajor.
|
||||
{
|
||||
using MatrixType = Matrix<float, Dynamic, Dynamic, RowMajor>;
|
||||
// Ensure rows/cols is larger than packet size.
|
||||
constexpr int PacketSize = Eigen::internal::packet_traits<float>::size;
|
||||
MatrixXfRowMajor X = MatrixXfRowMajor::Random(4 * PacketSize, 4 * PacketSize);
|
||||
TrackedVisitor<double, true> visitor;
|
||||
constexpr int PacketSize = Eigen::internal::packet_traits<MatrixType::Scalar>::size;
|
||||
MatrixType X = MatrixType::Random(4 * PacketSize, 4 * PacketSize);
|
||||
TrackedVisitor<MatrixType::Scalar, true> visitor;
|
||||
X.visit(visitor);
|
||||
Index previ = 0;
|
||||
Index prevj = -1;
|
||||
@ -312,7 +316,7 @@ void checkOptimalTraversal() {
|
||||
previ = i;
|
||||
prevj = j;
|
||||
}
|
||||
if (Eigen::internal::packet_traits<float>::Vectorizable) {
|
||||
if (Eigen::internal::packet_traits<MatrixType::Scalar>::Vectorizable) {
|
||||
VERIFY(visitor.vectorized);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user