MUQ  0.4.3
AnyAlgebra2.h
Go to the documentation of this file.
1 #ifndef ANYALGEBRA2_H_
2 #define ANYALGEBRA2_H_
3 
4 namespace muq {
5  namespace Modeling {
6 
23  class AnyMat{
24 
25  AnyMat(std::shared_ptr<boost::any> objIn);
26 
27  unsigned Size(const int dim=-1);
28  double Norm();
29 
30  AnyMat operator*(AnyMat const& otherMat) const;
31 
32  // Access operators
33  double operator(int i, int j=-1) const;
34  double& operator(int i, int j=-1);
35 
36  AnyMat operator+(AnyMat const& otherMat) const;
37  AnyMat operator-(AnyMat const& otherMat) const;
38 
39  AnyMat& operator+=(AnyMat const& otherMat);
40  AnyMat& operator-=(AnyMat const& otherMat);
41 
42  AnyMat operator=(AnyMat const& otherMat);
43 
44  AnyMat Solve(AnyMat const& rhs);
45 
47 
48  AnyMat Zero(int rows, int cols=-1) const;
49  AnyMat Ones(int rows, int cols=-1) const;
50 
51  bool IsZero() const;
52 
53  AnyMat Identity(int rows, int cols) const;
54 
55  double LogDeterminant() const;
56 
57  AnyMat Concatenate(AnyMat const& otherMat, int axis=-1) const;
58 
59  private:
60  std::shared_ptr<boost::any> obj;
61  };
62 
63 
65  class AnyAlgebra2 {
66  public:
67 
68  static unsigned int Size(boost::any const& obj, int const dim=-1);
69 
70 
72 
76  double Norm(boost::any const& obj) const;
77 
79 
84  double InnerProduct(boost::any const& vec1, boost::any const& vec2) const;
85 
87 
92  boost::any OuterProduct(boost::any const& vec1, boost::any const& vec2) const;
93 
95 
102  boost::any AccessElement(boost::any const& obj, unsigned int const i = 0, unsigned int const j = 0) const;
103 
105 
110  boost::any Zero(std::type_info const& type, unsigned int const rows = 0, unsigned int const cols = 0) const;
111 
113 
117  bool IsZero(boost::any const& obj) const;
118 
120 
127  boost::any Identity(std::type_info const& type, unsigned int const rows=0, unsigned int const cols=0) const;
128 
130 
137  boost::any Identity(std::type_index const& type, unsigned int const rows=0, unsigned int const cols=0) const;
138 
140 
145  boost::any Add(boost::any const& in0, boost::any const& in1) const;
146 
148 
153  boost::any Subtract(boost::any const& in0, boost::any const& in1) const;
154 
156 
161  boost::any Multiply(boost::any const& in0, boost::any const& in1) const;
162 
164 
170  boost::any ApplyInverse(boost::any const& A, boost::any const& x) const;
171 
173 
179  boost::any Apply(boost::any const& A, boost::any const& x) const;
180 
182 
186  boost::any Inverse(boost::any const& obj) const;
187 
189 
194  boost::any SquareRoot(boost::any const& obj) const;
195 
197 
202  double LogDeterminate(boost::any const& obj) const;
203 
205 
210  boost::any Concatenate(boost::any const& vec1, boost::any const& vec2) const;
211 
212  private:
213 
215 
220  virtual unsigned int SizeImpl(boost::any const& obj) const;
221 
223 
227  virtual double NormImpl(boost::any const& obj) const;
228 
230 
235  virtual double InnerProductImpl(boost::any const& vec1, boost::any const& vec2) const;
236 
238 
243  virtual boost::any OuterProductImpl(boost::any const& vec1, boost::any const& vec2) const;
244 
246 
252  virtual boost::any AccessElementImpl(boost::any const& vec, unsigned int const i) const;
253 
255 
261  virtual boost::any IdentityImpl(std::type_index const& type, unsigned int const rows, unsigned int const cols) const;
262 
264 
270  virtual boost::any AddImpl(boost::any const& in0, boost::any const& in1) const;
271 
273 
279  virtual boost::any SubtractImpl(boost::any const& in0, boost::any const& in1) const;
280 
282 
288  virtual boost::any MultiplyImpl(boost::any const& in0, boost::any const& in1) const;
289 
291 
297  virtual boost::any ApplyImpl(boost::any const& A, boost::any const& x) const;
298 
300 
306  virtual boost::any ApplyInverseImpl(boost::any const& A, boost::any const& x) const;
307 
309 
314  virtual boost::any ZeroImpl(std::type_info const& type, unsigned int const rows, unsigned int const cols) const;
315 
317 
321  virtual bool IsZeroImpl(boost::any const& obj) const;
322 
324 
328  virtual boost::any InverseImpl(boost::any const& obj) const;
329 
331 
336  virtual boost::any SquareRootImpl(boost::any const& obj) const;
337 
339 
344  virtual double LogDeterminateImpl(boost::any const& obj) const;
345 
347 
352  virtual boost::any ConcatenateImpl(boost::any const& vec1, boost::any const& vec2) const;
353 
354  };
355  } // namespace Modeling
356 } // namespace muq
357 
358 #endif
Implement a generic way to do algebric operations on boost::any's.
Definition: AnyAlgebra2.h:65
virtual boost::any ApplyInverseImpl(boost::any const &A, boost::any const &x) const
Apply the inverse of a matrix.
virtual boost::any OuterProductImpl(boost::any const &vec1, boost::any const &vec2) const
The outer product between two vectors.
double InnerProduct(boost::any const &vec1, boost::any const &vec2) const
The inner product between two vectors.
boost::any Zero(std::type_info const &type, unsigned int const rows=0, unsigned int const cols=0) const
Compute a zero vector.
virtual boost::any ApplyImpl(boost::any const &A, boost::any const &x) const
Apply a matrix (mat-vec)
boost::any ApplyInverse(boost::any const &A, boost::any const &x) const
Apply the inverse of a matrix.
boost::any Apply(boost::any const &A, boost::any const &x) const
Apply a matrix (mat-vec)
virtual boost::any IdentityImpl(std::type_index const &type, unsigned int const rows, unsigned int const cols) const
Compute an identity object.
virtual unsigned int SizeImpl(boost::any const &obj) const
The size of an object (implemented by a child for non standard types)
boost::any AccessElement(boost::any const &obj, unsigned int const i=0, unsigned int const j=0) const
Access an element of a vector/matrix.
virtual boost::any AccessElementImpl(boost::any const &vec, unsigned int const i) const
Access an element of a vector.
static unsigned int Size(boost::any const &obj, int const dim=-1)
boost::any SquareRoot(boost::any const &obj) const
Compute the square root of an object.
virtual boost::any SubtractImpl(boost::any const &in0, boost::any const &in1) const
Subtract two objects.
bool IsZero(boost::any const &obj) const
Determine if an object is the zero object.
boost::any Inverse(boost::any const &obj) const
The inverse.
boost::any Subtract(boost::any const &in0, boost::any const &in1) const
Subtract two objects.
boost::any Add(boost::any const &in0, boost::any const &in1) const
Add two objects together.
boost::any Identity(std::type_index const &type, unsigned int const rows=0, unsigned int const cols=0) const
Compute an identity object.
virtual boost::any ConcatenateImpl(boost::any const &vec1, boost::any const &vec2) const
Combine to vectors into one.
boost::any Identity(std::type_info const &type, unsigned int const rows=0, unsigned int const cols=0) const
Compute an identity object.
virtual double InnerProductImpl(boost::any const &vec1, boost::any const &vec2) const
The inner product between two vectors.
double Norm(boost::any const &obj) const
The norm of an object.
virtual double NormImpl(boost::any const &obj) const
The norm of an object.
boost::any OuterProduct(boost::any const &vec1, boost::any const &vec2) const
The outer product between two vectors.
double LogDeterminate(boost::any const &obj) const
Compute the log-determinate.
boost::any Multiply(boost::any const &in0, boost::any const &in1) const
Multiply two objects.
virtual boost::any MultiplyImpl(boost::any const &in0, boost::any const &in1) const
Multiply two objects.
boost::any Concatenate(boost::any const &vec1, boost::any const &vec2) const
Combine to vectors into one.
virtual boost::any AddImpl(boost::any const &in0, boost::any const &in1) const
Add two objects together.
virtual boost::any InverseImpl(boost::any const &obj) const
The inverse.
virtual double LogDeterminateImpl(boost::any const &obj) const
Compute the log-determinate.
virtual boost::any ZeroImpl(std::type_info const &type, unsigned int const rows, unsigned int const cols) const
Compute a zero object for boost::any.
virtual boost::any SquareRootImpl(boost::any const &obj) const
Compute the square root of an object.
virtual bool IsZeroImpl(boost::any const &obj) const
Determine if an object is the zero object.
AnyMat Concatenate(AnyMat const &otherMat, int axis=-1) const
AnyMat Identity(int rows, int cols) const
AnyMat & operator+=(AnyMat const &otherMat)
AnyMat Zero(int rows, int cols=-1) const
AnyMat operator=(AnyMat const &otherMat)
double LogDeterminant() const
AnyMat Ones(int rows, int cols=-1) const
AnyMat operator+(AnyMat const &otherMat) const
AnyMat & operator-=(AnyMat const &otherMat)
unsigned Size(const int dim=-1)
AnyMat(std::shared_ptr< boost::any > objIn)
AnyMat Solve(AnyMat const &rhs)
double operator(int i, int j=-1) const
AnyMat operator*(AnyMat const &otherMat) const
double & operator(int i, int j=-1)
std::shared_ptr< boost::any > obj
Definition: AnyAlgebra2.h:60
AnyMat operator-(AnyMat const &otherMat) const