mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Vectorize tensor.isnan() by using typed predicates.
This commit is contained in:
@@ -611,12 +611,13 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
||||
return operator!=(constant(threshold));
|
||||
}
|
||||
|
||||
// Checks
|
||||
// Predicates.
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_isnan_op<Scalar>, const Derived>
|
||||
EIGEN_STRONG_INLINE const TensorConversionOp<bool, const TensorCwiseUnaryOp<internal::scalar_isnan_op<Scalar, true>, const Derived>>
|
||||
(isnan)() const {
|
||||
return unaryExpr(internal::scalar_isnan_op<Scalar>());
|
||||
return unaryExpr(internal::scalar_isnan_op<Scalar, true>()).template cast<bool>();
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_isinf_op<Scalar>, const Derived>
|
||||
(isinf)() const {
|
||||
@@ -1219,4 +1220,3 @@ class TensorBase : public TensorBase<Derived, ReadOnlyAccessors> {
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_CXX11_TENSOR_TENSOR_BASE_H
|
||||
|
||||
|
||||
@@ -79,8 +79,36 @@ static void test_equality()
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void test_isnan()
|
||||
{
|
||||
Tensor<Scalar, 3> mat(2,3,7);
|
||||
|
||||
mat.setRandom();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
if (internal::random<bool>()) {
|
||||
mat(i,j,k) = std::numeric_limits<Scalar>::quiet_NaN();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Tensor<bool, 3> nan(2,3,7);
|
||||
nan = (mat.isnan)();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
for (int k = 0; k < 7; ++k) {
|
||||
VERIFY_IS_EQUAL(nan(i,j,k), (std::isnan)(mat(i,j,k)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_comparisons)
|
||||
{
|
||||
CALL_SUBTEST(test_orderings());
|
||||
CALL_SUBTEST(test_equality());
|
||||
CALL_SUBTEST(test_isnan());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user