From 3625734bc8e63b4ccb4c190d170fd5d29fba5b54 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 29 Jun 2015 10:49:55 -0700 Subject: Moved some utilities to TensorMeta.h to make it easier to reuse them accross several tensor operations. Created the TensorDimensionList class to encode the list of all the dimensions of a tensor of rank n. This could be done using TensorIndexList, however TensorIndexList require cxx11 which isn't yet supported as widely as we'd like. --- .../Eigen/CXX11/src/Tensor/TensorDimensionList.h | 235 +++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h new file mode 100644 index 000000000..19e922f92 --- /dev/null +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h @@ -0,0 +1,235 @@ +// 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/. + +#ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H +#define EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H + +namespace Eigen { + +/** \internal + * + * \class TensorDimensionList + * \ingroup CXX11_Tensor_Module + * + * \brief Special case of tensor index list used to list all the dimensions of a tensor of rank n. + * + * \sa Tensor + */ + +template struct DimensionList { + const Index operator[] (const Index i) const { return i; } +}; + +namespace internal { + +template struct array_size > { + static const size_t value = Rank; +}; +template struct array_size > { + static const size_t value = Rank; +}; + +template const Index array_get(DimensionList& a) { + return n; +} +template const Index array_get(const DimensionList& a) { + return n; +} + + +#if defined(EIGEN_HAS_CONSTEXPR) +template +struct index_known_statically > { + constexpr bool operator() (const DenseIndex) const { + return true; + } +}; +template +struct index_known_statically > { + constexpr bool operator() (const DenseIndex) const { + return true; + } +}; + +template +struct all_indices_known_statically > { + constexpr bool operator() () const { + return true; + } +}; +template +struct all_indices_known_statically > { + constexpr bool operator() () const { + return true; + } +}; + +template +struct indices_statically_known_to_increase > { + constexpr bool operator() () const { + return true; + } +}; +template +struct indices_statically_known_to_increase > { + constexpr bool operator() () const { + return true; + } +}; + +template +struct index_statically_eq > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i == value; + } +}; +template +struct index_statically_eq > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i == value; + } +}; + +template +struct index_statically_ne > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i != value; + } +}; +template +struct index_statically_ne > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i != value; + } +}; + +template +struct index_statically_gt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i > value; + } +}; +template +struct index_statically_gt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i > value; + } +}; + +template +struct index_statically_lt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i < value; + } +}; +template +struct index_statically_lt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i < value; + } +}; + +#else +template +struct index_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex) const { + return true; + } +}; +template +struct index_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex) const { + return true; + } +}; + +template +struct all_indices_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; +template +struct all_indices_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; + +template +struct indices_statically_known_to_increase > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; +template +struct indices_statically_known_to_increase > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; + +template +struct index_statically_eq > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_eq > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; + +template +struct index_statically_ne > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_ne > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; + +template +struct index_statically_gt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_gt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; + +template +struct index_statically_lt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_lt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +#endif + +} // end namespace internal +} // end namespace Eigen + + +#endif // EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H -- cgit v1.2.3