12 #include <Eigen/CXX11/Tensor> 22 TensorRef<Tensor<int, 1>> ref3(input);
23 TensorRef<Tensor<int, 1>> ref4 = input;
25 VERIFY_IS_EQUAL(ref3.data(), input.
data());
26 VERIFY_IS_EQUAL(ref4.data(), input.
data());
28 for (
int i = 0; i < 6; ++i) {
29 VERIFY_IS_EQUAL(ref3(i), input(i));
30 VERIFY_IS_EQUAL(ref4(i), input(i));
33 for (
int i = 0; i < 6; ++i) {
36 for (
int i = 0; i < 6; ++i) {
37 VERIFY_IS_EQUAL(input(i), i);
39 for (
int i = 0; i < 6; ++i) {
40 ref4.coeffRef(i) = -i * 2;
42 for (
int i = 0; i < 6; ++i) {
43 VERIFY_IS_EQUAL(input(i), -i*2);
55 TensorRef<Tensor<int, 1>> ref3(input1 + input2);
56 TensorRef<Tensor<int, 1>> ref4 = input1 + input2;
58 VERIFY_IS_NOT_EQUAL(ref3.data(), input1.
data());
59 VERIFY_IS_NOT_EQUAL(ref4.data(), input1.
data());
60 VERIFY_IS_NOT_EQUAL(ref3.data(), input2.data());
61 VERIFY_IS_NOT_EQUAL(ref4.data(), input2.data());
63 for (
int i = 0; i < 6; ++i) {
64 VERIFY_IS_EQUAL(ref3(i), input1(i) + input2(i));
65 VERIFY_IS_EQUAL(ref4(i), input1(i) + input2(i));
75 TensorRef<Tensor<float, 3>> ref(input);
76 VERIFY_IS_EQUAL(ref.data(), input.
data());
77 VERIFY_IS_EQUAL(ref.dimension(0), 3);
78 VERIFY_IS_EQUAL(ref.dimension(1), 5);
79 VERIFY_IS_EQUAL(ref.dimension(2), 7);
81 for (
int i = 0; i < 3; ++i) {
82 for (
int j = 0; j < 5; ++j) {
83 for (
int k = 0; k < 7; ++k) {
84 VERIFY_IS_EQUAL(ref(i,j,k), input(i,j,k));
98 TensorRef<Tensor<float, 5>> slice = tensor.
slice(indices, sizes);
99 VERIFY_IS_EQUAL(slice(0,0,0,0,0), tensor(1,2,3,4,5));
103 slice = tensor.
slice(indices2, sizes2);
104 for (
int i = 0; i < 2; ++i) {
105 for (
int j = 0; j < 2; ++j) {
106 for (
int k = 0; k < 3; ++k) {
107 VERIFY_IS_EQUAL(slice(0,0,i,j,k), tensor(1,1,3+i,4+j,5+k));
114 slice = tensor.
slice(indices3, sizes3);
115 VERIFY_IS_EQUAL(slice.data(), tensor.
data());
124 TensorRef<Tensor<float, 3>> ref(input);
125 TensorRef<Tensor<float, 3>> ref_of_ref(ref);
126 TensorRef<Tensor<float, 3>> ref_of_ref2;
129 VERIFY_IS_EQUAL(ref_of_ref.data(), input.
data());
130 VERIFY_IS_EQUAL(ref_of_ref.dimension(0), 3);
131 VERIFY_IS_EQUAL(ref_of_ref.dimension(1), 5);
132 VERIFY_IS_EQUAL(ref_of_ref.dimension(2), 7);
134 VERIFY_IS_EQUAL(ref_of_ref2.data(), input.
data());
135 VERIFY_IS_EQUAL(ref_of_ref2.dimension(0), 3);
136 VERIFY_IS_EQUAL(ref_of_ref2.dimension(1), 5);
137 VERIFY_IS_EQUAL(ref_of_ref2.dimension(2), 7);
139 for (
int i = 0; i < 3; ++i) {
140 for (
int j = 0; j < 5; ++j) {
141 for (
int k = 0; k < 7; ++k) {
142 VERIFY_IS_EQUAL(ref_of_ref(i,j,k), input(i,j,k));
143 VERIFY_IS_EQUAL(ref_of_ref2(i,j,k), input(i,j,k));
154 TensorRef<Tensor<float, 3>> input_ref(input);
158 TensorRef<Tensor<float, 3>> result_ref(result);
163 result_ref = input_ref + bias;
164 for (
int i = 0; i < 3; ++i) {
165 for (
int j = 0; j < 5; ++j) {
166 for (
int k = 0; k < 7; ++k) {
167 VERIFY_IS_EQUAL(result_ref(i,j,k), input(i,j,k) + bias(i,j,k));
168 VERIFY_IS_NOT_EQUAL(result(i,j,k), input(i,j,k) + bias(i,j,k));
174 for (
int i = 0; i < 3; ++i) {
175 for (
int j = 0; j < 5; ++j) {
176 for (
int k = 0; k < 7; ++k) {
177 VERIFY_IS_EQUAL(result(i,j,k), input(i,j,k) + bias(i,j,k));
190 TensorRef<Tensor<float, 4>> slice = tensor.
chip(7, 4);
191 slice.coeffRef(0, 0, 0, 0) = 1.0f;
192 slice.coeffRef(1, 0, 0, 0) += 2.0f;
194 VERIFY_IS_EQUAL(tensor(0,0,0,0,7), 1.0
f);
195 VERIFY_IS_EQUAL(tensor(1,0,0,0,7), original(1,0,0,0,7) + 2.0
f);
203 TensorMap<Tensor<const float, 4> > m(t.
data(), 2, 3, 5, 7);
204 array<std::pair<ptrdiff_t, ptrdiff_t>, 4> paddings;
205 paddings[0] = std::make_pair(0, 0);
206 paddings[1] = std::make_pair(2, 1);
207 paddings[2] = std::make_pair(3, 4);
208 paddings[3] = std::make_pair(0, 0);
209 DSizes<Eigen::DenseIndex, 4> shuffle_dims(0, 1, 2, 3);
210 TensorRef<Tensor<const float, 4> > ref(m.pad(paddings));
211 array<std::pair<ptrdiff_t, ptrdiff_t>, 4> trivial;
212 trivial[0] = std::make_pair(0, 0);
213 trivial[1] = std::make_pair(0, 0);
214 trivial[2] = std::make_pair(0, 0);
215 trivial[3] = std::make_pair(0, 0);
217 VERIFY_IS_EQUAL(padded.
dimension(0), 2+0);
218 VERIFY_IS_EQUAL(padded.
dimension(1), 3+3);
219 VERIFY_IS_EQUAL(padded.
dimension(2), 5+7);
220 VERIFY_IS_EQUAL(padded.
dimension(3), 7+0);
222 for (
int i = 0; i < 2; ++i) {
223 for (
int j = 0; j < 6; ++j) {
224 for (
int k = 0; k < 12; ++k) {
225 for (
int l = 0; l < 7; ++l) {
226 if (j >= 2 && j < 5 && k >= 3 && k < 8) {
227 VERIFY_IS_EQUAL(padded(i,j,k,l), t(i,j-2,k-3,l));
229 VERIFY_IS_EQUAL(padded(i,j,k,l), 0.0
f);
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorSlicingOp< const StartIndices, const Sizes, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > slice(const StartIndices &startIndices, const Sizes &sizes) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
void test_cxx11_tensor_ref()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorShufflingOp< const Shuffle, const Derived > shuffle(const Shuffle &shuffle) const
static void test_ref_in_expr()
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorChippingOp< DimId, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > chip(const Index offset) const
static void test_nested_ops_with_ref()
static void test_simple_rvalue_ref()
static void test_ref_of_ref()
static void test_multiple_dims()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
static void test_coeff_ref()
static void test_simple_lvalue_ref()