From 02db1228ed9ca3728ae0685a5e1602fe7299ae50 Mon Sep 17 00:00:00 2001 From: Ville Kallioniemi Date: Tue, 26 Jan 2016 23:41:01 -0700 Subject: [PATCH 1/4] Add constructor for long types. --- unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h b/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h index 4f2adb671..19352eb5e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h @@ -40,6 +40,12 @@ struct TensorUInt128 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128(unsigned int x) : high(0), low(x) { } EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE + TensorUInt128(long x) : high(0), low(x) { + eigen_assert(x >= 0); + } + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE + TensorUInt128(unsigned long x) : high(0), low(x) { } + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128(int64_t x) : high(0), low(x) { eigen_assert(x >= 0); } From aedea349aabb44d51a4e64cd2c96242f0cea95ba Mon Sep 17 00:00:00 2001 From: Ville Kallioniemi Date: Mon, 1 Feb 2016 20:25:02 -0700 Subject: [PATCH 2/4] Replace separate low word constructors with a single templated constructor. --- .../Eigen/CXX11/src/Tensor/TensorUInt128.h | 25 ++++++++----------- unsupported/test/cxx11_tensor_uint128.cpp | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h b/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h index 0d34f7ee6..981515f4b 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h @@ -33,24 +33,19 @@ struct TensorUInt128 HIGH high; LOW low; + template EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(int32_t x) : high(0), low(x) { + TensorUInt128(const TensorUInt128& other) : high(other.high), low(other.low) { + static_assert(sizeof(OTHER_HIGH) <= sizeof(HIGH), "high too wide"); + static_assert(sizeof(OTHER_LOW) <= sizeof(LOW), "low too wide"); + } + + template + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE + explicit TensorUInt128(const T& x) : high(0), low(x) { eigen_assert(x >= 0); } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(uint32_t x) : high(0), low(x) { } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(long x) : high(0), low(x) { - eigen_assert(x >= 0); - } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(unsigned long x) : high(0), low(x) { } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(int64_t x) : high(0), low(x) { - eigen_assert(x >= 0); - } - EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE - TensorUInt128(uint64_t x) : high(0), low(x) { } + EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128(uint64_t y, uint64_t x) : high(y), low(x) { } diff --git a/unsupported/test/cxx11_tensor_uint128.cpp b/unsupported/test/cxx11_tensor_uint128.cpp index ee3767e58..424c70197 100644 --- a/unsupported/test/cxx11_tensor_uint128.cpp +++ b/unsupported/test/cxx11_tensor_uint128.cpp @@ -127,7 +127,7 @@ void test_misc2() { TensorUInt128 result = (TensorUInt128 >(shift, 0) / TensorUInt128, uint64_t>(divider) - TensorUInt128, static_val<0> >(1, 0) + TensorUInt128, static_val<1> >(1)); uint64_t actual = static_cast(result); - VERIFY_EQUAL(actual, expected); + VERIFY_IS_EQUAL(actual, expected); } } } From 99cde88341145c43fc4134af07556d8c6ff12066 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 2 Feb 2016 11:06:53 -0800 Subject: [PATCH 3/4] Don't try to use direct offsets when computing a tensor product, since the required stride isn't available. --- unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h index 63c8ae126..392aa6d37 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContractionMapper.h @@ -344,7 +344,7 @@ class TensorContractionSubMapper { enum { // We can use direct offsets iff the parent mapper supports then and we can compute the strides. // TODO: we should also enable direct offsets for the Rhs case. - UseDirectOffsets = (side == Lhs) && inner_dim_contiguous && ParentMapper::DirectOffsets + UseDirectOffsets = ParentMapper::DirectOffsets && (side == Lhs) && inner_dim_contiguous && (array_size::value > 0) }; EIGEN_DEVICE_FUNC TensorContractionSubMapper(const ParentMapper& base_mapper, Index vert_offset, Index horiz_offset) From 783018d8f65faeec0fc6f795bc2630240ecdd051 Mon Sep 17 00:00:00 2001 From: Ville Kallioniemi Date: Tue, 2 Feb 2016 16:45:12 -0700 Subject: [PATCH 4/4] Use EIGEN_STATIC_ASSERT for backward compatibility. --- unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h b/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h index 981515f4b..52d5b7b1a 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorUInt128.h @@ -36,8 +36,8 @@ struct TensorUInt128 template EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128(const TensorUInt128& other) : high(other.high), low(other.low) { - static_assert(sizeof(OTHER_HIGH) <= sizeof(HIGH), "high too wide"); - static_assert(sizeof(OTHER_LOW) <= sizeof(LOW), "low too wide"); + EIGEN_STATIC_ASSERT(sizeof(OTHER_HIGH) <= sizeof(HIGH), "high too wide"); + EIGEN_STATIC_ASSERT(sizeof(OTHER_LOW) <= sizeof(LOW), "low too wide"); } template