25 template <
typename Real>
37 Real sum1 = svec.
Sum();
38 Real sum2 = vec.
Sum();
43 template <
typename Real>
60 other_vec2.
AddVec(0.7, vec);
65 template <
typename Real>
83 max1 = svec.
Max(&index1);
84 max2 = vec.
Max(&index2);
91 template <
typename Real>
106 Real product1 =
VecSvec(other_vec, svec);
107 Real product2 =
VecVec(other_vec, vec);
113 template <
typename Real>
126 Real sum1 = smat.
Sum();
127 Real sum2 = mat.
Sum();
132 template <
typename Real>
151 template <
typename Real>
169 other_mat2.
AddMat(0.7, mat);
174 template <
typename Real>
183 for (
int32 r = 0; r < num_rows; r++) {
184 for (
int32 c = 0; c < num_cols; c++) {
197 template <
typename Real>
228 template <
typename Real>
231 for (
int32 t = 0; t < 4; t++) {
263 KALDI_ASSERT(trace_abc_alpha != 0.0 && trace_abc_beta != 0.0);
265 result2 = alpha * trace_abc_alpha + beta * trace_abc_beta;
271 template <
typename Real>
274 for (
int32 t = 0; t < 4; t++) {
305 KALDI_ASSERT(trace_abc_alpha != 0.0 && trace_abc_beta != 0.0);
307 result2 = alpha * trace_abc_alpha + beta * trace_abc_beta;
313 template <
typename Real>
316 UnitTestSparseVectorSum<Real>();
317 UnitTestSparseVectorAddToVec<Real>();
318 UnitTestSparseVectorMax<Real>();
319 UnitTestSparseVectorVecSvec<Real>();
322 UnitTestSparseMatrixSum<Real>();
323 UnitTestSparseMatrixFrobeniusNorm<Real>();
324 UnitTestSparseMatrixAddToMat<Real>();
325 UnitTestSparseMatrixTraceMatSmat<Real>();
327 UnitTestSparseMatrixConstructor<Real>();
331 UnitTestMatrixAddMatSmat<Real>();
332 UnitTestMatrixAddSmatMat<Real>();
339 kaldi::SparseMatrixUnitTest<float>();
340 kaldi::SparseMatrixUnitTest<double>();
void CopyElementsToVec(VectorBase< OtherReal > *vec) const
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void UnitTestSparseVectorMax()
void UnitTestSparseMatrixTraceMatSmat()
void UnitTestMatrixAddSmatMat()
Real Max(int32 *index) const
void SetRandn(BaseFloat zero_prob)
Sets elements to zero with probability zero_prob, else normally distributed.
void AddToVec(Real alpha, VectorBase< OtherReal > *vec) const
void UnitTestSparseVectorAddToVec()
void AddMat(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans)
*this += alpha * M [or M^T]
float RandGauss(struct RandomState *state=NULL)
A class for storing matrices.
void SparseMatrixUnitTest()
void UnitTestSparseMatrixSum()
Real VecSvec(const VectorBase< Real > &vec, const SparseVector< Real > &svec)
void CopyToMat(MatrixBase< OtherReal > *other, MatrixTransposeType t=kNoTrans) const
Copy to matrix. It must already have the correct size.
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
void AddToMat(BaseFloat alpha, MatrixBase< Real > *other, MatrixTransposeType t=kNoTrans) const
Does *other = *other + alpha * *this.
void UnitTestSparseVectorVecSvec()
void UnitTestSparseVectorSum()
void SetRandn()
Sets to random values of a normal distribution.
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
void UnitTestSparseMatrixConstructor()
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
Real Sum() const
Returns sum of all elements in matrix.
int Rand(struct RandomState *state)
Real Sum() const
Returns sum of the elements.
void SetRandn()
Set vector to random normally-distributed noise.
void UnitTestSparseMatrixFrobeniusNorm()
void AddSmatMat(Real alpha, const SparseMatrix< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, Real beta)
(*this) = alpha * op(A) * B + beta * (*this), where A is sparse.
A class representing a vector.
void SetRandn(BaseFloat zero_prob)
Sets up to a pseudo-randomly initialized matrix, with each element zero with probability zero_prob an...
#define KALDI_ASSERT(cond)
Real FrobeniusNorm() const
Frobenius norm, which is the sqrt of sum of square elements.
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
void UnitTestSparseMatrixAddToMat()
void UnitTestMatrixAddMatSmat()
Real TraceMatSmat(const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType trans)
Real FrobeniusNorm() const
void AddMatSmat(Real alpha, const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType transB, Real beta)
(*this) = alpha * A * op(B) + beta * (*this), where B is sparse and op(B) is either B or trans(B) dep...
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)