MUQ  0.4.3
muq::Modeling::AnyAlgebra Class Reference

Implement a generic way to do algebric operations on boost::any's. More...

#include <AnyAlgebra.h>

Detailed Description

Implement a generic way to do algebric operations on boost::any's.

Definition at line 18 of file AnyAlgebra.h.

Public Member Functions

 AnyAlgebra ()
 Default constructor. More...
 
unsigned int Size (boost::any const &obj, int const dim=-1) const
 The size of an object. More...
 
double Norm (boost::any const &obj) const
 The norm of an object. More...
 
double InnerProduct (boost::any const &vec1, boost::any const &vec2) const
 The inner product between two vectors. More...
 
boost::any OuterProduct (boost::any const &vec1, boost::any const &vec2) const
 The outer product between two vectors. More...
 
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. More...
 
boost::any Zero (std::type_info const &type, unsigned int const rows=0, unsigned int const cols=0) const
 Compute a zero vector. More...
 
bool IsZero (boost::any const &obj) const
 Determine if an object is the zero object. More...
 
boost::any Identity (std::type_info const &type, unsigned int const rows=0, unsigned int const cols=0) const
 Compute an identity object. More...
 
boost::any Add (boost::any const &in0, boost::any const &in1) const
 Add two objects together. More...
 
boost::any Subtract (boost::any const &in0, boost::any const &in1) const
 Subtract two objects. More...
 
boost::any Multiply (boost::any const &in0, boost::any const &in1) const
 Multiply two objects. More...
 
boost::any ApplyInverse (boost::any const &A, boost::any const &x) const
 Apply the inverse of a matrix. More...
 
boost::any Apply (boost::any const &A, boost::any const &x) const
 Apply a matrix (mat-vec) More...
 
boost::any Inverse (boost::any const &obj) const
 The inverse. More...
 
boost::any SquareRoot (boost::any const &obj) const
 Compute the square root of an object. More...
 
double LogDeterminate (boost::any const &obj) const
 Compute the log-determinate. More...
 

Constructor & Destructor Documentation

◆ AnyAlgebra()

AnyAlgebra::AnyAlgebra ( )

Default constructor.

Definition at line 5 of file AnyAlgebra.cpp.

Member Function Documentation

◆ AccessElement()

boost::any AnyAlgebra::AccessElement ( boost::any const &  obj,
unsigned int const  i = 0,
unsigned int const  j = 0 
) const

Access an element of a vector/matrix.

The return type is whatever the elements of the vector/matrix are (doubles, ints, ect ...)

Parameters
[in]objThe vector/matrix whose data we want to access
[in]iWe want to access the \(i^{th}\) element/row of the vector/matrix (defaults to 0)
[in]jWe want to access the \(j^{th}\) col of the matrix (defaults to 0)
Returns
The \((i,j)^{th}}\) element of the vector/matrix

Definition at line 124 of file AnyAlgebra.cpp.

References muq::Modeling::SundialsAlgebra::AccessElement(), AccessElementImpl(), muq::Modeling::ScalarAlgebra::IsScalar(), and muq::Modeling::SundialsAlgebra::IsSundialsVector().

◆ AccessElementImpl()

boost::any AnyAlgebra::AccessElementImpl ( boost::any const &  vec,
unsigned int const  i 
) const
privatevirtual

Access an element of a vector.

MUQ automatically checks for some common input types. However, the user may need to overload this function for special types.

Parameters
[in]vecThe vector whose data we want to access
[in]iWe want to access the \(i^{th}\) element/row
Returns
The \(i^{th}\) element/row of the vector

Definition at line 138 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by AccessElement().

◆ Add()

boost::any AnyAlgebra::Add ( boost::any const &  in0,
boost::any const &  in1 
) const

Add two objects together.

Parameters
[in]in0The first input
[in]in1The second input
Returns
The addition of in0 and in1 (in0+in1)

Definition at line 164 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::Add(), AddImpl(), and muq::Modeling::ScalarAlgebra::IsScalar().

◆ AddImpl()

