blob: 38ce05bd8a858c678d217e46b942103f76cc7f87 [file] [log] [blame]
 // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2015 Benoit Steiner // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "main.h" #include #include #include #include using Eigen::Tensor; template static void test_map_as_index() { Tensor tensor(2, 3, 5, 7); tensor.setRandom(); using NormalIndex = DSizes; using CustomIndex = std::map; CustomIndex coeffC; coeffC[0] = 1; coeffC[1] = 2; coeffC[2] = 4; coeffC[3] = 1; NormalIndex coeff(1,2,4,1); VERIFY_IS_EQUAL(tensor.coeff(coeffC), tensor.coeff(coeff)); VERIFY_IS_EQUAL(tensor.coeffRef(coeffC), tensor.coeffRef(coeff)); } template static void test_matrix_as_index() { Tensor tensor(2, 3, 5, 7); tensor.setRandom(); using NormalIndex = DSizes; using CustomIndex = Matrix; CustomIndex coeffC(1,2,4,1); NormalIndex coeff(1,2,4,1); VERIFY_IS_EQUAL(tensor.coeff(coeffC), tensor.coeff(coeff)); VERIFY_IS_EQUAL(tensor.coeffRef(coeffC), tensor.coeffRef(coeff)); } template static void test_varlist_as_index() { Tensor tensor(2, 3, 5, 7); tensor.setRandom(); DSizes coeff(1,2,4,1); VERIFY_IS_EQUAL(tensor.coeff({1,2,4,1}), tensor.coeff(coeff)); VERIFY_IS_EQUAL(tensor.coeffRef({1,2,4,1}), tensor.coeffRef(coeff)); } template static void test_sizes_as_index() { Tensor tensor(2, 3, 5, 7); tensor.setRandom(); DSizes coeff(1,2,4,1); Sizes<1,2,4,1> coeffC; VERIFY_IS_EQUAL(tensor.coeff(coeffC), tensor.coeff(coeff)); VERIFY_IS_EQUAL(tensor.coeffRef(coeffC), tensor.coeffRef(coeff)); } EIGEN_DECLARE_TEST(cxx11_tensor_custom_index) { test_map_as_index(); test_map_as_index(); test_matrix_as_index(); test_matrix_as_index(); test_varlist_as_index(); test_varlist_as_index(); test_sizes_as_index(); test_sizes_as_index(); }