12 if( EigenVectorAlgebra::IsEigenVector(obj.type()) ) {
return EigenVectorAlgebra::Size(obj); }
15 if( EigenMatrixAlgebra::IsEigenMatrix(obj.type()) ) {
return EigenMatrixAlgebra::Size(obj, dim); }
18 #if MUQ_HAS_SUNDIALS==1
26 std::cerr << std::endl <<
"ERROR: cannot compute the size of an object with type " <<
boost::core::demangle(obj.type().name()) << std::endl;
27 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::SizeImpl()" << std::endl << std::endl;
28 std::cerr <<
"\tError in AnyAlgebra::SizeImpl()" << std::endl << std::endl;
33 boost::any
AnyAlgebra::Zero(std::type_info
const& type,
unsigned int rows,
unsigned int const cols)
const {
36 if( EigenVectorAlgebra::IsEigenVector(type) ) {
return EigenVectorAlgebra::Zero(type, rows); }
38 if( EigenMatrixAlgebra::IsEigenMatrix(type) ) {
return EigenMatrixAlgebra::Zero(type, rows, cols); }
40 if( type==
typeid(
double) ) {
47 boost::any
AnyAlgebra::ZeroImpl(std::type_info
const& type,
unsigned int const rows,
unsigned int const cols)
const {
48 std::cerr << std::endl <<
"ERROR: cannot compute zero of an object with type " <<
boost::core::demangle(type.name()) << std::endl;
49 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::ZeroImpl()" << std::endl << std::endl;
50 std::cerr <<
"\tError in AnyAlgebra::ZeroImpl()" << std::endl << std::endl;
58 if( EigenVectorAlgebra::IsEigenVector(obj.type()) ) {
return EigenVectorAlgebra::Norm(obj); }
60 if( EigenMatrixAlgebra::IsEigenMatrix(obj.type()) ) {
return EigenMatrixAlgebra::Norm(obj); }
66 std::cerr << std::endl <<
"ERROR: Cannot compute the norm of an object with type " <<
boost::core::demangle(obj.type().name()) << std::endl;
67 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::NormImpl()" << std::endl << std::endl;
68 std::cerr <<
"\tError in AnyAlgebra::NormImpl()" << std::endl << std::endl;
76 if( EigenVectorAlgebra::IsEigenVector(vec1.type()) && EigenVectorAlgebra::IsEigenVector(vec2.type()) ) {
return EigenVectorAlgebra::InnerProduct(vec1, vec2); }
82 std::cerr << std::endl <<
"ERROR: Cannot compute the inner product between vectors with types " <<
boost::core::demangle(vec1.type().name()) <<
" and " <<
boost::core::demangle(vec2.type().name()) << std::endl;
83 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::InnerProductImpl()" << std::endl << std::endl;
84 std::cerr <<
"\tError in AnyAlgebra::InnerProductImpl()" << std::endl << std::endl;
93 if( EigenVectorAlgebra::IsEigenVector(vec1.type()) && EigenVectorAlgebra::IsEigenVector(vec2.type()) ) {
return EigenVectorAlgebra::OuterProduct(vec1, vec2); }
99 std::cerr << std::endl <<
"ERROR: Cannot compute the outer product between vectors with types " <<
boost::core::demangle(vec1.type().name()) <<
" and " <<
boost::core::demangle(vec2.type().name()) << std::endl;
100 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::OuterProductImpl()" << std::endl << std::endl;
101 std::cerr <<
"\tError in AnyAlgebra::OuterProductImpl()" << std::endl << std::endl;
109 if( EigenVectorAlgebra::IsEigenVector(obj.type()) ) {
return EigenVectorAlgebra::IsZero(obj); }
111 if( EigenMatrixAlgebra::IsEigenMatrix(obj.type()) ) {
return EigenMatrixAlgebra::IsZero(obj); }
117 std::cerr << std::endl <<
"ERROR: No way to determine if an object with type " <<
boost::core::demangle(obj.type().name()) <<
" is the zero vector." << std::endl;
118 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::IsZero()" << std::endl << std::endl;
119 std::cerr <<
"\tError in AnyAlgebra::IsZero()" << std::endl << std::endl;
127 if( EigenVectorAlgebra::IsEigenVector(obj.type()) ) {
return EigenVectorAlgebra::AccessElement(obj, i); }
129 if( EigenMatrixAlgebra::IsEigenMatrix(obj.type()) ) {
return EigenMatrixAlgebra::AccessElement(obj, i, j); }
131 #if MUQ_HAS_SUNDIALS==1
139 std::cerr << std::endl <<
"ERROR: No way to access element " << i <<
" of a vector with type " <<
boost::core::demangle(vec.type().name()) << std::endl;
140 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::AccessElement()" << std::endl << std::endl;
141 std::cerr <<
"\tError in AnyAlgebra::AccessElement()" << std::endl << std::endl;
146 boost::any
AnyAlgebra::Identity(std::type_info
const& type,
unsigned int const rows,
unsigned int const cols)
const {
149 if( EigenVectorAlgebra::IsEigenVector(type) ) {
return EigenVectorAlgebra::Identity(type, rows, cols); }
151 if( EigenMatrixAlgebra::IsEigenMatrix(type) ) {
return EigenMatrixAlgebra::Identity(type, rows, cols); }
157 std::cerr << std::endl <<
"ERROR: No way to compute identy object with type " <<
boost::core::demangle(type.name()) << std::endl;
158 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::IdentityImpl()" << std::endl << std::endl;
159 std::cerr <<
"\tError in AnyAlgebra::IdentityImpl()" << std::endl << std::endl;
166 if( in0.type()==
typeid(boost::none) ) {
return in1; }
169 if( in1.type()==
typeid(boost::none) ) {
return in0; }
173 if( EigenVectorAlgebra::IsEigenVector(in0.type()) && EigenVectorAlgebra::IsEigenVector(in1.type()) ) {
return EigenVectorAlgebra::Add(in0, in1); }
175 if( EigenMatrixAlgebra::IsEigenMatrix(in0.type()) || EigenMatrixAlgebra::IsEigenMatrix(in1.type()) ) {
return EigenMatrixAlgebra::Add(in0, in1); }
182 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::AddImpl()" << std::endl << std::endl;
183 std::cerr <<
"\tError in AnyAlgebra::AddImpl()" << std::endl << std::endl;
191 if( EigenVectorAlgebra::IsEigenVector(in0.type()) && EigenVectorAlgebra::IsEigenVector(in1.type()) ) {
return EigenVectorAlgebra::Subtract(in0, in1); }
193 if( EigenMatrixAlgebra::IsEigenMatrix(in0.type()) && EigenMatrixAlgebra::IsEigenMatrix(in1.type()) ) {
return EigenMatrixAlgebra::Subtract(in0, in1); }
196 if( in0.type()==
typeid(boost::none) ) {
return in1; }
199 if( in1.type()==
typeid(boost::none) ) {
return in0; }
206 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::SubtractImpl()" << std::endl << std::endl;
207 std::cerr <<
"\tError in AnyAlgebra::SubtractImpl()" << std::endl << std::endl;
215 if(
ScalarAlgebra::IsScalar(in0.type()) && EigenVectorAlgebra::IsEigenVector(in1.type()) ) {
return EigenVectorAlgebra::ScalarMultiply(in0, in1); }
216 if(
ScalarAlgebra::IsScalar(in1.type()) && EigenVectorAlgebra::IsEigenVector(in0.type()) ) {
return EigenVectorAlgebra::ScalarMultiply(in1, in0); }
218 if( EigenMatrixAlgebra::IsEigenMatrix(in0.type()) && EigenMatrixAlgebra::IsEigenMatrix(in1.type()) ) {
return EigenMatrixAlgebra::Multiply(in0, in1); }
220 if(
ScalarAlgebra::IsScalar(in0.type()) && EigenMatrixAlgebra::IsEigenMatrix(in1.type()) ) {
return EigenMatrixAlgebra::ScalarMultiply(in0, in1); }
221 if(
ScalarAlgebra::IsScalar(in1.type()) && EigenMatrixAlgebra::IsEigenMatrix(in0.type()) ) {
return EigenMatrixAlgebra::ScalarMultiply(in1, in0); }
224 if( in0.type()==
typeid(boost::none) ) {
return in1; }
227 if( in1.type()==
typeid(boost::none) ) {
return in0; }
234 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::MultiplyImpl()" << std::endl << std::endl;
235 std::cerr <<
"\tError in AnyAlgebra::MultiplyImpl()" << std::endl << std::endl;
243 if( EigenVectorAlgebra::IsEigenVector(A.type()) ) {
return EigenVectorAlgebra::ApplyInverse(A, x); }
245 if( EigenMatrixAlgebra::IsEigenMatrix(A.type()) ) {
return EigenMatrixAlgebra::ApplyInverse(A, x); }
252 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::ApplyInverseImpl()" << std::endl << std::endl;
253 std::cerr <<
"\tError in AnyAlgebra::ApplyInverseImpl()" << std::endl << std::endl;
261 if( EigenVectorAlgebra::IsEigenVector(A.type()) ) {
return EigenVectorAlgebra::Apply(A, x); }
263 if( EigenMatrixAlgebra::IsEigenMatrix(A.type()) ) {
return EigenMatrixAlgebra::Apply(A, x); }
270 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::ApplyImpl()" << std::endl << std::endl;
271 std::cerr <<
"\tError in AnyAlgebra::ApplyImpl()" << std::endl << std::endl;
283 std::cerr << std::endl <<
"ERROR: No way to compute the inverse of type " <<
boost::core::demangle(obj.type().name()) << std::endl;
284 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::InverseImpl()" << std::endl << std::endl;
285 std::cerr <<
"\tError in AnyAlgebra::InverseImpl()" << std::endl << std::endl;
293 if( EigenVectorAlgebra::IsEigenVector(obj.type()) ) {
return EigenVectorAlgebra::SquareRoot(obj); }
295 if( EigenMatrixAlgebra::IsEigenMatrix(obj.type()) ) {
return EigenMatrixAlgebra::SquareRoot(obj); }
301 std::cerr << std::endl <<
"ERROR: No way to compute the square root of type " <<
boost::core::demangle(obj.type().name()) << std::endl;
302 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::SquareRootImpl()" << std::endl << std::endl;
303 std::cerr <<
"\tError in AnyAlgebra::SquareRootImpl()" << std::endl << std::endl;
311 if( EigenVectorAlgebra::IsEigenVector(obj.type()) ) {
return EigenVectorAlgebra::LogDeterminate(obj); }
313 if( EigenMatrixAlgebra::IsEigenMatrix(obj.type()) ) {
return EigenMatrixAlgebra::LogDeterminate(obj); }
319 std::cerr << std::endl <<
"ERROR: No way to compute the determinate of type " <<
boost::core::demangle(obj.type().name()) << std::endl;
320 std::cerr <<
"\tTry overloading boost::any AnyAlgebra::DeterminateImpl()" << std::endl << std::endl;
321 std::cerr <<
"\tError in AnyAlgebra::DeterminateImpl()" << std::endl << std::endl;
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 IdentityImpl(std::type_info const &type, unsigned int const rows, unsigned int const cols) const
Compute an identity object.
boost::any Add(boost::any const &in0, boost::any const &in1) const
Add two objects together.
AnyAlgebra()
Default constructor.
boost::any Identity(std::type_info const &type, unsigned int const rows=0, unsigned int const cols=0) const
Compute an identity object.
boost::any Inverse(boost::any const &obj) const
The inverse.
virtual boost::any SquareRootImpl(boost::any const &obj) const
Compute the square root of an object.
boost::any OuterProduct(boost::any const &vec1, boost::any const &vec2) const
The outer product between two vectors.
boost::any Apply(boost::any const &A, boost::any const &x) const
Apply a matrix (mat-vec)
boost::any Zero(std::type_info const &type, unsigned int const rows=0, unsigned int const cols=0) const
Compute a zero vector.
double InnerProduct(boost::any const &vec1, boost::any const &vec2) const
The inner product between two vectors.
virtual boost::any SubtractImpl(boost::any const &in0, boost::any const &in1) const
Subtract two objects.
virtual bool IsZeroImpl(boost::any const &obj) const
Determine if an object is the zero object.
double LogDeterminate(boost::any const &obj) const
Compute the log-determinate.
virtual boost::any AddImpl(boost::any const &in0, boost::any const &in1) const
Add two objects together.
virtual double InnerProductImpl(boost::any const &vec1, boost::any const &vec2) const
The inner product between two vectors.
virtual double LogDeterminateImpl(boost::any const &obj) const
Compute the log-determinate.
virtual double NormImpl(boost::any const &obj) const
The norm of an object.
virtual boost::any ApplyImpl(boost::any const &A, boost::any const &x) const
Apply a matrix (mat-vec)
boost::any SquareRoot(boost::any const &obj) const
Compute the square root of an object.
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.
boost::any Multiply(boost::any const &in0, boost::any const &in1) const
Multiply two objects.
unsigned int Size(boost::any const &obj, int const dim=-1) const
The size of an object.
bool IsZero(boost::any const &obj) const
Determine if an object is the zero object.
boost::any Subtract(boost::any const &in0, boost::any const &in1) const
Subtract two objects.
boost::any ApplyInverse(boost::any const &A, boost::any const &x) const
Apply the inverse of a matrix.
double Norm(boost::any const &obj) const
The norm of an object.
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.
virtual boost::any MultiplyImpl(boost::any const &in0, boost::any const &in1) const
Multiply two objects.
virtual boost::any InverseImpl(boost::any const &obj) const
The inverse.
virtual unsigned int SizeImpl(boost::any const &obj) const
The size of an object (implemented by a child for non standard types)
static boost::any SquareRoot(boost::any const &obj)
Compute the square root of an object.
static bool IsScalar(std::type_info const &obj_type)
Is a boost::any a scalar type (double, float, int, or unsigned int)?
static bool IsZero(boost::any const &obj)
Determine if a scalar is zero.
static boost::any OuterProduct(boost::any const &vec1, boost::any const &vec2)
The outer product between two scalars.
static boost::any Add(boost::any const &in0, boost::any const &in1)
Add two scalars together.
static double Norm(boost::any const &obj)
Get the norm of a scalar (the magnitude)
static boost::any Multiply(boost::any const &in0, boost::any const &in1)
Multiply two scalars.
static double InnerProduct(boost::any const &vec1, boost::any const &vec2)
The inner product between two scalars.
static boost::any Identity(std::type_info const &type)
Compute an identity object for a scalar.
static boost::any Subtract(boost::any const &in0, boost::any const &in1)
Subtract two scalars.
static double LogDeterminate(boost::any const &obj)
Compute the log-determinate.
static boost::any Inverse(boost::any const &obj)
The inverse.
static boost::any Zero(std::type_info const &type)
Compute a zero scalar.
static bool IsSundialsVector(std::type_info const &obj)
Is a boost::any an N_Vector type?
static unsigned int Size(boost::any const &vec)
The size of an N_Vector.
static boost::any AccessElement(N_Vector const &obj, unsigned int const i)
Access an element of a Sundials vector.
std::string demangle(const char *name)