Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:02

0001 //
0002 //  Copyright (c) 2018-2019, Cem Bassoy, cem.bassoy@gmail.com
0003 //
0004 //  Distributed under the Boost Software License, Version 1.0. (See
0005 //  accompanying file LICENSE_1_0.txt or copy at
0006 //  http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 //  The authors gratefully acknowledge the support of
0009 //  Fraunhofer IOSB, Ettlingen, Germany
0010 //
0011 
0012 #ifndef BOOST_UBLAS_TENSOR_MULTI_INDEX_HPP
0013 #define BOOST_UBLAS_TENSOR_MULTI_INDEX_HPP
0014 
0015 
0016 #include <cstddef>
0017 #include <array>
0018 #include <vector>
0019 
0020 #include "multi_index_utility.hpp"
0021 
0022 namespace boost {
0023 namespace numeric {
0024 namespace ublas {
0025 namespace index {
0026 
0027 template<std::size_t I>
0028 struct index_type;
0029 
0030 } // namespace indices
0031 }
0032 }
0033 }
0034 
0035 
0036 namespace boost {
0037 namespace numeric {
0038 namespace ublas {
0039 
0040 /** @brief Proxy class for the einstein summation notation
0041  *
0042  * Denotes an array of index_type types ::_a for 0<=K<=16 is used in tensor::operator()
0043 */
0044 template<std::size_t N>
0045 class multi_index
0046 {
0047 public:
0048     multi_index() = delete;
0049 
0050     template<std::size_t I, class ... indexes>
0051     constexpr multi_index(index::index_type<I> const& i, indexes ... is )
0052       : _base{i(), is()... }
0053     {
0054         static_assert( sizeof...(is)+1 == N,
0055                        "Static assert in boost::numeric::ublas::multi_index: number of constructor arguments is not equal to the template parameter." );
0056 
0057         static_assert( valid_multi_index<std::tuple<index::index_type<I>, indexes ...> >::value,
0058                        "Static assert in boost::numeric::ublas::multi_index: indexes occur twice in multi-index." );
0059     }
0060 
0061     multi_index(multi_index const& other)
0062       : _base(other._base)
0063     {
0064     }
0065 
0066     multi_index& operator=(multi_index const& other)
0067     {
0068         this->_base = other._base;
0069         return *this;
0070     }
0071 
0072     ~multi_index() = default;
0073 
0074     auto const& base() const { return _base; }
0075     constexpr auto size() const { return _base.size(); }
0076     constexpr auto at(std::size_t i) const { return _base.at(i); }
0077     constexpr auto operator[](std::size_t i) const { return _base.at(i); }
0078 
0079 private:
0080     std::array<std::size_t, N> _base;
0081 };
0082 
0083 template<std::size_t K, std::size_t N>
0084 constexpr auto get(multi_index<N> const& m) { return std::get<K>(m.base()); }
0085 
0086 template<std::size_t M, std::size_t N>
0087 auto array_to_vector(multi_index<M> const& lhs, multi_index<N> const& rhs)
0088 {
0089     using vtype = std::vector<std::size_t>;
0090 
0091     auto pair_of_vector = std::make_pair( vtype {}, vtype{}  );
0092 
0093     for(auto i = 0u; i < N; ++i)
0094         for(auto j = 0u; j < M; ++j)
0095             if ( lhs.at(i) == rhs.at(j) && lhs.at(i) != boost::numeric::ublas::index::_())
0096                 pair_of_vector.first .push_back( i+1 ),
0097                     pair_of_vector.second.push_back( j+1 );
0098 
0099     return pair_of_vector;
0100 }
0101 
0102 
0103 
0104 
0105 
0106 } // namespace ublas
0107 } // namespace numeric
0108 } // namespace boost
0109 
0110 #endif // MULTI_INDEX_HPP