1 // 2 // Copyright (c) 2018-2019, Cem Bassoy, [email protected] 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // The authors gratefully acknowledge the support of 9 // Fraunhofer IOSB, Ettlingen, Germany 10 // 11 12 #ifndef BOOST_UBLAS_TENSOR_INDEX_HPP 13 #define BOOST_UBLAS_TENSOR_INDEX_HPP 14 15 16 #include <cstddef> 17 #include <array> 18 #include <vector> 19 20 namespace boost { 21 namespace numeric { 22 namespace ublas { 23 namespace index { 24 25 /** @brief Proxy template class for the einstein summation notation 26 * 27 * @note index::index_type<K> for 0<=K<=16 is used in tensor::operator() 28 * 29 * @tparam I wrapped integer 30 */ 31 template<std::size_t I> 32 struct index_type 33 { 34 static constexpr std::size_t value = I; 35 operator ==boost::numeric::ublas::index::index_type36 constexpr bool operator == (std::size_t other) const { return value == other; } operator !=boost::numeric::ublas::index::index_type37 constexpr bool operator != (std::size_t other) const { return value != other; } 38 39 template <std::size_t K> operator ==boost::numeric::ublas::index::index_type40 constexpr bool operator == (index_type<K> /*other*/) const { return I==K; } 41 template <std::size_t K> operator !=boost::numeric::ublas::index::index_type42 constexpr bool operator != (index_type<K> /*other*/) const { return I!=K; } 43 operator ==boost::numeric::ublas::index::index_type44 constexpr bool operator == (index_type /*other*/) const { return true; } operator !=boost::numeric::ublas::index::index_type45 constexpr bool operator != (index_type /*other*/) const { return false; } 46 operator ()boost::numeric::ublas::index::index_type47 constexpr std::size_t operator()() const { return I; } 48 }; 49 50 /** @brief Proxy classes for the einstein summation notation 51 * 52 * @note index::_a ... index::_z is used in tensor::operator() 53 */ 54 55 static constexpr index_type< 0> _; 56 static constexpr index_type< 1> _a; 57 static constexpr index_type< 2> _b; 58 static constexpr index_type< 3> _c; 59 static constexpr index_type< 4> _d; 60 static constexpr index_type< 5> _e; 61 static constexpr index_type< 6> _f; 62 static constexpr index_type< 7> _g; 63 static constexpr index_type< 8> _h; 64 static constexpr index_type< 9> _i; 65 static constexpr index_type<10> _j; 66 static constexpr index_type<11> _k; 67 static constexpr index_type<12> _l; 68 static constexpr index_type<13> _m; 69 static constexpr index_type<14> _n; 70 static constexpr index_type<15> _o; 71 static constexpr index_type<16> _p; 72 static constexpr index_type<17> _q; 73 static constexpr index_type<18> _r; 74 static constexpr index_type<19> _s; 75 static constexpr index_type<20> _t; 76 static constexpr index_type<21> _u; 77 static constexpr index_type<22> _v; 78 static constexpr index_type<23> _w; 79 static constexpr index_type<24> _x; 80 static constexpr index_type<25> _y; 81 static constexpr index_type<26> _z; 82 83 } // namespace indices 84 85 } 86 } 87 } 88 89 #endif // _BOOST_UBLAS_TENSOR_INDEX_HPP_ 90