elem_math.h
Go to the documentation of this file.
#ifndef ELEM_MATH_H
#define ELEM_MATH_H
#include <itpp/base/help_functions.h>
#include <itpp/base/converters.h>
#include <cstdlib> // required by std::abs()
#include <itpp/itexports.h>
namespace itpp
{
// -------------------- sqr function --------------------
inline double sqr(double x) { return (x * x); }
inline double sqr(const std::complex<double>& x)
{
return (x.real() * x.real() + x.imag() * x.imag());
}
inline vec sqr(const vec &x) { return apply_function<double>(sqr, x); }
inline mat sqr(const mat &x) { return apply_function<double>(sqr, x); }
ITPP_EXPORT vec sqr(const cvec &x);
ITPP_EXPORT mat sqr(const cmat &x);
// -------------------- abs function --------------------
inline vec abs(const vec &x) { return apply_function<double>(std::fabs, x); }
inline mat abs(const mat &x) { return apply_function<double>(std::fabs, x); }
inline ivec abs(const ivec &x) { return apply_function<int>(std::abs, x); }
inline imat abs(const imat &x) { return apply_function<int>(std::abs, x); }
ITPP_EXPORT vec abs(const cvec &x);
ITPP_EXPORT mat abs(const cmat &x);
// -------------------- sign/sgn functions --------------------
inline double sign(double x)
{
return (x == 0.0 ? 0.0 : (x < 0.0 ? -1.0 : 1.0));
}
inline vec sign(const vec &x) { return apply_function<double>(sign, x); }
inline mat sign(const mat &x) { return apply_function<double>(sign, x); }
inline double sgn(double x) { return sign(x); }
inline vec sgn(const vec &x) { return apply_function<double>(sign, x); }
inline mat sgn(const mat &x) { return apply_function<double>(sign, x); }
inline int sign_i(int x)
{
return (x == 0 ? 0 : (x < 0 ? -1 : 1));
}
inline ivec sign_i(const ivec &x) { return apply_function<int>(sign_i, x); }
inline imat sign_i(const imat &x) { return apply_function<int>(sign_i, x); }
inline int sgn_i(int x) { return sign_i(x); }
inline ivec sgn_i(const ivec &x) { return apply_function<int>(sign_i, x); }
inline imat sgn_i(const imat &x) { return apply_function<int>(sign_i, x); }
inline int sign_i(double x)
{
return (x == 0.0 ? 0 : (x < 0.0 ? -1 : 1));
}
// -------------------- sqrt function --------------------
inline vec sqrt(const vec &x) { return apply_function<double>(std::sqrt, x); }
inline mat sqrt(const mat &x) { return apply_function<double>(std::sqrt, x); }
// -------------------- gamma function --------------------
ITPP_EXPORT double gamma(double x);
ITPP_EXPORT vec gamma(const vec &x);
ITPP_EXPORT mat gamma(const mat &x);
// -------------------- rem function --------------------
inline double rem(double x, double y) { return fmod(x, y); }
inline vec rem(const vec &x, double y)
{
return apply_function<double>(rem, x, y);
}
inline vec rem(double x, const vec &y)
{
return apply_function<double>(rem, x, y);
}
inline mat rem(const mat &x, double y)
{
return apply_function<double>(rem, x, y);
}
inline mat rem(double x, const mat &y)
{
return apply_function<double>(rem, x, y);
}
// -------------------- mod function --------------------
inline int mod(int k, int n)
{
return (n == 0) ? k : (k - n * floor_i(static_cast<double>(k) / n));
}
// -------------------- factorial coefficient function --------------------
ITPP_EXPORT double fact(int index);
// -------------------- binomial coefficient function --------------------
ITPP_EXPORT double binom(int n, int k);
ITPP_EXPORT int binom_i(int n, int k);
ITPP_EXPORT double log_binom(int n, int k);
// -------------------- greatest common divisor function --------------------
ITPP_EXPORT int gcd(int a, int b);
// -------------------- complex related functions --------------------
ITPP_EXPORT vec real(const cvec &x);
ITPP_EXPORT mat real(const cmat &x);
ITPP_EXPORT vec imag(const cvec &x);
ITPP_EXPORT mat imag(const cmat &x);
ITPP_EXPORT vec arg(const cvec &x);
ITPP_EXPORT mat arg(const cmat &x);
inline vec angle(const cvec &x) { return arg(x); }
inline mat angle(const cmat &x) { return arg(x); }
// Added due to a failure in MSVC++ .NET 2005, which crashes on this
// code.
#ifndef _MSC_VER
inline cvec conj(const cvec &x)
{
return apply_function<std::complex<double> >(std::conj, x);
}
inline cmat conj(const cmat &x)
{
return apply_function<std::complex<double> >(std::conj, x);
}
#else
ITPP_EXPORT cvec conj(const cvec &x);
ITPP_EXPORT cmat conj(const cmat &x);
#endif
} // namespace itpp
#endif // #ifndef ELEM_MATH_H
itpp::binom
double binom(int n, int k)
Compute the binomial coefficient "n over k".
Definition: elem_math.cpp:95
itpp::gamma
double gamma(double x)
Deprecated gamma function - please use tgamma() instead.
Definition: elem_math.cpp:79
itpp::imag
vec imag(const cvec &data)
Imaginary part of complex values.
Definition: elem_math.cpp:180
help_functions.h
Help functions to make functions with vec and mat as arguments.
itpp::arg
vec arg(const cvec &data)
Argument (angle)
Definition: elem_math.cpp:202
itpp::conj
cvec conj(const cvec &x)
Conjugate of complex value.
Definition: elem_math.h:226
itpp::mod
int mod(int k, int n)
Calculates the modulus, i.e. the signed reminder after division.
Definition: elem_math.h:166
itpp::binom_i
int binom_i(int n, int k)
Compute the binomial coefficient "n over k".
Definition: elem_math.cpp:110
itpp::sgn_i
int sgn_i(int x)
Signum function.
Definition: elem_math.h:108
converters.h
Definitions of converters between different vector and matrix types.
itpp::angle
vec angle(const cvec &x)
Angle.
Definition: elem_math.h:218
itpp::rem
double rem(double x, double y)
The reminder of the division x/y.
Definition: elem_math.h:141
itpp::sqrt
mat sqrt(const mat &x)
Square root of the elements.
Definition: elem_math.h:125
itpp::abs
imat abs(const imat &x)
Absolute value.
Definition: elem_math.h:71
itpp::sgn
double sgn(double x)
Signum function.
Definition: elem_math.h:91
itpp::floor_i
int floor_i(double x)
The nearest smaller integer.
Definition: converters.h:350
itpp::conj
cmat conj(const cmat &x)
Conjugate of complex value.
Definition: elem_math.h:231
itpp::sqr
vec sqr(const cvec &data)
Absolute square of elements.
Definition: elem_math.cpp:36
itpp::sign
double sign(double x)
Signum function.
Definition: elem_math.h:81
itpp::sqrt
vec sqrt(const vec &x)
Square root of the elements.
Definition: elem_math.h:123
itpp::sign_i
int sign_i(int x)
Signum function.
Definition: elem_math.h:98
itpp::log_binom
double log_binom(int n, int k)
Compute the base 10 logarithm of the binomial coefficient "n over k".
Definition: elem_math.cpp:125
itpp::abs
bin abs(const bin &inbin)
absolute value of bin
Definition: binary.h:174
itpp::gcd
int gcd(int a, int b)
Compute the greatest common divisor (GCD) g of the elements a and b.
Definition: elem_math.cpp:140
itpp::real
vec real(const cvec &data)
Real part of complex values.
Definition: elem_math.cpp:157
itpp::fact
double fact(int index)
Calculates factorial coefficient for index <= 170.
Definition: elem_math.cpp:84

Generated on Thu Mar 20 2014 12:26:41 for IT++ by Doxygen 1.8.6