boost::any AnyAlgebra::AddImpl ( boost::any const &  in0,
boost::any const &  in1 
) const
privatevirtual

Add two objects together.

MUQ automatically checks for some common pairs. However, the user may need to overload this function for special types.

Parameters
[in]in0The first input
[in]in1The second input
Returns
The addition of in0 and in1 (in0+in1)

Definition at line 180 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Add().

◆ Apply()

boost::any AnyAlgebra::Apply ( boost::any const &  A,
boost::any const &  x 
) const

Apply a matrix (mat-vec)

If the input is a vector, treat is as the diagonal of a matrix

Parameters
[in]AWe are applying this matrix
[in]xWe are applying the matrix to this vector
Returns
The result \(y=A x\)

Definition at line 258 of file AnyAlgebra.cpp.

References ApplyImpl(), muq::Modeling::ScalarAlgebra::IsScalar(), and Multiply().

◆ ApplyImpl()

boost::any AnyAlgebra::ApplyImpl ( boost::any const &  A,
boost::any const &  x 
) const
privatevirtual

Apply a matrix (mat-vec)

If the input is a vector, treat is as the diagonal of a matrix

Parameters
[in]AWe are applying this matrix
[in]xWe are applying the matrix to this vector
Returns
The result \(y=A x\)

Definition at line 268 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Apply().

◆ ApplyInverse()

boost::any AnyAlgebra::ApplyInverse ( boost::any const &  A,
boost::any const &  x 
) const

Apply the inverse of a matrix.

If the input is a vector, treat is as the diagonal of a matrix

Parameters
[in]AWe are applying the inverse of this matrix
[in]xWe are applying the inverse to this vector
Returns
The result \(y=A^{-1} x\)

Definition at line 240 of file AnyAlgebra.cpp.

References ApplyInverseImpl(), Inverse(), muq::Modeling::ScalarAlgebra::IsScalar(), and Multiply().

◆ ApplyInverseImpl()

boost::any AnyAlgebra::ApplyInverseImpl ( boost::any const &  A,
boost::any const &  x 
) const
privatevirtual

Apply the inverse of a matrix.

If the input is a vector, treat is as the diagonal of a matrix

Parameters
[in]AWe are applying the inverse of this matrix
[in]xWe are applying the inverse to this vector
Returns
The result \(y=A^{-1} x\)

Definition at line 250 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by ApplyInverse().

◆ Identity()

boost::any AnyAlgebra::Identity ( std::type_info const &  type,
unsigned int const  rows = 0,
unsigned int const  cols = 0 
) const

Compute an identity object.

If the input type is a vector (e.g., Eigen::Vector), return an identity matrix of corresponding type (e.g., Eigen::Matrix)

Parameters
[in]typeThe type—return an identity of this type
[in]rowsThe number of rows (e.g., for a matrix) defaults to 0 since some types imply the size
[in]colsThe number of columns (e.g., for a matrix) defaults to 0 since some types imply the size
Returns
An identity of some type

Definition at line 146 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::Identity(), IdentityImpl(), and muq::Modeling::ScalarAlgebra::IsScalar().

◆ IdentityImpl()

boost::any AnyAlgebra::IdentityImpl ( std::type_info const &  type,
unsigned int const  rows,
unsigned int const  cols 
) const
privatevirtual

Compute an identity object.

Parameters
[in]typeThe type—return an identity of this type
[in]rowsThe number of rows (e.g., for a matrix)
[in]colsThe number of columns (e.g., for a matrix)
Returns
An identity of some type

Definition at line 156 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Identity().

◆ InnerProduct()

double AnyAlgebra::InnerProduct ( boost::any const &  vec1,
boost::any const &  vec2 
) const

The inner product between two vectors.

Parameters
[in]vec1The first vector
[in]vec2The second vector
Returns
The inner product

Definition at line 73 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::InnerProduct(), InnerProductImpl(), and muq::Modeling::ScalarAlgebra::IsScalar().

◆ InnerProductImpl()

