cxx11_tensor_map.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Functions

static void test_0d ()
 
static void test_1d ()
 
static void test_2d ()
 
static void test_3d ()
 
static void test_from_tensor ()
 
static int f (const TensorMap< Tensor< int, 3 > > &tensor)
 
static void test_casting ()
 
template<typename T >
static const Tadd_const (T &value)
 
static void test_0d_const_tensor ()
 
static void test_0d_const_tensor_map ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_map)
 

Function Documentation

◆ add_const()

template<typename T >
static const T& add_const ( T value)
static
267  {
268  return value;
269 }
squared absolute value
Definition: GlobalFunctions.h:87

References Eigen::value.

Referenced by test_0d_const_tensor().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_map  )
311  {
316 
319 
322 }
static void test_3d()
Definition: cxx11_tensor_map.cpp:119
static void test_0d_const_tensor_map()
Definition: cxx11_tensor_map.cpp:288
static void test_0d()
Definition: cxx11_tensor_map.cpp:17
static void test_2d()
Definition: cxx11_tensor_map.cpp:73
static void test_casting()
Definition: cxx11_tensor_map.cpp:245
static void test_0d_const_tensor()
Definition: cxx11_tensor_map.cpp:271
static void test_1d()
Definition: cxx11_tensor_map.cpp:34
static void test_from_tensor()
Definition: cxx11_tensor_map.cpp:161
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, test_0d(), test_0d_const_tensor(), test_0d_const_tensor_map(), test_1d(), test_2d(), test_3d(), test_casting(), and test_from_tensor().

◆ f()

