index.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Copyright (c) 2018-2019, Cem Bassoy, cem.bassoy@gmail.com
  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. #ifndef BOOST_UBLAS_TENSOR_INDEX_HPP
  12. #define BOOST_UBLAS_TENSOR_INDEX_HPP
  13. #include <cstddef>
  14. #include <array>
  15. #include <vector>
  16. namespace boost {
  17. namespace numeric {
  18. namespace ublas {
  19. namespace index {
  20. /** @brief Proxy template class for the einstein summation notation
  21. *
  22. * @note index::index_type<K> for 0<=K<=16 is used in tensor::operator()
  23. *
  24. * @tparam I wrapped integer
  25. */
  26. template<std::size_t I>
  27. struct index_type
  28. {
  29. static constexpr std::size_t value = I;
  30. constexpr bool operator == (std::size_t other) const { return value == other; }
  31. constexpr bool operator != (std::size_t other) const { return value != other; }
  32. template <std::size_t K>
  33. constexpr bool operator == (index_type<K> /*other*/) const { return I==K; }
  34. template <std::size_t K>
  35. constexpr bool operator != (index_type<K> /*other*/) const { return I!=K; }
  36. constexpr bool operator == (index_type /*other*/) const { return true; }
  37. constexpr bool operator != (index_type /*other*/) const { return false; }
  38. constexpr std::size_t operator()() const { return I; }
  39. };
  40. /** @brief Proxy classes for the einstein summation notation
  41. *
  42. * @note index::_a ... index::_z is used in tensor::operator()
  43. */
  44. static constexpr index_type< 0> _;
  45. static constexpr index_type< 1> _a;
  46. static constexpr index_type< 2> _b;
  47. static constexpr index_type< 3> _c;
  48. static constexpr index_type< 4> _d;
  49. static constexpr index_type< 5> _e;
  50. static constexpr index_type< 6> _f;
  51. static constexpr index_type< 7> _g;
  52. static constexpr index_type< 8> _h;
  53. static constexpr index_type< 9> _i;
  54. static constexpr index_type<10> _j;
  55. static constexpr index_type<11> _k;
  56. static constexpr index_type<12> _l;
  57. static constexpr index_type<13> _m;
  58. static constexpr index_type<14> _n;
  59. static constexpr index_type<15> _o;
  60. static constexpr index_type<16> _p;
  61. static constexpr index_type<17> _q;
  62. static constexpr index_type<18> _r;
  63. static constexpr index_type<19> _s;
  64. static constexpr index_type<20> _t;
  65. static constexpr index_type<21> _u;
  66. static constexpr index_type<22> _v;
  67. static constexpr index_type<23> _w;
  68. static constexpr index_type<24> _x;
  69. static constexpr index_type<25> _y;
  70. static constexpr index_type<26> _z;
  71. } // namespace indices
  72. }
  73. }
  74. }
  75. #endif // _BOOST_UBLAS_TENSOR_INDEX_HPP_