Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Typedefs | Functions | Variables
JMATH Namespace Reference

Auxiliary classes and methods for mathematical operations. More...

Classes

struct  JCalculator
 Auxiliary class for product evaluation of objects. More...
 
class  JGauss
 Data structure for Gaussian function on top of a flat background. More...
 
struct  JLimits
 Auxiliary class for minimum and maximum values for any class. More...
 
struct  JLimits< T, true >
 Template spacialisation of JMATH::JLimits for numerical values. More...
 
struct  JLimits< T, false >
 Template spacialisation of JMATH::JRandom for other data types. More...
 
struct  JMath
 Auxiliary base class for aritmetic operations of derived class types. More...
 
struct  JMath< T, JNullType >
 Template class for data structures with arithmetic capabilities. More...
 
class  JMatrix1D
 1 x 1 matrix More...
 
class  JMatrix1S
 1 x 1 symmetric matrix More...
 
class  JMatrix2D
 2 x 2 matrix More...
 
class  JMatrix2S
 2 x 2 symmetric matrix More...
 
class  JMatrix3D
 3 x 3 matrix More...
 
class  JMatrix3S
 3 x 3 symmetric matrix More...
 
class  JMatrix4D
 4 x 4 matrix More...
 
class  JMatrix4S
 4 x 4 symmetric matrix More...
 
class  JMatrix5D
 5 x 5 matrix More...
 
class  JMatrix5S
 5 x 5 symmetric matrix More...
 
struct  JMatrixND_t
 Type definition of a NxN matrix. More...
 
class  JMatrixND
 N x N matrix. More...
 
class  JMatrixNS
 N x N symmetric matrix. More...
 
struct  JNumber
 Simple wrapper around template data type to ensure that zero is the default value. More...
 
class  JPolynome
 Polynome function object. More...
 
class  JPower
 Power law function object. More...
 
struct  JRandom
 Template definition of random value generator. More...
 
struct  JRandom< T, true >
 Template spacialisation of JMATH::JRandom for numerical values. More...
 
struct  JRandom< T, false >
 Template spacialisation of JMATH::JRandom for non-numerical data types. More...
 
class  JTrigonometric
 Trigonometric function object for sin and cos. More...
 
struct  JZero
 Auxiliary class to assign zero value. More...
 

Typedefs

typedef std::vector< std::pair
< int, int > > 
JPermutationMatrix
 Type definition of permutation matrix. More...
 

Functions

template<class T >
const JCalculator< T, 1 > & operator* (const T &first, const T &second)
 Product evaluation of objects. More...
 
template<class T , int N>
const JCalculator< T, N+1 > & operator* (const T &first, const JCalculator< T, N > &second)
 Recursive product evaluation of objects. More...
 
template<class T , int N>
const JCalculator< T, N+1 > & operator* (const JCalculator< T, N > &first, const T &second)
 Recursive product evaluation of objects. More...
 
long long int factorial (const long long int n)
 Determine factorial. More...
 
long long int factorial (const long long int n, const long long int m)
 Determine combinatorics. More...
 
template<class JFirst_t , class JSecond_t >
double getDistanceSquared (const JFirst_t &first, const JSecond_t &second)
 Get square of distance between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getDistance (const JFirst_t &first, const JSecond_t &second)
 Get distance between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getDot (const JFirst_t &first, const JSecond_t &second)
 Get dot product of objects. More...
 
template<class JFirst_t , class JSecond_t >
double getAngle (const JFirst_t &first, const JSecond_t &second)
 Get space angle between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getPerpDot (const JFirst_t &first, const JSecond_t &second)
 Get perpendicular dot product of objects. More...
 
template<class T >
interpolate (const T &first, const T &second, const double alpha)
 Interpolation between objects. More...
 
template<class T >
double getDot (T __begin, T __end, const JMatrixND &V)
 Determine dot product Y^T x V x Y, where. More...
 
template<class T >
getRandom ()
 Get random value. More...
 
template<class T >
getRandom (const T min, const T max)
 Get uniformly distributed random value between given limits. More...
 
template<class T >
getRandom (const T min, const T max, const T precision)
 Get uniformly distributed random value between given limits. More...
 
template<>
double getRandom (const double min, const double max, const double precision)
 Template specialisation for data type double. More...
 
