Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OuterContainer.hh
Go to the documentation of this file.
1 ///
2 /// @file OuterContainer.hh
3 /// @brief (Sum of) Outer product tensor data container
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_MULTIDIMS_OUTERCONTAINER
13 #define HAMMER_MATH_MULTIDIMS_OUTERCONTAINER
14 
15 #include <memory>
16 #include <vector>
17 #include <tuple>
18 #include <functional>
19 
23 
24 namespace Hammer {
25 
26  class Log;
27 
28  namespace Serial {
29 
30  struct FBTensorList;
31 
32  }
33 
34  namespace MultiDimensional {
35 
36  namespace Ops {
37 
38  class Sum;
39  class Multiply;
40  class Divide;
41  class OuterSquare;
42  class Dot;
43  class Optimize;
44  class Trace;
45  class Convert;
46 
47  } // namespace Ops
48 
49  class OuterContainer final : public IContainer {
50  private:
52  using DataType = std::vector<EntryType>;
53 
54  private:
55 
57 
58  public:
60  OuterContainer(TensorData toBeSquared, bool conjugate = true);
61  OuterContainer(std::vector<TensorData>&& group);
62  // OuterContainer(std::vector<SharedTensorData>&& group, std::vector<bool>&& isConjugate = {});
63  OuterContainer(EntryType&& data);
64  OuterContainer(SharedTensorData toBeSquared, bool conjugate = true);
65  OuterContainer(const Serial::FBTensorList* input);
66 
67  OuterContainer(const OuterContainer& other);
69 
70  OuterContainer(OuterContainer&& other) = default;
71  OuterContainer& operator=(OuterContainer&& other) = default;
72 
73  ~OuterContainer() override = default;
74 
75  ElementType value(const IndexList& indices) const;
76  ElementType value(IndexList::const_iterator first, IndexList::const_iterator last) const;
77  ElementType value(const std::vector<IndexList>& indices) const;
78 
79  size_t numAddends() const;
80 
81  using iterator = DataType::iterator;
82  using const_iterator = DataType::const_iterator;
83 
84 
85  iterator begin();
86  const_iterator begin() const;
87 
88  iterator end();
89  const_iterator end() const;
90 
91  public:
92  size_t rank() const override;
93  IndexList dims() const override;
94  LabelsList labels() const override;
95  size_t numValues() const override;
96  size_t dataSize() const override;
97  size_t entrySize() const override;
98  IndexType labelToIndex(IndexLabel label) const override;
99 
101  const UniqueLabelsList& indices) const override;
102  IndexPairList getSpinLabelPairs() const override;
103 
104  bool isSameShape(const IContainer& other) const override;
105  bool canAddAt(const IContainer& subContainer, IndexLabel coord, IndexType position) const override;
106 
107  reference element(const IndexList& coords = {}) override;
108  ElementType element(const IndexList& coords = {}) const override;
109 
110  reference element(IndexList::const_iterator start, IndexList::const_iterator end) override;
111  ElementType element(IndexList::const_iterator start, IndexList::const_iterator end) const override;
112 
113  bool compare(const IContainer& other) const override;
114  TensorData clone() const override;
115  void clear() override;
116 
117  IContainer& operator*=(double value) override;
118  IContainer& operator*=(const ElementType value) override;
119 
120  IContainer& conjugate() override;
121 
122  SerialType write(flatbuffers::FlatBufferBuilder* msgwriter) const override;
123 
124 
125  protected:
126  /// @brief logging facility
127  /// @return stream to be used for logging
128  Log& getLog() const;
129 
130  protected:
131 
132  std::set<IContainer*> getUniquePtrs(bool decoupleConjugates = false);
133  std::set<IContainer*> getUniquePtrs(size_t pos, bool decoupleConjugates = false);
134  void swapElement(IContainer* oldContainer, TensorData newContainer);
135  bool shouldBeEvaluated() const;
136 
137  private:
138  // all these classes are friends to be able to use getIndexing, swap, swapIndexing, addTerm and reserve
139  // (not necessary, but cleaner)
140  friend class Ops::Sum;
141  friend class Ops::Multiply;
142  friend class Ops::Divide;
143  friend class Ops::OuterSquare;
144  friend class Ops::Dot;
145  friend class Ops::Optimize;
146  friend class Ops::Trace;
147  friend class Ops::Convert;
148 
149  const BlockIndexing& getIndexing() const;
150  void swap(DataType values);
151  void swapIndexing(BlockIndexing values);
152  void reserve(size_t numTerms);
153  void addTerm(std::vector<std::pair<SharedTensorData, bool>> tensorsAndConjFlags);
154  bool isDataShared() const;
155  bool isOuterSquare() const;
156 
157  private:
158 
159  mutable DataType _data;
162  std::vector<std::function<ElementType(const IndexList&, IContainer*)>> _accessors;
163  };
164 
167  TensorData combineTensors(const std::vector<TensorData>& base);
168  TensorData combineTensors(std::vector<TensorData>&& base);
169 
170  TensorData combineSharedTensors(std::vector<std::pair<SharedTensorData, bool>>&& data);
171 
172 
173 
174  } // namespace MultiDimensional
175 
176 } // namespace Hammer
177 
178 #endif
void swapElement(IContainer *oldContainer, TensorData newContainer)
reference element(const IndexList &coords={}) override
bool canAddAt(const IContainer &subContainer, IndexLabel coord, IndexType position) const override
void swapIndexing(BlockIndexing values)
std::pair< flatbuffers::Offset< void >, Serial::FBTensorTypes > SerialType
Definition: IContainer.hh:68
IndexType labelToIndex(IndexLabel label) const override
std::vector< IndexPair > IndexPairList
OuterContainer & operator=(const OuterContainer &other)
Log & getLog() const
logging facility
OuterElemIterator::EntryType EntryType
bool compare(const IContainer &other) const override
std::vector< std::pair< SharedTensorData, bool >> EntryType
std::complex< double > ElementType
Definition: IContainer.hh:34
uint16_t IndexType
SerialType write(flatbuffers::FlatBufferBuilder *msgwriter) const override
bool isSameShape(const IContainer &other) const override
std::unique_ptr< IContainer > TensorData
std::shared_ptr< IContainer > SharedTensorData
TensorData clone() const override
TensorData combineTensors(const std::vector< TensorData > &base)
Interface class for tensor container data structure.
DataType::const_iterator const_iterator
std::vector< IndexType > IndexList
TensorData makeOuterSquare(const TensorData &base)
Logging class.
Definition: Logging.hh:33
IndexList dims() const override
IndexLabel
label identifiers of tensor indices they are used to determine which indices can be contracted togeth...
Definition: IndexLabels.hh:27
Outer product tensor indexer.
Interface class for single container data structure.
void addTerm(std::vector< std::pair< SharedTensorData, bool >> tensorsAndConjFlags)
const BlockIndexing & getIndexing() const
TensorData combineSharedTensors(std::vector< std::pair< SharedTensorData, bool >> &&data)
std::vector< IndexLabel > LabelsList
std::set< IndexLabel > UniqueLabelsList
IndexPairList getSameLabelPairs(const IContainer &other, const UniqueLabelsList &indices) const override
IContainer & operator*=(double value) override
LabelsList labels() const override
ElementType value(const IndexList &indices) const
IndexPairList getSpinLabelPairs() const override
std::vector< std::function< ElementType(const IndexList &, IContainer *)> > _accessors
std::set< IContainer * > getUniquePtrs(bool decoupleConjugates=false)