Jpp
Classes | Typedefs | Functions | Variables
JMATH Namespace Reference

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

Classes

struct  JCalculator
 Auxiliary class for arithmetic operations on 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, false >
 Template spacialisation of JMATH::JRandom for other data types. More...
 
struct  JLimits< T, true >
 Template spacialisation of JMATH::JLimits for numerical values. 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...
 
class  JMatrixND
 N x N matrix. More...
 
struct  JMatrixND_t
 Type definition of a NxN 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, false >
 Template spacialisation of JMATH::JRandom for non-numerical data types. More...
 
struct  JRandom< T, true >
 Template spacialisation of JMATH::JRandom for numerical values. 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 >
bool equals (const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
 Check equality. 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

◆ JPermutationMatrix

Type definition of permutation matrix.

Definition at line 57 of file JMatrixND.hh.

Function Documentation

◆ operator*() [1/3]

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 53 of file JCalculator.hh.

54  {
55  JCalculator<T, 1>::calculator.mul(first, second);
56 
58  }

◆ operator*() [2/3]

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 69 of file JCalculator.hh.

70  {
71  JCalculator<T, N+1>::calculator.mul(first, second);
72 
74  }

◆ operator*() [3/3]

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 85 of file JCalculator.hh.

86  {
87  JCalculator<T, N+1>::calculator.mul(first, second);
88 
90  }

◆ factorial() [1/2]

long long int JMATH::factorial ( const long long int  n)
inline

Determine factorial.

Parameters
nnumber
Returns
factorial (= n!)

Definition at line 41 of file JMathToolkit.hh.

42  {
43  if (n < 0) {
44  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n);
45  }
46 
47  if (n != 1)
48  return n * factorial(n - 1);
49  else
50  return 1;
51  }

◆ factorial() [2/2]

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 61 of file JMathToolkit.hh.

62  {
63  if (n < 0 || m < 0 || n < m) {
64  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n << ' ' << m);
65  }
66 
67  if (n == m)
68  return 1;
69  else if (m == 0)
70  return 1;
71  else
72  return factorial(n - 1, m - 1) + factorial(n - 1, m);
73  }

◆ equals()

template<class JFirst_t , class JSecond_t >
bool JMATH::equals ( const JFirst_t &  first,
const JSecond_t &  second,
const double  precision = std::numeric_limits<double>::min() 
)
inline

Check equality.

Parameters
firstfirst object
secondsecond object
precisionprecision
Returns
true if two objects are equals; else false

Definition at line 85 of file JMathToolkit.hh.

88  {
89  return first.equals(second, precision);
90  }

◆ getDistanceSquared()

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 101 of file JMathToolkit.hh.

103  {
104  return first.getDistanceSquared(second);
105  }

◆ getDistance()

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 116 of file JMathToolkit.hh.

118  {
119  return first.getDistance(second);
120  }

◆ getDot() [1/2]

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 131 of file JMathToolkit.hh.

133  {
134  return first.getDot(second);
135  }

◆ getAngle()

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 146 of file JMathToolkit.hh.

148  {
149  const double dot = getDot(first,second);
150 
151  if (dot >= +1.0)
152  return 0.0;
153  else if (dot <= -1.0)
154  return 180.0;
155  else
156  return acos(dot) * 180.0 / acos(-1.0);
157  }

◆ getPerpDot()

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 168 of file JMathToolkit.hh.

170  {
171  return first.getPerpDot(second);
172  }

◆ interpolate()

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 185 of file JMathToolkit.hh.

188  {
189  return T(first).interpolate(second, alpha);
190  }

◆ getDot() [2/2]

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  }

◆ getRandom() [1/4]

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  }

◆ getRandom() [2/4]

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  }

◆ getRandom() [3/4]

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  }

◆ getRandom() [4/4]

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  }

◆ getZero()

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  }

◆ getZero< float >()

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  }

◆ getZero< double >()

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  }

◆ getZero< long double >()

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

◆ zero

const JZero JMATH::zero
static

Function object to assign zero value.

Definition at line 94 of file JZero.hh.

JTOOLS::n
const int n
Definition: JPolint.hh:628
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:669
JMATH::getRandom
double getRandom(const double min, const double max, const double precision)
Template specialisation for data type double.
Definition: JRandom.hh:155
JMATH::factorial
long long int factorial(const long long int n, const long long int m)
Determine combinatorics.
Definition: JMathToolkit.hh:61
JMATH::JCalculator
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18
JMATH::getDot
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
Definition: JMathToolkit.hh:131