1 #ifndef SCALARALGEBRA_H_
2 #define SCALARALGEBRA_H_
7 #include <boost/none.hpp>
8 #include <boost/any.hpp>
25 static bool IsScalar(std::type_info
const& obj_type);
32 static bool IsZero(boost::any
const& obj);
38 static boost::any
Zero(std::type_info
const& type);
45 static double Norm(boost::any
const& obj);
53 static double InnerProduct(boost::any
const& vec1, boost::any
const& vec2);
61 static boost::any
OuterProduct(boost::any
const& vec1, boost::any
const& vec2);
68 static boost::any
Identity(std::type_info
const& type);
76 static boost::any
Add(boost::any
const& in0, boost::any
const& in1);
84 static boost::any
Subtract(boost::any
const& in0, boost::any
const& in1);
92 static boost::any
Multiply(boost::any
const& in0, boost::any
const& in1);
99 static boost::any
Inverse(boost::any
const& obj);
106 static boost::any
SquareRoot(boost::any
const& obj);
122 template<
typename type>
124 const double x = (double)boost::any_cast<type const>(obj);
135 template<
typename type0,
typename type1>
136 static inline boost::any
Add(boost::any
const& in0, boost::any
const& in1) {
137 const type0 x0 = boost::any_cast<type0 const>(in0);
138 const type1 x1 = boost::any_cast<type1 const>(in1);
149 template<
typename type0>
150 static inline boost::any
Add(boost::any
const& in0, boost::any
const& in1) {
151 if( in1.type()==
typeid(
double) ) {
return Add<type0, double>(in0, in1); }
152 if( in1.type()==
typeid(
float) ) {
return Add<type0, float>(in0, in1); }
153 if( in1.type()==
typeid(
int) ) {
return Add<type0, int>(in0, in1); }
154 if( in1.type()==
typeid(
unsigned int) ) {
return Add<type0, unsigned int>(in0, in1); }
167 template<
typename type0,
typename type1>
168 static inline boost::any
Subtract(boost::any
const& in0, boost::any
const& in1) {
169 const type0 x0 = boost::any_cast<type0 const>(in0);
170 const type1 x1 = boost::any_cast<type1 const>(in1);
181 template<
typename type0>
182 static inline boost::any
Subtract(boost::any
const& in0, boost::any
const& in1) {
183 if( in1.type()==
typeid(
double) ) {
return Subtract<type0, double>(in0, in1); }
184 if( in1.type()==
typeid(
float) ) {
return Subtract<type0, float>(in0, in1); }
185 if( in1.type()==
typeid(
int) ) {
return Subtract<type0, int>(in0, in1); }
186 if( in1.type()==
typeid(
unsigned int) ) {
return Subtract<type0, unsigned int>(in0, in1); }
199 template<
typename type0,
typename type1>
200 static inline boost::any
Multiply(boost::any
const& in0, boost::any
const& in1) {
201 const type0 x0 = boost::any_cast<type0 const>(in0);
202 const type1 x1 = boost::any_cast<type1 const>(in1);
213 template<
typename type0>
214 static inline boost::any
Multiply(boost::any
const& in0, boost::any
const& in1) {
215 if( in1.type()==
typeid(
double) ) {
return Multiply<type0, double>(in0, in1); }
216 if( in1.type()==
typeid(
float) ) {
return Multiply<type0, float>(in0, in1); }
217 if( in1.type()==
typeid(
int) ) {
return Multiply<type0, int>(in0, in1); }
218 if( in1.type()==
typeid(
unsigned int) ) {
return Multiply<type0, unsigned int>(in0, in1); }
Linear algebra for scalar objects.
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 Add(boost::any const &in0, boost::any const &in1)
Add two scalars together.
static boost::any OuterProduct(boost::any const &vec1, boost::any const &vec2)
The outer product between two scalars.
static boost::any Subtract(boost::any const &in0, boost::any const &in1)
Subtract 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 boost::any Multiply(boost::any const &in0, boost::any const &in1)
Multiply two scalars.
static boost::any Add(boost::any const &in0, boost::any const &in1)
Add two scalars together.
static double InnerProduct(boost::any const &vec1, boost::any const &vec2)
The inner product between two scalars.
static boost::any Subtract(boost::any const &in0, boost::any const &in1)
Subtract two scalars.
static double Magnitude(boost::any const &obj)
The magnitude of a scalar.
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 Multiply(boost::any const &in0, boost::any const &in1)
Multiply two scalars.
static boost::any Zero(std::type_info const &type)
Compute a zero scalar.