aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_casts.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-02-27 09:27:30 -0800
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-02-27 09:27:30 -0800
commit05089aba75f8bf1ab3d1bfd566decfc08ce729f9 (patch)
treeef866b5e9b4707a5e7c8a185c5868f9c795300f1 /unsupported/test/cxx11_tensor_casts.cpp
parent573b377110d488886bfc6b319c140a3375d5d91a (diff)
Switch to truncated casting when converting floating point types to integer. This ensures that vectorized casts are consistent with scalar casts
Diffstat (limited to 'unsupported/test/cxx11_tensor_casts.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_casts.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/unsupported/test/cxx11_tensor_casts.cpp b/unsupported/test/cxx11_tensor_casts.cpp
index f53679d7b..729e43327 100644
--- a/unsupported/test/cxx11_tensor_casts.cpp
+++ b/unsupported/test/cxx11_tensor_casts.cpp
@@ -56,6 +56,25 @@ static void test_vectorized_cast()
}
+static void test_float_to_int_cast()
+{
+ Tensor<float, 2> ftensor(20,30);
+ ftensor = ftensor.random() * 1000.0f;
+ Tensor<double, 2> dtensor(20,30);
+ dtensor = dtensor.random() * 1000.0;
+
+ Tensor<int, 2> i1tensor = ftensor.cast<int>();
+ Tensor<int, 2> i2tensor = dtensor.cast<int>();
+
+ for (int i = 0; i < 20; ++i) {
+ for (int j = 0; j < 30; ++j) {
+ VERIFY_IS_EQUAL(i1tensor(i,j), static_cast<int>(ftensor(i,j)));
+ VERIFY_IS_EQUAL(i2tensor(i,j), static_cast<int>(dtensor(i,j)));
+ }
+ }
+}
+
+
static void test_big_to_small_type_cast()
{
Tensor<double, 2> dtensor(20, 30);
@@ -90,6 +109,7 @@ void test_cxx11_tensor_casts()
{
CALL_SUBTEST(test_simple_cast());
CALL_SUBTEST(test_vectorized_cast());
+ CALL_SUBTEST(test_float_to_int_cast());
CALL_SUBTEST(test_big_to_small_type_cast());
CALL_SUBTEST(test_small_to_big_type_cast());
}