double AnyAlgebra::InnerProductImpl ( boost::any const &  vec1,
boost::any const &  vec2 
) const
privatevirtual

The inner product between two vectors.

Parameters
[in]vec1The first vector
[in]vec2The second vector
Returns
The inner product

Definition at line 81 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by InnerProduct().

◆ Inverse()

boost::any AnyAlgebra::Inverse ( boost::any const &  obj) const

The inverse.

Parameters
[in]objWe need the inverse of this object
Returns
The inverse

Definition at line 276 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::Inverse(), InverseImpl(), and muq::Modeling::ScalarAlgebra::IsScalar().

Referenced by ApplyInverse().

◆ InverseImpl()

boost::any AnyAlgebra::InverseImpl ( boost::any const &  obj) const
privatevirtual

The inverse.

Parameters
[in]objWe need the inverse of this object
Returns
The inverse

Definition at line 282 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Inverse().

◆ IsZero()

bool AnyAlgebra::IsZero ( boost::any const &  obj) const

Determine if an object is the zero object.

Parameters
[in]objAn input object
Returns
true: if obj is the zero object, false: if obj is not the zero object

Definition at line 106 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::IsZero(), and IsZeroImpl().

◆ IsZeroImpl()

bool AnyAlgebra::IsZeroImpl ( boost::any const &  obj) const
privatevirtual

Determine if an object is the zero object.

Parameters
[in]objAn input object
Returns
true: if obj is the zero object, false: if obj is not the zero object

Definition at line 116 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by IsZero().

◆ LogDeterminate()

double AnyAlgebra::LogDeterminate ( boost::any const &  obj) const

Compute the log-determinate.

In the vector case, compute the determinate of a diagonal matrix.

Parameters
[in]objWe need the determinate of this object
Returns
The determinate

Definition at line 308 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::LogDeterminate(), and LogDeterminateImpl().

◆ LogDeterminateImpl()

double AnyAlgebra::LogDeterminateImpl ( boost::any const &  obj) const
privatevirtual

Compute the log-determinate.

In the vector case, compute the determinate of a diagonal matrix.

Parameters
[in]objWe need the determinate of this object
Returns
The determinate

Definition at line 318 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by LogDeterminate().

◆ Multiply()

boost::any AnyAlgebra::Multiply ( boost::any const &  in0,
boost::any const &  in1 
) const

Multiply two objects.

Parameters
[in]in0The first input
[in]in1The second input
Returns
The multiplication of in0 and in1 (in0-in1)

Definition at line 212 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::Multiply(), and MultiplyImpl().

Referenced by Apply(), and ApplyInverse().

◆ MultiplyImpl()

boost::any AnyAlgebra::MultiplyImpl ( boost::any const &  in0,
boost::any const &  in1 
) const
privatevirtual

Multiply two objects.

MUQ automatically checks for some common pairs. However, the user may need to overload this function for special types.

Parameters
[in]in0The first input
[in]in1The second input
Returns
The multiplication of in0 and in1 (in0*in1)

Definition at line 232 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Multiply().

◆ Norm()

double AnyAlgebra::Norm ( boost::any const &  obj) const

The norm of an object.

Parameters
[in]objWe need the norm of this object
Returns
The norm

Definition at line 55 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::Norm(), and NormImpl().

◆ NormImpl()

double AnyAlgebra::NormImpl ( boost::any const &  obj) const
privatevirtual

The norm of an object.

Parameters
[in]objWe need the norm of this object
Returns
The norm

Definition at line 65 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Norm().

◆ OuterProduct()

boost::any AnyAlgebra::OuterProduct ( boost::any const &  vec1,
boost::any const &  vec2 
) const

The outer product between two vectors.

Parameters
[in]vec1The first vector
[in]vec2The second vector
Returns
The outer product

Definition at line 89 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::OuterProduct(), and OuterProductImpl().

◆ OuterProductImpl()

boost::any AnyAlgebra::OuterProductImpl ( boost::any const &  vec1,
boost::any const &  vec2 
) const
privatevirtual

