Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Abdelwahab HEBA
kaldi_2015
Commits
36cad857
Commit
36cad857
authored
Jul 22, 2015
by
Jan "yenda" Trmal
Browse files
Merge pull request #8 from jtrmal/windows-test-fixes
Windows test fixes
parents
db63ae29
b0439a2e
Changes
81
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
108 additions
and
104 deletions
+108
-104
src/base/kaldi-error.h
src/base/kaldi-error.h
+1
-1
src/base/kaldi-math-test.cc
src/base/kaldi-math-test.cc
+12
-9
src/base/kaldi-math.h
src/base/kaldi-math.h
+50
-52
src/bin/analyze-counts.cc
src/bin/analyze-counts.cc
+1
-1
src/bin/compute-mce-scale.cc
src/bin/compute-mce-scale.cc
+1
-1
src/bin/get-silence-probs.cc
src/bin/get-silence-probs.cc
+2
-2
src/bin/logprob-to-post.cc
src/bin/logprob-to-post.cc
+1
-1
src/bin/thresh-post.cc
src/bin/thresh-post.cc
+1
-1
src/cudamatrix/cu-matrix-test.cc
src/cudamatrix/cu-matrix-test.cc
+1
-1
src/cudamatrix/cu-matrix.cc
src/cudamatrix/cu-matrix.cc
+2
-2
src/cudamatrix/cu-vector-test.cc
src/cudamatrix/cu-vector-test.cc
+2
-2
src/feat/feature-fbank.cc
src/feat/feature-fbank.cc
+2
-2
src/feat/feature-functions.cc
src/feat/feature-functions.cc
+2
-2
src/feat/feature-mfcc.cc
src/feat/feature-mfcc.cc
+2
-2
src/feat/feature-plp.cc
src/feat/feature-plp.cc
+2
-2
src/feat/feature-sdc-test.cc
src/feat/feature-sdc-test.cc
+1
-0
src/feat/feature-spectrogram.cc
src/feat/feature-spectrogram.cc
+2
-2
src/feat/online-feature-test.cc
src/feat/online-feature-test.cc
+3
-1
src/feat/pitch-functions.cc
src/feat/pitch-functions.cc
+17
-17
src/feat/resample-test.cc
src/feat/resample-test.cc
+3
-3
No files found.
src/base/kaldi-error.h
View file @
36cad857
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
#include <sstream>
#include <sstream>
#include <cstdio>
#include <cstdio>
#if _MSC_VER >=
0x14
00 || !defined(MSC_VER) && __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
#if _MSC_VER >=
19
00 ||
(
!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)
...
...
src/base/kaldi-math-test.cc
View file @
36cad857
...
@@ -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
=
e
xp
(
LogAdd
(
l
og
(
f1
),
l
og
(
f2
)));
double
add1
=
E
xp
(
LogAdd
(
L
og
(
f1
),
L
og
(
f2
)));
double
add2
=
e
xp
(
LogAdd
(
l
og
(
f2
),
l
og
(
f1
)));
double
add2
=
E
xp
(
LogAdd
(
L
og
(
f2
),
L
og
(
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
=
e
xp
(
LogSub
(
l
og
(
add
),
l
og
(
f1
))),
thresh
=
(
f2
*
0.01
)
+
0.001
;
double
f2_check
=
E
xp
(
LogSub
(
L
og
(
add
),
L
og
(
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
(
e
xp
(
kLogZeroFloat
)
==
0.0
);
KALDI_ASSERT
(
E
xp
(
kLogZeroFloat
)
==
0.0
);
KALDI_ASSERT
(
e
xp
(
kLogZeroDouble
)
==
0.0
);
KALDI_ASSERT
(
E
xp
(
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
(
e
xp
(
M_LOG_2PI
)))
<
1.0e-05
);
KALDI_ASSERT
(
std
::
abs
(
sin
(
E
xp
(
M_LOG_2PI
)))
<
1.0e-05
);
KALDI_ASSERT
(
std
::
abs
(
cos
(
e
xp
(
M_LOG_2PI
))
-
1.0
)
<
1.0e-05
);
KALDI_ASSERT
(
std
::
abs
(
cos
(
E
xp
(
M_LOG_2PI
))
-
1.0
)
<
1.0e-05
);
}
}
void
UnitTestAssertFunc
()
{
// Testing Assert** *functions
void
UnitTestAssertFunc
()
{
// Testing Assert** *functions
...
...
src/base/kaldi-math.h
View file @
36cad857
...
@@ -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
*
l
og
f
(
RandUniform
(
state
)))
return
static_cast
<
float
>
(
sqrtf
(
-
2
*
L
og
(
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
+
l
og
(
1.0
-
e
xp
(
diff
));
double
res
=
x
+
L
og
(
1.0
-
E
xp
(
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
+
l
og
f
(
1.0
-
e
xp
f
(
diff
));
float
res
=
x
+
L
og
(
1.0
f
-
E
xp
(
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
...
...
src/bin/analyze-counts.cc
View file @
36cad857
...
@@ -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
());
...
...
src/bin/compute-mce-scale.cc
View file @
36cad857
...
@@ -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
+
e
xp
(
score_difference
));
BaseFloat
sigmoid_difference
=
1.0
/
(
1.0
+
E
xp
(
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
);
...
...
src/bin/get-silence-probs.cc
View file @
36cad857
...
@@ -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
=
l
og
(
sil_prior
/
(
1.0
-
sil_prior
));
double
sil_log_bias
=
L
og
(
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
=
e
xp
(
sil_loglike
);
BaseFloat
e_sil_loglike
=
E
xp
(
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"
;
...
...
src/bin/logprob-to-post.cc
View file @
36cad857
...
@@ -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
=
e
xp
(
row
(
j
));
BaseFloat
p
=
E
xp
(
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
())
{
...
...
src/bin/thresh-post.cc
View file @
36cad857
...
@@ -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
);
...
...
src/cudamatrix/cu-matrix-test.cc
View file @
36cad857
...
@@ -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
)
=
l
og
(
Hi
(
r
,
col_tgt
));
Hlogpost
(
r
)
=
L
og
(
Hi
(
r
,
col_tgt
));
Hi
(
r
,
col_tgt
)
-=
1.0
;
Hi
(
r
,
col_tgt
)
-=
1.0
;
}
}
...
...
src/cudamatrix/cu-matrix.cc
View file @
36cad857
...
@@ -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
*
l
og
(
this_prob
);
*
tot_objf
+=
weight
*
L
og
(
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
)
=
l
og
(
value
);
log_post_tgt
->
Vec
()(
r
)
=
L
og
(
value
);
value
-=
1.0
;
value
-=
1.0
;
}
}
}
}
...
...
src/cudamatrix/cu-vector-test.cc
View file @
36cad857
...
@@ -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
(
e
xp
(
vector2
(
j
))
-
vector
(
j
))
<
0.000001
);
KALDI_ASSERT
(
std
::
abs
(
E
xp
(
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
(
l
og
(
vector2
(
j
))
-
vector
(
j
))
<
0.000001
);
KALDI_ASSERT
(
std
::
abs
(
L
og
(
vector2
(
j
))
-
vector
(
j
))
<
0.000001
);
}
}
}
}
...
...
src/feat/feature-fbank.cc
View file @
36cad857
...
@@ -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_
=
l
og
(
opts
.
energy_floor
);
log_energy_floor_
=
L
og
(
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
=
l
og
(
std
::
max
(
VecVec
(
window
,
window
),
log_energy
=
L
og
(
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.
...
...
src/feat/feature-functions.cc
View file @
36cad857
...
@@ -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
=
l
og
(
energy
);
*
log_energy_pre_window
=
L
og
(
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
-
l
og
((
double
)
1.0
/
ans
);
// forms the C0 value
return
-
L
og
((
double
)
1.0
/
ans
);
// forms the C0 value
}
}
void
SpliceFrames
(
const
MatrixBase
<
BaseFloat
>
&
input_features
,
void
SpliceFrames
(
const
MatrixBase
<
BaseFloat
>
&
input_features
,
...
...
src/feat/feature-mfcc.cc
View file @
36cad857
...
@@ -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_
=
l
og
(
opts
.
energy_floor
);
log_energy_floor_
=
L
og
(
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
=
l
og
(
std
::
max
(
VecVec
(
window
,
window
),
log_energy
=
L
og
(
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.
...
...
src/feat/feature-plp.cc
View file @
36cad857
...
@@ -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_
=
l
og
(
opts
.
energy_floor
);
log_energy_floor_
=
L
og
(
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
=
l
og
(
std
::
max
(
VecVec
(
window
,
window
),
log_energy
=
L
og
(
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.
...
...
src/feat/feature-sdc-test.cc
View file @
36cad857
...
@@ -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
;
}
}
...
...
src/feat/feature-spectrogram.cc
View file @
36cad857
...
@@ -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
)