diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h index 201b0fc9e..86e72c3a4 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h @@ -520,48 +520,101 @@ class TensorBase : public TensorBase + const TensorLayoutSwapOp swap_layout() const { + return TensorLayoutSwapOp(derived()); + } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + TensorLayoutSwapOp + swap_layout() { return TensorLayoutSwapOp(derived()); } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorConcatenationOp + concatenate(const OtherDerived& other, const Axis& axis) const { + return TensorConcatenationOp(derived(), other, axis); + } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConcatenationOp - concatenate(const OtherDerived& other, const Axis& axis) const { - return TensorConcatenationOp(derived(), other.derived(), axis); + concatenate(const OtherDerived& other, const Axis& axis) { + return TensorConcatenationOp(derived(), other, axis); + } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorReshapingOp + reshape(const NewDimensions& newDimensions) const { + return TensorReshapingOp(derived(), newDimensions); } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorReshapingOp - reshape(const NewDimensions& newDimensions) const { + reshape(const NewDimensions& newDimensions) { return TensorReshapingOp(derived(), newDimensions); } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorSlicingOp + slice(const StartIndices& startIndices, const Sizes& sizes) const { + return TensorSlicingOp(derived(), startIndices, sizes); + } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorSlicingOp - slice(const StartIndices& startIndices, const Sizes& sizes) const { + slice(const StartIndices& startIndices, const Sizes& sizes) { return TensorSlicingOp(derived(), startIndices, sizes); } + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - TensorChippingOp + const TensorChippingOp chip(const Index offset) const { + return TensorChippingOp(derived(), offset, DimId); + } + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + TensorChippingOp + chip(const Index offset) { return TensorChippingOp(derived(), offset, DimId); } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorChippingOp + chip(const Index offset, const Index dim) const { + return TensorChippingOp(derived(), offset, dim); + } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorChippingOp - chip(const Index offset, const Index dim) const { + chip(const Index offset, const Index dim) { return TensorChippingOp(derived(), offset, dim); } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorReverseOp + reverse(const ReverseDimensions& rev) const { + return TensorReverseOp(derived(), rev); + } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorReverseOp - reverse(const ReverseDimensions& rev) const { + reverse(const ReverseDimensions& rev) { return TensorReverseOp(derived(), rev); } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorShufflingOp + shuffle(const Shuffle& shuffle) const { + return TensorShufflingOp(derived(), shuffle); + } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorShufflingOp - shuffle(const Shuffle& shuffle) const { + shuffle(const Shuffle& shuffle) { return TensorShufflingOp(derived(), shuffle); } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + const TensorStridingOp + stride(const Strides& strides) const { + return TensorStridingOp(derived(), strides); + } template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorStridingOp - stride(const Strides& strides) const { + stride(const Strides& strides) { return TensorStridingOp(derived(), strides); } diff --git a/unsupported/test/cxx11_tensor_const.cpp b/unsupported/test/cxx11_tensor_const.cpp index 0ffb02afd..ad9c9da39 100644 --- a/unsupported/test/cxx11_tensor_const.cpp +++ b/unsupported/test/cxx11_tensor_const.cpp @@ -13,8 +13,6 @@ using Eigen::Tensor; - - static void test_simple_assign() { Tensor random(2,3,7); @@ -33,7 +31,32 @@ static void test_simple_assign() } } + +static void test_assign_of_const_tensor() +{ + Tensor random(2,3,7); + random.setRandom(); + + TensorMap > constant1(random.data(), 2, 3, 7); + TensorMap > constant2(random.data(), 2, 3, 7); + const TensorMap > constant3(random.data(), 2, 3, 7); + + Tensor result1 = constant1.chip(0, 2); + Tensor result2 = constant2.chip(0, 2); + Tensor result3 = constant3.chip(0, 2); + + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 3; ++j) { + VERIFY_IS_EQUAL((result1(i,j)), random(i,j,0)); + VERIFY_IS_EQUAL((result2(i,j)), random(i,j,0)); + VERIFY_IS_EQUAL((result3(i,j)), random(i,j,0)); + } + } +} + + void test_cxx11_tensor_const() { CALL_SUBTEST(test_simple_assign()); + CALL_SUBTEST(test_assign_of_const_tensor()); }