Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LabeledIndexing.hh
Go to the documentation of this file.
1 ///
2 /// @file LabeledIndexing.hh
3 /// @brief Tensor labeled indexer
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #ifndef HAMMER_MATH_MULTIDIM_LABELEDINDEXING
13 #define HAMMER_MATH_MULTIDIM_LABELEDINDEXING
14 
16 
17 namespace Hammer {
18 
19  namespace MultiDimensional {
20 
21 
22  template<class BasicIndexing>
23  class LabeledIndexing : public BasicIndexing {
24 
25  public:
27 
29 
30  LabeledIndexing(const LabeledIndexing&) = default;
31  LabeledIndexing(LabeledIndexing&&) = default;
32  LabeledIndexing& operator=(const LabeledIndexing&) = default;
34 
35  ~LabeledIndexing() = default;
36 
37  public:
38  /// @brief dimension of a specific component by label.
39  /// If multiple components with the same label exists,
40  /// returns the dimension of first (they should all be the same
41  /// by consistency)
42  /// @param[in] label the component label
43  /// @return the dimension
44  IndexType dim(IndexLabel label) const;
45 
46  using BasicIndexing::dim;
47 
48  /// @brief get the labels of all the indices at once
49  /// @return the list of labels
50  const LabelsList& labels() const;
51 
52  /// @brief returns only the labels corresponding to spin indices
53  /// @return the set of labels of the spin indices (squashes repetitions if present)
55 
56  protected:
57 
58  /// @brief returns the set of indices of this tensor that can be contracted
59  /// using dot with those of another given tensor
60  /// @param[in] otherLabels the other tensor
61  /// @return the set of labels
62  UniqueLabelsList sameIndices(const LabelsList& otherLabels) const;
63 
64  /// @brief returns the pairs of indices that can be traced over. Valid pairs
65  /// are composed by opposite sign labels which correspond to (reference)
66  /// spin indices
67  /// @return the set of label pairs
69 
70  public:
71 
72  /// @brief returns the position of the indices in the two tensor (this and another) that can be
73  /// contracted together, given a set of allowed index labels
74  /// @param[in] otherLabels the list of labels of the other tensor
75  /// @param[in] indices the list of labels of the allowed indices to be contracted
76  /// @param[in] sortedBySecond whether the result should be sorted according to the second element of the pair
77  /// @return pairs of indices corresponding to coordinates in this and other tensor that needs to be contracted together
78  IndexPairList getSameLabelPairs(const LabelsList& otherLabels, const UniqueLabelsList& indices, bool sortedBySecond = true) const;
79 
80  /// @brief returns the position of the indices that can be traced together, given a set of allowed index
81  /// labels
82  /// @param[in] indices the list of labels of the allowed indices to be traced
83  /// @return pairs of coordinate indices that needs to be traced together
85 
86 
87  IndexType labelIndex(IndexLabel label) const;
88 
89  bool isSameLabelShape(const LabelsList& otherLabels, const IndexList& otherIndices) const;
90 
91  template<typename S>
92  bool isSameLabelShape(const LabeledIndexing<S>& other) const;
93 
94  bool canAddAt(const LabelsList& otherLabels, const IndexList& otherIndices, IndexLabel coord,
95  IndexType position) const;
96 
97  void flipLabels();
98 
99  private:
100 
101  LabelsList _labels; ///< the labels of each tensor index
102  };
103 
105  }
106 
107 } // namespace Hammer
108 
110 
111 #endif
IndexType dim(IndexLabel label) const
dimension of a specific component by label.
LabeledIndexing & operator=(const LabeledIndexing &)=default
std::vector< IndexPair > IndexPairList
UniqueLabelsList sameIndices(const LabelsList &otherLabels) const
returns the set of indices of this tensor that can be contracted using dot with those of another give...
UniqueLabelsList spinIndices() const
returns only the labels corresponding to spin indices
bool isSameLabelShape(const LabelsList &otherLabels, const IndexList &otherIndices) const
uint16_t IndexType
LabelPairsSet oppositeIndices() const
returns the pairs of indices that can be traced over.
const LabelsList & labels() const
get the labels of all the indices at once
IndexPairList getSameLabelPairs(const LabelsList &otherLabels, const UniqueLabelsList &indices, bool sortedBySecond=true) const
returns the position of the indices in the two tensor (this and another) that can be contracted toget...
Forward declarations of types used in the tensor classes.
std::vector< IndexType > IndexList
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
Definition: IndexLabels.hh:27
Tensor labeled indexer template methods definitions.
IndexType labelIndex(IndexLabel label) const
bool canAddAt(const LabelsList &otherLabels, const IndexList &otherIndices, IndexLabel coord, IndexType position) const
std::vector< IndexLabel > LabelsList
std::set< IndexLabel > UniqueLabelsList
IndexPairList getOppositeLabelPairs(const UniqueLabelsList &indices) const
returns the position of the indices that can be traced together, given a set of allowed index labels ...
std::set< LabelPair > LabelPairsSet
LabelsList flipListOfLabels(LabelsList labels)
LabelsList _labels
the labels of each tensor index