12 #include <Eigen/CXX11/Tensor> 27 tensor2 = tensor1.
reshape(dim1);
29 tensor3 = tensor1.
reshape(dim2);
31 tensor4 = tensor1.
reshape(dim1).reshape(dim3);
33 for (
int i = 0;
i < 2; ++
i) {
34 for (
int j = 0;
j < 3; ++
j) {
35 for (
int k = 0; k < 7; ++k) {
46 MatrixXf
m1(2,3*5*7*11);
47 MatrixXf
m2(3*5*7*11,13);
50 MatrixXf m3 = m1 *
m2;
59 tensor3 = tensor1.
reshape(newDims1).contract(tensor2.reshape(newDims2), contract_along);
62 for (
int i = 0;
i < 2; ++
i) {
63 for (
int j = 0;
j < 13; ++
j) {
79 float scratch[2*3*1*7*1];
83 for (
int i = 0;
i < 2; ++
i) {
84 for (
int j = 0;
j < 3; ++
j) {
85 for (
int k = 0; k < 7; ++k) {
93 template<
int DataLayout>
102 slice1 = tensor.
slice(indices, sizes);
108 slice2 = tensor.
slice(indices2, sizes2);
109 for (
int i = 0;
i < 2; ++
i) {
110 for (
int j = 0;
j < 2; ++
j) {
111 for (
int k = 0; k < 3; ++k) {
118 template<
typename=
void>
121 const float b[1] = {42};
129 template<
int DataLayout>
137 Mtx m3 = m1.block(1, 2, 3, 3) * m2.block(0, 2, 3, 1);
149 tensor3 = tensor1.
slice(indices1, sizes1).contract(tensor2.slice(indices2, sizes2), contract_along);
152 for (
int i = 0;
i < 3; ++
i) {
153 for (
int j = 0;
j < 1; ++
j) {
161 for (
int i = 0;
i < 35; ++
i) {
166 template<
int DataLayout>
183 result.
slice(first_slice, sizes12) = tensor1;
189 result.
slice(third_slice, sizes3) = tensor3;
193 result.
slice(fourth_slice, sizes4) = tensor4;
195 for (
int j = 0;
j < 2; ++
j) {
196 for (
int k = 0; k < 7; ++k) {
197 for (
int i = 0;
i < 2; ++
i) {
203 for (
int i = 0;
i < 4; ++
i) {
204 for (
int j = 2;
j < 5; ++
j) {
205 for (
int k = 0; k < 5; ++k) {
208 for (
int k = 5; k < 7; ++k) {
216 result.
slice(fifth_slice, sizes5) = tensor5.
slice(fifth_slice, sizes5);
217 for (
int i = 0;
i < 4; ++
i) {
218 for (
int j = 2;
j < 5; ++
j) {
219 for (
int k = 0; k < 7; ++k) {
226 template<
int DataLayout>
263 for (
int i = 0;
i < 3; ++
i) {
264 for (
int j = 0;
j < 2; ++
j) {
273 for (
int l = 0;
l < 11; ++
l) {
274 for (
int k = 0; k < 2; ++k) {
285 for (
int i = 0;
i < 3; ++
i) {
286 for (
int j = 0;
j < 5; ++
j) {
287 for (
int k = 0; k < 7; ++k) {
288 for (
int l = 0;
l < 2; ++
l) {
289 int slice_index =
i + 3 * (
j + 5 * (k + 7 *
l));
300 for (
int l = 0;
l < 11; ++
l) {
301 for (
int k = 0; k < 7; ++k) {
302 for (
int j = 0;
j < 5; ++
j) {
303 for (
int i = 0;
i < 2; ++
i) {
304 int slice_index =
l + 11 * (k + 7 * (
j + 5 *
i));
321 template<
int DataLayout>
335 Index2 strides(-2,-1);
336 Index2 indicesStart(5,7);
337 Index2 indicesStop(0,4);
338 slice = tensor2.
stridedSlice(indicesStart, indicesStop, strides);
339 for (
int j = 0;
j < 2; ++
j) {
340 for (
int k = 0; k < 3; ++k) {
349 Index2 indicesStart(5,4);
350 Index2 indicesStop(5,5);
351 slice = tensor2.
stridedSlice(indicesStart, indicesStop, strides);
355 Tensor2f slice(7,11);
356 Index2 strides(1,-1);
357 Index2 indicesStart(-3,20);
358 Index2 indicesStop(20,-11);
359 slice = tensor2.
stridedSlice(indicesStart, indicesStop, strides);
360 for (
int j = 0;
j < 7; ++
j) {
361 for (
int k = 0; k < 11; ++k) {
368 Tensor5f slice1(1,1,1,1,1);
372 slice1 = tensor.
stridedSlice(indicesStart, indicesStop, strides);
377 Tensor5f slice(1,1,2,2,3);
378 Index5 start(1, 1, 3, 4, 5);
379 Index5 stop(2, 2, 5, 6, 8);
380 Index5 strides(1, 1, 1, 1, 1);
382 for (
int i = 0;
i < 2; ++
i) {
383 for (
int j = 0;
j < 2; ++
j) {
384 for (
int k = 0; k < 3; ++k) {
392 Tensor5f slice(1,1,2,2,3);
393 Index5 strides3(1, 1, -2, 1, -1);
394 Index5 indices3Start(1, 1, 4, 4, 7);
395 Index5 indices3Stop(2, 2, 0, 6, 4);
396 slice = tensor.
stridedSlice(indices3Start, indices3Stop, strides3);
397 for (
int i = 0;
i < 2; ++
i) {
398 for (
int j = 0;
j < 2; ++
j) {
399 for (
int k = 0; k < 3; ++k) {
407 Tensor5f slice(1,1,2,2,3);
408 Index5 strides3(1, 1, 2, 1, 1);
409 Index5 indices3Start(1, 1, 4, 4, 7);
410 Index5 indices3Stop(2, 2, 0, 6, 4);
411 slice = tensor.
stridedSlice(indices3Start, indices3Stop, strides3);
415 template<
int DataLayout>
429 Index2 indicesStart(3,4);
430 Index2 indicesStop(5,7);
433 tensor.slice(indicesStart,lengths)=slice;
434 tensor2.
stridedSlice(indicesStart,indicesStop,strides)=slice;
436 for(
int i=0;
i<7;
i++)
for(
int j=0;
j<11;
j++){
442 template<
int DataLayout>
456 for (
int i = 0;
i < 11; ++
i) {
464 CALL_SUBTEST_1(test_simple_reshape<void>());
465 CALL_SUBTEST_1(test_reshape_in_expr<void>());
466 CALL_SUBTEST_1(test_reshape_as_lvalue<void>());
468 CALL_SUBTEST_1(test_simple_slice<ColMajor>());
469 CALL_SUBTEST_1(test_simple_slice<RowMajor>());
471 CALL_SUBTEST_2(test_slice_in_expr<ColMajor>());
472 CALL_SUBTEST_3(test_slice_in_expr<RowMajor>());
473 CALL_SUBTEST_4(test_slice_as_lvalue<ColMajor>());
474 CALL_SUBTEST_4(test_slice_as_lvalue<RowMajor>());
475 CALL_SUBTEST_5(test_slice_raw_data<ColMajor>());
476 CALL_SUBTEST_5(test_slice_raw_data<RowMajor>());
478 CALL_SUBTEST_6(test_strided_slice_write<ColMajor>());
479 CALL_SUBTEST_6(test_strided_slice<ColMajor>());
480 CALL_SUBTEST_6(test_strided_slice_write<RowMajor>());
481 CALL_SUBTEST_6(test_strided_slice<RowMajor>());
483 CALL_SUBTEST_7(test_composition<ColMajor>());
484 CALL_SUBTEST_7(test_composition<RowMajor>());
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
static void test_simple_reshape()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static void test_strided_slice_write()
static void test_slice_as_lvalue()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorStridingSlicingOp< const StartIndices, const StopIndices, const Strides, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > stridedSlice(const StartIndices &startIndices, const StopIndices &stopIndices, const Strides &strides) const
static void test_reshape_as_lvalue()
A matrix or vector expression mapping an existing array of data.
static void test_const_slice()
std::vector< Array2i > sizes
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
A cost model used to limit the number of threads used for evaluating tensor expression.
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
static void test_strided_slice()
static void test_slice_raw_data()
#define VERIFY_IS_APPROX(a, b)
static const Line3 l(Rot3(), 1, 1)
static void test_reshape_in_expr()
#define VERIFY_IS_EQUAL(a, b)
A tensor expression mapping an existing array of data.
Tensor< float, 1 >::DimensionPair DimPair
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorReshapingOp< const NewDimensions, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > reshape(const NewDimensions &newDimensions) const
void test_cxx11_tensor_morphing()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set offsets
static void test_simple_slice()
static void test_composition()
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PointerType data()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
A reference to a tensor expression The expression will be evaluated lazily (as much as possible)...
static void test_slice_in_expr()
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
The matrix class, also used for vectors and row-vectors.