MUQ  0.4.3
MultiIndex.h
Go to the documentation of this file.
1 #ifndef MULTIINDEX_H_
2 #define MULTIINDEX_H_
3 
4 #include <unordered_map>
5 #include <memory>
6 #include <initializer_list>
7 
8 #include <Eigen/Core>
9 
10 namespace muq {
11  namespace Utilities {
12 
13  class MultiIndexSet;
14 
16 
40  class MultiIndex {
41  friend class MultiIndexSet;
42 
43  public:
44 
45  MultiIndex() : MultiIndex(0) {};
46 
51  explicit MultiIndex(unsigned lengthIn);
52 
58  MultiIndex(unsigned lengthIn, unsigned val);
59 
65  MultiIndex(Eigen::RowVectorXi const& indIn);
66 
71  MultiIndex(std::initializer_list<unsigned> const& indIn);
72 
77  static std::shared_ptr<MultiIndex> Copy(std::shared_ptr<MultiIndex> const& indIn){return std::make_shared<MultiIndex>(*indIn);};
78 
80  virtual ~MultiIndex() = default;
81 
85  Eigen::RowVectorXi GetVector() const;
86 
90  unsigned Sum() const{return totalOrder;};
91 
95  unsigned Max() const{return maxValue;};
96 
102  bool SetValue(unsigned ind, unsigned val);
103 
108  unsigned GetValue(unsigned ind) const;
109 
115  void SetLength(unsigned newLength);
116 
119  unsigned int NumNz() const;
120 
121  std::string ToString() const;
122 
128  unsigned GetLength() const{return length;};
129 
130  bool operator==(const MultiIndex &b) const;
131  bool operator!=(const MultiIndex &b) const;
132  bool operator<(const MultiIndex &b) const;
133  bool operator>(const MultiIndex &b) const;
134  bool operator>=(const MultiIndex &b) const;
135  bool operator<=(const MultiIndex &b) const;
136 
137  MultiIndex& operator+=(const MultiIndex &b);
138  MultiIndex& operator++();
139  MultiIndex operator+(const MultiIndex &b) const;
140  MultiIndex& operator-=(const MultiIndex &b);
141  MultiIndex& operator--();
142  MultiIndex operator-(const MultiIndex &b) const;
143 
144  std::unordered_map<unsigned, unsigned>::const_iterator GetNzBegin() const{return nzInds.begin();};
145  std::unordered_map<unsigned, unsigned>::const_iterator GetNzEnd() const{return nzInds.end();};
146 
147  private:
148 
149  unsigned int length;
150 
152  std::unordered_map<unsigned, unsigned> nzInds;
153 
155  unsigned maxValue;
156 
157  // the total order of the multiindex (i.e. the sum of the indices)
158  unsigned totalOrder;
159 
160  }; // class MultiIndex
161 
162 
163  struct MultiPtrComp{
164  bool operator()(std::shared_ptr<MultiIndex> const& a, std::shared_ptr<MultiIndex> const& b) const{return (*a)<(*b);};
165  };
166 
167  std::ostream& operator<< (std::ostream &out, const muq::Utilities::MultiIndex &ind);
168 
169  } // namespace Utilities
170 } // namespace muq
171 
172 
173 
174 #endif
SumMean operator+(MeanType1 const &mu1, MeanType2 const &mu2)
std::shared_ptr< MultiIndexSet > operator+=(std::shared_ptr< MultiIndexSet > x, std::shared_ptr< MultiIndexSet > y)
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition: json.h:3404