Sub-matrix representation. More...
#include <kaldi-matrix.h>
Public Member Functions | |
SubMatrix (const MatrixBase< Real > &T, const MatrixIndexT ro, const MatrixIndexT r, const MatrixIndexT co, const MatrixIndexT c) | |
SubMatrix (Real *data, MatrixIndexT num_rows, MatrixIndexT num_cols, MatrixIndexT stride) | |
~SubMatrix () | |
SubMatrix (const SubMatrix &other) | |
This type of constructor is needed for Range() to work [in Matrix base class]. More... | |
Public Member Functions inherited from MatrixBase< Real > | |
MatrixIndexT | NumRows () const |
Returns number of rows (or zero for empty matrix). More... | |
MatrixIndexT | NumCols () const |
Returns number of columns (or zero for empty matrix). More... | |
MatrixIndexT | Stride () const |
Stride (distance in memory between each row). Will be >= NumCols. More... | |
size_t | SizeInBytes () const |
Returns size in bytes of the data held by the matrix. More... | |
const Real * | Data () const |
Gives pointer to raw data (const). More... | |
Real * | Data () |
Gives pointer to raw data (non-const). More... | |
Real * | RowData (MatrixIndexT i) |
Returns pointer to data for one row (non-const) More... | |
const Real * | RowData (MatrixIndexT i) const |
Returns pointer to data for one row (const) More... | |
Real & | operator() (MatrixIndexT r, MatrixIndexT c) |
Indexing operator, non-const (only checks sizes if compiled with -DKALDI_PARANOID) More... | |
Real & | Index (MatrixIndexT r, MatrixIndexT c) |
Indexing operator, provided for ease of debugging (gdb doesn't work with parenthesis operator). More... | |
const Real | operator() (MatrixIndexT r, MatrixIndexT c) const |
Indexing operator, const (only checks sizes if compiled with -DKALDI_PARANOID) More... | |
void | SetZero () |
Sets matrix to zero. More... | |
void | Set (Real) |
Sets all elements to a specific value. More... | |
void | SetUnit () |
Sets to zero, except ones along diagonal [for non-square matrices too]. More... | |
void | SetRandn () |
Sets to random values of a normal distribution. More... | |
void | SetRandUniform () |
Sets to numbers uniformly distributed on (0, 1) More... | |
template<typename OtherReal > | |
void | CopyFromMat (const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans) |
Copy given matrix. (no resize is done). More... | |
void | CopyFromMat (const CompressedMatrix &M) |
Copy from compressed matrix. More... | |
template<typename OtherReal > | |
void | CopyFromSp (const SpMatrix< OtherReal > &M) |
Copy given spmatrix. (no resize is done). More... | |
template<typename OtherReal > | |
void | CopyFromTp (const TpMatrix< OtherReal > &M, MatrixTransposeType trans=kNoTrans) |
Copy given tpmatrix. (no resize is done). More... | |
template<typename OtherReal > | |
void | CopyFromMat (const CuMatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans) |
Copy from CUDA matrix. Implemented in ../cudamatrix/cu-matrix.h. More... | |
void | CopyRowsFromVec (const VectorBase< Real > &v) |
This function has two modes of operation. More... | |
void | CopyRowsFromVec (const CuVectorBase< Real > &v) |
This version of CopyRowsFromVec is implemented in ../cudamatrix/cu-vector.cc. More... | |
template<typename OtherReal > | |
void | CopyRowsFromVec (const VectorBase< OtherReal > &v) |
void | CopyColsFromVec (const VectorBase< Real > &v) |
Copies vector into matrix, column-by-column. More... | |
void | CopyColFromVec (const VectorBase< Real > &v, const MatrixIndexT col) |
Copy vector into specific column of matrix. More... | |
void | CopyRowFromVec (const VectorBase< Real > &v, const MatrixIndexT row) |
Copy vector into specific row of matrix. More... | |
void | CopyDiagFromVec (const VectorBase< Real > &v) |
Copy vector into diagonal of matrix. More... | |
const SubVector< Real > | Row (MatrixIndexT i) const |
Return specific row of matrix [const]. More... | |
SubVector< Real > | Row (MatrixIndexT i) |
Return specific row of matrix. More... | |
SubMatrix< Real > | Range (const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const |
Return a sub-part of matrix. More... | |
SubMatrix< Real > | RowRange (const MatrixIndexT row_offset, const MatrixIndexT num_rows) const |
SubMatrix< Real > | ColRange (const MatrixIndexT col_offset, const MatrixIndexT num_cols) const |
Real | Sum () const |
Returns sum of all elements in matrix. More... | |
Real | Trace (bool check_square=true) const |
Returns trace of matrix. More... | |
Real | Max () const |
Returns maximum element of matrix. More... | |
Real | Min () const |
Returns minimum element of matrix. More... | |
void | MulElements (const MatrixBase< Real > &A) |
Element by element multiplication with a given matrix. More... | |
void | DivElements (const MatrixBase< Real > &A) |
Divide each element by the corresponding element of a given matrix. More... | |
void | Scale (Real alpha) |
Multiply each element with a scalar value. More... | |
void | Max (const MatrixBase< Real > &A) |
Set, element-by-element, *this = max(*this, A) More... | |
void | Min (const MatrixBase< Real > &A) |
Set, element-by-element, *this = min(*this, A) More... | |
void | MulColsVec (const VectorBase< Real > &scale) |
Equivalent to (*this) = (*this) * diag(scale). More... | |
void | MulRowsVec (const VectorBase< Real > &scale) |
Equivalent to (*this) = diag(scale) * (*this). More... | |
void | MulRowsGroupMat (const MatrixBase< Real > &src) |
Divide each row into src.NumCols() equal groups, and then scale i'th row's j'th group of elements by src(i, j). More... | |
Real | LogDet (Real *det_sign=NULL) const |
Returns logdet of matrix. More... | |
void | Invert (Real *log_det=NULL, Real *det_sign=NULL, bool inverse_needed=true) |
matrix inverse. More... | |
void | InvertDouble (Real *LogDet=NULL, Real *det_sign=NULL, bool inverse_needed=true) |
matrix inverse [double]. More... | |
void | InvertElements () |
Inverts all the elements of the matrix. More... | |
void | Transpose () |
Transpose the matrix. More... | |
void | CopyCols (const MatrixBase< Real > &src, const MatrixIndexT *indices) |
Copies column r from column indices[r] of src. More... | |
void | CopyRows (const MatrixBase< Real > &src, const MatrixIndexT *indices) |
Copies row r from row indices[r] of src (does nothing As a special case, if indexes[i] == -1, sets row i to zero. More... | |
void | AddCols (const MatrixBase< Real > &src, const MatrixIndexT *indices) |
Add column indices[r] of src to column r. More... | |
void | CopyRows (const Real *const *src) |
Copies row r of this matrix from an array of floats at the location given by src[r]. More... | |
void | CopyToRows (Real *const *dst) const |
Copies row r of this matrix to the array of floats at the location given by dst[r]. More... | |
void | AddRows (Real alpha, const MatrixBase< Real > &src, const MatrixIndexT *indexes) |
Does for each row r, this.Row(r) += alpha * src.row(indexes[r]). More... | |
void | AddRows (Real alpha, const Real *const *src) |
Does for each row r, this.Row(r) += alpha * src[r], treating src[r] as the beginning of a region of memory representing a vector of floats, of the same length as this.NumCols(). More... | |
void | AddToRows (Real alpha, Real *const *dst) const |
For each row r of this matrix, adds it (times alpha) to the array of floats at the location given by dst[r]. More... | |
void | AddToRows (Real alpha, const MatrixIndexT *indexes, MatrixBase< Real > *dst) const |
For each row i of *this, adds this->Row(i) to dst->Row(indexes(i)) if indexes(i) >= 0, else do nothing. More... | |
void | ApplyPow (Real power) |
void | ApplyPowAbs (Real power, bool include_sign=false) |
void | ApplyHeaviside () |
void | ApplyFloor (Real floor_val) |
void | ApplyCeiling (Real ceiling_val) |
void | ApplyExp () |
void | ApplyExpSpecial () |
void | ApplyExpLimited (Real lower_limit, Real upper_limit) |
void | ApplyLog () |
void | Eig (MatrixBase< Real > *P, VectorBase< Real > *eigs_real, VectorBase< Real > *eigs_imag) const |
Eigenvalue Decomposition of a square NxN matrix into the form (*this) = P D P^{-1}. More... | |
bool | Power (Real pow) |
The Power method attempts to take the matrix to a power using a method that works in general for fractional and negative powers. More... | |
void | DestructiveSvd (VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt) |
Singular value decomposition Major limitations: For nonsquare matrices, we assume m>=n (NumRows >= NumCols), and we return the "skinny" Svd, i.e. More... | |
void | Svd (VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt) const |
Compute SVD (*this) = U diag(s) Vt. More... | |
void | Svd (VectorBase< Real > *s) const |
Compute SVD but only retain the singular values. More... | |
Real | MinSingularValue () const |
Returns smallest singular value. More... | |
void | TestUninitialized () const |
Real | Cond () const |
Returns condition number by computing Svd. More... | |
bool | IsSymmetric (Real cutoff=1.0e-05) const |
Returns true if matrix is Symmetric. More... | |
bool | IsDiagonal (Real cutoff=1.0e-05) const |
Returns true if matrix is Diagonal. More... | |
bool | IsUnit (Real cutoff=1.0e-05) const |
Returns true if the matrix is all zeros, except for ones on diagonal. More... | |
bool | IsZero (Real cutoff=1.0e-05) const |
Returns true if matrix is all zeros. More... | |
Real | FrobeniusNorm () const |
Frobenius norm, which is the sqrt of sum of square elements. More... | |
bool | ApproxEqual (const MatrixBase< Real > &other, float tol=0.01) const |
Returns true if ((*this)-other).FrobeniusNorm() <= tol * (*this).FrobeniusNorm(). More... | |
bool | Equal (const MatrixBase< Real > &other) const |
Tests for exact equality. It's usually preferable to use ApproxEqual. More... | |
Real | LargestAbsElem () const |
largest absolute value. More... | |
Real | LogSumExp (Real prune=-1.0) const |
Returns log(sum(exp())) without exp overflow If prune > 0.0, it uses a pruning beam, discarding terms less than (max - prune). More... | |
Real | ApplySoftMax () |
Apply soft-max to the collection of all elements of the matrix and return normalizer (log sum of exponentials). More... | |
void | Sigmoid (const MatrixBase< Real > &src) |
Set each element to the sigmoid of the corresponding element of "src". More... | |
void | Heaviside (const MatrixBase< Real > &src) |
Sets each element to the Heaviside step function (x > 0 ? 1 : 0) of the corresponding element in "src". More... | |
void | Exp (const MatrixBase< Real > &src) |
void | Pow (const MatrixBase< Real > &src, Real power) |
void | Log (const MatrixBase< Real > &src) |
void | PowAbs (const MatrixBase< Real > &src, Real power, bool include_sign=false) |
Apply power to the absolute value of each element. More... | |
void | Floor (const MatrixBase< Real > &src, Real floor_val) |
void | Ceiling (const MatrixBase< Real > &src, Real ceiling_val) |
void | ExpSpecial (const MatrixBase< Real > &src) |
For each element x of the matrix, set it to (x < 0 ? exp(x) : x + 1). More... | |
void | ExpLimited (const MatrixBase< Real > &src, Real lower_limit, Real upper_limit) |
This is equivalent to running: Floor(src, lower_limit); Ceiling(src, upper_limit); Exp(src) More... | |
void | SoftHinge (const MatrixBase< Real > &src) |
Set each element to y = log(1 + exp(x)) More... | |
void | GroupPnorm (const MatrixBase< Real > &src, Real power) |
Apply the function y(i) = (sum_{j = i*G}^{(i+1)*G-1} x_j^(power))^(1 / p). More... | |
void | GroupPnormDeriv (const MatrixBase< Real > &input, const MatrixBase< Real > &output, Real power) |
Calculate derivatives for the GroupPnorm function above... More... | |
void | GroupMax (const MatrixBase< Real > &src) |
Apply the function y(i) = (max_{j = i*G}^{(i+1)*G-1} x_j Requires src.NumRows() == this->NumRows() and src.NumCols() % this->NumCols() == 0. More... | |
void | GroupMaxDeriv (const MatrixBase< Real > &input, const MatrixBase< Real > &output) |
Calculate derivatives for the GroupMax function above, where "input" is the input to the GroupMax function above (i.e. More... | |
void | Tanh (const MatrixBase< Real > &src) |
Set each element to the tanh of the corresponding element of "src". More... | |
void | DiffSigmoid (const MatrixBase< Real > &value, const MatrixBase< Real > &diff) |
void | DiffTanh (const MatrixBase< Real > &value, const MatrixBase< Real > &diff) |
void | SymPosSemiDefEig (VectorBase< Real > *s, MatrixBase< Real > *P, Real check_thresh=0.001) |
Uses Svd to compute the eigenvalue decomposition of a symmetric positive semi-definite matrix: (*this) = rP * diag(rS) * rP^T, with rP an orthogonal matrix so rP^{-1} = rP^T. More... | |
void | Add (const Real alpha) |
Add a scalar to each element. More... | |
void | AddToDiag (const Real alpha) |
Add a scalar to each diagonal element. More... | |
template<typename OtherReal > | |
void | AddVecVec (const Real alpha, const VectorBase< OtherReal > &a, const VectorBase< OtherReal > &b) |
*this += alpha * a * b^T More... | |
template<typename OtherReal > | |
void | AddVecToRows (const Real alpha, const VectorBase< OtherReal > &v) |
[each row of *this] += alpha * v More... | |
template<typename OtherReal > | |
void | AddVecToCols (const Real alpha, const VectorBase< OtherReal > &v) |
[each col of *this] += alpha * v More... | |
void | AddMat (const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans) |
*this += alpha * M [or M^T] More... | |
void | AddSmat (Real alpha, const SparseMatrix< Real > &A, MatrixTransposeType trans=kNoTrans) |
*this += alpha * A [or A^T]. More... | |
void | AddSmatMat (Real alpha, const SparseMatrix< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, Real beta) |
(*this) = alpha * op(A) * B + beta * (*this), where A is sparse. More... | |
void | AddMatSmat (Real alpha, const MatrixBase< Real > &A, const SparseMatrix< Real > &B, MatrixTransposeType transB, Real beta) |
(*this) = alpha * A * op(B) + beta * (*this), where B is sparse and op(B) is either B or trans(B) depending on the 'transB' argument. More... | |
void | SymAddMat2 (const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA, Real beta) |
*this = beta * *this + alpha * M M^T, for symmetric matrices. More... | |
void | AddDiagVecMat (const Real alpha, const VectorBase< Real > &v, const MatrixBase< Real > &M, MatrixTransposeType transM, Real beta=1.0) |
*this = beta * *this + alpha * diag(v) * M [or M^T]. More... | |
void | AddMatDiagVec (const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, VectorBase< Real > &v, Real beta=1.0) |
*this = beta * *this + alpha * M [or M^T] * diag(v) The same as adding M but scaling each column M_j by v(j). More... | |
void | AddMatMatElements (const Real alpha, const MatrixBase< Real > &A, const MatrixBase< Real > &B, const Real beta) |
*this = beta * *this + alpha * A .* B (.* element by element multiplication) More... | |
template<typename OtherReal > | |
void | AddSp (const Real alpha, const SpMatrix< OtherReal > &S) |
*this += alpha * S More... | |
void | AddMatMat (const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta) |
void | SetMatMatDivMat (const MatrixBase< Real > &A, const MatrixBase< Real > &B, const MatrixBase< Real > &C) |
*this = a * b / c (by element; when c = 0, *this = a) More... | |
void | AddMatSmat (const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta) |
A version of AddMatMat specialized for when the second argument contains a lot of zeroes. More... | |
void | AddSmatMat (const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta) |
A version of AddMatMat specialized for when the first argument contains a lot of zeroes. More... | |
void | AddMatMatMat (const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const MatrixBase< Real > &C, MatrixTransposeType transC, const Real beta) |
this <– beta*this + alpha*A*B*C. More... | |
void | AddSpMat (const Real alpha, const SpMatrix< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta) |
this <– beta*this + alpha*SpA*B. More... | |
void | AddTpMat (const Real alpha, const TpMatrix< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta) |
this <– beta*this + alpha*A*B. More... | |
void | AddMatSp (const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const SpMatrix< Real > &B, const Real beta) |
this <– beta*this + alpha*A*B. More... | |
void | AddSpMatSp (const Real alpha, const SpMatrix< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType transB, const SpMatrix< Real > &C, const Real beta) |
this <– beta*this + alpha*A*B*C. More... | |
void | AddMatTp (const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const TpMatrix< Real > &B, MatrixTransposeType transB, const Real beta) |
this <– beta*this + alpha*A*B. More... | |
void | AddTpTp (const Real alpha, const TpMatrix< Real > &A, MatrixTransposeType transA, const TpMatrix< Real > &B, MatrixTransposeType transB, const Real beta) |
this <– beta*this + alpha*A*B. More... | |
void | AddSpSp (const Real alpha, const SpMatrix< Real > &A, const SpMatrix< Real > &B, const Real beta) |
this <– beta*this + alpha*A*B. More... | |
void | CopyLowerToUpper () |
Copy lower triangle to upper triangle (symmetrize) More... | |
void | CopyUpperToLower () |
Copy upper triangle to lower triangle (symmetrize) More... | |
void | OrthogonalizeRows () |
This function orthogonalizes the rows of a matrix using the Gram-Schmidt process. More... | |
void | Read (std::istream &in, bool binary, bool add=false) |
stream read. More... | |
void | Write (std::ostream &out, bool binary) const |
write to stream. More... | |
void | LapackGesvd (VectorBase< Real > *s, MatrixBase< Real > *U, MatrixBase< Real > *Vt) |
template<> | |
void | AddVecVec (const float alpha, const VectorBase< float > &ra, const VectorBase< float > &rb) |
template<> | |
void | AddVecVec (const double alpha, const VectorBase< double > &ra, const VectorBase< double > &rb) |
template<> | |
void | AddVecVec (const float alpha, const VectorBase< float > &a, const VectorBase< float > &rb) |
template<> | |
void | AddVecVec (const double alpha, const VectorBase< double > &a, const VectorBase< double > &rb) |
template<> | |
void | CopyFromSp (const SpMatrix< float > &M) |
template<> | |
void | CopyFromSp (const SpMatrix< double > &M) |
Private Member Functions | |
SubMatrix< Real > & | operator= (const SubMatrix< Real > &other) |
Disallow assignment. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from MatrixBase< Real > | |
MatrixBase (Real *data, MatrixIndexT cols, MatrixIndexT rows, MatrixIndexT stride) | |
Initializer, callable only from child. More... | |
MatrixBase () | |
Initializer, callable only from child. More... | |
~MatrixBase () | |
Real * | Data_workaround () const |
A workaround that allows SubMatrix to get a pointer to non-const data for const Matrix. More... | |
Protected Attributes inherited from MatrixBase< Real > | |
Real * | data_ |
data memory area More... | |
MatrixIndexT | num_cols_ |
these attributes store the real matrix size as it is stored in memory including memalignment More... | |
MatrixIndexT | num_rows_ |
< Number of columns More... | |
MatrixIndexT | stride_ |
< Number of rows More... | |
Sub-matrix representation.
Can work with sub-parts of a matrix using this class. Note that SubMatrix is not very const-correct– it allows you to change the contents of a const Matrix. Be careful!
Definition at line 988 of file kaldi-matrix.h.
SubMatrix | ( | const MatrixBase< Real > & | T, |
const MatrixIndexT | ro, | ||
const MatrixIndexT | r, | ||
const MatrixIndexT | co, | ||
const MatrixIndexT | c | ||
) |
Definition at line 1627 of file kaldi-matrix.cc.
References data_, MatrixBase< Real >::Data_workaround(), KALDI_ASSERT, MatrixBase< Real >::num_cols_, MatrixBase< Real >::num_rows_, and MatrixBase< Real >::Stride().
SubMatrix | ( | Real * | data, |
MatrixIndexT | num_rows, | ||
MatrixIndexT | num_cols, | ||
MatrixIndexT | stride | ||
) |
Definition at line 1660 of file kaldi-matrix.cc.
References KALDI_ASSERT, MatrixBase< Real >::num_cols_, MatrixBase< Real >::num_rows_, and MatrixBase< Real >::stride_.
|
inline |
Definition at line 1008 of file kaldi-matrix.h.
This type of constructor is needed for Range() to work [in Matrix base class].
Cannot make it explicit.
Definition at line 1012 of file kaldi-matrix.h.