For an overview of the matrix library, see The Kaldi Matrix library. More...
Modules | |
Matrix-vector functions returning scalars | |
Miscellaneous matrix/vector library functions and classes | |
Classes | |
class | CompressedMatrix |
class | MatrixBase< Real > |
Base class which provides matrix operations not involving resizing or allocation. More... | |
class | Matrix< Real > |
A class for storing matrices. More... | |
class | VectorBase< Real > |
Provides a vector abstraction class. More... | |
class | Vector< Real > |
A class representing a vector. More... | |
class | SubVector< Real > |
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vector [or as the row of a matrix]. More... | |
class | PackedMatrix< Real > |
Packed matrix: base class for triangular and symmetric matrices. More... | |
class | SpMatrix< Real > |
Packed symetric matrix class. More... | |
class | SparseVector< Real > |
class | SparseMatrix< Real > |
class | GeneralMatrix |
This class is a wrapper that enables you to store a matrix in one of three forms: either as a Matrix<BaseFloat>, or a CompressedMatrix, or a SparseMatrix<BaseFloat>. More... | |
class | TpMatrix< Real > |
Packed symetric matrix class. More... | |
Enumerations | |
enum | CompressionMethod { kAutomaticMethod = 1, kSpeechFeature = 2, kTwoByteAuto = 3, kTwoByteSignedInteger = 4, kOneByteAuto = 5, kOneByteUnsignedInteger = 6, kOneByteZeroOne = 7 } |
enum | GeneralMatrixType { kFullMatrix, kCompressedMatrix, kSparseMatrix } |
Functions | |
template<typename Real > | |
Real | VecSvec (const VectorBase< Real > &vec, const SparseVector< Real > &svec) |
template<typename Real > | |
Real | TraceMatSmat (const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType trans) |
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. More... | |
template<typename Real > | |
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. More... | |
template<typename Real > | |
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. More... | |
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. More... | |
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. More... | |
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 same type of underlying matrix. More... | |
For an overview of the matrix library, see The Kaldi Matrix library.
enum CompressionMethod |
Enumerator | |
---|---|
kAutomaticMethod | |
kSpeechFeature | |
kTwoByteAuto | |
kTwoByteSignedInteger | |
kOneByteAuto | |
kOneByteUnsignedInteger | |
kOneByteZeroOne |
Definition at line 75 of file compressed-matrix.h.
enum GeneralMatrixType |
Enumerator | |
---|---|
kFullMatrix | |
kCompressedMatrix | |
kSparseMatrix |
Definition at line 271 of file sparse-matrix.h.
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.
Preserves sparsity if all inputs were sparse (or empty). Does not preserve compression, if inputs were compressed; you have to re-compress manually, if that's what you need.
Definition at line 929 of file sparse-matrix.cc.
References SparseMatrix< Real >::AppendSparseMatrixRows(), GeneralMatrix::Clear(), GeneralMatrix::CopyToMat(), rnnlm::i, KALDI_ASSERT, KALDI_ERR, kaldi::kSparseMatrix, kaldi::kUndefined, GeneralMatrix::NumCols(), GeneralMatrix::NumRows(), GeneralMatrix::SwapFullMatrix(), and GeneralMatrix::SwapSparseMatrix().
Referenced by kaldi::nnet3::MergeIo().
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 same type of underlying matrix.
If the row-range is partly outside the row-range of 'in' (i.e. if row_offset < 0 or row_offset + num_rows > in.NumRows()) then it will pad with copies of the first and last row as needed. This is more efficient than un-compressing and re-compressing the underlying CompressedMatrix, and causes less accuracy loss due to re-compression (no loss in most cases).
Definition at line 1233 of file sparse-matrix.cc.
References VectorBase< Real >::CopyFromVec(), GeneralMatrix::GetCompressedMatrix(), GeneralMatrix::GetFullMatrix(), GeneralMatrix::GetSparseMatrix(), KALDI_ASSERT, KALDI_ERR, kaldi::kCompressedMatrix, kaldi::kFullMatrix, kaldi::kSparseMatrix, kaldi::kUndefined, MatrixBase< Real >::NumCols(), SparseMatrix< Real >::NumCols(), CompressedMatrix::NumCols(), MatrixBase< Real >::NumRows(), SparseMatrix< Real >::NumRows(), SparseMatrix< Real >::Row(), SparseMatrix< Real >::SetRow(), GeneralMatrix::SwapCompressedMatrix(), GeneralMatrix::SwapFullMatrix(), GeneralMatrix::SwapSparseMatrix(), and GeneralMatrix::Type().
Referenced by kaldi::nnet3::ProcessFile(), and kaldi::UnitTestGeneralMatrix().
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.
keep_rows.size() must equal in.NumRows(), and rows must contain at least one "true" element.
Definition at line 979 of file sparse-matrix.cc.
References CompressedMatrix::CopyRowToVec(), CompressedMatrix::CopyToMat(), kaldi::FilterMatrixRows(), KALDI_ASSERT, KALDI_ERR, kaldi::kUndefined, CompressedMatrix::NumCols(), CompressedMatrix::NumRows(), and Matrix< Real >::Resize().
Referenced by kaldi::FilterGeneralMatrixRows().
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.
keep_rows.size() must equal in.NumRows(), and keep_rows must contain at least one "true" element. If in.Type() is kCompressedMatrix, the result will not be compressed; otherwise, the type is preserved.
Definition at line 1101 of file sparse-matrix.cc.
References GeneralMatrix::Clear(), kaldi::FilterCompressedMatrixRows(), kaldi::FilterMatrixRows(), kaldi::FilterSparseMatrixRows(), GeneralMatrix::GetCompressedMatrix(), GeneralMatrix::GetFullMatrix(), GeneralMatrix::GetSparseMatrix(), KALDI_ASSERT, KALDI_ERR, kaldi::kCompressedMatrix, kaldi::kFullMatrix, kaldi::kSparseMatrix, GeneralMatrix::NumRows(), GeneralMatrix::SwapFullMatrix(), GeneralMatrix::SwapSparseMatrix(), and GeneralMatrix::Type().
Referenced by kaldi::nnet3::FilterExample().
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.
keep_rows.size() must equal in.NumRows(), and keep_rows must contain at least one "true" element.
Definition at line 1023 of file sparse-matrix.cc.
References VectorBase< Real >::CopyFromVec(), kaldi::FilterMatrixRows(), KALDI_ASSERT, KALDI_ERR, kaldi::kUndefined, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and Matrix< Real >::Resize().
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.
keep_rows.size() must equal in.NumRows(), and rows must contain at least one "true" element.
Definition at line 1063 of file sparse-matrix.cc.
References kaldi::FilterSparseMatrixRows(), KALDI_ASSERT, KALDI_ERR, kaldi::kUndefined, SparseMatrix< Real >::NumCols(), SparseMatrix< Real >::NumRows(), SparseMatrix< Real >::Resize(), SparseMatrix< Real >::Row(), and SparseMatrix< Real >::SetRow().
Real TraceMatSmat | ( | const MatrixBase< Real > & | A, |
const SparseMatrix< Real > & | B, | ||
MatrixTransposeType | trans | ||
) |
Definition at line 704 of file sparse-matrix.cc.
References MatrixBase< Real >::Data(), SparseVector< Real >::Data(), rnnlm::i, KALDI_ASSERT, kaldi::kTrans, MatrixBase< Real >::NumCols(), SparseMatrix< Real >::NumCols(), SparseVector< Real >::NumElements(), MatrixBase< Real >::NumRows(), SparseMatrix< Real >::NumRows(), MatrixBase< Real >::Row(), SparseMatrix< Real >::Row(), MatrixBase< Real >::Stride(), kaldi::TraceMatSmat(), and kaldi::VecSvec().
Referenced by kaldi::nnet3::ComputeObjectiveFunction(), kaldi::TestCuSparseMatrixTraceMatSmat(), kaldi::UnitTestCuSparseMatrixTraceMatSmat(), kaldi::UnitTestMatrixAddMatSmat(), kaldi::UnitTestMatrixAddSmatMat(), and kaldi::UnitTestSparseMatrixTraceMatSmat().
Real VecSvec | ( | const VectorBase< Real > & | vec, |
const SparseVector< Real > & | svec | ||
) |
Definition at line 523 of file sparse-matrix.cc.
References VectorBase< Real >::Data(), SparseVector< Real >::Data(), SparseVector< Real >::Dim(), VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, rnnlm::n, and SparseVector< Real >::NumElements().
Referenced by kaldi::UnitTestSparseVectorVecSvec().