template<class T >
getZero ()
 Get zero value for a given data type. More...
 
template<>
float getZero< float > ()
 Get zero value for float. More...
 
template<>
double getZero< double > ()
 Get zero value for double. More...
 
template<>
long double getZero< long double > ()
 Get zero value for long double. More...
 

Variables

static const JZero zero
 Function object to assign zero value. More...
 

Detailed Description

Auxiliary classes and methods for mathematical operations.

Author
mdejong

Typedef Documentation

Type definition of permutation matrix.

Definition at line 57 of file JMatrixND.hh.

Function Documentation

template<class T >
const JCalculator<T, 1>& JMATH::operator* ( const T &  first,
const T &  second 
)
inline

Product evaluation of objects.

Multiply objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 40 of file JCalculator.hh.

41  {
42  JCalculator<T, 1>::calculator.mul(first, second);
43 
45  }
Auxiliary class for product evaluation of objects.
Definition: JCalculator.hh:18
template<class T , int N>
const JCalculator<T, N+1>& JMATH::operator* ( const T &  first,
const JCalculator< T, N > &  second 
)
inline

Recursive product evaluation of objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 56 of file JCalculator.hh.

57  {
58  JCalculator<T, N+1>::calculator.mul(first, second);
59 
61  }
Auxiliary class for product evaluation of objects.
Definition: JCalculator.hh:18
template<class T , int N>
const JCalculator<T, N+1>& JMATH::operator* ( const JCalculator< T, N > &  first,
const T &  second 
)
inline

Recursive product evaluation of objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 72 of file JCalculator.hh.

73  {
74  JCalculator<T, N+1>::calculator.mul(first, second);
75 
77  }
Auxiliary class for product evaluation of objects.
Definition: JCalculator.hh:18
long long int JMATH::factorial ( const long long int  n)
inline

Determine factorial.

Parameters
nnumber
Returns
factorial (= n!)

Definition at line 40 of file JMathToolkit.hh.

41  {
42  if (n < 0) {
43  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n);
44  }
45 
46  if (n != 1)
47  return n * factorial(n - 1);
48  else
49  return 1;
50  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
long long int factorial(const long long int n)
Determine factorial.
Definition: JMathToolkit.hh:40
long long int JMATH::factorial ( const long long int  n,
const long long int  m 
)
inline

Determine combinatorics.

Parameters
nnumber
mnumber
Returns
n!/(m!*(n-m)!)

Definition at line 60 of file JMathToolkit.hh.

61  {
62  if (n < 0 || m < 0 || n < m) {
63  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n << ' ' << m);
64  }
65 
66  if (n == m)
67  return 1;
68  else if (m == 0)
69  return 1;
70  else
71  return factorial(n - 1, m - 1) + factorial(n - 1, m);
72  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
long long int factorial(const long long int n)
Determine factorial.
Definition: JMathToolkit.hh:40
template<class JFirst_t , class JSecond_t >
double JMATH::getDistanceSquared ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get square of distance between objects.

Parameters
firstfirst object
secondsecond object
Returns
square of distance

Definition at line 83 of file JMathToolkit.hh.

85  {
86  return first.getDistanceSquared(second);
87  }
template<class JFirst_t , class JSecond_t >
double JMATH::getDistance ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get distance between objects.

Parameters
firstfirst object
secondsecond object
Returns
distance

Definition at line 98 of file JMathToolkit.hh.

100  {
101  return first.getDistance(second);
102  }
template<class JFirst_t , class JSecond_t >
double JMATH::getDot ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get dot product of objects.

Parameters
firstfirst object
secondsecond object
Returns
dot product

Definition at line 113 of file JMathToolkit.hh.

115  {
116  return first.getDot(second);
117  }
template<class JFirst_t , class JSecond_t >
double JMATH::getAngle ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get space angle between objects.

Parameters
firstfirst object
secondsecond object
Returns
angle [deg]

Definition at line 128 of file JMathToolkit.hh.

130  {
131  const double dot = getDot(first,second);
132 
133  if (dot >= +1.0)
134  return 0.0;
135  else if (dot <= -1.0)
136  return 180.0;
137  else
138  return acos(dot) * 180.0 / acos(-1.0);
139  }
double getDot(const JNeutrinoDirection &first, const JNeutrinoDirection &second)
Dot product.
Definition: JAstronomy.hh:409
template<class JFirst_t , class JSecond_t >
double JMATH::getPerpDot ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get perpendicular dot product of objects.

