23 #ifndef KALDI_MATRIX_SPARSE_MATRIX_H_ 24 #define KALDI_MATRIX_SPARSE_MATRIX_H_ 1 40 template <
typename Real>
47 template <
class OtherReal>
51 template <
class OtherReal>
55 template <
class OtherReal>
82 std::pair<MatrixIndexT, Real> *
Data();
86 const std::pair<MatrixIndexT, Real> *
Data()
const;
98 const std::vector<std::pair<MatrixIndexT, Real> > &pairs);
107 void Write(std::ostream &os,
bool binary)
const;
109 void Read(std::istream &os,
bool binary);
112 void Scale(Real alpha);
118 std::vector<std::pair<MatrixIndexT, Real> >
pairs_;
122 template <
typename Real>
128 template <
typename Real>
139 Real FrobeniusNorm()
const;
147 template <
class OtherReal>
156 template<
class OtherReal>
168 this->CopyFromSmat(other, trans);
185 const std::vector<std::vector<std::pair<MatrixIndexT, Real> > > &pairs);
192 void Write(std::ostream &os,
bool binary)
const;
194 void Read(std::istream &os,
bool binary);
205 void SelectRows(
const std::vector<int32> &row_indexes,
252 void Scale(Real alpha);
261 std::vector<SparseVector<Real> >
rows_;
265 template<
typename Real>
294 void Write(std::ostream &os,
bool binary)
const;
299 void Read(std::istream &is,
bool binary);
401 template <
typename Real>
403 const std::vector<bool> &keep_rows,
409 template <
typename Real>
411 const std::vector<bool> &keep_rows,
418 const std::vector<bool> &keep_rows,
428 const std::vector<bool> &keep_rows,
452 #endif // KALDI_MATRIX_SPARSE_MATRIX_H_
void CopyElementsToVec(VectorBase< OtherReal > *vec) const
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Scale(Real alpha)
Scale all elements of sparse vector.
This class is a wrapper that enables you to store a matrix in one of three forms: either as a Matrix<...
GeneralMatrix(const MatrixBase< BaseFloat > &mat)
void FilterMatrixRows(const Matrix< Real > &in, const std::vector< bool > &keep_rows, Matrix< Real > *out)
Outputs a Matrix<Real> containing only the rows r of "in" such that keep_keep_rows[r] == true...
SparseVector< Real > & operator=(const SparseVector< Real > &other)
Real Max(int32 *index) const
void SetRandn(BaseFloat zero_prob)
Sets elements to zero with probability zero_prob, else normally distributed.
SparseVector(MatrixIndexT dim)
Base class which provides matrix operations not involving resizing or allocation. ...
void Read(std::istream &os, bool binary)
const std::pair< MatrixIndexT, Real > & GetElement(MatrixIndexT i) const
get an indexed element (0 <= i < NumElements()).
void AddToVec(Real alpha, VectorBase< OtherReal > *vec) const
std::vector< std::pair< MatrixIndexT, Real > > pairs_
std::vector< SparseVector< Real > > rows_
GeneralMatrix(const CompressedMatrix &cmat)
SparseVector(const SparseVector< Real > &other)
SparseMatrix(int32 num_rows, int32 num_cols)
void CopyFromSvec(const SparseVector< OtherReal > &other)
void FilterGeneralMatrixRows(const GeneralMatrix &in, const std::vector< bool > &keep_rows, GeneralMatrix *out)
Outputs a GeneralMatrix containing only the rows r of "in" such that keep_rows[r] == true...
Real VecSvec(const VectorBase< Real > &vec, const SparseVector< Real > &svec)
SparseMatrix(const SparseMatrix< Real > &other, MatrixTransposeType trans=kNoTrans)
GeneralMatrix(const GeneralMatrix &other)
void FilterSparseMatrixRows(const SparseMatrix< Real > &in, const std::vector< bool > &keep_rows, SparseMatrix< Real > *out)
Outputs a SparseMatrix<Real> containing only the rows r of "in" such that keep_rows[r] == true...
void FilterCompressedMatrixRows(const CompressedMatrix &in, const std::vector< bool > &keep_rows, Matrix< BaseFloat > *out)
Outputs a Matrix<Real> containing only the rows r of "in" such that keep_rows[r] == true...
void ExtractRowRangeWithPadding(const GeneralMatrix &in, int32 row_offset, int32 num_rows, GeneralMatrix *out)
This function extracts a row-range of a GeneralMatrix and writes as a GeneralMatrix containing the sa...
MatrixIndexT NumElements() const
Returns the number of nonzero elements.
void AppendGeneralMatrixRows(const std::vector< const GeneralMatrix *> &src, GeneralMatrix *mat)
Appends all the matrix rows of a list of GeneralMatrixes, to get a single GeneralMatrix.
GeneralMatrix(const SparseMatrix< BaseFloat > &smat)
void Write(std::ostream &os, bool binary) const
Matrix for CUDA computing.
#define KALDI_ASSERT(cond)
Real TraceMatSmat(const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType trans)
void Resize(MatrixIndexT dim, MatrixResizeType resize_type=kSetZero)
Resizes to this dimension.
SparseMatrix< BaseFloat > smat_
Provides a vector abstraction class.
void Swap(SparseVector< Real > *other)
std::pair< MatrixIndexT, Real > * Data()