static int f ( const TensorMap< Tensor< int, 3 > > &  tensor)
static
237  {
238  // Size<0> empty;
239  EIGEN_STATIC_ASSERT((internal::array_size<Sizes<> >::value == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
240  EIGEN_STATIC_ASSERT((internal::array_size<DSizes<int, 0> >::value == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
241  Tensor<int, 0> result = tensor.sum();
242  return result();
243 }
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
The tensor class.
Definition: Tensor.h:68
Definition: TensorDimensions.h:161
Definition: TensorDimensions.h:85

References EIGEN_STATIC_ASSERT, and Eigen::value.

Referenced by ChangingTOIParticle::actionsAfterTimeStep(), MercuryProblem::actionsAfterTimeStep(), VolumeCoupling::actionsAfterTimeStep(), HeatFluidCoupledSpecies< NormalForceSpecies >::actionsAfterTimeStep(), oomph::DGElement::add_flux_contributions_to_residuals(), SSPorousChannelEquations::add_generic_residual_contribution(), Membrane::adjustVertexParticleSize(), adolc_forward_jacobian(), bench(), CRBond_Bessel::bessikna(), CRBond_Bessel::bessiknb(), CRBond_Bessel::bessikv(), CRBond_Bessel::bessjyna(), CRBond_Bessel::bessjynb(), CRBond_Bessel::bessjyv(), oomph::GmshTetMesh< ELEMENT >::build_from_scaffold(), oomph::CubicTetMeshFacetedSurface::build_it(), oomph::GmshTetMesh< ELEMENT >::build_it(), oomph::TetgenMesh< ELEMENT >::build_tetgenio(), Membrane::buildMesh(), pcast_array< SrcPacket, TgtPacket, 8, 1 >::cast(), DarcyProblem< ELEMENT >::complete_problem_setup(), Eigen::RealQZ< MatrixType_ >::compute(), SCoupling< M, O >::computeSCouplingForcesFromTriangles(), Eigen::StlThreadEnvironment::CreateTask(), Eigen::StlThreadEnvironment::CreateThread(), cwise_ref(), CylinderAndInterfaceDomain::CylinderAndInterfaceDomain(), oomph::Domain::d2macro_element_boundary(), oomph::TopologicallyRectangularDomain::d2macro_element_boundary(), tetgenio::deinitialize(), SSPorousChannelEquations::df_dt(), Eigen::BDCSVD< MatrixType_, Options_ >::divide(), oomph::Domain::dmacro_element_boundary(), oomph::TopologicallyRectangularDomain::dmacro_element_boundary(), DarcyProblem< ELEMENT >::doc_shape_functions(), EIGEN_DECLARE_TEST(), File::File(), oomph::KirchhoffLoveBeamEquations::fill_in_contribution_to_residuals_beam(), oomph::KirchhoffLoveShellEquations::fill_in_contribution_to_residuals_shell(), oomph::DarcyEquations< DIM >::fill_in_generic_residual_contribution(), Eigen::RealQZ< MatrixType_ >::findSmallDiagEntry(), Eigen::half_impl::float_to_half_rtne(), ProblemParameters::Fluid_body_force(), oomph::EulerEquations< DIM >::flux(), oomph::ScalarAdvectionEquations< DIM >::flux(), Eigen::ThreadLocal< T, Initialize, Release >::ForEach(), forward_jacobian(), forward_jacobian_cpp11(), gemv_complex_col(), oomph::Problem::get_dvaluesdt(), RachelsAdvectionDiffusion::get_exact_u(), TwoNodePoissonElement::get_residuals(), NurbsSurface::getDistance(), Membrane::getVolume(), Eigen::internal::idrs(), tetgenio::init(), Membrane::initializeEdgeBendingQuantities(), SSPorousChannelEquations::interpolated_f(), TwoDDGProblem< ELEMENT >::limit(), oomph::FullCircleDomain::lin_interpolate(), oomph::TubeDomain::lin_interpolate(), oomph::CylinderWithFlagDomain::linear_interpolate(), oomph::RectangleWithHoleAndAnnularRegionDomain::linear_interpolate(), CylinderAndInterfaceDomain::linear_interpolate(), RectangleWithHoleDomain::linear_interpolate(), oomph::HalfRectangleWithHoleDomain::linear_interpolate(), oomph::RectangleWithHoleDomain::linear_interpolate(), oomph::RectangleWithHoleAndAnnularRegionDomain::macro_element_boundary(), oomph::Domain::macro_element_boundary(), oomph::WarpedCubeDomain::macro_element_boundary(), oomph::AnnularDomain::macro_element_boundary(), oomph::FullCircleDomain::macro_element_boundary(), oomph::QuarterCircleSectorDomain::macro_element_boundary(), oomph::QuarterPipeDomain::macro_element_boundary(), oomph::QuarterTubeDomain::macro_element_boundary(), oomph::TopologicallyRectangularDomain::macro_element_boundary(), oomph::TubeDomain::macro_element_boundary(), oomph::EighthSphereDomain::macro_element_boundary(), RectangleWithHoleDomain::macro_element_boundary(), oomph::HalfRectangleWithHoleDomain::macro_element_boundary(), CylinderAndInterfaceDomain::macro_element_boundary(), oomph::CylinderWithFlagDomain::macro_element_boundary(), oomph::RectangleWithHoleDomain::macro_element_boundary(), main_gemm(), main_gemv(), ProblemParameters::Mass_source(), Eigen::MatrixBase< Derived >::matrixFunction(), CRBond_Bessel::msta1(), CRBond_Bessel::msta2(), Eigen::type2indexpair< f, s >::operator IndexPair< Index >(), Eigen::internal::operator*(), oomph::OomphInfo::operator<<(), oomph::QMacroElement< 2 >::output(), oomph::QMacroElement< 3 >::output(), oomph::DGElement::output_faces(), oomph::QMacroElement< 2 >::output_macro_element_boundaries(), oomph::QMacroElement< 3 >::output_macro_element_boundaries(), Eigen::CoreThreadPoolDevice::parallelFor(), Eigen::CoreThreadPoolDevice::parallelForImpl(), Eigen::internal::pcast(), Eigen::internal::pcast< Packet2d, Packet16c >(), Eigen::internal::pcast< Packet2d, Packet16uc >(), Eigen::internal::pcast< Packet2l, Packet16c >(), Eigen::internal::pcast< Packet2l, Packet16uc >(), Eigen::internal::pcast< Packet2ul, Packet16c >(), Eigen::internal::pcast< Packet2ul, Packet16uc >(), Eigen::internal::pdiv_float_common(), Eigen::internal::pload1< Packet4f >(), Eigen::internal::ploaddup< Packet16bf >(), Eigen::internal::ploaddup< Packet16h >(), GlobalFct::plot_it(), LiquidMigrationMPI2Test::printTime(), Eigen::internal::ptranspose(), Eigen::RealQZ< MatrixType_ >::pushDownZero(), oomph::WarpedCubeDomain::r_B(), oomph::QuarterPipeDomain::r_B(), oomph::QuarterTubeDomain::r_bot_right_B(), oomph::QuarterTubeDomain::r_bot_right_D(), oomph::QuarterCircleSectorDomain::r_bot_right_E(), oomph::QuarterTubeDomain::r_bot_right_F(), oomph::QuarterTubeDomain::r_bot_right_L(), oomph::QuarterCircleSectorDomain::r_bot_right_N(), oomph::QuarterTubeDomain::r_bot_right_R(), oomph::QuarterCircleSectorDomain::r_bot_right_S(), oomph::QuarterTubeDomain::r_bot_right_U(), oomph::QuarterCircleSectorDomain::r_bot_right_W(), oomph::QuarterTubeDomain::r_centr_B(), oomph::EighthSphereDomain::r_centr_B(), oomph::QuarterTubeDomain::r_centr_D(), oomph::EighthSphereDomain::r_centr_D(), oomph::QuarterCircleSectorDomain::r_centr_E(), oomph::QuarterTubeDomain::r_centr_F(), oomph::EighthSphereDomain::r_centr_F(), oomph::QuarterTubeDomain::r_centr_L(), oomph::EighthSphereDomain::r_centr_L(), oomph::QuarterCircleSectorDomain::r_centr_N(), oomph::QuarterTubeDomain::r_centr_R(), oomph::EighthSphereDomain::r_centr_R(), oomph::QuarterCircleSectorDomain::r_centr_S(), oomph::QuarterTubeDomain::r_centr_U(), oomph::EighthSphereDomain::r_centr_U(), oomph::QuarterCircleSectorDomain::r_centr_W(), oomph::WarpedCubeDomain::r_D(), oomph::QuarterPipeDomain::r_D(), oomph::TopologicallyRectangularDomain::r_E(), oomph::WarpedCubeDomain::r_F(), oomph::QuarterPipeDomain::r_F(), oomph::EighthSphereDomain::r_front_B(), oomph::EighthSphereDomain::r_front_D(), oomph::EighthSphereDomain::r_front_F(), oomph::EighthSphereDomain::r_front_L(), oomph::EighthSphereDomain::r_front_R(), oomph::EighthSphereDomain::r_front_U(), oomph::WarpedCubeDomain::r_L(), oomph::QuarterPipeDomain::r_L(), oomph::FishDomain::r_lower_body_E(), oomph::FishDomain::r_lower_body_N(), oomph::FishDomain::r_lower_body_S(), oomph::FishDomain::r_lower_body_W(), oomph::FishDomain::r_lower_fin_E(), oomph::FishDomain::r_lower_fin_N(), oomph::FishDomain::r_lower_fin_S(), oomph::FishDomain::r_lower_fin_W(), oomph::TopologicallyRectangularDomain::r_N(), oomph::WarpedCubeDomain::r_R(), oomph::QuarterPipeDomain::r_R(), oomph::EighthSphereDomain::r_right_B(), oomph::EighthSphereDomain::r_right_D(), oomph::EighthSphereDomain::r_right_F(), oomph::EighthSphereDomain::r_right_L(), oomph::EighthSphereDomain::r_right_R(), oomph::EighthSphereDomain::r_right_U(), oomph::TopologicallyRectangularDomain::r_S(), oomph::QuarterTubeDomain::r_top_left_B(), oomph::QuarterTubeDomain::r_top_left_D(), oomph::QuarterCircleSectorDomain::r_top_left_E(), oomph::QuarterTubeDomain::r_top_left_F(), oomph::QuarterTubeDomain::r_top_left_L(), oomph::QuarterCircleSectorDomain::r_top_left_N(), oomph::QuarterTubeDomain::r_top_left_R(), oomph::QuarterCircleSectorDomain::r_top_left_S(), oomph::QuarterTubeDomain::r_top_left_U(), oomph::QuarterCircleSectorDomain::r_top_left_W(), oomph::WarpedCubeDomain::r_U(), oomph::QuarterPipeDomain::r_U(), oomph::EighthSphereDomain::r_up_B(), oomph::EighthSphereDomain::r_up_D(), oomph::EighthSphereDomain::r_up_F(), oomph::EighthSphereDomain::r_up_L(), oomph::EighthSphereDomain::r_up_R(), oomph::EighthSphereDomain::r_up_U(), oomph::TopologicallyRectangularDomain::r_W(), Membrane::read(), TriangulatedWall::readVTK(), oomph::RefineableQuadMeshWithMovingCylinder< MyRefineableQTaylorHoodElement >::RefineableQuadMeshWithMovingCylinder(), oomph::AugmentedBlockFoldLinearSolver::resolve(), oomph::AugmentedBlockPitchForkLinearSolver::resolve(), Quaternion::rotateInverseInertiaTensor(), Eigen::internal::redux_vec_unroller< Func, Evaluator, Start, 0 >::run(), Eigen::internal::LU_kernel_bmod< 1 >::run(), Membrane::saveAsOFF(), Eigen::seq(), Eigen::type2indexpair< f, s >::set(), TriangulatedWall::set(), AxiPoroProblem< ELEMENT, TIMESTEPPER >::set_boundary_values(), my_problem::set_Frequency(), Camera::setFrame(), Binary::setFrequency(), oomph::DGElement::setup_face_neighbour_info(), oomph::TetMeshFacetedSurface::setup_facet_connectivity_for_tetgen(), oomph::TetgenMesh< ELEMENT >::setup_reverse_lookup_schemes_for_faceted_surface(), RotatingDrum::setVibrationFrequency(), oomph::TetMeshBase::snap_nodes_onto_geometric_objects(), oomph::AugmentedBlockFoldLinearSolver::solve(), oomph::AugmentedBlockPitchForkLinearSolver::solve(), oomph::CG< MATRIX >::solve(), oomph::BiCGStab< MATRIX >::solve(), oomph::GS< MATRIX >::solve(), oomph::GS< CRDoubleMatrix >::solve(), oomph::DampedJacobi< MATRIX >::solve(), oomph::GMRES< MATRIX >::solve(), oomph::AugmentedProblemGMRES::solve(), oomph::HelmholtzGMRESMG< MATRIX >::solve(), oomph::HelmholtzFGMRESMG< MATRIX >::solve(), TestProblem::source(), SphericalTetMeshFacetedSurface::SphericalTetMeshFacetedSurface(), Eigen::RealQZ< MatrixType_ >::step(), WearableTriangulatedWall::storeDebris(), BiharmonicTestFunctions1::surface_load(), BiharmonicTestFunctions2::surface_load(), test_casting(), oomph::TetMeshFacetedClosedSurfaceForRemesh::TetMeshFacetedClosedSurfaceForRemesh(), TriangulatedWall::TriangulatedWall(), oomph::ProjectionProblem< PROJECTABLE_ELEMENT >::unpin_all(), oomph::RefineableTetgenMesh< ELEMENT >::update_faceted_surface_using_face_mesh(), SCoupling< M, O >::updateTriangleWall(), oomph::TetMeshFacetedSurface::vertex_index_in_tetgen(), oomph::WarpedCubeDomain::warp_it(), WallVTKWriter::write(), Membrane::write(), oomph::GmshTetScaffoldMesh::write_geo_file(), SingleParticle< SpeciesType >::writeEneTimeStep(), ParticleVtkWriter::writeExtraFields(), TriangulatedWall::writeVTK(), InteractionVTKWriter::writeVTKPointData(), and oomph::TetMeshFacetedClosedSurfaceForRemesh::~TetMeshFacetedClosedSurfaceForRemesh().

◆ test_0d()

static void test_0d ( )
static
17  {
18  Tensor<int, 0> scalar1;
20 
21  TensorMap<const Tensor<int, 0> > scalar3(scalar1.data());
23 
24  scalar1() = 7;
25  scalar2() = 13;
26 
27  VERIFY_IS_EQUAL(scalar1.rank(), 0);
28  VERIFY_IS_EQUAL(scalar1.size(), 1);
29 
30  VERIFY_IS_EQUAL(scalar3(), 7);
31  VERIFY_IS_EQUAL(scalar4(), 13);
32 }
A tensor expression mapping an existing array of data.
Definition: TensorMap.h:33
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
Definition: Tensor.h:101
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: Tensor.h:102
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const
Definition: Tensor.h:98
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::rank(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_0d_const_tensor()

static void test_0d_const_tensor ( )
static
271  {
272  Tensor<int, 0> scalar1;
273  Tensor<int, 0, RowMajor> scalar2;
274 
275  TensorMap<const Tensor<int, 0> > scalar3(add_const(scalar1).data());
277 
278  scalar1() = 7;
279  scalar2() = 13;
280 
281  VERIFY_IS_EQUAL(scalar1.rank(), 0);
282  VERIFY_IS_EQUAL(scalar1.size(), 1);
283 
284  VERIFY_IS_EQUAL(scalar3(), 7);
285  VERIFY_IS_EQUAL(scalar4(), 13);
286 }
int data[]
Definition: Map_placement_new.cpp:1
static const T & add_const(T &value)
Definition: cxx11_tensor_map.cpp:267

References add_const(), data, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::rank(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_0d_const_tensor_map()

static void test_0d_const_tensor_map ( )
static
288  {
289  Tensor<int, 0> scalar1;
290  Tensor<int, 0, RowMajor> scalar2;
291 
292  const TensorMap<Tensor<int, 0> > scalar3(scalar1.data());
293  const TensorMap<Tensor<int, 0, RowMajor> > scalar4(scalar2.data());
294 
295  // Although TensorMap is constant, we still can write to the underlying
296  // storage, because we map over non-constant Tensor.
297  scalar3() = 7;
298  scalar4() = 13;
299 
300  VERIFY_IS_EQUAL(scalar1(), 7);
301  VERIFY_IS_EQUAL(scalar2(), 13);
302 
303  // Pointer to the underlying storage is also non-const.
304  scalar3.data()[0] = 8;
305  scalar4.data()[0] = 14;
306 
307  VERIFY_IS_EQUAL(scalar1(), 8);
308  VERIFY_IS_EQUAL(scalar2(), 14);
309 }

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::data(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_1d()

static void test_1d ( )
static
34  {
37 
38  TensorMap<const Tensor<int, 1> > vec3(vec1.data(), 6);
39  TensorMap<const Tensor<int, 1, RowMajor> > vec4(vec2.data(), 6);
40 
41  vec1(0) = 4;
42  vec2(0) = 0;
43  vec1(1) = 8;
44  vec2(1) = 1;
45  vec1(2) = 15;
46  vec2(2) = 2;
47  vec1(3) = 16;
48  vec2(3) = 3;
49  vec1(4) = 23;
50  vec2(4) = 4;
51  vec1(5) = 42;
52  vec2(5) = 5;
53 
54  VERIFY_IS_EQUAL(vec1.rank(), 1);
55  VERIFY_IS_EQUAL(vec1.size(), 6);
56  VERIFY_IS_EQUAL(vec1.dimension(0), 6);
57 
58  VERIFY_IS_EQUAL(vec3(0), 4);
59  VERIFY_IS_EQUAL(vec3(1), 8);
60  VERIFY_IS_EQUAL(vec3(2), 15);
61  VERIFY_IS_EQUAL(vec3(3), 16);
62  VERIFY_IS_EQUAL(vec3(4), 23);
63  VERIFY_IS_EQUAL(vec3(5), 42);
64 
65  VERIFY_IS_EQUAL(vec4(0), 0);
66  VERIFY_IS_EQUAL(vec4(1), 1);
67  VERIFY_IS_EQUAL(vec4(2), 2);
68  VERIFY_IS_EQUAL(vec4(3), 3);
69  VERIFY_IS_EQUAL(vec4(4), 4);
70  VERIFY_IS_EQUAL(vec4(5), 5);
71 }
RowVectorXd vec1(3)

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), vec1(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_2d()

static void test_2d ( )
static
73  {
74  Tensor<int, 2> mat1(2, 3);
75  Tensor<int, 2, RowMajor> mat2(2, 3);
76 
77  mat1(0, 0) = 0;
78  mat1(0, 1) = 1;
79  mat1(0, 2) = 2;
80  mat1(1, 0) = 3;
81  mat1(1, 1) = 4;
82  mat1(1, 2) = 5;
83 
84  mat2(0, 0) = 0;
85  mat2(0, 1) = 1;
86  mat2(0, 2) = 2;
87  mat2(1, 0) = 3;
88  mat2(1, 1) = 4;
89  mat2(1, 2) = 5;
90 
91  TensorMap<const Tensor<int, 2> > mat3(mat1.data(), 2, 3);
92  TensorMap<const Tensor<int, 2, RowMajor> > mat4(mat2.data(), 2, 3);
93 
94  VERIFY_IS_EQUAL(mat3.rank(), 2);
95  VERIFY_IS_EQUAL(mat3.size(), 6);
96  VERIFY_IS_EQUAL(mat3.dimension(0), 2);
97  VERIFY_IS_EQUAL(mat3.dimension(1), 3);
98 
99  VERIFY_IS_EQUAL(mat4.rank(), 2);
100  VERIFY_IS_EQUAL(mat4.size(), 6);
101  VERIFY_IS_EQUAL(mat4.dimension(0), 2);
102  VERIFY_IS_EQUAL(mat4.dimension(1), 3);
103 
104  VERIFY_IS_EQUAL(mat3(0, 0), 0);
105  VERIFY_IS_EQUAL(mat3(0, 1), 1);
106  VERIFY_IS_EQUAL(mat3(0, 2), 2);
107  VERIFY_IS_EQUAL(mat3(1, 0), 3);
108  VERIFY_IS_EQUAL(mat3(1, 1), 4);
109  VERIFY_IS_EQUAL(mat3(1, 2), 5);
110 
111  VERIFY_IS_EQUAL(mat4(0, 0), 0);
112  VERIFY_IS_EQUAL(mat4(0, 1), 1);
113  VERIFY_IS_EQUAL(mat4(0, 2), 2);
114  VERIFY_IS_EQUAL(mat4(1, 0), 3);
115  VERIFY_IS_EQUAL(mat4(1, 1), 4);
116  VERIFY_IS_EQUAL(mat4(1, 2), 5);
117 }
MatrixXd mat1(size, size)

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::dimension(), mat1(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::rank(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::size(), and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_3d()

static void test_3d ( )
static
119  {
120  Tensor<int, 3> mat1(2, 3, 7);
121  Tensor<int, 3, RowMajor> mat2(2, 3, 7);
122 
123  int val = 0;
124  for (int i = 0; i < 2; ++i) {
125  for (int j = 0; j < 3; ++j) {
126  for (int k = 0; k < 7; ++k) {
127  mat1(i, j, k) = val;
128  mat2(i, j, k) = val;
129  val++;
130  }
131  }
132  }
133 
134  TensorMap<const Tensor<int, 3> > mat3(mat1.data(), 2, 3, 7);
135  TensorMap<const Tensor<int, 3, RowMajor> > mat4(mat2.data(), 2, 3, 7);
136 
137  VERIFY_IS_EQUAL(mat3.rank(), 3);
138  VERIFY_IS_EQUAL(mat3.size(), 2 * 3 * 7);
139  VERIFY_IS_EQUAL(mat3.dimension(0), 2);
140  VERIFY_IS_EQUAL(mat3.dimension(1), 3);
141  VERIFY_IS_EQUAL(mat3.dimension(2), 7);
142 
143  VERIFY_IS_EQUAL(mat4.rank(), 3);
144  VERIFY_IS_EQUAL(mat4.size(), 2 * 3 * 7);
145  VERIFY_IS_EQUAL(mat4.dimension(0), 2);
146  VERIFY_IS_EQUAL(mat4.dimension(1), 3);
147  VERIFY_IS_EQUAL(mat4.dimension(2), 7);
148 
149  val = 0;
150  for (int i = 0; i < 2; ++i) {
151  for (int j = 0; j < 3; ++j) {
152  for (int k = 0; k < 7; ++k) {
153  VERIFY_IS_EQUAL(mat3(i, j, k), val);
154  VERIFY_IS_EQUAL(mat4(i, j, k), val);
155  val++;
156  }
157  }
158  }
159 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
char char char int int * k
Definition: level2_impl.h:374
val
Definition: calibrate.py:119
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::dimension(), i, j, k, mat1(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::rank(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::size(), calibrate::val, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_casting()

static void test_casting ( )
static
245  {
246  Tensor<int, 3> tensor(2, 3, 7);
247 
248  int val = 0;
249  for (int i = 0; i < 2; ++i) {
250  for (int j = 0; j < 3; ++j) {
251  for (int k = 0; k < 7; ++k) {
252  tensor(i, j, k) = val;
253  val++;
254  }
255  }
256  }
257 
258  TensorMap<Tensor<int, 3> > map(tensor);
259  int sum1 = f(map);
260  int sum2 = f(tensor);
261 
262  VERIFY_IS_EQUAL(sum1, sum2);
263  VERIFY_IS_EQUAL(sum1, 861);
264 }
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237

References f(), i, j, k, calibrate::val, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ test_from_tensor()

static void test_from_tensor ( )
static
161  {
162  Tensor<int, 3> mat1(2, 3, 7);
163  Tensor<int, 3, RowMajor> mat2(2, 3, 7);
164 
165  int val = 0;
166  for (int i = 0; i < 2; ++i) {
167  for (int j = 0; j < 3; ++j) {
168  for (int k = 0; k < 7; ++k) {
169  mat1(i, j, k) = val;
170  mat2(i, j, k) = val;
171  val++;
172  }
173  }
174  }
175 
178 
179  VERIFY_IS_EQUAL(mat3.rank(), 3);
180  VERIFY_IS_EQUAL(mat3.size(), 2 * 3 * 7);
181  VERIFY_IS_EQUAL(mat3.dimension(0), 2);
182  VERIFY_IS_EQUAL(mat3.dimension(1), 3);
183  VERIFY_IS_EQUAL(mat3.dimension(2), 7);
184 
185  VERIFY_IS_EQUAL(mat4.rank(), 3);
186  VERIFY_IS_EQUAL(mat4.size(), 2 * 3 * 7);
187  VERIFY_IS_EQUAL(mat4.dimension(0), 2);
188  VERIFY_IS_EQUAL(mat4.dimension(1), 3);
189  VERIFY_IS_EQUAL(mat4.dimension(2), 7);
190 
191  val = 0;
192  for (int i = 0; i < 2; ++i) {
193  for (int j = 0; j < 3; ++j) {
194  for (int k = 0; k < 7; ++k) {
195  VERIFY_IS_EQUAL(mat3(i, j, k), val);
196  VERIFY_IS_EQUAL(mat4(i, j, k), val);
197  val++;
198  }
199  }
200  }
201 
203 
204  val = 0;
205  for (int i = 0; i < 2; ++i) {
206  for (int j = 0; j < 3; ++j) {
207  for (int k = 0; k < 7; ++k) {
208  array<ptrdiff_t, 3> coords;
209  coords[0] = i;
210  coords[1] = j;
211  coords[2] = k;
212  mat5(coords) = val;
213  val++;
214  }
215  }
216  }
217 
219 
220  VERIFY_IS_EQUAL(mat6.rank(), 3);
221  VERIFY_IS_EQUAL(mat6.size(), 2 * 3 * 7);
222  VERIFY_IS_EQUAL(mat6.dimension(0), 2);
223  VERIFY_IS_EQUAL(mat6.dimension(1), 3);
224  VERIFY_IS_EQUAL(mat6.dimension(2), 7);
225 
226  val = 0;
227  for (int i = 0; i < 2; ++i) {
228  for (int j = 0; j < 3; ++j) {
229  for (int k = 0; k < 7; ++k) {
230  VERIFY_IS_EQUAL(mat6(i, j, k), val);
231  val++;
232  }
233  }
234  }
235 }
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:30
std::array< T, N > array
Definition: EmulateArray.h:231

References Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::dimension(), i, j, k, mat1(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::rank(), Eigen::TensorMap< PlainObjectType, Options_, MakePointer_ >::size(), calibrate::val, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().