Commit 36cad857 authored by Jan "yenda" Trmal's avatar Jan "yenda" Trmal
Browse files

Merge pull request #8 from jtrmal/windows-test-fixes

Windows test fixes
parents db63ae29 b0439a2e
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <sstream> #include <sstream>
#include <cstdio> #include <cstdio>
#if _MSC_VER >= 0x1400 || !defined(MSC_VER) && __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__) #if _MSC_VER >= 1900 || (!defined(_MSC_VER) && __cplusplus > 199711L) || defined(__GXX_EXPERIMENTAL_CXX0X__)
#define NOEXCEPT(Predicate) noexcept((Predicate)) #define NOEXCEPT(Predicate) noexcept((Predicate))
#else #else
#define NOEXCEPT(Predicate) #define NOEXCEPT(Predicate)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
// limitations under the License. // limitations under the License.
#include "base/kaldi-math.h" #include "base/kaldi-math.h"
#include "base/timer.h" #include "base/timer.h"
#include <limits>
namespace kaldi { namespace kaldi {
...@@ -25,8 +26,10 @@ template<class I> void UnitTestGcdLcmTpl() { ...@@ -25,8 +26,10 @@ template<class I> void UnitTestGcdLcmTpl() {
for (I a = 1; a < 15; a++) { // a is min gcd. for (I a = 1; a < 15; a++) { // a is min gcd.
I b = (I)(Rand() % 10); I b = (I)(Rand() % 10);
I c = (I)(Rand() % 10); I c = (I)(Rand() % 10);
if (Rand()%2 == 0 && std::numeric_limits<I>::is_signed) b = -b; if (std::numeric_limits<I>::is_signed) {
if (Rand()%2 == 0 && std::numeric_limits<I>::is_signed) c = -c; if (Rand() % 2 == 0) b = -b;
if (Rand() % 2 == 0) c = -c;
}
if (b == 0 && c == 0) continue; // gcd not defined for such numbers. if (b == 0 && c == 0) continue; // gcd not defined for such numbers.
I g = Gcd(b*a, c*a); I g = Gcd(b*a, c*a);
KALDI_ASSERT(g >= a); KALDI_ASSERT(g >= a);
...@@ -157,14 +160,14 @@ void UnitTestLogAddSub() { ...@@ -157,14 +160,14 @@ void UnitTestLogAddSub() {
using namespace kaldi; using namespace kaldi;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
double f1 = Rand() % 10000, f2 = Rand() % 20; double f1 = Rand() % 10000, f2 = Rand() % 20;
double add1 = exp(LogAdd(log(f1), log(f2))); double add1 = Exp(LogAdd(Log(f1), Log(f2)));
double add2 = exp(LogAdd(log(f2), log(f1))); double add2 = Exp(LogAdd(Log(f2), Log(f1)));
double add = f1 + f2, thresh = add*0.00001; double add = f1 + f2, thresh = add*0.00001;
KALDI_ASSERT(std::abs(add-add1) < thresh && std::abs(add-add2) < thresh); KALDI_ASSERT(std::abs(add-add1) < thresh && std::abs(add-add2) < thresh);
try { try {
double f2_check = exp(LogSub(log(add), log(f1))), thresh = (f2*0.01)+0.001; double f2_check = Exp(LogSub(Log(add), Log(f1))), thresh = (f2*0.01)+0.001;
KALDI_ASSERT(std::abs(f2_check-f2) < thresh); KALDI_ASSERT(std::abs(f2_check-f2) < thresh);
} catch(...) { } catch(...) {
KALDI_ASSERT(f2 == 0); // It will probably crash for f2=0. KALDI_ASSERT(f2 == 0); // It will probably crash for f2=0.
...@@ -173,8 +176,8 @@ void UnitTestLogAddSub() { ...@@ -173,8 +176,8 @@ void UnitTestLogAddSub() {
} }
void UnitTestDefines() { // Yes, we even unit-test the preprocessor statements. void UnitTestDefines() { // Yes, we even unit-test the preprocessor statements.
KALDI_ASSERT(exp(kLogZeroFloat) == 0.0); KALDI_ASSERT(Exp(kLogZeroFloat) == 0.0);
KALDI_ASSERT(exp(kLogZeroDouble) == 0.0); KALDI_ASSERT(Exp(kLogZeroDouble) == 0.0);
BaseFloat den = 0.0; BaseFloat den = 0.0;
KALDI_ASSERT(KALDI_ISNAN(0.0 / den)); KALDI_ASSERT(KALDI_ISNAN(0.0 / den));
KALDI_ASSERT(!KALDI_ISINF(0.0 / den)); KALDI_ASSERT(!KALDI_ISINF(0.0 / den));
...@@ -194,8 +197,8 @@ void UnitTestDefines() { // Yes, we even unit-test the preprocessor statements. ...@@ -194,8 +197,8 @@ void UnitTestDefines() { // Yes, we even unit-test the preprocessor statements.
&& "If this test fails, you can probably just comment it out-- may mean your CPU exceeds expected floating point precision"); && "If this test fails, you can probably just comment it out-- may mean your CPU exceeds expected floating point precision");
KALDI_ASSERT(std::abs(sin(M_PI)) < 1.0e-05 && std::abs(cos(M_PI)+1.0) < 1.0e-05); KALDI_ASSERT(std::abs(sin(M_PI)) < 1.0e-05 && std::abs(cos(M_PI)+1.0) < 1.0e-05);
KALDI_ASSERT(std::abs(sin(M_2PI)) < 1.0e-05 && std::abs(cos(M_2PI)-1.0) < 1.0e-05); KALDI_ASSERT(std::abs(sin(M_2PI)) < 1.0e-05 && std::abs(cos(M_2PI)-1.0) < 1.0e-05);
KALDI_ASSERT(std::abs(sin(exp(M_LOG_2PI))) < 1.0e-05); KALDI_ASSERT(std::abs(sin(Exp(M_LOG_2PI))) < 1.0e-05);
KALDI_ASSERT(std::abs(cos(exp(M_LOG_2PI)) - 1.0) < 1.0e-05); KALDI_ASSERT(std::abs(cos(Exp(M_LOG_2PI)) - 1.0) < 1.0e-05);
} }
void UnitTestAssertFunc() { // Testing Assert** *functions void UnitTestAssertFunc() { // Testing Assert** *functions
......
...@@ -75,6 +75,51 @@ ...@@ -75,6 +75,51 @@
namespace kaldi { namespace kaldi {
#if !defined(_MSC_VER) || (_MSC_VER >= 1900)
inline double Exp(double x) { return exp(x); }
#ifndef KALDI_NO_EXPF
inline float Exp(float x) { return expf(x); }
#else
inline float Exp(float x) { return exp(static_cast<double>(x)); }
#endif // KALDI_NO_EXPF
#else
inline double Exp(double x) { return exp(x); }
#if !defined(__INTEL_COMPILER) && _MSC_VER == 1800 && defined(_M_X64)
// Microsoft CL v18.0 buggy 64-bit implementation of
// expf() incorrectly returns -inf for exp(-inf).
inline float Exp(float x) { return exp(static_cast<double>(x)); }
#else
inline float Exp(float x) { return expf(x); }
#endif // !defined(__INTEL_COMPILER) && _MSC_VER == 1800 && defined(_M_X64)
#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
inline double Log(double x) { return log(x); }
inline float Log(float x) { return logf(x); }
#if !defined(_MSC_VER) || (_MSC_VER >= 1700)
inline double Log1p(double x) { return log1p(x); }
inline float Log1p(float x) { return log1pf(x); }
#else
inline double Log1p(double x) {
const double cutoff = 1.0e-08;
if (x < cutoff)
return x - 2 * x * x;
else
return Log(1.0 + x);
}
inline float Log1p(float x) {
const float cutoff = 1.0e-07;
if (x < cutoff)
return x - 2 * x * x;
else
return Log(1.0 + x);
}
#endif
static const double kMinLogDiffDouble = Log(DBL_EPSILON); // negative!
static const float kMinLogDiffFloat = Log(FLT_EPSILON); // negative!
// -infinity // -infinity
const float kLogZeroFloat = -std::numeric_limits<float>::infinity(); const float kLogZeroFloat = -std::numeric_limits<float>::infinity();
const double kLogZeroDouble = -std::numeric_limits<double>::infinity(); const double kLogZeroDouble = -std::numeric_limits<double>::infinity();
...@@ -103,7 +148,7 @@ inline float RandUniform(struct RandomState* state = NULL) { ...@@ -103,7 +148,7 @@ inline float RandUniform(struct RandomState* state = NULL) {
} }
inline float RandGauss(struct RandomState* state = NULL) { inline float RandGauss(struct RandomState* state = NULL) {
return static_cast<float>(sqrtf (-2 * logf(RandUniform(state))) return static_cast<float>(sqrtf (-2 * Log(RandUniform(state)))
* cosf(2*M_PI*RandUniform(state))); * cosf(2*M_PI*RandUniform(state)));
} }
...@@ -129,8 +174,6 @@ inline Float RandPrune(Float post, BaseFloat prune_thresh, struct RandomState* s ...@@ -129,8 +174,6 @@ inline Float RandPrune(Float post, BaseFloat prune_thresh, struct RandomState* s
(RandUniform(state) <= fabs(post)/prune_thresh ? prune_thresh : 0.0); (RandUniform(state) <= fabs(post)/prune_thresh ? prune_thresh : 0.0);
} }
static const double kMinLogDiffDouble = std::log(DBL_EPSILON); // negative!
static const float kMinLogDiffFloat = std::log(FLT_EPSILON); // negative!
inline double LogAdd(double x, double y) { inline double LogAdd(double x, double y) {
double diff; double diff;
...@@ -144,13 +187,7 @@ inline double LogAdd(double x, double y) { ...@@ -144,13 +187,7 @@ inline double LogAdd(double x, double y) {
if (diff >= kMinLogDiffDouble) { if (diff >= kMinLogDiffDouble) {
double res; double res;
#if _MSC_VER >= 1800 || __cplusplus >= 201103L res = x + Log1p(Exp(diff));
res = x + std::log1p(std::exp(diff));
#elif defined _MSC_VER
res = x + log(1.0 + exp(diff));
#else
res = x + log1p(exp(diff));
#endif
return res; return res;
} else { } else {
return x; // return the larger one. return x; // return the larger one.
...@@ -170,13 +207,7 @@ inline float LogAdd(float x, float y) { ...@@ -170,13 +207,7 @@ inline float LogAdd(float x, float y) {
if (diff >= kMinLogDiffFloat) { if (diff >= kMinLogDiffFloat) {
float res; float res;
#if _MSC_VER >= 1800 || __cplusplus >= 201103L res = x + Log1p(Exp(diff));
res = x + std::log1p(std::exp(diff));
#elif defined _MSC_VER
res = x + logf(1.0 + expf(diff));
#else
res = x + log1pf(expf(diff));
#endif
return res; return res;
} else { } else {
return x; // return the larger one. return x; // return the larger one.
...@@ -194,7 +225,7 @@ inline double LogSub(double x, double y) { ...@@ -194,7 +225,7 @@ inline double LogSub(double x, double y) {
} }
double diff = y - x; // Will be negative. double diff = y - x; // Will be negative.
double res = x + log(1.0 - exp(diff)); double res = x + Log(1.0 - Exp(diff));
// res might be NAN if diff ~0.0, and 1.0-exp(diff) == 0 to machine precision // res might be NAN if diff ~0.0, and 1.0-exp(diff) == 0 to machine precision
if (KALDI_ISNAN(res)) if (KALDI_ISNAN(res))
...@@ -213,7 +244,7 @@ inline float LogSub(float x, float y) { ...@@ -213,7 +244,7 @@ inline float LogSub(float x, float y) {
} }
float diff = y - x; // Will be negative. float diff = y - x; // Will be negative.
float res = x + logf(1.0 - expf(diff)); float res = x + Log(1.0f - Exp(diff));
// res might be NAN if diff ~0.0, and 1.0-exp(diff) == 0 to machine precision // res might be NAN if diff ~0.0, and 1.0-exp(diff) == 0 to machine precision
if (KALDI_ISNAN(res)) if (KALDI_ISNAN(res))
...@@ -301,42 +332,9 @@ template<class I> void Factorize(I m, std::vector<I> *factors) { ...@@ -301,42 +332,9 @@ template<class I> void Factorize(I m, std::vector<I> *factors) {
} }
inline double Hypot(double x, double y) { return hypot(x, y); } inline double Hypot(double x, double y) { return hypot(x, y); }
inline float Hypot(float x, float y) { return hypotf(x, y); } inline float Hypot(float x, float y) { return hypotf(x, y); }
#if !defined(_MSC_VER) || (_MSC_VER >= 1800)
inline double Log1p(double x) { return log1p(x); }
inline float Log1p(float x) { return log1pf(x); }
#else
inline double Log1p(double x) {
const double cutoff = 1.0e-08;
if (x < cutoff)
return x - 2 * x * x;
else
return log(1.0 + x);
}
inline float Log1p(float x) {
const float cutoff = 1.0e-07;
if (x < cutoff)
return x - 2 * x * x;
else
return log(1.0 + x);
}
#endif
inline double Exp(double x) { return exp(x); }
#ifndef KALDI_NO_EXPF
inline float Exp(float x) { return expf(x); }
#else
inline float Exp(float x) { return exp(x); }
#endif
inline double Log(double x) { return log(x); }
inline float Log(float x) { return logf(x); }
} // namespace kaldi } // namespace kaldi
......
...@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) { ...@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
// sort the counts // sort the counts
std::vector<std::pair<int32,int32> > sorted_counts; std::vector<std::pair<int32,int32> > sorted_counts;
for (int32 i = 0; i < counts.size(); i++) { for (int32 i = 0; i < counts.size(); i++) {
sorted_counts.push_back(std::make_pair(counts[i], i)); sorted_counts.push_back(std::make_pair(static_cast<int32>(counts[i]), i));
} }
std::sort(sorted_counts.begin(), sorted_counts.end()); std::sort(sorted_counts.begin(), sorted_counts.end());
......
...@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) { ...@@ -71,7 +71,7 @@ int main(int argc, char *argv[]) {
// means it's more comparable with MMI/MPE. // means it's more comparable with MMI/MPE.
BaseFloat den_score = den_score_reader.Value(key); BaseFloat den_score = den_score_reader.Value(key);
BaseFloat score_difference = mce_alpha * (num_score - den_score) + mce_beta; BaseFloat score_difference = mce_alpha * (num_score - den_score) + mce_beta;
BaseFloat sigmoid_difference = 1.0 / (1.0 + exp(score_difference)); BaseFloat sigmoid_difference = 1.0 / (1.0 + Exp(score_difference));
// It might be more natural to make the scale // It might be more natural to make the scale
// //
BaseFloat scale = 4.0 * sigmoid_difference * (1 - sigmoid_difference); BaseFloat scale = 4.0 * sigmoid_difference * (1 - sigmoid_difference);
......
...@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) { ...@@ -66,7 +66,7 @@ int main(int argc, char *argv[]) {
KALDI_ASSERT(quantize >= 0.0 && quantize <= 1.0); KALDI_ASSERT(quantize >= 0.0 && quantize <= 1.0);
double sil_log_bias = log(sil_prior / (1.0 - sil_prior)); double sil_log_bias = Log(sil_prior / (1.0 - sil_prior));
std::string silence_likes_rspecifier = po.GetArg(1), std::string silence_likes_rspecifier = po.GetArg(1),
nonsilence_likes_rspecifier = po.GetArg(2), nonsilence_likes_rspecifier = po.GetArg(2),
...@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) { ...@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) {
if (sil_loglike > 10) { if (sil_loglike > 10) {
sil_probs(f) = 1.0; // because the exp below might fail. sil_probs(f) = 1.0; // because the exp below might fail.
} else { } else {
BaseFloat e_sil_loglike = exp(sil_loglike); BaseFloat e_sil_loglike = Exp(sil_loglike);
BaseFloat sil_prob = e_sil_loglike / (1.0 + e_sil_loglike); BaseFloat sil_prob = e_sil_loglike / (1.0 + e_sil_loglike);
if ( !(sil_prob >= 0.0 && sil_prob <= 1.0)) { if ( !(sil_prob >= 0.0 && sil_prob <= 1.0)) {
KALDI_WARN << "Bad silence prob (NaNs found?), setting to 0.5"; KALDI_WARN << "Bad silence prob (NaNs found?), setting to 0.5";
......
...@@ -80,7 +80,7 @@ int main(int argc, char *argv[]) { ...@@ -80,7 +80,7 @@ int main(int argc, char *argv[]) {
for (int32 i = 0; i < logprobs.NumRows(); i++) { for (int32 i = 0; i < logprobs.NumRows(); i++) {
SubVector<BaseFloat> row(logprobs, i); SubVector<BaseFloat> row(logprobs, i);
for (int32 j = 0; j < row.Dim(); j++) { for (int32 j = 0; j < row.Dim(); j++) {
BaseFloat p = exp(row(j)); BaseFloat p = Exp(row(j));
if (p >= min_post) { if (p >= min_post) {
post[i].push_back(std::make_pair(j, p)); post[i].push_back(std::make_pair(j, p));
} else if (random_prune && (p / min_post) >= RandUniform()) { } else if (random_prune && (p / min_post) >= RandUniform()) {
......
...@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) { ...@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
if (weight < threshold) weight *= scale; if (weight < threshold) weight *= scale;
total_weight_out += weight; total_weight_out += weight;
if (weight != 0.0) if (weight != 0.0)
new_post[i].push_back(std::make_pair(tid, weight)); new_post[i].push_back(std::make_pair(tid, static_cast<BaseFloat>(weight)));
} }
} }
posterior_writer.Write(posterior_reader.Key(), new_post); posterior_writer.Write(posterior_reader.Key(), new_post);
......
...@@ -1621,7 +1621,7 @@ static void UnitTestCuDiffXent() { ...@@ -1621,7 +1621,7 @@ static void UnitTestCuDiffXent() {
//cpu //cpu
for(MatrixIndexT r=0; r<Hi.NumRows(); r++) { for(MatrixIndexT r=0; r<Hi.NumRows(); r++) {
int32 col_tgt = Htgt[r]; int32 col_tgt = Htgt[r];
Hlogpost(r) = log(Hi(r, col_tgt)); Hlogpost(r) = Log(Hi(r, col_tgt));
Hi(r, col_tgt) -= 1.0; Hi(r, col_tgt) -= 1.0;
} }
......
...@@ -1193,7 +1193,7 @@ void CuMatrix<Real>::CompObjfAndDeriv(const std::vector<MatrixElement<Real> >& s ...@@ -1193,7 +1193,7 @@ void CuMatrix<Real>::CompObjfAndDeriv(const std::vector<MatrixElement<Real> >& s
//KALDI_ASSERT(label >= 0 && label < nnet_.OutputDim()); //KALDI_ASSERT(label >= 0 && label < nnet_.OutputDim());
Real this_prob = output(m, label); Real this_prob = output(m, label);
KALDI_ASSERT(this_prob >= 0.99e-20); // we floored to 1.0e-20 in SoftmaxLayer. KALDI_ASSERT(this_prob >= 0.99e-20); // we floored to 1.0e-20 in SoftmaxLayer.
*tot_objf += weight * log(this_prob); *tot_objf += weight * Log(this_prob);
*tot_weight += weight; *tot_weight += weight;
(*this)(m, label) += weight / this_prob; (*this)(m, label) += weight / this_prob;
} }
...@@ -1399,7 +1399,7 @@ void CuMatrixBase<Real>::DiffXent(const CuArray<int32> &tgt, ...@@ -1399,7 +1399,7 @@ void CuMatrixBase<Real>::DiffXent(const CuArray<int32> &tgt,
for(int32 r = 0; r < num_rows; r++) { for(int32 r = 0; r < num_rows; r++) {
int32 col_tgt = tgt.Data()[r]; int32 col_tgt = tgt.Data()[r];
Real &value = Mat()(r, col_tgt); Real &value = Mat()(r, col_tgt);
log_post_tgt->Vec()(r) = log(value); log_post_tgt->Vec()(r) = Log(value);
value -= 1.0; value -= 1.0;
} }
} }
......
...@@ -463,7 +463,7 @@ template<typename Real> void CuVectorUnitTestApplyExp() { ...@@ -463,7 +463,7 @@ template<typename Real> void CuVectorUnitTestApplyExp() {
vector.ApplyExp(); vector.ApplyExp();
for(int32 j = 0; j < dim; j++) { for(int32 j = 0; j < dim; j++) {
//std::cout<<"diff is "<<exp(vector2(j))-vector(j)<<std::endl;; //std::cout<<"diff is "<<exp(vector2(j))-vector(j)<<std::endl;;
KALDI_ASSERT(std::abs(exp(vector2(j))-vector(j)) < 0.000001 ); KALDI_ASSERT(std::abs(Exp(vector2(j))-vector(j)) < 0.000001 );
} }
} }
...@@ -482,7 +482,7 @@ template<typename Real> void CuVectorUnitTestApplyLog() { ...@@ -482,7 +482,7 @@ template<typename Real> void CuVectorUnitTestApplyLog() {
vector.ApplyLog(); vector.ApplyLog();
for(int32 j = 0; j < dim; j++) { for(int32 j = 0; j < dim; j++) {
//std::cout<<"diff is "<<exp(vector2(j))-vector(j)<<std::endl;; //std::cout<<"diff is "<<exp(vector2(j))-vector(j)<<std::endl;;
KALDI_ASSERT(std::abs(log(vector2(j))-vector(j)) < 0.000001 ); KALDI_ASSERT(std::abs(Log(vector2(j))-vector(j)) < 0.000001 );
} }
} }
......
...@@ -26,7 +26,7 @@ namespace kaldi { ...@@ -26,7 +26,7 @@ namespace kaldi {
Fbank::Fbank(const FbankOptions &opts) Fbank::Fbank(const FbankOptions &opts)
: opts_(opts), feature_window_function_(opts.frame_opts), srfft_(NULL) { : opts_(opts), feature_window_function_(opts.frame_opts), srfft_(NULL) {
if (opts.energy_floor > 0.0) if (opts.energy_floor > 0.0)
log_energy_floor_ = log(opts.energy_floor); log_energy_floor_ = Log(opts.energy_floor);
int32 padded_window_size = opts.frame_opts.PaddedWindowSize(); int32 padded_window_size = opts.frame_opts.PaddedWindowSize();
if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two... if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two...
...@@ -136,7 +136,7 @@ void Fbank::ComputeInternal(const VectorBase<BaseFloat> &wave, ...@@ -136,7 +136,7 @@ void Fbank::ComputeInternal(const VectorBase<BaseFloat> &wave,
// Compute energy after window function (not the raw one) // Compute energy after window function (not the raw one)
if (opts_.use_energy && !opts_.raw_energy) if (opts_.use_energy && !opts_.raw_energy)
log_energy = log(std::max(VecVec(window, window), log_energy = Log(std::max(VecVec(window, window),
std::numeric_limits<BaseFloat>::min())); std::numeric_limits<BaseFloat>::min()));
if (srfft_ != NULL) // Compute FFT using split-radix algorithm. if (srfft_ != NULL) // Compute FFT using split-radix algorithm.
......
...@@ -153,7 +153,7 @@ void ExtractWindow(const VectorBase<BaseFloat> &wave, ...@@ -153,7 +153,7 @@ void ExtractWindow(const VectorBase<BaseFloat> &wave,
if (log_energy_pre_window != NULL) { if (log_energy_pre_window != NULL) {
BaseFloat energy = std::max(VecVec(window_part, window_part), BaseFloat energy = std::max(VecVec(window_part, window_part),
std::numeric_limits<BaseFloat>::min()); std::numeric_limits<BaseFloat>::min());
*log_energy_pre_window = log(energy); *log_energy_pre_window = Log(energy);
} }
if (opts.preemph_coeff != 0.0) if (opts.preemph_coeff != 0.0)
...@@ -385,7 +385,7 @@ BaseFloat ComputeLpc(const VectorBase<BaseFloat> &autocorr_in, ...@@ -385,7 +385,7 @@ BaseFloat ComputeLpc(const VectorBase<BaseFloat> &autocorr_in,
tmp.Data()); tmp.Data());
if (ans <= 0.0) if (ans <= 0.0)
KALDI_WARN << "Zero energy in LPC computation"; KALDI_WARN << "Zero energy in LPC computation";
return -log((double)1.0/ans); // forms the C0 value return -Log((double)1.0/ans); // forms the C0 value
} }
void SpliceFrames(const MatrixBase<BaseFloat> &input_features, void SpliceFrames(const MatrixBase<BaseFloat> &input_features,
......
...@@ -39,7 +39,7 @@ Mfcc::Mfcc(const MfccOptions &opts) ...@@ -39,7 +39,7 @@ Mfcc::Mfcc(const MfccOptions &opts)
ComputeLifterCoeffs(opts.cepstral_lifter, &lifter_coeffs_); ComputeLifterCoeffs(opts.cepstral_lifter, &lifter_coeffs_);
} }
if (opts.energy_floor > 0.0) if (opts.energy_floor > 0.0)
log_energy_floor_ = log(opts.energy_floor); log_energy_floor_ = Log(opts.energy_floor);
int32 padded_window_size = opts.frame_opts.PaddedWindowSize(); int32 padded_window_size = opts.frame_opts.PaddedWindowSize();
if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two... if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two...
...@@ -138,7 +138,7 @@ void Mfcc::ComputeInternal(const VectorBase<BaseFloat> &wave, ...@@ -138,7 +138,7 @@ void Mfcc::ComputeInternal(const VectorBase<BaseFloat> &wave,
(opts_.use_energy && opts_.raw_energy ? &log_energy : NULL)); (opts_.use_energy && opts_.raw_energy ? &log_energy : NULL));
if (opts_.use_energy && !opts_.raw_energy) if (opts_.use_energy && !opts_.raw_energy)
log_energy = log(std::max(VecVec(window, window), log_energy = Log(std::max(VecVec(window, window),
std::numeric_limits<BaseFloat>::min())); std::numeric_limits<BaseFloat>::min()));
if (srfft_ != NULL) // Compute FFT using the split-radix algorithm. if (srfft_ != NULL) // Compute FFT using the split-radix algorithm.
......
...@@ -34,7 +34,7 @@ Plp::Plp(const PlpOptions &opts) ...@@ -34,7 +34,7 @@ Plp::Plp(const PlpOptions &opts)
&idft_bases_); &idft_bases_);
if (opts.energy_floor > 0.0) if (opts.energy_floor > 0.0)
log_energy_floor_ = log(opts.energy_floor); log_energy_floor_ = Log(opts.energy_floor);
int32 padded_window_size = opts.frame_opts.PaddedWindowSize(); int32 padded_window_size = opts.frame_opts.PaddedWindowSize();
if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two... if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two...
...@@ -193,7 +193,7 @@ void Plp::ComputeInternal(const VectorBase<BaseFloat> &wave, ...@@ -193,7 +193,7 @@ void Plp::ComputeInternal(const VectorBase<BaseFloat> &wave,
(opts_.use_energy && opts_.raw_energy ? &log_energy : NULL)); (opts_.use_energy && opts_.raw_energy ? &log_energy : NULL));
if (opts_.use_energy && !opts_.raw_energy) if (opts_.use_energy && !opts_.raw_energy)
log_energy = log(std::max(VecVec(window, window), log_energy = Log(std::max(VecVec(window, window),
std::numeric_limits<BaseFloat>::min())); std::numeric_limits<BaseFloat>::min()));
if (srfft_ != NULL) // Compute FFT using split-radix algorithm. if (srfft_ != NULL) // Compute FFT using split-radix algorithm.
......
...@@ -162,6 +162,7 @@ int main() { ...@@ -162,6 +162,7 @@ int main() {
} }
return 0; return 0;
} catch (const std::exception &e) { } catch (const std::exception &e) {
static_cast<void>(e);
return 1; return 1;
} }
......
...@@ -27,7 +27,7 @@ namespace kaldi { ...@@ -27,7 +27,7 @@ namespace kaldi {
Spectrogram::Spectrogram(const SpectrogramOptions &opts) Spectrogram::Spectrogram(const SpectrogramOptions &opts)
: opts_(opts), feature_window_function_(opts.frame_opts), srfft_(NULL) { : opts_(opts), feature_window_function_(opts.frame_opts), srfft_(NULL) {
if (opts.energy_floor > 0.0)