Packed matrix: base class for triangular and symmetric matrices. More...
#include <matrix-common.h>
Public Member Functions | |
PackedMatrix () | |
PackedMatrix (MatrixIndexT r, MatrixResizeType resize_type=kSetZero) | |
PackedMatrix (const PackedMatrix< Real > &orig) | |
template<typename OtherReal > | |
PackedMatrix (const PackedMatrix< OtherReal > &orig) | |
void | SetZero () |
void | SetUnit () |
< Set to zero More... | |
void | SetRandn () |
< Set to unit matrix. More... | |
Real | Trace () const |
< Set to random values of a normal distribution More... | |
PackedMatrix< Real > & | operator= (const PackedMatrix< Real > &other) |
~PackedMatrix () | |
void | Resize (MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero) |
Set packed matrix to a specified size (can be zero). More... | |
void | AddToDiag (const Real r) |
void | ScaleDiag (const Real alpha) |
void | SetDiag (const Real alpha) |
template<typename OtherReal > | |
void | CopyFromPacked (const PackedMatrix< OtherReal > &orig) |
template<typename OtherReal > | |
void | CopyFromVec (const SubVector< OtherReal > &orig) |
CopyFromVec just interprets the vector as having the same layout as the packed matrix. More... | |
Real * | Data () |
const Real * | Data () const |
MatrixIndexT | NumRows () const |
MatrixIndexT | NumCols () const |
size_t | SizeInBytes () const |
Real | operator() (MatrixIndexT r, MatrixIndexT c) const |
Real & | operator() (MatrixIndexT r, MatrixIndexT c) |
Real | Max () const |
Real | Min () const |
void | Scale (Real c) |
void | Read (std::istream &in, bool binary, bool add=false) |
void | Write (std::ostream &out, bool binary) const |
void | Destroy () |
void | Swap (PackedMatrix< Real > *other) |
Swaps the contents of *this and *other. Shallow swap. More... | |
void | Swap (Matrix< Real > *other) |
Protected Member Functions | |
void | AddPacked (const Real alpha, const PackedMatrix< Real > &M) |
Protected Attributes | |
Real * | data_ |
MatrixIndexT | num_rows_ |
Private Member Functions | |
void | Init (MatrixIndexT dim) |
Init assumes the current contents of the class are is invalid (i.e. More... | |
Friends | |
class | CuPackedMatrix< Real > |
std::ostream & | operator<< (std::ostream &out, const PackedMatrix< Real > &m) |
Packed matrix: base class for triangular and symmetric matrices.
Definition at line 64 of file matrix-common.h.
|
inline |
Definition at line 45 of file packed-matrix.h.
|
inlineexplicit |
Definition at line 47 of file packed-matrix.h.
|
inlineexplicit |
Definition at line 50 of file packed-matrix.h.
|
inlineexplicit |
Definition at line 56 of file packed-matrix.h.
|
inline |
Definition at line 74 of file packed-matrix.h.
|
protected |
Definition at line 40 of file packed-matrix.cc.
Referenced by SpMatrix< float >::AddSp(), TpMatrix< float >::AddTp(), and PackedMatrix< float >::Min().
void AddToDiag | ( | const Real | r | ) |
Definition at line 123 of file packed-matrix.cc.
Referenced by IvectorExtractor::GetIvectorDistPrior(), OnlineIvectorEstimationStats::OnlineIvectorEstimationStats(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), kaldi::UnitTestAddToDiag(), kaldi::UnitTestCuSpMatrixAddToDiag(), kaldi::UnitTestCuSpMatrixInvert(), UnitTestEstimateFullGmm(), and PackedMatrix< float >::~PackedMatrix().
template void CopyFromPacked | ( | const PackedMatrix< OtherReal > & | orig | ) |
Definition at line 153 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::CopyFromPacked(), SpMatrix< float >::CopyFromSp(), TpMatrix< float >::CopyFromTp(), CuPackedMatrix< Real >::CopyToPacked(), PackedMatrix< float >::operator=(), PackedMatrix< float >::PackedMatrix(), and PackedMatrix< float >::~PackedMatrix().
CopyFromVec just interprets the vector as having the same layout as the packed matrix.
Must have the same dimension, i.e. orig.Dim() == (NumRows()*(NumRows()+1)) / 2;
Definition at line 181 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::CopyFromVec(), CompressedAffineXformStats::ExtractOneG(), kaldi::UnitTestSpVec(), EbwAmSgmm2Updater::UpdateW(), MleAmSgmm2Updater::UpdateW(), and PackedMatrix< float >::~PackedMatrix().
|
inline |
Definition at line 102 of file packed-matrix.h.
Referenced by SpMatrix< float >::AddMat2Sp(), PackedMatrix< float >::AddPacked(), MatrixBase< float >::AddSp(), VectorBase< float >::AddSpVec(), SpMatrix< float >::AddVec2Sp(), TpMatrix< float >::Cholesky(), FmllrRawAccs::CommitSingleFrameStats(), IvectorExtractorStats::CommitStatsForM(), IvectorExtractorStats::CommitStatsForWPoint(), IvectorExtractor::ComputeDerivedVars(), FmllrRawAccs::ConvertToSimpleStats(), PackedMatrix< float >::CopyFromPacked(), MatrixBase< float >::CopyFromSp(), MatrixBase< float >::CopyFromTp(), VectorBase< float >::CopyRowFromSp(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::GetIvectorDistMean(), VectorBase< float >::MulTp(), VectorBase< float >::Solve(), SubVector< Real >::SubVector(), kaldi::TraceSpMat(), kaldi::TraceSpSp(), kaldi::TraceSpSpLower(), IvectorExtractorStats::UpdateVariances(), IvectorExtractorStats::UpdateWeight(), and kaldi::VecSpVec().
|
inline |
Definition at line 103 of file packed-matrix.h.
void Destroy | ( | ) |
Definition at line 227 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::Min(), and PackedMatrix< float >::~PackedMatrix().
|
inlineprivate |
Init assumes the current contents of the class are is invalid (i.e.
junk or has already been freed), and it sets the matrixd to newly allocated memory with the specified dimension. dim == 0 is acceptable. The memory contents pointed to by data_ will be undefined.
Definition at line 56 of file packed-matrix.cc.
|
inline |
Definition at line 133 of file packed-matrix.h.
Referenced by kaldi::ApproxEqual(), OnlineNaturalGradient::ReorthogonalizeRt1(), OnlinePreconditioner::ReorthogonalizeXt1(), and kaldi::UnitTestMaxMin().
|
inline |
Definition at line 138 of file packed-matrix.h.
Referenced by kaldi::ApproxEqual(), and kaldi::UnitTestMaxMin().
|
inline |
Definition at line 105 of file packed-matrix.h.
Referenced by VectorBase< float >::CopyDiagFromPacked(), VectorBase< float >::CopyRowFromSp(), kaldi::LinearCgd(), Matrix< BaseFloat >::Matrix(), kaldi::TraceMatSpMatSp(), and kaldi::TraceSpMat().
|
inline |
Definition at line 104 of file packed-matrix.h.
Referenced by SpMatrix< float >::AddMat2Sp(), PackedMatrix< float >::AddPacked(), SpMatrix< float >::AddSmat2Sp(), MatrixBase< float >::AddSp(), MatrixBase< float >::AddSpSp(), VectorBase< float >::AddSpVec(), VectorBase< float >::AddTpVec(), SpMatrix< float >::AddVec2Sp(), SpMatrix< float >::ApplyFloor(), kaldi::ApproxEqual(), SpMatrix< float >::ApproxEqual(), kaldi::AssertDiagEqual(), kaldi::AssertEqual(), IvectorExtractorStats::CheckDims(), TpMatrix< float >::Cholesky(), BasisFmllrEstimate::ComputeAmDiagPrecond(), Sgmm2Project::ComputeLdaTransform(), kaldi::ComputeNormalizingTransform(), FastNnetCombiner::ComputePreconditioner(), PackedMatrix< float >::CopyFromPacked(), CuPackedMatrix< Real >::CopyFromPacked(), MatrixBase< float >::CopyFromSp(), MatrixBase< float >::CopyFromTp(), VectorBase< float >::CopyRowFromSp(), CuPackedMatrix< Real >::CopyToPacked(), CovarianceStats::Dim(), LdaEstimate::Estimate(), FeatureTransformEstimate::EstimateInternal(), kaldi::EstimateSgmm2FmllrSubspace(), CompressedAffineXformStats::ExtractOneG(), kaldi::GetLogDetNoFailure(), GetLogLikeTest(), IvectorExtractor::GetPriorAuxf(), kaldi::InitRand(), kaldi::InitRandNonsingular(), IvectorExtractor::InvertWithFlooring(), IvectorExtractor::IvectorExtractor(), kaldi::LinearCgd(), main(), Matrix< BaseFloat >::Matrix(), VectorBase< float >::MulTp(), kaldi::NonDiagonalness(), kaldi::NonUnitness(), CompressedAffineXformStats::PrepareOneG(), Sgmm2Project::ProjectVariance(), kaldi::unittest::RandFullGaussFeatures(), AffineXformStats::Read(), PackedMatrix< float >::Read(), VectorBase< float >::Solve(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), SubVector< Real >::SubVector(), CuMatrixBase< float >::SymInvertPosDef(), kaldi::TraceMatSpMat(), kaldi::TraceMatSpMatSp(), kaldi::TraceSpMat(), kaldi::TraceSpSp(), kaldi::TraceSpSpLower(), kaldi::UnitTestCuSpMatrixOperator(), kaldi::UnitTestSpInvert(), kaldi::UnitTestTpInvert(), kaldi::UnitTestTransposeScatter(), IvectorExtractorStats::UpdateVariances(), MleAmSgmm2Updater::UpdateVars(), kaldi::VecSpVec(), and FisherComputationClass::~FisherComputationClass().
|
inline |
Definition at line 114 of file packed-matrix.h.
|
inline |
Definition at line 124 of file packed-matrix.h.
|
inline |
Definition at line 68 of file packed-matrix.h.
Referenced by TpMatrix< float >::operator=(), and SpMatrix< float >::operator=().
Definition at line 298 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::Min(), AffineXformStats::Read(), AccumFullGmm::Read(), LdaEstimate::Read(), CuPackedMatrix< Real >::Read(), PackedMatrix< float >::Read(), IvectorExtractorStats::Read(), kaldi::UnitTestIo(), and kaldi::UnitTestIoCross().
void Resize | ( | MatrixIndexT | nRows, |
MatrixResizeType | resize_type = kSetZero |
||
) |
Set packed matrix to a specified size (can be zero).
The value of the new data depends on resize_type: -if kSetZero, the new data will be zero -if kUndefined, the new data will be undefined -if kCopyData, the new data will be the same as the old data in any shared positions, and zero elsewhere. This function takes time proportional to the number of data elements.
Definition at line 94 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::operator=(), PackedMatrix< float >::PackedMatrix(), SpMatrix< float >::Resize(), TpMatrix< float >::Resize(), CuPackedMatrix< Real >::Swap(), and PackedMatrix< float >::~PackedMatrix().
void Scale | ( | Real | c | ) |
Definition at line 33 of file packed-matrix.cc.
Referenced by SpMatrix< float >::ApplyFloor(), Fmpe::ComputeC(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeHsmFromModel(), FastNnetCombiner::ComputePreconditioner(), PldaEstimator::EstimateFromStats(), kaldi::EstPca(), IvectorExtractor::GetAcousticAuxfVariance(), LdaEstimate::GetStats(), CovarianceStats::GetTotalCovar(), CovarianceStats::GetWithinCovar(), IvectorExtractorStats::IvectorVarianceDiagnostic(), main(), MleAmSgmm2Updater::MapUpdateM(), FullGmm::MergedComponentsLogdet(), PackedMatrix< float >::Min(), kaldi::MleFullGmmUpdate(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), CompressedAffineXformStats::PrepareOneG(), IvectorExtractorStats::PriorDiagnostics(), MleAmSgmm2Updater::RenormalizeN(), MleAmSgmm2Updater::RenormalizeV(), LdaEstimate::Scale(), kaldi::UnitTestCuPackedMatrixScale(), kaldi::UnitTestDeterminantSign(), UnitTestEstimateLda(), kaldi::UnitTestFloorChol(), kaldi::UnitTestIo(), kaldi::UnitTestIoCross(), kaldi::UnitTestMat2Vec(), kaldi::UnitTestNorm(), kaldi::UnitTestTraceSpSpLower(), EbwAmSgmm2Updater::UpdateM(), EbwAmSgmm2Updater::UpdateN(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), PldaUnsupervisedAdaptor::UpdatePlda(), IvectorExtractorStats::UpdatePrior(), EbwAmSgmm2Updater::UpdateU(), IvectorExtractorStats::UpdateVariances(), EbwAmSgmm2Updater::UpdateVars(), and MleAmSgmm2Updater::UpdateVars().
void ScaleDiag | ( | const Real | alpha | ) |
Definition at line 132 of file packed-matrix.cc.
Referenced by FullGmm::LogLikelihoodsPreselect(), kaldi::UnitTestCuPackedMatrixScaleDiag(), kaldi::UnitTestScaleDiag(), kaldi::UnitTestTraceSpSpLower(), and PackedMatrix< float >::~PackedMatrix().
void SetDiag | ( | const Real | alpha | ) |
Definition at line 141 of file packed-matrix.cc.
Referenced by kaldi::UnitTestCuSpMatrixConstructor(), kaldi::UnitTestSetDiag(), and PackedMatrix< float >::~PackedMatrix().
void SetRandn | ( | ) |
< Set to unit matrix.
Definition at line 48 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::PackedMatrix(), kaldi::UnitTestAddMat2(), kaldi::UnitTestAddMat2Sp(), kaldi::UnitTestAddSp(), kaldi::UnitTestAddToDiag(), kaldi::UnitTestAddVec2Sp(), kaldi::UnitTestCuMatrixAddMatTp(), kaldi::UnitTestCuMatrixAddTpMat(), kaldi::UnitTestCuMatrixCopyFromTp(), kaldi::UnitTestCuPackedMatrixAddToDiag(), kaldi::UnitTestCuPackedMatrixConstructor(), kaldi::UnitTestCuPackedMatrixCopy(), kaldi::UnitTestCuPackedMatrixScale(), kaldi::UnitTestCuPackedMatrixScaleDiag(), kaldi::UnitTestCuPackedMatrixTrace(), kaldi::UnitTestCuSpMatrixAddMat2(), kaldi::UnitTestCuSpMatrixAddSp(), kaldi::UnitTestCuSpMatrixAddToDiag(), kaldi::UnitTestCuSpMatrixAddVec2(), kaldi::UnitTestCuSpMatrixApproxEqual(), kaldi::UnitTestCuSpMatrixOperator(), kaldi::UnitTestCuSpMatrixTraceSpSp(), kaldi::UnitTestCuTpMatrixCholesky(), kaldi::UnitTestCuTpMatrixCopyFromTp(), kaldi::UnitTestCuTpMatrixInvert(), kaldi::UnitTestCuVectorAddTp(), kaldi::UnitTestCuVectorAddTpVec(), kaldi::UnitTestCuVectorMulTp(), kaldi::UnitTestEigSymmetric(), kaldi::UnitTestInnerProd(), kaldi::UnitTestIo(), kaldi::UnitTestIoCross(), kaldi::UnitTestMaxAbsEig(), kaldi::UnitTestMaxMin(), kaldi::UnitTestMul(), kaldi::UnitTestMulTp(), kaldi::UnitTestNorm(), kaldi::UnitTestResize(), kaldi::UnitTestScaleDiag(), kaldi::UnitTestSimpleForMat(), kaldi::UnitTestSpAddDiagVec(), kaldi::UnitTestSpAddVecVec(), kaldi::UnitTestSvdSpeed(), kaldi::UnitTestTp2(), kaldi::UnitTestTp2Sp(), kaldi::UnitTestTrace(), kaldi::UnitTestTraceSpSpLower(), and kaldi::UnitTestTriVecSolver().
void SetUnit | ( | ) |
< Set to zero
Definition at line 212 of file packed-matrix.cc.
Referenced by AmSgmm2::ComputeHsmFromModel(), PldaEstimator::InitParameters(), kaldi::NonOrthogonality(), kaldi::NonUnitness(), PackedMatrix< float >::PackedMatrix(), kaldi::UnitTestCuSpMatrixSetUnit(), and MleAmSgmm2Updater::UpdateVars().
void SetZero | ( | ) |
Definition at line 207 of file packed-matrix.cc.
Referenced by IvectorExtractorUtteranceStats::AccStats(), RegtreeMllrDiagGmmAccs::AccumulateForGmm(), FmllrRawAccs::CommitSingleFrameStats(), AmSgmm2::ComputeHsmFromModel(), PackedMatrix< float >::PackedMatrix(), LdaEstimate::Read(), kaldi::UnitTestCopySp(), kaldi::UnitTestCuSpMatrixConstructor(), kaldi::UnitTestSimpleForMat(), MleAmSgmm2Updater::UpdateWGetStats(), and LdaEstimate::ZeroAccumulators().
|
inline |
Definition at line 106 of file packed-matrix.h.
Referenced by SpMatrix< float >::AddMat2Sp(), and CuPackedMatrix< Real >::CopyFromPacked().
void Swap | ( | PackedMatrix< Real > * | other | ) |
Swaps the contents of *this and *other. Shallow swap.
Definition at line 81 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::Min(), PackedMatrix< float >::Resize(), and CuPackedMatrix< Real >::Swap().
void Swap | ( | Matrix< Real > * | other | ) |
Definition at line 87 of file packed-matrix.cc.
Real Trace | ( | ) | const |
< Set to random values of a normal distribution
Definition at line 219 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::PackedMatrix(), kaldi::UnitTestCuPackedMatrixTrace(), and kaldi::UnitTestCuTpMatrixCopyFromMat().
void Write | ( | std::ostream & | out, |
bool | binary | ||
) | const |
Definition at line 236 of file packed-matrix.cc.
Referenced by PackedMatrix< float >::Min(), kaldi::UnitTestIoCross(), AffineXformStats::Write(), AccumFullGmm::Write(), LdaEstimate::Write(), CuPackedMatrix< Real >::Write(), and IvectorExtractorStats::Write().
|
friend |
Definition at line 41 of file packed-matrix.h.
|
friend |
Definition at line 181 of file packed-matrix.h.
|
protected |
Definition at line 163 of file packed-matrix.h.
Referenced by CuPackedMatrix< Real >::CopyFromPacked(), CuPackedMatrix< Real >::CopyToPacked(), PackedMatrix< float >::Data(), PackedMatrix< float >::Max(), PackedMatrix< float >::Min(), TpMatrix< float >::operator()(), SpMatrix< float >::operator()(), PackedMatrix< float >::operator()(), PackedMatrix< float >::Resize(), SpMatrix< float >::Swap(), TpMatrix< float >::Swap(), CuPackedMatrix< Real >::Swap(), and PackedMatrix< float >::Swap().
|
protected |
Definition at line 164 of file packed-matrix.h.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), PackedMatrix< float >::Max(), PackedMatrix< float >::Min(), PackedMatrix< float >::NumCols(), PackedMatrix< float >::NumRows(), TpMatrix< float >::operator()(), SpMatrix< float >::operator()(), PackedMatrix< float >::operator()(), PackedMatrix< float >::SizeInBytes(), SpMatrix< float >::Swap(), TpMatrix< float >::Swap(), CuPackedMatrix< Real >::Swap(), and PackedMatrix< float >::Swap().