22 #ifndef KALDI_MATRIX_PACKED_MATRIX_H_ 23 #define KALDI_MATRIX_PACKED_MATRIX_H_ 32 template<
typename Real>
33 std::ostream & operator <<(std::ostream & out, const PackedMatrix<Real>& M);
40 template<
typename Real>
class PackedMatrix {
55 template<
typename OtherReal>
93 template<
typename OtherReal>
99 template<
typename OtherReal>
107 size_t nr =
static_cast<size_t>(
num_rows_);
108 return ((nr * (nr+1)) / 2) *
sizeof(Real);
116 static_cast<UnsignedMatrixIndexT>(
num_rows_) &&
117 static_cast<UnsignedMatrixIndexT>(c) <
118 static_cast<UnsignedMatrixIndexT>(
num_rows_)
120 return *(
data_ + (r * (r + 1)) / 2 + c);
126 static_cast<UnsignedMatrixIndexT>(
num_rows_) &&
127 static_cast<UnsignedMatrixIndexT>(c) <
128 static_cast<UnsignedMatrixIndexT>(
num_rows_)
130 return *(
data_ + (r * (r + 1)) / 2 + c);
145 friend std::ostream & operator << <> (std::ostream & out,
149 void Read(std::istream &in,
bool binary,
bool add =
false);
151 void Write(std::ostream &out,
bool binary)
const;
180 template<
typename Real>
181 std::ostream & operator << (std::ostream & os, const PackedMatrix<Real>& M) {
186 template<
typename Real>
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void CopyFromVec(const SubVector< OtherReal > &orig)
CopyFromVec just interprets the vector as having the same layout as the packed matrix.
PackedMatrix(MatrixIndexT r, MatrixResizeType resize_type=kSetZero)
Real Trace() const
< Set to random values of a normal distribution
void Read(std::istream &in, bool binary, bool add=false)
void Write(std::ostream &out, bool binary) const
const Real * Data() const
void AddPacked(const Real alpha, const PackedMatrix< Real > &M)
A class for storing matrices.
void ScaleDiag(const Real alpha)
void SetUnit()
< Set to zero
MatrixIndexT NumRows() const
void SetRandn()
< Set to unit matrix.
void AddToDiag(const Real r)
MatrixIndexT NumCols() const
PackedMatrix(const PackedMatrix< OtherReal > &orig)
Packed matrix: base class for triangular and symmetric matrices.
void Swap(PackedMatrix< Real > *other)
Swaps the contents of *this and *other. Shallow swap.
void SetDiag(const Real alpha)
Real operator()(MatrixIndexT r, MatrixIndexT c) const
PackedMatrix(const PackedMatrix< Real > &orig)
std::istream & operator>>(std::istream &is, Matrix< Real > &M)
PackedMatrix< Real > & operator=(const PackedMatrix< Real > &other)
void Init(MatrixIndexT dim)
Init assumes the current contents of the class are is invalid (i.e.
void CopyFromPacked(const PackedMatrix< OtherReal > &orig)
size_t SizeInBytes() const
#define KALDI_ASSERT(cond)
Matrix for CUDA computing.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void Resize(MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero)
Set packed matrix to a specified size (can be zero).