2014-10-03 01:39:36 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
// for linear algebra.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
|
|
|
|
//
|
|
|
|
// 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 <Eigen/CXX11/Tensor>
|
|
|
|
|
|
|
|
using Eigen::Tensor;
|
|
|
|
|
|
|
|
|
|
|
|
static void test_dynamic_size()
|
|
|
|
{
|
2015-01-15 07:46:04 +08:00
|
|
|
Eigen::DSizes<int, 3> dimensions(2,3,7);
|
2014-10-03 01:39:36 +08:00
|
|
|
|
|
|
|
VERIFY_IS_EQUAL((int)Eigen::internal::array_get<0>(dimensions), 2);
|
|
|
|
VERIFY_IS_EQUAL((int)Eigen::internal::array_get<1>(dimensions), 3);
|
|
|
|
VERIFY_IS_EQUAL((int)Eigen::internal::array_get<2>(dimensions), 7);
|
2016-07-07 15:05:15 +08:00
|
|
|
VERIFY_IS_EQUAL((int)dimensions.TotalSize(), 2*3*7);
|
2015-01-15 07:46:04 +08:00
|
|
|
VERIFY_IS_EQUAL((int)dimensions[0], 2);
|
|
|
|
VERIFY_IS_EQUAL((int)dimensions[1], 3);
|
|
|
|
VERIFY_IS_EQUAL((int)dimensions[2], 7);
|
2014-10-03 01:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_fixed_size()
|
|
|
|
{
|
|
|
|
Eigen::Sizes<2,3,7> dimensions;
|
|
|
|
|
|
|
|
VERIFY_IS_EQUAL((int)Eigen::internal::array_get<0>(dimensions), 2);
|
|
|
|
VERIFY_IS_EQUAL((int)Eigen::internal::array_get<1>(dimensions), 3);
|
|
|
|
VERIFY_IS_EQUAL((int)Eigen::internal::array_get<2>(dimensions), 7);
|
2016-07-07 15:05:15 +08:00
|
|
|
VERIFY_IS_EQUAL((int)dimensions.TotalSize(), 2*3*7);
|
2014-10-03 01:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_match()
|
|
|
|
{
|
2016-07-07 21:18:23 +08:00
|
|
|
Eigen::DSizes<unsigned int, 3> dyn((unsigned int)2,(unsigned int)3,(unsigned int)7);
|
2014-10-03 01:39:36 +08:00
|
|
|
Eigen::Sizes<2,3,7> stat;
|
2015-01-15 07:46:04 +08:00
|
|
|
VERIFY_IS_EQUAL(Eigen::dimensions_match(dyn, stat), true);
|
2015-07-18 07:46:30 +08:00
|
|
|
|
|
|
|
Eigen::DSizes<int, 3> dyn1(2,3,7);
|
|
|
|
Eigen::DSizes<int, 2> dyn2(2,3);
|
2015-07-18 07:50:47 +08:00
|
|
|
VERIFY_IS_EQUAL(Eigen::dimensions_match(dyn1, dyn2), false);
|
2014-10-03 01:39:36 +08:00
|
|
|
}
|
|
|
|
|
2016-04-30 09:15:34 +08:00
|
|
|
static void test_rank_zero()
|
|
|
|
{
|
|
|
|
Eigen::Sizes<> scalar;
|
2016-07-07 15:05:15 +08:00
|
|
|
VERIFY_IS_EQUAL((int)scalar.TotalSize(), 1);
|
|
|
|
VERIFY_IS_EQUAL((int)scalar.rank(), 0);
|
|
|
|
VERIFY_IS_EQUAL((int)internal::array_prod(scalar), 1);
|
2016-04-30 09:15:34 +08:00
|
|
|
|
|
|
|
Eigen::DSizes<ptrdiff_t, 0> dscalar;
|
2016-07-07 15:05:15 +08:00
|
|
|
VERIFY_IS_EQUAL((int)dscalar.TotalSize(), 1);
|
|
|
|
VERIFY_IS_EQUAL((int)dscalar.rank(), 0);
|
2016-04-30 09:15:34 +08:00
|
|
|
}
|
2014-10-03 01:39:36 +08:00
|
|
|
|
2018-07-17 20:46:15 +08:00
|
|
|
EIGEN_DECLARE_TEST(cxx11_tensor_dimension)
|
2014-10-03 01:39:36 +08:00
|
|
|
{
|
|
|
|
CALL_SUBTEST(test_dynamic_size());
|
|
|
|
CALL_SUBTEST(test_fixed_size());
|
|
|
|
CALL_SUBTEST(test_match());
|
2016-04-30 09:15:34 +08:00
|
|
|
CALL_SUBTEST(test_rank_zero());
|
2014-10-03 01:39:36 +08:00
|
|
|
}
|