diff options
author | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2014-09-05 07:47:43 -0700 |
---|---|---|
committer | Benoit Steiner <benoit.steiner.goog@gmail.com> | 2014-09-05 07:47:43 -0700 |
commit | 74db22455ae0172faaae91321da0b303bb82369d (patch) | |
tree | 773686acd6d7e8abc5a9dfe17d13ca9138f6108e | |
parent | 1abe4ed14c0012d85e833c5f507f282cf26edc36 (diff) |
Misc fixes.
-rw-r--r-- | unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h | 12 | ||||
-rw-r--r-- | unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h | 2 | ||||
-rw-r--r-- | unsupported/test/cxx11_tensor_padding.cpp | 38 |
3 files changed, 43 insertions, 9 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h b/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h index d9a6b3f1b..28ae7b3c6 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorMorphing.h @@ -163,7 +163,7 @@ template<typename NewDimensions, typename ArgType, typename Device> { return this->m_impl.coeffRef(index); } - template <int StoreMode> EIGEN_STRONG_INLINE + template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType& x) { this->m_impl.template writePacket<StoreMode>(index, x); @@ -314,7 +314,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi Scalar* src = m_impl.data(); for (int i = 0; i < internal::array_prod(dimensions()); i += contiguous_values) { Index offset = srcCoeff(i); - m_device.memcpy(data+i, src+offset, contiguous_values * sizeof(Scalar)); + m_device.memcpy((void*)(data+i), src+offset, contiguous_values * sizeof(Scalar)); } return false; } @@ -334,7 +334,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi template<int LoadMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const { - static const int packetSize = internal::unpacket_traits<PacketReturnType>::size; + const int packetSize = internal::unpacket_traits<PacketReturnType>::size; EIGEN_STATIC_ASSERT(packetSize > 1, YOU_MADE_A_PROGRAMMING_MISTAKE) eigen_assert(index+packetSize-1 < dimensions().TotalSize()); @@ -355,7 +355,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi return rslt; } else { - CoeffReturnType values[packetSize]; + typename internal::remove_const<CoeffReturnType>::type values[packetSize]; values[0] = m_impl.coeff(inputIndices[0]); values[packetSize-1] = m_impl.coeff(inputIndices[1]); for (int i = 1; i < packetSize-1; ++i) { @@ -420,10 +420,10 @@ struct TensorEvaluator<TensorSlicingOp<StartIndices, Sizes, ArgType>, Device> return this->m_impl.coeffRef(this->srcCoeff(index)); } - template <int StoreMode> EIGEN_STRONG_INLINE + template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType& x) { - static const int packetSize = internal::unpacket_traits<PacketReturnType>::size; + const int packetSize = internal::unpacket_traits<PacketReturnType>::size; Index inputIndices[] = {0, 0}; Index indices[] = {index, index + packetSize - 1}; for (int i = NumDims - 1; i > 0; --i) { diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h b/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h index 4482c0992..7da89458f 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorPadding.h @@ -48,7 +48,7 @@ struct nested<TensorPaddingOp<PaddingDimensions, XprType>, 1, typename eval<Tens template<typename PaddingDimensions, typename XprType> -class TensorPaddingOp : public TensorBase<TensorPaddingOp<PaddingDimensions, XprType> > +class TensorPaddingOp : public TensorBase<TensorPaddingOp<PaddingDimensions, XprType>, ReadOnlyAccessors> { public: typedef typename Eigen::internal::traits<TensorPaddingOp>::Scalar Scalar; diff --git a/unsupported/test/cxx11_tensor_padding.cpp b/unsupported/test/cxx11_tensor_padding.cpp index cb010f512..6f74216dd 100644 --- a/unsupported/test/cxx11_tensor_padding.cpp +++ b/unsupported/test/cxx11_tensor_padding.cpp @@ -37,9 +37,42 @@ static void test_simple_padding() for (int k = 0; k < 12; ++k) { for (int l = 0; l < 7; ++l) { if (j >= 2 && j < 5 && k >= 3 && k < 8) { - VERIFY_IS_EQUAL(tensor(i,j-2,k-3,l), padded(i,j,k,l)); + VERIFY_IS_EQUAL(padded(i,j,k,l), tensor(i,j-2,k-3,l)); } else { - VERIFY_IS_EQUAL(0.0f, padded(i,j,k,l)); + VERIFY_IS_EQUAL(padded(i,j,k,l), 0.0f); + } + } + } + } + } +} + +static void test_padded_expr() +{ + Tensor<float, 4> tensor(2,3,5,7); + tensor.setRandom(); + + array<std::pair<ptrdiff_t, ptrdiff_t>, 4> paddings; + paddings[0] = std::make_pair(0, 0); + paddings[1] = std::make_pair(2, 1); + paddings[2] = std::make_pair(3, 4); + paddings[3] = std::make_pair(0, 0); + + Eigen::DSizes<ptrdiff_t, 2> reshape_dims; + reshape_dims[0] = 12; + reshape_dims[1] = 84; + + Tensor<float, 2> result; + result = tensor.pad(paddings).reshape(reshape_dims); + + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 6; ++j) { + for (int k = 0; k < 12; ++k) { + for (int l = 0; l < 7; ++l) { + if (j >= 2 && j < 5 && k >= 3 && k < 8) { + VERIFY_IS_EQUAL(result(i+2*j,k+12*l), tensor(i,j-2,k-3,l)); + } else { + VERIFY_IS_EQUAL(result(i+2*j,k+12*l), 0.0f); } } } @@ -51,4 +84,5 @@ static void test_simple_padding() void test_cxx11_tensor_padding() { CALL_SUBTEST(test_simple_padding()); + CALL_SUBTEST(test_padded_expr()); } |