The outer product between two vectors.

Parameters
[in]vec1The first vector
[in]vec2The second vector
Returns
The outer product

Definition at line 98 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by OuterProduct().

◆ Size()

unsigned int AnyAlgebra::Size ( boost::any const &  obj,
int const  dim = -1 
) const

The size of an object.

For vectors/matrices, return the number of elements.

For matrices, the default behavior is to return the total number of elements. For dim=0, return the number of rows, for dim=1 return the number of colums

Parameters
[in]objWe need the size of this object
[in]dimThe dimension For matrices: for dim=-1 (default) return the total number of elements, for dim=0, return the number of rows, for dim=1, return the number of colums
Returns
The size

Definition at line 7 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::SundialsAlgebra::IsSundialsVector(), muq::Modeling::SundialsAlgebra::Size(), and SizeImpl().

◆ SizeImpl()

unsigned int AnyAlgebra::SizeImpl ( boost::any const &  obj) const
privatevirtual

The size of an object (implemented by a child for non standard types)

For vectors/matrices, return the number of elements.

Parameters
[in]objWe need the size of this object
Returns
The size

Definition at line 25 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Size().

◆ SquareRoot()

boost::any AnyAlgebra::SquareRoot ( boost::any const &  obj) const

Compute the square root of an object.

In the vector case, compute the square root of each component. In the matrix case, compute the Cholesky

Parameters
[in]objWe need the square root of this object
Returns
The square root

Definition at line 290 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::SquareRoot(), and SquareRootImpl().

◆ SquareRootImpl()

boost::any AnyAlgebra::SquareRootImpl ( boost::any const &  obj) const
privatevirtual

Compute the square root of an object.

In the vector case, compute the square root of each component. In the matrix case, compute the Cholesky

Parameters
[in]objWe need the square root of this object
Returns
The square root

Definition at line 300 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by SquareRoot().

◆ Subtract()

boost::any AnyAlgebra::Subtract ( boost::any const &  in0,
boost::any const &  in1 
) const

Subtract two objects.

Parameters
[in]in0The first input
[in]in1The second input
Returns
The subtraction of in0 and in1 (in0-in1)

Definition at line 188 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::Subtract(), and SubtractImpl().

◆ SubtractImpl()

boost::any AnyAlgebra::SubtractImpl ( boost::any const &  in0,
boost::any const &  in1 
) const
privatevirtual

Subtract two objects.

MUQ automatically checks for some common pairs. However, the user may need to overload this function for special types.

Parameters
[in]in0The first input
[in]in1The second input
Returns
The subtraction of in0 and in1 (in0-in1)

Definition at line 204 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Subtract().

◆ Zero()

boost::any AnyAlgebra::Zero ( std::type_info const &  type,
unsigned int const  rows = 0,
unsigned int const  cols = 0 
) const

Compute a zero vector.

Parameters
[in]typeWe need a zero object of this type
[in]rowsThe size of the vector (defaults to 0 because some types have implied sizes (e.g., Eigen::Vector2d)) or number of rows of the matrix
[in]colsThe number of columns in the matrix (defaults to 0 but, again, some types imply a size)

Definition at line 33 of file AnyAlgebra.cpp.

References muq::Modeling::ScalarAlgebra::IsScalar(), muq::Modeling::ScalarAlgebra::Zero(), and ZeroImpl().

◆ ZeroImpl()

boost::any AnyAlgebra::ZeroImpl ( std::type_info const &  type,
unsigned int const  rows,
unsigned int const  cols 
) const
privatevirtual

Compute a zero object for boost::any.

Parameters
[in]typeWe need a zero object of this type
[in]rowsThe size of the vector (defaults to 0 because some types have implied sizes (e.g., Eigen::Vector2d)) or number of rows of the matrix
[in]colsThe number of columns in the matrix (defaults to 0 but, again, some types imply a size)

Definition at line 47 of file AnyAlgebra.cpp.

References muq::Utilities::demangle().

Referenced by Zero().


The documentation for this class was generated from the following files: