30 template<
typename Real> std::string
NameOf() {
31 return (
sizeof(Real) == 8 ?
"<double>" :
"<float>");
34 template<
typename Real>
static void CsvResult(std::string test,
int dim,
BaseFloat measure, std::string units) {
35 std::cout << test <<
"," << (
sizeof(Real) == 8 ?
"double" :
"float") <<
"," << dim <<
"," << measure <<
"," << units <<
"\n";
43 if (
i % 1000 == 0)
KALDI_LOG <<
"done 1000 [ == ten seconds of speech]";
47 CsvResult<Real>(__func__, 512, t.
Elapsed(),
"seconds");
56 KALDI_LOG <<
"done 1000 [ == ten seconds of speech, split-radix]";
60 CsvResult<Real>(__func__, 512, t.
Elapsed(),
"seconds");
63 template<
typename Real>
66 std::vector<MatrixIndexT> sizes;
73 for (
size_t i = 0;
i < sizes.size();
i++) {
80 CsvResult<Real>(
"Eig w/o eigenvectors", size, t1.
Elapsed(),
"seconds");
89 CsvResult<Real>(
"Eig with eigenvectors", size, t1.
Elapsed(),
"seconds");
96 M.
Svd(&l, NULL, NULL);
97 CsvResult<Real>(
"SVD w/o eigenvectors", size, t1.
Elapsed(),
"seconds");
101 Matrix<Real> M(size, size), U(size, size), V(size, size);
105 CsvResult<Real>(
"SVD with eigenvectors", size, t1.
Elapsed(),
"seconds");
108 CsvResult<Real>(__func__, sizes.size(), t.
Elapsed(),
"seconds");
111 template<
typename Real>
114 std::vector<MatrixIndexT> sizes;
115 sizes.push_back(512);
116 sizes.push_back(1024);
117 for (
size_t i = 0;
i < sizes.size();
i++) {
123 A.SetRandn(); B.SetRandn();
129 CsvResult<Real>(
"AddMatMat", size, t1.
Elapsed(),
"seconds");
132 CsvResult<Real>(__func__, sizes.size(), t.
Elapsed(),
"seconds");
135 template<
typename Real>
138 std::vector<MatrixIndexT> sizes;
139 int32 size = 4, num = 5;
141 sizes.push_back(size);
145 for(
size_t i = 0;
i < sizes.size();
i++) {
154 for (;t1.
Elapsed() < time_in_secs; iter++) {
160 CsvResult<Real>(
"AddRowSumMat", size, gflops,
"gigaflops");
162 CsvResult<Real>(__func__, sizes.size(), t.
Elapsed(),
"seconds");
165 template<
typename Real>
168 std::vector<MatrixIndexT> sizes;
169 int32 size = 4, num = 5;
171 sizes.push_back(size);
175 for(
size_t i = 0;
i < sizes.size();
i++) {
184 for (;t1.
Elapsed() < time_in_secs; iter++) {
190 CsvResult<Real>(
"AddColSumMat", size, gflops,
"gigaflops");
192 CsvResult<Real>(__func__, sizes.size(), t.
Elapsed(),
"seconds");
195 template<
typename Real>
198 std::vector<MatrixIndexT> sizes;
199 int32 size = 4, num = 5;
201 sizes.push_back(size);
205 for(
size_t i = 0;
i < sizes.size();
i++) {
215 for (;t1.
Elapsed() < time_in_secs; iter++) {
221 CsvResult<Real>(
"AddVecToRows", size, gflops,
"gigaflops");
223 CsvResult<Real>(__func__, sizes.size(), t.
Elapsed(),
"seconds");
226 template<
typename Real>
229 std::vector<MatrixIndexT> sizes;
230 int32 size = 4, num = 5;
232 sizes.push_back(size);
236 for(
size_t i = 0;
i < sizes.size();
i++) {
246 for (;t1.
Elapsed() < time_in_secs; iter++) {
252 CsvResult<Real>(
"AddVecToCols", size, gflops,
"gigaflops");
254 CsvResult<Real>(__func__, sizes.size(), t.
Elapsed(),
"seconds");
258 UnitTestRealFftSpeed<Real>();
259 UnitTestSplitRadixRealFftSpeed<Real>();
260 UnitTestSvdSpeed<Real>();
261 UnitTestAddMatMatSpeed<Real>();
262 UnitTestAddRowSumMatSpeed<Real>();
263 UnitTestAddColSumMatSpeed<Real>();
264 UnitTestAddVecToRowsSpeed<Real>();
265 UnitTestAddVecToColsSpeed<Real>();
271 using namespace kaldi;
273 KALDI_LOG <<
"Starting, Single precision";
274 kaldi::MatrixUnitSpeedTest<float>();
275 KALDI_LOG <<
"Starting, Double precision";
276 kaldi::MatrixUnitSpeedTest<double>();
277 KALDI_LOG <<
"Tests succeeded, total duration " << t.
Elapsed() <<
" seconds.";
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Packed symetric matrix class.
static void CsvResult(std::string test, int dim, BaseFloat measure, std::string units)
static void MatrixUnitSpeedTest()
void AddRowSumMat(Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
Does *this = alpha * (sum of rows of M) + beta * *this.
static void UnitTestRealFftSpeed()
void Eig(VectorBase< Real > *s, MatrixBase< Real > *P=NULL) const
Solves the symmetric eigenvalue problem: at end we should have (*this) = P * diag(s) * P^T...
A class for storing matrices.
void SetRandn()
< Set to unit matrix.
static void UnitTestSplitRadixRealFftSpeed()
static void UnitTestAddRowSumMatSpeed()
void AddVecToRows(const Real alpha, const VectorBase< OtherReal > &v)
[each row of *this] += alpha * v
static void UnitTestSvdSpeed()
static void UnitTestAddVecToRowsSpeed()
void SetRandn()
Sets to random values of a normal distribution.
static void UnitTestAddColSumMatSpeed()
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
Real * Data()
Returns a pointer to the start of the vector's data.
void SetRandn()
Set vector to random normally-distributed noise.
A class representing a vector.
static void UnitTestAddMatMatSpeed()
void AddVecToCols(const Real alpha, const VectorBase< OtherReal > &v)
[each col of *this] += alpha * v
void Svd(VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt) const
Compute SVD (*this) = U diag(s) Vt.
void AddColSumMat(Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
Does *this = alpha * (sum of columns of M) + beta * *this.
double Elapsed() const
Returns time in seconds.
static void UnitTestAddVecToColsSpeed()
void Compute(Real *x, bool forward)
If forward == true, this function transforms from a sequence of N real points to its complex fourier ...
void RealFft(VectorBase< Real > *v, bool forward)
RealFft is a fourier transform of real inputs.