Parameters
firstfirst object
secondsecond object
Returns
perpendicular dot product

Definition at line 150 of file JMathToolkit.hh.

152  {
153  return first.getPerpDot(second);
154  }
template<class T >
T JMATH::interpolate ( const T &  first,
const T &  second,
const double  alpha 
)
inline

Interpolation between objects.

The result is equal to result = (1 - alpha) x (first) + (alpha) x (second).

Parameters
firstfirst object
secondsecond object
alphainterpolation factor (normally between 0 and 1)
Returns
result

Definition at line 167 of file JMathToolkit.hh.

170  {
171  return T(first).interpolate(second, alpha);
172  }
template<class T >
double JMATH::getDot ( __begin,
__end,
const JMatrixND V 
)
inline

Determine dot product Y^T x V x Y, where.

  • Y is a 1xN matrix; and
  • V is a NxN matrix.
Parameters
__beginbegin of data
__endend of data
Vmatrix
Returns
dot product

Definition at line 647 of file JMatrixND.hh.

650  {
651  double dot = 0.0;
652 
653  T yl = __begin;
654 
655  for (JMatrixND::const_row_type row = V.begin(); row != V.end(); ++row, ++yl) {
656 
657  T yr = __begin;
658 
659  for (JMatrixND::const_col_type col = row->begin(); col != row->end(); ++col, ++yr) {
660  dot += (*yl) * (*col) * (*yr);
661  }
662  }
663 
664  return dot;
665  }
template<class T >
T JMATH::getRandom ( )
inline

Get random value.

Returns
random value

Definition at line 113 of file JRandom.hh.

114  {
115  return JRandom<T>::getRandom();
116  }
T getRandom()
Get random value.
Definition: JRandom.hh:113
template<class T >
T JMATH::getRandom ( const T  min,
const T  max 
)
inline

Get uniformly distributed random value between given limits.

Parameters
minminimal value
maxmaximal value
Returns
random value

Definition at line 127 of file JRandom.hh.

129  {
130  return JRandom<T, true>::getRandom(min, max);
131  }
T getRandom()
Get random value.
Definition: JRandom.hh:113
template<class T >
T JMATH::getRandom ( const T  min,
const T  max,
const T  precision 
)
inline

Get uniformly distributed random value between given limits.

Parameters
minminimal value
maxmaximal value
precisionprecision
Returns
random value

Definition at line 143 of file JRandom.hh.

146  {
147  return JRandom<T, true>::getRandom(min, max);
148  }
T getRandom()
Get random value.
Definition: JRandom.hh:113
template<>
double JMATH::getRandom ( const double  min,
const double  max,
const double  precision 
)
inline

Template specialisation for data type double.

Definition at line 155 of file JRandom.hh.

158  {
159  double value = getRandom<double>(min, max);
160 
161  if (precision != 0.0) {
162 
163  const long long int ip = (long long int) (1.0 / precision);
164 
165  value = ((double) ((long long int) (value * ip))) / ip;
166  }
167 
168  return value;
169  }
template<class T >
T JMATH::getZero ( )
inline

Get zero value for a given data type.

The default implementation of this method returns an object which is created with the default constructor. This method should be specialised if this value does not correspond to the equivalent of a zero result.

Returns
zero

Definition at line 26 of file JZero.hh.

27  {
28  return T();
29  }
template<>
float JMATH::getZero< float > ( )
inline

Get zero value for float.

Returns
zero

Definition at line 37 of file JZero.hh.

38  {
39  return float(0.0);
40  }
template<>
double JMATH::getZero< double > ( )
inline

Get zero value for double.

Returns
zero

Definition at line 49 of file JZero.hh.

50  {
51  return double(0.0);
52  }
template<>
long double JMATH::getZero< long double > ( )
inline

Get zero value for long double.

Returns
zero

Definition at line 61 of file JZero.hh.

62  {
63  return (long double)(0.0);
64  }

Variable Documentation

const JZero JMATH::zero
static

Function object to assign zero value.

Definition at line 94 of file JZero.hh.