cxx11_tensor_layout_swap.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #include "main.h"
11 
12 #include <Eigen/CXX11/Tensor>
13 
14 using Eigen::Tensor;
15 
16 static void test_simple_swap()
17 {
18  Tensor<float, 3, ColMajor> tensor(2,3,7);
19  tensor.setRandom();
20 
21  Tensor<float, 3, RowMajor> tensor2 = tensor.swap_layout();
22  VERIFY_IS_EQUAL(tensor.dimension(0), tensor2.dimension(2));
23  VERIFY_IS_EQUAL(tensor.dimension(1), tensor2.dimension(1));
24  VERIFY_IS_EQUAL(tensor.dimension(2), tensor2.dimension(0));
25 
26  for (int i = 0; i < 2; ++i) {
27  for (int j = 0; j < 3; ++j) {
28  for (int k = 0; k < 7; ++k) {
29  VERIFY_IS_EQUAL(tensor(i,j,k), tensor2(k,j,i));
30  }
31  }
32  }
33 }
34 
35 
36 static void test_swap_as_lvalue()
37 {
38  Tensor<float, 3, ColMajor> tensor(2,3,7);
39  tensor.setRandom();
40 
41  Tensor<float, 3, RowMajor> tensor2(7,3,2);
42  tensor2.swap_layout() = tensor;
43  VERIFY_IS_EQUAL(tensor.dimension(0), tensor2.dimension(2));
44  VERIFY_IS_EQUAL(tensor.dimension(1), tensor2.dimension(1));
45  VERIFY_IS_EQUAL(tensor.dimension(2), tensor2.dimension(0));
46 
47  for (int i = 0; i < 2; ++i) {
48  for (int j = 0; j < 3; ++j) {
49  for (int k = 0; k < 7; ++k) {
50  VERIFY_IS_EQUAL(tensor(i,j,k), tensor2(k,j,i));
51  }
52  }
53  }
54 }
55 
56 
58 {
61 }
static void test_swap_as_lvalue()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
Definition: Tensor.h:101
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition: TensorBase.h:850
static void test_simple_swap()
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:331
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorLayoutSwapOp< const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > swap_layout() const
Definition: TensorBase.h:887
#define CALL_SUBTEST(FUNC)
Definition: main.h:342
void test_cxx11_tensor_layout_swap()
std::ptrdiff_t j
The tensor class.
Definition: Tensor.h:63


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:55