diff options
author | Rasmus Munk Larsen <rmlarsen@google.com> | 2018-05-14 16:07:13 -0700 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2018-05-14 16:07:13 -0700 |
commit | b8c8e5f436743ac6a6a5ed0ad7ec5cce7dd00248 (patch) | |
tree | 8dd48fd88fa87fd9c492bfcbf5fd3ed4ea8cb150 /unsupported/test/cxx11_tensor_expr.cpp | |
parent | 6118c6ff4f898dad99564ffdeb99036beb2ff0ea (diff) |
Add vectorized clip functor for Eigen Tensors.
Diffstat (limited to 'unsupported/test/cxx11_tensor_expr.cpp')
-rw-r--r-- | unsupported/test/cxx11_tensor_expr.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_expr.cpp b/unsupported/test/cxx11_tensor_expr.cpp index 129b4e659..30e5a9860 100644 --- a/unsupported/test/cxx11_tensor_expr.cpp +++ b/unsupported/test/cxx11_tensor_expr.cpp @@ -340,6 +340,26 @@ void test_minmax_nan_propagation_templ() { } } +static void test_clip() +{ + Tensor<float, 1> vec(6); + vec(0) = 4.0; + vec(1) = 8.0; + vec(2) = 15.0; + vec(3) = 16.0; + vec(4) = 23.0; + vec(5) = 42.0; + + float kMin = 20; + float kMax = 30; + + Tensor<float, 1> vec_clipped(6); + vec_clipped = vec.clip(kMin, kMax); + for (int i = 0; i < 6; ++i) { + VERIFY_IS_EQUAL(vec_clipped(i), std::min(std::max(vec(i), kMin), kMax)); + } +} + static void test_minmax_nan_propagation() { test_minmax_nan_propagation_templ<float>(); @@ -356,5 +376,6 @@ void test_cxx11_tensor_expr() CALL_SUBTEST(test_functors()); CALL_SUBTEST(test_type_casting()); CALL_SUBTEST(test_select()); + CALL_SUBTEST(test_clip()); CALL_SUBTEST(test_minmax_nan_propagation()); } |