aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unsupported/test/cxx11_tensor_expr.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_expr.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_expr.cpp b/unsupported/test/cxx11_tensor_expr.cpp
index 77e24cb67..129b4e659 100644
--- a/unsupported/test/cxx11_tensor_expr.cpp
+++ b/unsupported/test/cxx11_tensor_expr.cpp
@@ -300,6 +300,51 @@ static void test_select()
}
}
+template <typename Scalar>
+void test_minmax_nan_propagation_templ() {
+ for (int size = 1; size < 17; ++size) {
+ const Scalar kNan = std::numeric_limits<Scalar>::quiet_NaN();
+ Tensor<Scalar, 1> vec_nan(size);
+ Tensor<Scalar, 1> vec_zero(size);
+ Tensor<Scalar, 1> vec_res(size);
+ vec_nan.setConstant(kNan);
+ vec_zero.setZero();
+ vec_res.setZero();
+
+ // Test that we propagate NaNs in the tensor when applying the
+ // cwiseMax(scalar) operator, which is used for the Relu operator.
+ vec_res = vec_nan.cwiseMax(Scalar(0));
+ for (int i = 0; i < size; ++i) {
+ VERIFY((numext::isnan)(vec_res(i)));
+ }
+
+ // Test that NaNs do not propagate if we reverse the arguments.
+ vec_res = vec_zero.cwiseMax(kNan);
+ for (int i = 0; i < size; ++i) {
+ VERIFY_IS_EQUAL(vec_res(i), Scalar(0));
+ }
+
+ // Test that we propagate NaNs in the tensor when applying the
+ // cwiseMin(scalar) operator.
+ vec_res.setZero();
+ vec_res = vec_nan.cwiseMin(Scalar(0));
+ for (int i = 0; i < size; ++i) {
+ VERIFY((numext::isnan)(vec_res(i)));
+ }
+
+ // Test that NaNs do not propagate if we reverse the arguments.
+ vec_res = vec_zero.cwiseMin(kNan);
+ for (int i = 0; i < size; ++i) {
+ VERIFY_IS_EQUAL(vec_res(i), Scalar(0));
+ }
+ }
+}
+
+static void test_minmax_nan_propagation()
+{
+ test_minmax_nan_propagation_templ<float>();
+ test_minmax_nan_propagation_templ<double>();
+}
void test_cxx11_tensor_expr()
{
@@ -311,4 +356,5 @@ void test_cxx11_tensor_expr()
CALL_SUBTEST(test_functors());
CALL_SUBTEST(test_type_casting());
CALL_SUBTEST(test_select());
+ CALL_SUBTEST(test_minmax_nan_propagation());
}