From 17268b155d54422f1294130c0fb8c178757d911a Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Tue, 17 Nov 2020 15:32:44 -0800 Subject: Add bit_cast for half/bfloat to/from uint16_t, fix TensorRandom The existing `TensorRandom.h` implementation makes the assumption that `half` (`bfloat16`) has a `uint16_t` member `x` (`value`), which is not always true. This currently fails on arm64, where `x` has type `__fp16`. Added `bit_cast` specializations to allow casting to/from `uint16_t` for both `half` and `bfloat16`. Also added tests in `half_float`, `bfloat16_float`, and `cxx11_tensor_random` to catch these errors in the future. --- unsupported/test/cxx11_tensor_random.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'unsupported/test/cxx11_tensor_random.cpp') diff --git a/unsupported/test/cxx11_tensor_random.cpp b/unsupported/test/cxx11_tensor_random.cpp index 4740d5811..b9d4c5584 100644 --- a/unsupported/test/cxx11_tensor_random.cpp +++ b/unsupported/test/cxx11_tensor_random.cpp @@ -11,9 +11,10 @@ #include +template static void test_default() { - Tensor vec(6); + Tensor vec(6); vec.setRandom(); // Fixme: we should check that the generated numbers follow a uniform @@ -23,10 +24,11 @@ static void test_default() } } +template static void test_normal() { - Tensor vec(6); - vec.setRandom>(); + Tensor vec(6); + vec.template setRandom>(); // Fixme: we should check that the generated numbers follow a gaussian // distribution instead. @@ -72,7 +74,13 @@ static void test_custom() EIGEN_DECLARE_TEST(cxx11_tensor_random) { - CALL_SUBTEST(test_default()); - CALL_SUBTEST(test_normal()); + CALL_SUBTEST((test_default())); + CALL_SUBTEST((test_normal())); + CALL_SUBTEST((test_default())); + CALL_SUBTEST((test_normal())); + CALL_SUBTEST((test_default())); + CALL_SUBTEST((test_normal())); + CALL_SUBTEST((test_default())); + CALL_SUBTEST((test_normal())); CALL_SUBTEST(test_custom()); } -- cgit v1.2.3