mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-12 17:33:15 +08:00
gcc doesn't consider that
template<typename OtherDerived> TensorStridingOp& operator = (const OtherDerived& other) provides a valid assignment operator for the striding operation, and therefore refuses to compile code like: result.stride(foo) = source.stride(bar); Added the explicit TensorStridingOp& operator = (const TensorStridingOp& other) as a workaround to get the code to compile, and did the same in all the operations that can be used as lvalues.
This commit is contained in:
parent
641e824c56
commit
14f537c296
@ -101,6 +101,16 @@ class TensorChippingOp : public TensorBase<TensorChippingOp<DimId, XprType> >
|
|||||||
const typename internal::remove_all<typename XprType::Nested>::type&
|
const typename internal::remove_all<typename XprType::Nested>::type&
|
||||||
expression() const { return m_xpr; }
|
expression() const { return m_xpr; }
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE TensorChippingOp& operator = (const TensorChippingOp& other)
|
||||||
|
{
|
||||||
|
typedef TensorAssignOp<TensorChippingOp, const TensorChippingOp> Assign;
|
||||||
|
Assign assign(*this, other);
|
||||||
|
static const bool Vectorize = TensorEvaluator<const Assign, DefaultDevice>::PacketAccess;
|
||||||
|
internal::TensorExecutor<const Assign, DefaultDevice, Vectorize>::run(assign, DefaultDevice());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_DEVICE_FUNC
|
EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE TensorChippingOp& operator = (const OtherDerived& other)
|
EIGEN_STRONG_INLINE TensorChippingOp& operator = (const OtherDerived& other)
|
||||||
|
@ -73,6 +73,15 @@ class TensorReshapingOp : public TensorBase<TensorReshapingOp<NewDimensions, Xpr
|
|||||||
const typename internal::remove_all<typename XprType::Nested>::type&
|
const typename internal::remove_all<typename XprType::Nested>::type&
|
||||||
expression() const { return m_xpr; }
|
expression() const { return m_xpr; }
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE TensorReshapingOp& operator = (const TensorReshapingOp& other)
|
||||||
|
{
|
||||||
|
typedef TensorAssignOp<TensorReshapingOp, const TensorReshapingOp> Assign;
|
||||||
|
Assign assign(*this, other);
|
||||||
|
internal::TensorExecutor<const Assign, DefaultDevice, false>::run(assign, DefaultDevice());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_DEVICE_FUNC
|
EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE TensorReshapingOp& operator = (const OtherDerived& other)
|
EIGEN_STRONG_INLINE TensorReshapingOp& operator = (const OtherDerived& other)
|
||||||
@ -257,6 +266,16 @@ class TensorSlicingOp : public TensorBase<TensorSlicingOp<StartIndices, Sizes, X
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE TensorSlicingOp& operator = (const TensorSlicingOp& other)
|
||||||
|
{
|
||||||
|
typedef TensorAssignOp<TensorSlicingOp, const TensorSlicingOp> Assign;
|
||||||
|
Assign assign(*this, other);
|
||||||
|
internal::TensorExecutor<const Assign, DefaultDevice, false>::run(assign, DefaultDevice());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typename XprType::Nested m_xpr;
|
typename XprType::Nested m_xpr;
|
||||||
const StartIndices m_indices;
|
const StartIndices m_indices;
|
||||||
|
@ -73,6 +73,15 @@ class TensorShufflingOp : public TensorBase<TensorShufflingOp<Shuffle, XprType>
|
|||||||
const typename internal::remove_all<typename XprType::Nested>::type&
|
const typename internal::remove_all<typename XprType::Nested>::type&
|
||||||
expression() const { return m_xpr; }
|
expression() const { return m_xpr; }
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE TensorShufflingOp& operator = (const TensorShufflingOp& other)
|
||||||
|
{
|
||||||
|
typedef TensorAssignOp<TensorShufflingOp, const TensorShufflingOp> Assign;
|
||||||
|
Assign assign(*this, other);
|
||||||
|
internal::TensorExecutor<const Assign, DefaultDevice, false>::run(assign, DefaultDevice());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_DEVICE_FUNC
|
EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE TensorShufflingOp& operator = (const OtherDerived& other)
|
EIGEN_STRONG_INLINE TensorShufflingOp& operator = (const OtherDerived& other)
|
||||||
|
@ -73,6 +73,15 @@ class TensorStridingOp : public TensorBase<TensorStridingOp<Strides, XprType> >
|
|||||||
const typename internal::remove_all<typename XprType::Nested>::type&
|
const typename internal::remove_all<typename XprType::Nested>::type&
|
||||||
expression() const { return m_xpr; }
|
expression() const { return m_xpr; }
|
||||||
|
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
EIGEN_STRONG_INLINE TensorStridingOp& operator = (const TensorStridingOp& other)
|
||||||
|
{
|
||||||
|
typedef TensorAssignOp<TensorStridingOp, const TensorStridingOp> Assign;
|
||||||
|
Assign assign(*this, other);
|
||||||
|
internal::TensorExecutor<const Assign, DefaultDevice, false>::run(assign, DefaultDevice());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
EIGEN_DEVICE_FUNC
|
EIGEN_DEVICE_FUNC
|
||||||
EIGEN_STRONG_INLINE TensorStridingOp& operator = (const OtherDerived& other)
|
EIGEN_STRONG_INLINE TensorStridingOp& operator = (const OtherDerived& other)
|
||||||
|
@ -318,7 +318,28 @@ static void test_chip_as_lvalue()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Tensor<float, 5, DataLayout> input7(2,3,5,7,11);
|
||||||
|
input7.setRandom();
|
||||||
|
tensor = input1;
|
||||||
|
tensor.chip(0, 0) = input7.chip(0, 0);
|
||||||
|
for (int i = 0; i < 2; ++i) {
|
||||||
|
for (int j = 0; j < 3; ++j) {
|
||||||
|
for (int k = 0; k < 5; ++k) {
|
||||||
|
for (int l = 0; l < 7; ++l) {
|
||||||
|
for (int m = 0; m < 11; ++m) {
|
||||||
|
if (i != 0) {
|
||||||
|
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
|
||||||
|
} else {
|
||||||
|
VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input7(i,j,k,l,m));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<int DataLayout>
|
template<int DataLayout>
|
||||||
static void test_chip_raw_data()
|
static void test_chip_raw_data()
|
||||||
|
@ -161,6 +161,8 @@ static void test_slice_as_lvalue()
|
|||||||
tensor3.setRandom();
|
tensor3.setRandom();
|
||||||
Tensor<float, 3, DataLayout> tensor4(4,3,2);
|
Tensor<float, 3, DataLayout> tensor4(4,3,2);
|
||||||
tensor4.setRandom();
|
tensor4.setRandom();
|
||||||
|
Tensor<float, 3, DataLayout> tensor5(10,13,12);
|
||||||
|
tensor5.setRandom();
|
||||||
|
|
||||||
Tensor<float, 3, DataLayout> result(4,5,7);
|
Tensor<float, 3, DataLayout> result(4,5,7);
|
||||||
Eigen::DSizes<ptrdiff_t, 3> sizes12(2,2,7);
|
Eigen::DSizes<ptrdiff_t, 3> sizes12(2,2,7);
|
||||||
@ -195,6 +197,17 @@ static void test_slice_as_lvalue()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Eigen::DSizes<ptrdiff_t, 3> sizes5(4,5,7);
|
||||||
|
Eigen::DSizes<ptrdiff_t, 3> fifth_slice(0,0,0);
|
||||||
|
result.slice(fifth_slice, sizes5) = tensor5.slice(fifth_slice, sizes5);
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
for (int j = 2; j < 5; ++j) {
|
||||||
|
for (int k = 0; k < 7; ++k) {
|
||||||
|
VERIFY_IS_EQUAL(result(i,j,k), tensor5(i,j,k));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int DataLayout>
|
template<int DataLayout>
|
||||||
|
@ -157,6 +157,23 @@ static void test_shuffling_as_value()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array<ptrdiff_t, 4> no_shuffle;
|
||||||
|
no_shuffle[0] = 0;
|
||||||
|
no_shuffle[1] = 1;
|
||||||
|
no_shuffle[2] = 2;
|
||||||
|
no_shuffle[3] = 3;
|
||||||
|
Tensor<float, 4, DataLayout> shuffle2(5,7,3,2);
|
||||||
|
shuffle2.shuffle(shuffles) = tensor.shuffle(no_shuffle);
|
||||||
|
for (int i = 0; i < 5; ++i) {
|
||||||
|
for (int j = 0; j < 7; ++j) {
|
||||||
|
for (int k = 0; k < 3; ++k) {
|
||||||
|
for (int l = 0; l < 2; ++l) {
|
||||||
|
VERIFY_IS_EQUAL(shuffle2(i,j,k,l), shuffle(i,j,k,l));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_cxx11_tensor_shuffling()
|
void test_cxx11_tensor_shuffling()
|
||||||
|
@ -89,6 +89,24 @@ static void test_striding_as_lvalue()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
array<ptrdiff_t, 4> no_strides;
|
||||||
|
no_strides[0] = 1;
|
||||||
|
no_strides[1] = 1;
|
||||||
|
no_strides[2] = 1;
|
||||||
|
no_strides[3] = 1;
|
||||||
|
Tensor<float, 4, DataLayout> result2(3, 12, 10, 21);
|
||||||
|
result2.stride(strides) = tensor.stride(no_strides);
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; ++i) {
|
||||||
|
for (int j = 0; j < 3; ++j) {
|
||||||
|
for (int k = 0; k < 5; ++k) {
|
||||||
|
for (int l = 0; l < 7; ++l) {
|
||||||
|
VERIFY_IS_EQUAL(tensor(i,j,k,l), result2(2*i,4*j,2*k,3*l));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user