16#ifndef KALDI_NATIVE_FBANK_CSRC_KALDI_MATH_H_
17#define KALDI_NATIVE_FBANK_CSRC_KALDI_MATH_H_
24#define M_PI 3.1415926535897932384626433832795
28#define M_2PI 6.283185307179586476925286766559005
32#define M_SQRT2 1.4142135623730950488016887
38inline float Log(
float x) {
return logf(x); }
41inline double Log(
double x) {
return log(x); }
44inline float Exp(
float x) {
return expf(x); }
47inline double Exp(
double x) {
return exp(x); }
58inline I
Gcd(I m, I n) {
75inline I
Lcm(I m, I n) {
77 return tmp == 0 ? 0 : (m / tmp * n);
90template <
typename Real>
92 return (std::abs(a - b) <= tol * (std::abs(a) + std::abs(b)));
110 return static_cast<float>((
Rand(state) + 1.0) / (RAND_MAX + 2.0));
129void Sqrt(
float *in_out, int32_t n);
#define M_PI
Definition kaldi-math.h:24
This file is part of kaldi-native-fbank.
Definition feature-cmvn.h:42
void Sqrt(float *in_out, int32_t n)
Compute the square root of each element of an array in place.
float Exp(float x)
Exponential of x (float overload; matches kaldi's Exp).
Definition kaldi-math.h:44
int Rand(struct RandomState *state=nullptr)
Return a random integer between 0 and RAND_MAX, inclusive.
float RandUniform(struct RandomState *state=nullptr)
Returns a random number strictly between 0 and 1.
Definition kaldi-math.h:109
bool ApproxEqual(Real a, Real b, Real tol=0.01)
Approximate floating-point equality test.
Definition kaldi-math.h:91
I Gcd(I m, I n)
Greatest common divisor of two integers.
Definition kaldi-math.h:58
float RandGauss(struct RandomState *state=nullptr)
Return a random sample from the standard normal distribution.
Definition kaldi-math.h:120
float Log(float x)
Natural logarithm of x (float overload; matches kaldi's Log).
Definition kaldi-math.h:38
I Lcm(I m, I n)
Least common multiple of two integers.
Definition kaldi-math.h:75
State for the thread-safe random number generator.
Definition kaldi-math.h:99
RandomState()
Construct; initializes seed from the current time.
unsigned seed
Seed of the random number generator.
Definition kaldi-math.h:103