31 template <
typename Real>
39 template <
typename Real>
47 template <
typename Real>
50 for (
int32 i = 0;
i < pairs_.size(); ++
i) {
51 sum += pairs_[
i].second;
56 template<
typename Real>
58 for (
int32 i = 0;
i < pairs_.size(); ++
i)
59 pairs_[
i].second *= alpha;
62 template <
typename Real>
63 template <
typename OtherReal>
68 typename std::vector<std::pair<MatrixIndexT, Real> >::const_iterator
69 iter = pairs_.begin(), end = pairs_.end();
70 for (; iter != end; ++iter)
71 other_data[iter->first] = iter->second;
82 template <
typename Real>
83 template <
typename OtherReal>
88 typename std::vector<std::pair<MatrixIndexT, Real> >::const_iterator
89 iter = pairs_.begin(), end = pairs_.end();
91 for (; iter != end; ++iter)
92 other_data[iter->first] += iter->second;
94 for (; iter != end; ++iter)
95 other_data[iter->first] += alpha * iter->second;
109 template <
typename Real>
110 template <
typename OtherReal>
114 if (dim_ == 0)
return;
116 pairs_.push_back(std::make_pair(
131 template <
typename Real>
134 this->CopyFromSvec(other);
140 template <
typename Real>
142 pairs_.swap(other->
pairs_);
146 template <
typename Real>
153 typename std::vector<std::pair<MatrixIndexT, Real> >::const_iterator
154 iter = pairs_.begin(), end = pairs_.end();
155 for (; iter != end; ++iter) {
162 os <<
"dim=" << dim_ <<
" [ ";
163 typename std::vector<std::pair<MatrixIndexT, Real> >::const_iterator
164 iter = pairs_.begin(), end = pairs_.end();
165 for (; iter != end; ++iter)
166 os << iter->first <<
' ' << iter->second <<
' ';
172 template <
typename Real>
181 pairs_.resize(num_elems);
182 typename std::vector<std::pair<MatrixIndexT, Real> >::iterator
183 iter = pairs_.begin(), end = pairs_.end();
184 for (; iter != end; ++iter) {
192 if (str.substr(0, 4) !=
"dim=")
193 KALDI_ERR <<
"Reading sparse vector, expected 'dim=xxx', got " << str;
194 std::string dim_str = str.substr(4, std::string::npos);
195 std::istringstream dim_istr(dim_str);
198 if (dim < 0 || dim_istr.fail()) {
199 KALDI_ERR <<
"Reading sparse vector, expected 'dim=[int]', got " << str;
205 KALDI_ERR <<
"Reading sparse vector, expected '[', got " << str;
209 if (is.peek() ==
']') {
217 KALDI_ERR <<
"Error reading sparse vector, expecting numbers.";
219 && (pairs_.empty() || i > pairs_.back().first));
220 pairs_.push_back(std::pair<MatrixIndexT, BaseFloat>(i, p));
226 namespace sparse_vector_utils {
227 template <
typename Real>
229 inline bool operator() (
const std::pair<MatrixIndexT, Real> &p1,
230 const std::pair<MatrixIndexT, Real> &p2)
const {
231 return p1.first < p2.first;
236 template <
typename Real>
238 MatrixIndexT dim,
const std::vector<std::pair<MatrixIndexT, Real> > &pairs):
243 typename std::vector<std::pair<MatrixIndexT, Real> >::iterator
247 while (in + 1 < end && in[0].first != in[1].first && in[0].second != 0.0) {
256 while (in < end && in->first == out->first) {
257 out->second += in->second;
260 if (out->second != Real(0.0))
270 template <
typename Real>
279 template <
typename Real>
282 if (resize_type !=
kCopyData || dim == 0)
291 template <
typename Real>
296 template <
typename Real>
301 return rows_[0].Dim();
304 template <
typename Real>
306 int32 num_elements = 0;
307 for (
int32 i = 0;
i < rows_.size(); ++
i) {
308 num_elements += rows_[
i].NumElements();
313 template <
typename Real>
321 template <
typename Real>
329 template <
typename Real>
332 for (
int32 i = 0;
i < rows_.size(); ++
i) {
333 sum += rows_[
i].Sum();
338 template<
typename Real>
340 Real squared_sum = 0;
341 for (
int32 i = 0;
i < rows_.size(); ++
i) {
342 const std::pair<MatrixIndexT, Real> *row_data = rows_[
i].Data();
343 for (
int32 j = 0;
j < rows_[
i].NumElements(); ++
j) {
344 squared_sum += row_data[
j].second * row_data[
j].second;
347 return std::sqrt(squared_sum);
350 template <
typename Real>
351 template <
typename OtherReal>
359 rows_[
i].CopyElementsToVec(&vec);
364 num_rows = NumRows(), num_cols = NumCols();
367 for (
MatrixIndexT row = 0; row < num_rows; row++, other_col_data++) {
370 const std::pair<MatrixIndexT, Real> *sdata = svec.
Data();
372 other_col_data[sdata[e].first * other_stride] = sdata[e].second;
390 template <
typename Real>
393 Real *dst_data = other->
Data();
395 for (
int32 i = 0;
i < rows_.size(); ++
i) {
396 for (
int32 j = 0;
j < rows_[
i].NumElements(); ++
j) {
397 dst_data[dst_index] =
398 static_cast<Real
>(rows_[
i].GetElement(
j).second);
404 template<
typename Real>
405 template<
typename OtherReal>
410 if (rows_.size() == 0)
412 for (
int32 r = 0; r < rows_.size(); ++r) {
413 rows_[r].CopyFromSvec(other.
Row(r));
416 std::vector<std::vector<std::pair<MatrixIndexT, Real> > > pairs(
419 for (
int id = 0;
id < other.
Row(
i).NumElements(); ++id) {
421 Real v =
static_cast<Real
>(other.
Row(
i).GetElement(
id).second);
422 pairs[
j].push_back( {
i, v });
442 template <
typename Real>
450 int32 num_rows = rows_.size();
452 for (
int32 row = 0; row < num_rows; row++)
453 rows_[row].
Write(os, binary);
458 int32 num_rows = rows_.size();
459 os <<
"rows=" << num_rows <<
" ";
460 for (
int32 row = 0; row < num_rows; row++)
461 rows_[row].
Write(os, binary);
466 template <
typename Real>
473 rows_.resize(num_rows);
474 for (
int32 row = 0; row < num_rows; row++)
475 rows_[row].
Read(is, binary);
479 if (str.substr(0, 5) !=
"rows=")
480 KALDI_ERR <<
"Reading sparse matrix, expected 'rows=xxx', got " << str;
481 std::string rows_str = str.substr(5, std::string::npos);
482 std::istringstream rows_istr(rows_str);
484 rows_istr >> num_rows;
485 if (num_rows < 0 || rows_istr.fail()) {
486 KALDI_ERR <<
"Reading sparse vector, expected 'rows=[int]', got " << str;
488 rows_.resize(num_rows);
489 for (
int32 row = 0; row < num_rows; row++)
490 rows_[row].
Read(is, binary);
495 template <
typename Real>
504 rows_[
i].AddToVec(alpha, &vec);
507 Real *other_col_data = other->
Data();
509 num_rows = NumRows(), num_cols = NumCols();
511 for (
MatrixIndexT row = 0; row < num_rows; row++, other_col_data++) {
514 const std::pair<MatrixIndexT, Real> *sdata = svec.
Data();
516 other_col_data[sdata[e].first * other_stride] +=
517 alpha * sdata[e].second;
522 template <
typename Real>
527 const std::pair<MatrixIndexT, Real> *sdata = svec.
Data();
528 const Real *data = vec.
Data();
531 ans += data[sdata[
i].first] * sdata[
i].second;
542 template <
typename Real>
548 template <
typename Real>
551 vec.
Dim() == rows_[0].Dim());
556 template<
typename Real>
560 for (
int i = 0;
i < row_indexes.size(); ++
i) {
561 SetRow(
i, smat_other.
Row(row_indexes[
i]));
565 template<
typename Real>
568 const std::vector<int32>& idx = indexes;
569 std::vector<std::vector<std::pair<MatrixIndexT, Real> > > pair(idx.size());
570 for (
int i = 0;
i < idx.size(); ++
i) {
572 pair[
i].push_back( { idx[
i], Real(1) });
577 this->
Swap(&smat_cpu);
584 template<
typename Real>
588 const std::vector<int32>& idx = indexes;
590 std::vector<std::vector<std::pair<MatrixIndexT, Real> > > pair(idx.size());
591 for (
int i = 0;
i < idx.size(); ++
i) {
593 pair[
i].push_back( { idx[
i], w(
i) });
598 this->
Swap(&smat_cpu);
605 template <
typename Real>
612 template <
typename Real>
614 rows_.swap(other->
rows_);
617 template<
typename Real>
620 const std::vector<std::vector<std::pair<MatrixIndexT, Real> > > &pairs):
621 rows_(pairs.size()) {
625 rows_[row].Swap(&svec);
629 template <
typename Real>
633 rows_[row].SetRandn(zero_prob);
636 template <
typename Real>
646 int32 old_num_rows = rows_.size(), old_num_cols = NumCols();
648 rows_.resize(num_rows, initializer);
649 if (num_cols != old_num_cols)
650 for (
int32 row = 0; row < old_num_rows; row++)
655 template <
typename Real>
660 typename std::vector<SparseMatrix<Real> >::iterator
661 input_iter = inputs->begin(),
662 input_end = inputs->end();
663 for (; input_iter != input_end; ++input_iter)
664 num_rows += input_iter->rows_.size();
665 rows_.resize(num_rows);
666 typename std::vector<SparseVector<Real> >::iterator
667 row_iter = rows_.begin(),
668 row_end = rows_.end();
669 for (input_iter = inputs->begin(); input_iter != input_end; ++input_iter) {
670 typename std::vector<SparseVector<Real> >::iterator
671 input_row_iter = input_iter->rows_.begin(),
672 input_row_end = input_iter->rows_.end();
673 for (; input_row_iter != input_row_end; ++input_row_iter, ++row_iter)
674 row_iter->Swap(&(*input_row_iter));
677 int32 num_cols = NumCols();
678 for (row_iter = rows_.begin(); row_iter != row_end; ++row_iter) {
679 if (row_iter->Dim() != num_cols)
680 KALDI_ERR <<
"Appending rows with inconsistent dimensions, " 681 << row_iter->Dim() <<
" vs. " << num_cols;
686 template<
typename Real>
690 rows_[row].Scale(alpha);
693 template<
typename Real>
696 rows_.resize(num_rows);
697 for (
int32 row = 0; row < num_rows; row++) {
699 rows_[row].
Swap(&this_row);
703 template<
typename Real>
714 const Real *A_col_data = A.
Data();
722 const std::pair<MatrixIndexT, Real> *sdata = svec.
Data();
724 col_sum += A_col_data[Astride * sdata[e].first] * sdata[e].second;
740 void GeneralMatrix::Clear() {
773 if (smat_.NumRows() != 0)
775 else if (cmat_.NumRows() != 0)
788 return mat_.NumRows();
798 return mat_.NumCols();
802 void GeneralMatrix::Compress() {
803 if (mat_.NumRows() != 0) {
804 cmat_.CopyFromMat(mat_);
809 void GeneralMatrix::Uncompress() {
810 if (cmat_.NumRows() != 0) {
811 mat_.Resize(cmat_.NumRows(), cmat_.NumCols(),
kUndefined);
812 cmat_.CopyToMat(&mat_);
818 if (mat_.NumRows() !=0) {
820 }
else if (cmat_.NumRows() != 0) {
822 cmat_.CopyToMat(mat);
823 }
else if (smat_.NumRows() != 0) {
825 smat_.CopyToMat(mat);
833 if (mat_.NumRows() !=0) {
835 }
else if (cmat_.NumRows() != 0) {
836 cmat_.CopyToMat(mat, trans);
837 }
else if (smat_.NumRows() != 0) {
838 smat_.CopyToMat(mat, trans);
845 if (mat_.NumRows() != 0) {
847 }
else if (cmat_.NumRows() != 0) {
849 }
else if (smat_.NumRows() != 0) {
855 if (mat_.NumRows() != 0 || cmat_.NumRows() != 0)
856 KALDI_ERR <<
"GetSparseMatrix called on GeneralMatrix of wrong type.";
861 if (mat_.NumRows() != 0 || cmat_.NumRows() != 0)
862 KALDI_ERR <<
"GetSparseMatrix called on GeneralMatrix of wrong type.";
867 if (mat_.NumRows() != 0 || smat_.NumRows() != 0)
868 KALDI_ERR <<
"GetSparseMatrix called on GeneralMatrix of wrong type.";
873 if (mat_.NumRows() != 0 || smat_.NumRows() != 0)
874 KALDI_ERR <<
"GetCompressedMatrix called on GeneralMatrix of wrong type.";
879 if (smat_.NumRows() != 0 || cmat_.NumRows() != 0)
880 KALDI_ERR <<
"GetFullMatrix called on GeneralMatrix of wrong type.";
886 if (cmat_.NumRows() != 0 || smat_.NumRows() != 0)
887 KALDI_ERR <<
"SwapMatrix called on GeneralMatrix of wrong type.";
891 void GeneralMatrix::Write(std::ostream &os,
bool binary)
const {
892 if (smat_.NumRows() != 0) {
893 smat_.Write(os, binary);
894 }
else if (cmat_.NumRows() != 0) {
895 cmat_.Write(os, binary);
897 mat_.Write(os, binary);
901 void GeneralMatrix::Read(std::istream &is,
bool binary) {
904 int peekval = is.peek();
905 if (peekval ==
'C') {
907 cmat_.Read(is, binary);
908 }
else if (peekval ==
'S') {
910 smat_.Read(is, binary);
912 mat_.Read(is, binary);
919 int peekval = is.peek();
920 if (peekval ==
'r') {
921 smat_.Read(is, binary);
923 mat_.Read(is, binary);
932 int32 size = src.size();
935 bool all_sparse =
true;
943 std::vector<SparseMatrix<BaseFloat> > sparse_mats(size);
945 sparse_mats[
i] = src[
i]->GetSparseMatrix();
950 int32 tot_rows = 0, num_cols = -1;
955 tot_rows += src_rows;
956 if (num_cols == -1) num_cols = src_cols;
957 else if (num_cols != src_cols)
958 KALDI_ERR <<
"Appending rows of matrices with inconsistent num-cols: " 959 << num_cols <<
" vs. " << src_cols;
963 int32 row_offset = 0;
971 row_offset += src_rows;
980 const std::vector<bool> &keep_rows,
983 int32 num_kept_rows = 0;
984 std::vector<bool>::const_iterator iter = keep_rows.begin(),
985 end = keep_rows.end();
986 for (; iter != end; ++iter)
989 if (num_kept_rows == 0)
991 if (num_kept_rows == static_cast<int32>(keep_rows.size())) {
1000 if (num_kept_rows > heuristic * in.
NumRows()) {
1009 iter = keep_rows.begin();
1011 for (
int32 in_row = 0; iter != end; ++iter, ++in_row) {
1022 template <
typename Real>
1024 const std::vector<bool> &keep_rows,
1027 int32 num_kept_rows = 0;
1028 std::vector<bool>::const_iterator iter = keep_rows.begin(),
1029 end = keep_rows.end();
1030 for (; iter != end; ++iter)
1033 if (num_kept_rows == 0)
1035 if (num_kept_rows == static_cast<int32>(keep_rows.size())) {
1040 iter = keep_rows.begin();
1042 for (
int32 in_row = 0; iter != end; ++iter, ++in_row) {
1055 const std::vector<bool> &keep_rows,
1059 const std::vector<bool> &keep_rows,
1062 template <
typename Real>
1064 const std::vector<bool> &keep_rows,
1067 int32 num_kept_rows = 0;
1068 std::vector<bool>::const_iterator iter = keep_rows.begin(),
1069 end = keep_rows.end();
1070 for (; iter != end; ++iter)
1073 if (num_kept_rows == 0)
1075 if (num_kept_rows == static_cast<int32>(keep_rows.size())) {
1080 iter = keep_rows.begin();
1082 for (
int32 in_row = 0; iter != end; ++iter, ++in_row) {
1093 const std::vector<bool> &keep_rows,
1097 const std::vector<bool> &keep_rows,
1102 const std::vector<bool> &keep_rows,
1106 int32 num_kept_rows = 0;
1107 std::vector<bool>::const_iterator iter = keep_rows.begin(),
1108 end = keep_rows.end();
1109 for (; iter != end; ++iter)
1112 if (num_kept_rows == 0)
1114 if (num_kept_rows == static_cast<int32>(keep_rows.size())) {
1118 switch (in.
Type()) {
1141 KALDI_ERR <<
"Invalid general-matrix type.";
1147 switch (this->Type()) {
1149 mat->
AddMat(alpha, mat_, trans);
1153 smat_.AddToMat(alpha, mat, trans);
1158 mat->
AddMat(alpha, temp_mat, trans);
1162 KALDI_ERR <<
"Invalid general-matrix type.";
1166 template <
class Real>
1168 KALDI_ASSERT(dim_ > 0 && pairs_.size() <=
static_cast<size_t>(dim_));
1169 Real ans = -std::numeric_limits<Real>::infinity();
1171 typename std::vector<std::pair<MatrixIndexT, Real> >::const_iterator
1172 iter = pairs_.begin(), end = pairs_.end();
1173 for (; iter != end; ++iter) {
1174 if (iter->second > ans) {
1176 index = iter->first;
1179 if (ans >= 0 || pairs_.size() == dim_) {
1192 iter = pairs_.begin();
1193 for (; iter != end; ++iter) {
1194 if (iter->first > index) {
1199 index = iter->first + 1;
1204 if (!pairs_.empty())
1205 index = pairs_.back().first + 1;
1212 template <
typename Real>
1218 const Real *ptr = vec.
Data();
1222 pairs_.push_back(std::pair<MatrixIndexT,Real>(
i,val));
1227 mat_.Swap(&(other->
mat_));
1228 cmat_.Swap(&(other->
cmat_));
1229 smat_.Swap(&(other->
smat_));
1241 if (num_rows == 0)
return;
1242 switch (in.
Type()) {
1249 for (
int32 row = 0; row < num_rows; row++) {
1250 int32 row_in = row + row_offset;
1251 if (row_in < 0) row_in = 0;
1252 else if (row_in >= num_rows_in) row_in = num_rows_in - 1;
1254 vec_out(mat_out, row);
1267 for (
int32 row = 0; row < num_rows; row++) {
1268 int32 row_in = row + row_offset;
1269 if (row_in < 0) row_in = 0;
1270 else if (row_in >= num_rows_in) row_in = num_rows_in - 1;
1271 smat_out.
SetRow(row, smat_in.
Row(row_in));
1278 bool allow_padding =
true;
1280 0, cmat_in.
NumCols(), allow_padding);
void CopyElementsToVec(VectorBase< OtherReal > *vec) const
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
This class provides a way for switching between double and float types.
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<...
void SelectRows(const std::vector< int32 > &row_indexes, const SparseMatrix< Real > &smat_other)
Select a subset of the rows of a SparseMatrix.
void CopyRowToVec(MatrixIndexT row, VectorBase< Real > *v) const
Copies row #row of the matrix into vector v.
SparseVector< Real > & operator=(const SparseVector< Real > &other)
void SetRandn(BaseFloat zero_prob)
Sets elements to zero with probability zero_prob, else normally distributed.
void Swap(CompressedMatrix *other)
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Base class which provides matrix operations not involving resizing or allocation. ...
void Read(std::istream &os, bool binary)
const Real * Data() const
Gives pointer to raw data (const).
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
bool operator()(const std::pair< MatrixIndexT, Real > &p1, const std::pair< MatrixIndexT, Real > &p2) const
const std::pair< MatrixIndexT, Real > & GetElement(MatrixIndexT i) const
get an indexed element (0 <= i < NumElements()).
bool WithProb(BaseFloat prob, struct RandomState *state)
void SetRow(int32 r, const SparseVector< Real > &vec)
Sets row r to "vec"; makes sure it has the correct dimension.
const CompressedMatrix & GetCompressedMatrix() const
Returns the contents as a compressed matrix.
void AddToVec(Real alpha, VectorBase< OtherReal > *vec) const
std::vector< std::pair< MatrixIndexT, Real > > pairs_
void AddMat(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans)
*this += alpha * M [or M^T]
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
float RandGauss(struct RandomState *state=NULL)
void Write(std::ostream &os, bool binary) const
const Matrix< BaseFloat > & GetFullMatrix() const
Returns the contents as a Matrix<BaseFloat>.
void Swap(Matrix< Real > *other)
Swaps the contents of *this and *other. Shallow swap.
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
void SwapSparseMatrix(SparseMatrix< BaseFloat > *smat)
Swaps the with the given SparseMatrix.
std::vector< SparseVector< Real > > rows_
template double VecSvec(const VectorBase< double > &vec, const SparseVector< double > &svec)
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)
void CopyToMat(MatrixBase< OtherReal > *other, MatrixTransposeType t=kNoTrans) const
Copy to matrix. It must already have the correct size.
template void FilterMatrixRows(const Matrix< double > &in, const std::vector< bool > &keep_rows, Matrix< double > *out)
void AddToMat(BaseFloat alpha, MatrixBase< Real > *other, MatrixTransposeType t=kNoTrans) const
Does *other = *other + alpha * *this.
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
MatrixIndexT NumCols() const
MatrixIndexT NumCols() const
SparseVector< Real > * Data()
MatrixIndexT Stride() const
Stride (distance in memory between each row). Will be >= NumCols.
void Read(std::istream &os, bool binary)
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void CopyElementsToVec(VectorBase< Real > *other) const
Copies the values of all the elements in SparseMatrix into a VectorBase object.
GeneralMatrixType Type() const
Returns the type of the matrix: kSparseMatrix, kCompressedMatrix or kFullMatrix.
void CopyFromSmat(const SparseMatrix< OtherReal > &other, MatrixTransposeType trans=kNoTrans)
Copies data from another sparse matrix.
template void FilterSparseMatrixRows(const SparseMatrix< double > &in, const std::vector< bool > &keep_rows, SparseMatrix< double > *out)
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
void SwapCompressedMatrix(CompressedMatrix *cmat)
Swaps the with the given CompressedMatrix.
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.
Real * Data()
Returns a pointer to the start of the vector's data.
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
MatrixIndexT Dim() const
Returns the dimension of the vector.
void SetZero()
Sets matrix to zero.
void CopyToMat(MatrixBase< BaseFloat > *mat, MatrixTransposeType trans=kNoTrans) const
Copies contents, regardless of type, to "mat", which must be correctly sized.
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.
void Write(std::ostream &os, bool binary) const
MatrixIndexT NumRows() const
Returns number of rows (or zero for emtpy matrix).
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
MatrixIndexT NumRows() const
MatrixIndexT NumRows() const
void SwapFullMatrix(Matrix< BaseFloat > *mat)
Swaps the with the given Matrix.
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
void AppendSparseMatrixRows(std::vector< SparseMatrix< Real > > *inputs)
Sets *this to all the rows of *inputs appended together; this function is destructive of the inputs...
Real FrobeniusNorm() const
void Resize(MatrixIndexT dim, MatrixResizeType resize_type=kSetZero)
Resizes to this dimension.
SparseMatrix< BaseFloat > smat_
void Swap(SparseMatrix< Real > *other)
const SparseMatrix< BaseFloat > & GetSparseMatrix() const
Returns the contents as a SparseMatrix.
Provides a vector abstraction class.
void SetZero()
Set vector to all zeros.
MatrixIndexT NumCols() const
Returns number of columns (or zero for emtpy matrix).
SparseMatrix< Real > & operator=(const SparseMatrix< Real > &other)
void CopyToMat(MatrixBase< Real > *mat, MatrixTransposeType trans=kNoTrans) const
Copies contents to matrix.
void Swap(SparseVector< Real > *other)
std::pair< MatrixIndexT, Real > * Data()
Sub-matrix representation.
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero)
Resizes the matrix; analogous to Matrix::Resize().
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
template double TraceMatSmat(const MatrixBase< double > &A, const SparseMatrix< double > &B, MatrixTransposeType trans)
MatrixIndexT NumElements() const
const SparseVector< Real > & Row(MatrixIndexT r) const