cxx11_tensor_custom_index.cpp File Reference
#include "main.h"
#include <limits>
#include <map>
#include <Eigen/Dense>
#include <Eigen/CXX11/Tensor>

Functions

template<int DataLayout>
static void test_map_as_index ()
 
template<int DataLayout>
static void test_matrix_as_index ()
 
template<int DataLayout>
static void test_varlist_as_index ()
 
template<int DataLayout>
static void test_sizes_as_index ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_custom_index)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_custom_index  )
74  {
75  test_map_as_index<ColMajor>();
76  test_map_as_index<RowMajor>();
77  test_matrix_as_index<ColMajor>();
78  test_matrix_as_index<RowMajor>();
79  test_varlist_as_index<ColMajor>();
80  test_varlist_as_index<RowMajor>();
81  test_sizes_as_index<ColMajor>();
82  test_sizes_as_index<RowMajor>();
83 }

◆ test_map_as_index()

template<int DataLayout>
static void test_map_as_index ( )
static
20  {
21  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
22  tensor.setRandom();
23 
24  using NormalIndex = DSizes<ptrdiff_t, 4>;
25  using CustomIndex = std::map<ptrdiff_t, ptrdiff_t>;
26  CustomIndex coeffC;
27  coeffC[0] = 1;
28  coeffC[1] = 2;
29  coeffC[2] = 4;
30  coeffC[3] = 1;
31  NormalIndex coeff(1, 2, 4, 1);
32 
33  VERIFY_IS_EQUAL(tensor.coeff(coeffC), tensor.coeff(coeff));
34  VERIFY_IS_EQUAL(tensor.coeffRef(coeffC), tensor.coeffRef(coeff));
35 }
The tensor class.
Definition: Tensor.h:68
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
Definition: TensorDimensions.h:161

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeff(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeffRef(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

◆ test_matrix_as_index()

template<int DataLayout>
static void test_matrix_as_index ( )
static
38  {
39  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
40  tensor.setRandom();
41 
42  using NormalIndex = DSizes<ptrdiff_t, 4>;
43  using CustomIndex = Matrix<unsigned int, 4, 1>;
44  CustomIndex coeffC(1, 2, 4, 1);
45  NormalIndex coeff(1, 2, 4, 1);
46 
47  VERIFY_IS_EQUAL(tensor.coeff(coeffC), tensor.coeff(coeff));
48  VERIFY_IS_EQUAL(tensor.coeffRef(coeffC), tensor.coeffRef(coeff));
49 }
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeff(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeffRef(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

◆ test_sizes_as_index()

template<int DataLayout>
static void test_sizes_as_index ( )
static
63  {
64  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
65  tensor.setRandom();
66 
67  DSizes<ptrdiff_t, 4> coeff(1, 2, 4, 1);
68  Sizes<1, 2, 4, 1> coeffC;
69 
70  VERIFY_IS_EQUAL(tensor.coeff(coeffC), tensor.coeff(coeff));
71  VERIFY_IS_EQUAL(tensor.coeffRef(coeffC), tensor.coeffRef(coeff));
72 }
Definition: TensorDimensions.h:85

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeff(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeffRef(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.

◆ test_varlist_as_index()

template<int DataLayout>
static void test_varlist_as_index ( )
static
52  {
53  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
54  tensor.setRandom();
55 
56  DSizes<ptrdiff_t, 4> coeff(1, 2, 4, 1);
57 
58  VERIFY_IS_EQUAL(tensor.coeff({1, 2, 4, 1}), tensor.coeff(coeff));
59  VERIFY_IS_EQUAL(tensor.coeffRef({1, 2, 4, 1}), tensor.coeffRef(coeff));
60 }

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeff(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::coeffRef(), Eigen::TensorBase< Derived, AccessLevel >::setRandom(), and VERIFY_IS_EQUAL.