OnlineMatrixInput Class Reference
Inheritance diagram for OnlineMatrixInput:
Collaboration diagram for OnlineMatrixInput:

Public Member Functions

 OnlineMatrixInput (const Matrix< BaseFloat > &feats)
 
virtual int32 Dim () const
 
virtual bool Compute (Matrix< BaseFloat > *output)
 
- Public Member Functions inherited from OnlineFeatInputItf
virtual ~OnlineFeatInputItf ()
 

Private Attributes

int32 position_
 
Matrix< BaseFloatfeats_
 

Detailed Description

Definition at line 30 of file online-feat-test.cc.

Constructor & Destructor Documentation

◆ OnlineMatrixInput()

OnlineMatrixInput ( const Matrix< BaseFloat > &  feats)
inline

Definition at line 32 of file online-feat-test.cc.

32  :
33  position_(0), feats_(feats) { }
Matrix< BaseFloat > feats_

Member Function Documentation

◆ Compute()

virtual bool Compute ( Matrix< BaseFloat > *  output)
inlinevirtual

Implements OnlineFeatInputItf.

Definition at line 37 of file online-feat-test.cc.

References MatrixBase< Real >::CopyFromMat(), OnlineMatrixInput::feats_, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), OnlineMatrixInput::position_, kaldi::Rand(), MatrixBase< Real >::Range(), and Matrix< Real >::Resize().

37  {
38  if (feats_.NumRows() == 0) { // empty input.
39  output->Resize(0, 0);
40  return false;
41  }
42 
43  KALDI_ASSERT(output->NumRows() > 0 &&
44  output->NumCols() == feats_.NumCols());
45 
46  // Because this is a kind of stress test, we completely ignore
47  // the number of frames requested, and return whatever number of
48  // frames we please.
49 
50  int32 num_frames_left = feats_.NumRows() - position_;
51  int32 num_frames_return = std::min((Rand() % 5), num_frames_left);
52  if (num_frames_return == 0) {
53  output->Resize(0, 0);
54  } else {
55  output->Resize(num_frames_return, feats_.NumCols());
56  output->CopyFromMat(feats_.Range(position_, num_frames_return,
57  0, feats_.NumCols()));
58  }
59  position_ += num_frames_return;
60  if (position_ == feats_.NumRows()) return false;
61  else return true;
62  }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< BaseFloat > feats_
kaldi::int32 int32
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
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.
Definition: kaldi-matrix.h:202
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).

◆ Dim()

virtual int32 Dim ( ) const
inlinevirtual

Implements OnlineFeatInputItf.

Definition at line 35 of file online-feat-test.cc.

References OnlineMatrixInput::feats_, and MatrixBase< Real >::NumCols().

35 { return feats_.NumCols(); }
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Matrix< BaseFloat > feats_

Member Data Documentation

◆ feats_

Matrix<BaseFloat> feats_
private

Definition at line 66 of file online-feat-test.cc.

Referenced by OnlineMatrixInput::Compute(), and OnlineMatrixInput::Dim().

◆ position_

int32 position_
private

Definition at line 65 of file online-feat-test.cc.

Referenced by OnlineMatrixInput::Compute().


The documentation for this class was generated from the following file: