All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VectorBase< Real > Singleton Reference

Provides a vector abstraction class. More...

#include <kaldi-vector.h>

Inheritance diagram for VectorBase< Real >:
Collaboration diagram for VectorBase< Real >:

Public Member Functions

void SetZero ()
 Set vector to all zeros. More...
 
bool IsZero (Real cutoff=1.0e-06) const
 Returns true if matrix is all zeros. More...
 
void Set (Real f)
 Set all members of a vector to a specified value. More...
 
void SetRandn ()
 Set vector to random normally-distributed noise. More...
 
void SetRandUniform ()
 Sets to numbers uniformly distributed on (0,1) More...
 
MatrixIndexT RandCategorical () const
 This function returns a random index into this vector, chosen with probability proportional to the corresponding element. More...
 
MatrixIndexT Dim () const
 Returns the dimension of the vector. More...
 
MatrixIndexT SizeInBytes () const
 Returns the size in memory of the vector, in bytes. More...
 
Real * Data ()
 Returns a pointer to the start of the vector's data. More...
 
const Real * Data () const
 Returns a pointer to the start of the vector's data (const). More...
 
Real operator() (MatrixIndexT i) const
 Indexing operator (const). More...
 
Real & operator() (MatrixIndexT i)
 Indexing operator (non-const). More...
 
SubVector< Real > Range (const MatrixIndexT o, const MatrixIndexT l)
 Returns a sub-vector of a vector (a range of elements). More...
 
const SubVector< Real > Range (const MatrixIndexT o, const MatrixIndexT l) const
 Returns a const sub-vector of a vector (a range of elements). More...
 
void CopyFromVec (const VectorBase< Real > &v)
 Copy data from another vector (must match own size). More...
 
template<typename OtherReal >
void CopyFromPacked (const PackedMatrix< OtherReal > &M)
 Copy data from a SpMatrix or TpMatrix (must match own size). More...
 
template<typename OtherReal >
void CopyFromVec (const VectorBase< OtherReal > &v)
 Copy data from another vector of different type (double vs. float) More...
 
template<typename OtherReal >
void CopyFromVec (const CuVectorBase< OtherReal > &v)
 Copy from CuVector. This is defined in ../cudamatrix/cu-vector.h. More...
 
void ApplyLog ()
 Apply natural log to all elements. More...
 
void ApplyLogAndCopy (const VectorBase< Real > &v)
 Apply natural log to another vector and put result in *this. More...
 
void ApplyExp ()
 Apply exponential to each value in vector. More...
 
void ApplyAbs ()
 Take absolute value of each of the elements. More...
 
MatrixIndexT ApplyFloor (Real floor_val)
 Applies floor to all elements. Returns number of elements floored. More...
 
MatrixIndexT ApplyCeiling (Real ceil_val)
 Applies ceiling to all elements. Returns number of elements changed. More...
 
MatrixIndexT ApplyFloor (const VectorBase< Real > &floor_vec)
 Applies floor to all elements. Returns number of elements floored. More...
 
Real ApplySoftMax ()
 Apply soft-max to vector and return normalizer (log sum of exponentials). More...
 
Real ApplyLogSoftMax ()
 Applies log soft-max to vector and returns normalizer (log sum of exponentials). More...
 
void Tanh (const VectorBase< Real > &src)
 Sets each element of *this to the tanh of the corresponding element of "src". More...
 
void Sigmoid (const VectorBase< Real > &src)
 Sets each element of *this to the sigmoid function of the corresponding element of "src". More...
 
void ApplyPow (Real power)
 Take all elements of vector to a power. More...
 
void ApplyPowAbs (Real power, bool include_sign=false)
 Take the absolute value of all elements of a vector to a power. More...
 
Real Norm (Real p) const
 Compute the p-th norm of the vector. More...
 
bool ApproxEqual (const VectorBase< Real > &other, float tol=0.01) const
 Returns true if ((*this)-other).Norm(2.0) <= tol * (*this).Norm(2.0). More...
 
void InvertElements ()
 Invert all elements. More...
 
template<typename OtherReal >
void AddVec (const Real alpha, const VectorBase< OtherReal > &v)
 Add vector : *this = *this + alpha * rv (with casting between floats and doubles) More...
 
void AddVec2 (const Real alpha, const VectorBase< Real > &v)
 Add vector : *this = *this + alpha * rv^2 [element-wise squaring]. More...
 
template<typename OtherReal >
void AddVec2 (const Real alpha, const VectorBase< OtherReal > &v)
 Add vector : *this = *this + alpha * rv^2 [element-wise squaring], with casting between floats and doubles. More...
 
void AddMatVec (const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
 Add matrix times vector : this <– beta*this + alpha*M*v. More...
 
void AddMatSvec (const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
 This is as AddMatVec, except optimized for where v contains a lot of zeros. More...
 
void AddSpVec (const Real alpha, const SpMatrix< Real > &M, const VectorBase< Real > &v, const Real beta)
 Add symmetric positive definite matrix times vector: this <– beta*this + alpha*M*v. More...
 
void AddTpVec (const Real alpha, const TpMatrix< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
 Add triangular matrix times vector: this <– beta*this + alpha*M*v. More...
 
void ReplaceValue (Real orig, Real changed)
 Set each element to y = (x == orig ? changed : x). More...
 
void MulElements (const VectorBase< Real > &v)
 Multipy element-by-element by another vector. More...
 
template<typename OtherReal >
void MulElements (const VectorBase< OtherReal > &v)
 Multipy element-by-element by another vector of different type. More...
 
void DivElements (const VectorBase< Real > &v)
 Divide element-by-element by a vector. More...
 
template<typename OtherReal >
void DivElements (const VectorBase< OtherReal > &v)
 Divide element-by-element by a vector of different type. More...
 
void Add (Real c)
 Add a constant to each element of a vector. More...
 
void AddVecVec (Real alpha, const VectorBase< Real > &v, const VectorBase< Real > &r, Real beta)
 Add element-by-element product of vectlrs: More...
 
void AddVecDivVec (Real alpha, const VectorBase< Real > &v, const VectorBase< Real > &r, Real beta)
 Add element-by-element quotient of two vectors. More...
 
void Scale (Real alpha)
 Multiplies all elements by this constant. More...
 
void MulTp (const TpMatrix< Real > &M, const MatrixTransposeType trans)
 Multiplies this vector by lower-triangular marix: *this <– *this *M. More...
 
void Solve (const TpMatrix< Real > &M, const MatrixTransposeType trans)
 If trans == kNoTrans, solves M x = b, where b is the value of *this at input and x is the value of *this at output. More...
 
void CopyRowsFromMat (const MatrixBase< Real > &M)
 Performs a row stack of the matrix M. More...
 
template<typename OtherReal >
void CopyRowsFromMat (const MatrixBase< OtherReal > &M)
 
void CopyRowsFromMat (const CuMatrixBase< Real > &M)
 The following is implemented in ../cudamatrix/cu-matrix.cc. More...
 
void CopyColsFromMat (const MatrixBase< Real > &M)
 Performs a column stack of the matrix M. More...
 
void CopyRowFromMat (const MatrixBase< Real > &M, MatrixIndexT row)
 Extracts a row of the matrix M. More...
 
template<typename OtherReal >
void CopyRowFromMat (const MatrixBase< OtherReal > &M, MatrixIndexT row)
 Extracts a row of the matrix M with type conversion. More...
 
template<typename OtherReal >
void CopyRowFromSp (const SpMatrix< OtherReal > &S, MatrixIndexT row)
 Extracts a row of the symmetric matrix S. More...
 
template<typename OtherReal >
void CopyColFromMat (const MatrixBase< OtherReal > &M, MatrixIndexT col)
 Extracts a column of the matrix M. More...
 
void CopyDiagFromMat (const MatrixBase< Real > &M)
 Extracts the diagonal of the matrix M. More...
 
void CopyDiagFromPacked (const PackedMatrix< Real > &M)
 Extracts the diagonal of a packed matrix M; works for Sp or Tp. More...
 
void CopyDiagFromSp (const SpMatrix< Real > &M)
 Extracts the diagonal of a symmetric matrix. More...
 
void CopyDiagFromTp (const TpMatrix< Real > &M)
 Extracts the diagonal of a triangular matrix. More...
 
Real Max () const
 Returns the maximum value of any element, or -infinity for the empty vector. More...
 
Real Max (MatrixIndexT *index) const
 Returns the maximum value of any element, and the associated index. More...
 
Real Min () const
 Returns the minimum value of any element, or +infinity for the empty vector. More...
 
Real Min (MatrixIndexT *index) const
 Returns the minimum value of any element, and the associated index. More...
 
Real Sum () const
 Returns sum of the elements. More...
 
Real SumLog () const
 Returns sum of the logs of the elements. More...
 
void AddRowSumMat (Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
 Does *this = alpha * (sum of rows of M) + beta * *this. More...
 
void AddColSumMat (Real alpha, const MatrixBase< Real > &M, Real beta=1.0)
 Does *this = alpha * (sum of columns of M) + beta * *this. More...
 
void AddDiagMat2 (Real alpha, const MatrixBase< Real > &M, MatrixTransposeType trans=kNoTrans, Real beta=1.0)
 Add the diagonal of a matrix times itself: *this = diag(M M^T) + beta * *this (if trans == kNoTrans), or *this = diag(M^T M) + beta * *this (if trans == kTrans). More...
 
void AddDiagMatMat (Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transM, const MatrixBase< Real > &N, MatrixTransposeType transN, Real beta=1.0)
 Add the diagonal of a matrix product: *this = diag(M N), assuming the "trans" arguments are both kNoTrans; for transpose arguments, it behaves as you would expect. More...
 
Real LogSumExp (Real prune=-1.0) const
 Returns log(sum(exp())) without exp overflow If prune > 0.0, ignores terms less than the max - prune. More...
 
void Read (std::istream &in, bool binary, bool add=false)
 Reads from C++ stream (option to add to existing contents). More...
 
void Write (std::ostream &Out, bool binary) const
 Writes to C++ stream (option to write in binary). More...
 
template<>
void AddVec (const float alpha, const VectorBase< float > &rv)
 
template<>
void AddVec (const double alpha, const VectorBase< double > &rv)
 
template<>
void AddVec (const float alpha, const VectorBase< float > &v)
 
template<>
void AddVec (const double alpha, const VectorBase< double > &v)
 

Protected Member Functions

 ~VectorBase ()
 Destructor; does not deallocate memory, this is handled by child classes. More...
 
 VectorBase ()
 Empty initializer, corresponds to vector of zero size. More...
 
void CopyFromPtr (const Real *Data, MatrixIndexT sz)
 Load data into the vector: sz must match own size. More...
 
 KALDI_DISALLOW_COPY_AND_ASSIGN (VectorBase)
 

Protected Attributes

Real * data_
 data memory area More...
 
MatrixIndexT dim_
 dimension of vector More...
 

Friends

class VectorBase< double >
 
class VectorBase< float >
 
class CuVectorBase< Real >
 
class CuVector< Real >
 

Detailed Description

template<typename Real>
singleton kaldi::VectorBase< Real >

Provides a vector abstraction class.

This class provides a way to work with vectors in kaldi. It encapsulates basic operations and memory optimizations.

Definition at line 39 of file kaldi-vector.h.

Constructor & Destructor Documentation

~VectorBase ( )
inlineprotected

Destructor; does not deallocate memory, this is handled by child classes.

This destructor is protected so this object so this object can only be deleted via a child.

Definition at line 357 of file kaldi-vector.h.

357 {}
VectorBase ( )
inlineexplicitprotected

Empty initializer, corresponds to vector of zero size.

Definition at line 360 of file kaldi-vector.h.

360  : data_(NULL), dim_(0) {
362  }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ASSERT_IS_FLOATING_TYPE(F)
Definition: kaldi-utils.h:133
Real * data_
data memory area
Definition: kaldi-vector.h:376

Member Function Documentation

void Add ( Real  c)

Add a constant to each element of a vector.

Definition at line 941 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by AmSgmm2::ComponentLogLikes(), kaldi::ComputeCorrelation(), OnlineNaturalGradient::ComputeZt(), OnlinePreconditioner::ComputeZt(), IvectorExtractor::GetAcousticAuxfWeight(), LogisticRegression::GetLogPosteriors(), Plda::GetNormalizationFactor(), ConstantComponent::InitFromConfig(), ConstantFunctionComponent::InitFromConfig(), Plda::LogLikelihoodRatio(), main(), kaldi::nnet1::MomentStatistics(), PitchInterpolator::MultiplyObsProb(), OnlinePitchFeatureImpl::OnlinePitchFeatureImpl(), PdfPrior::PdfPrior(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradient::PreconditionDirectionsInternal(), OnlinePreconditioner::PreconditionDirectionsInternal(), kaldi::ProcessWindow(), AccumDiagGmm::SmoothStats(), AccumDiagGmm::SmoothWithModel(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdateSubstateWeights(), MleAmSgmm2Updater::UpdateW(), MleAmSgmm2Updater::UpdateWGetStats(), and MleSgmm2SpeakerAccs::UpdateWithU().

941  {
942  for (MatrixIndexT i = 0; i < dim_; i++) {
943  data_[i] += c;
944  }
945 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
void AddColSumMat ( Real  alpha,
const MatrixBase< Real > &  M,
Real  beta = 1.0 
)

Does *this = alpha * (sum of columns of M) + beta * *this.

Definition at line 736 of file kaldi-vector.cc.

References data_, rnnlm::i, rnnlm::j, KALDI_ASSERT, kaldi::kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::RowData(), and VectorBase< Real >::Set().

Referenced by kaldi::CuVectorUnitTestAddColSumMat(), KlHmm::PropagateFnc(), kaldi::UnitTestAddColSumMatSpeed(), kaldi::UnitTestCuDiffLogSoftmax(), kaldi::UnitTestCuVectorAddColSumMat(), kaldi::UnitTestCuVectorAddColSumMatLarge(), and kaldi::UnitTestSimpleForVec().

736  {
737  KALDI_ASSERT(dim_ == M.NumRows());
738  MatrixIndexT num_cols = M.NumCols();
739 
740  // implement the function according to a dimension cutoff for computation efficiency
741  if (num_cols <= 64) {
742  for (MatrixIndexT i = 0; i < dim_; i++) {
743  double sum = 0.0;
744  const Real *src = M.RowData(i);
745  for (MatrixIndexT j = 0; j < num_cols; j++)
746  sum += src[j];
747  data_[i] = alpha * sum + beta * data_[i];
748  }
749  } else {
750  Vector<Real> ones(M.NumCols());
751  ones.Set(1.0);
752  this->AddMatVec(alpha, M, kNoTrans, ones, beta);
753  }
754 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
void AddMatVec(const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
Add matrix times vector : this <– beta*this + alpha*M*v.
Definition: kaldi-vector.cc:91
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddDiagMat2 ( Real  alpha,
const MatrixBase< Real > &  M,
MatrixTransposeType  trans = kNoTrans,
Real  beta = 1.0 
)

Add the diagonal of a matrix times itself: *this = diag(M M^T) + beta * *this (if trans == kNoTrans), or *this = diag(M^T M) + beta * *this (if trans == kTrans).

Definition at line 1283 of file kaldi-vector.cc.

References kaldi::cblas_Xdot(), MatrixBase< Real >::Data(), data_, rnnlm::i, KALDI_ASSERT, kaldi::kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Stride().

Referenced by kaldi::CuVectorUnitTestAddDiagMat2(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), kaldi::SlidingWindowCmnInternal(), kaldi::UnitTestAddDiagMat2(), and kaldi::UnitTestCuDiffNormalizePerRow().

1285  {
1286  if (trans == kNoTrans) {
1287  KALDI_ASSERT(this->dim_ == M.NumRows());
1288  MatrixIndexT rows = this->dim_, cols = M.NumCols(),
1289  mat_stride = M.Stride();
1290  Real *data = this->data_;
1291  const Real *mat_data = M.Data();
1292  for (MatrixIndexT i = 0; i < rows; i++, mat_data += mat_stride, data++)
1293  *data = beta * *data + alpha * cblas_Xdot(cols,mat_data,1,mat_data,1);
1294  } else {
1295  KALDI_ASSERT(this->dim_ == M.NumCols());
1296  MatrixIndexT rows = M.NumRows(), cols = this->dim_,
1297  mat_stride = M.Stride();
1298  Real *data = this->data_;
1299  const Real *mat_data = M.Data();
1300  for (MatrixIndexT i = 0; i < cols; i++, mat_data++, data++)
1301  *data = beta * *data + alpha * cblas_Xdot(rows, mat_data, mat_stride,
1302  mat_data, mat_stride);
1303  }
1304 }
float cblas_Xdot(const int N, const float *const X, const int incX, const float *const Y, const int incY)
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddDiagMatMat ( Real  alpha,
const MatrixBase< Real > &  M,
MatrixTransposeType  transM,
const MatrixBase< Real > &  N,
MatrixTransposeType  transN,
Real  beta = 1.0 
)

Add the diagonal of a matrix product: *this = diag(M N), assuming the "trans" arguments are both kNoTrans; for transpose arguments, it behaves as you would expect.

Definition at line 1307 of file kaldi-vector.cc.

References kaldi::cblas_Xdot(), MatrixBase< Real >::Data(), data_, rnnlm::i, KALDI_ASSERT, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Stride(), and kaldi::swap().

Referenced by kaldi::UnitTestAddDiagMatMat(), kaldi::UnitTestCuDiffNormalizePerRow(), and kaldi::UnitTestCuDiffSoftmax().

1311  {
1312  MatrixIndexT dim = this->dim_,
1313  M_col_dim = (transM == kTrans ? M.NumRows() : M.NumCols()),
1314  N_row_dim = (transN == kTrans ? N.NumCols() : N.NumRows());
1315  KALDI_ASSERT(M_col_dim == N_row_dim); // this is the dimension we sum over
1316  MatrixIndexT M_row_stride = M.Stride(), M_col_stride = 1;
1317  if (transM == kTrans) std::swap(M_row_stride, M_col_stride);
1318  MatrixIndexT N_row_stride = N.Stride(), N_col_stride = 1;
1319  if (transN == kTrans) std::swap(N_row_stride, N_col_stride);
1320 
1321  Real *data = this->data_;
1322  const Real *Mdata = M.Data(), *Ndata = N.Data();
1323  for (MatrixIndexT i = 0; i < dim; i++, Mdata += M_row_stride, Ndata += N_col_stride, data++) {
1324  *data = beta * *data + alpha * cblas_Xdot(M_col_dim, Mdata, M_col_stride, Ndata, N_row_stride);
1325  }
1326 }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
float cblas_Xdot(const int N, const float *const X, const int incX, const float *const Y, const int incY)
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddMatSvec ( const Real  alpha,
const MatrixBase< Real > &  M,
const MatrixTransposeType  trans,
const VectorBase< Real > &  v,
const Real  beta 
)

This is as AddMatVec, except optimized for where v contains a lot of zeros.

Definition at line 104 of file kaldi-vector.cc.

References VectorBase< Real >::Data(), MatrixBase< Real >::Data(), data_, VectorBase< Real >::dim_, KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::Stride(), and kaldi::Xgemv_sparsevec().

Referenced by kaldi::UnitTestVecmul().

108  {
109  KALDI_ASSERT((trans == kNoTrans && M.NumCols() == v.dim_ && M.NumRows() == dim_)
110  || (trans == kTrans && M.NumRows() == v.dim_ && M.NumCols() == dim_));
111  KALDI_ASSERT(&v != this);
112  Xgemv_sparsevec(trans, M.NumRows(), M.NumCols(), alpha, M.Data(), M.Stride(),
113  v.Data(), 1, beta, data_, 1);
114  return;
115  /*
116  MatrixIndexT this_dim = this->dim_, v_dim = v.dim_,
117  M_stride = M.Stride();
118  Real *this_data = this->data_;
119  const Real *M_data = M.Data(), *v_data = v.data_;
120  if (beta != 1.0) this->Scale(beta);
121  if (trans == kNoTrans) {
122  for (MatrixIndexT i = 0; i < v_dim; i++) {
123  Real v_i = v_data[i];
124  if (v_i == 0.0) continue;
125  // Add to *this, the i'th column of the Matrix, times v_i.
126  cblas_Xaxpy(this_dim, v_i * alpha, M_data + i, M_stride, this_data, 1);
127  }
128  } else { // The transposed case is slightly more efficient, I guess.
129  for (MatrixIndexT i = 0; i < v_dim; i++) {
130  Real v_i = v.data_[i];
131  if (v_i == 0.0) continue;
132  // Add to *this, the i'th row of the Matrix, times v_i.
133  cblas_Xaxpy(this_dim, v_i * alpha,
134  M_data + (i * M_stride), 1, this_data, 1);
135  }
136  }*/
137 }
void Xgemv_sparsevec(MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, Real alpha, const Real *Mdata, MatrixIndexT stride, const Real *xdata, MatrixIndexT incX, Real beta, Real *ydata, MatrixIndexT incY)
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddMatVec ( const Real  alpha,
const MatrixBase< Real > &  M,
const MatrixTransposeType  trans,
const VectorBase< Real > &  v,
const Real  beta 
)

Add matrix times vector : this <– beta*this + alpha*M*v.

Calls BLAS GEMV.

Definition at line 91 of file kaldi-vector.cc.

References kaldi::cblas_Xgemv(), VectorBase< Real >::Data(), MatrixBase< Real >::Data(), data_, VectorBase< Real >::dim_, KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Stride().

Referenced by OnlineIvectorEstimationStats::AccStats(), FmllrDiagGmmAccs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), LdaEstimate::AddMeanOffset(), kaldi::ApplyAffineTransform(), ApplyFmllrXform(), Fmpe::ApplyProjection(), IvectorExtractorStats::CommitStatsForWPoint(), AmSgmm2::ComponentLogLikes(), MfccComputer::Compute(), PlpComputer::Compute(), kaldi::ComputeAmGmmFeatureDeriv(), Plda::ComputeDerivedVars(), AmSgmm2::ComputeFmllrPreXform(), AmSgmm2::ComputePerSpkDerivedVars(), MleAmSgmm2Updater::ComputeSMeans(), FmllrRawAccs::ConvertToSimpleStats(), kaldi::CuVectorUnitTestAddMatVec(), BasisFmllrEstimate::EstimateFmllrBasis(), FeatureTransformEstimateMulti::EstimateTransformPart(), kaldi::generate_features(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::GetAcousticAuxfWeight(), kaldi::GetFeatDeriv(), OnlineTransform::GetFrame(), IvectorExtractor::GetIvectorDistMean(), IvectorExtractor::GetIvectorDistWeight(), LogisticRegression::GetLogPosteriors(), IvectorExtractorStats::GetOrthogonalIvectorTransform(), RegtreeMllrDiagGmm::GetTransformedMeans(), FmllrRawAccs::InitSingleFrameStats(), FullGmm::LogLikelihoods(), DiagGmm::LogLikelihoods(), DiagGmm::LogLikelihoodsPreselect(), DecodableAmDiagGmmUnmapped::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), main(), MleAmSgmm2Updater::RenormalizeV(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), Plda::TransformIvector(), UnitTestEstimateLda(), kaldi::UnitTestMul(), kaldi::UnitTestPldaEstimation(), HldaAccsDiagGmm::Update(), FmllrRawAccs::Update(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), IvectorExtractorStats::UpdatePrior(), MleSgmm2SpeakerAccs::UpdateWithU(), and kaldi::VecMatVec().

95  {
96  KALDI_ASSERT((trans == kNoTrans && M.NumCols() == v.dim_ && M.NumRows() == dim_)
97  || (trans == kTrans && M.NumRows() == v.dim_ && M.NumCols() == dim_));
98  KALDI_ASSERT(&v != this);
99  cblas_Xgemv(trans, M.NumRows(), M.NumCols(), alpha, M.Data(), M.Stride(),
100  v.Data(), 1, beta, data_, 1);
101 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void cblas_Xgemv(MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, float alpha, const float *Mdata, MatrixIndexT stride, const float *xdata, MatrixIndexT incX, float beta, float *ydata, MatrixIndexT incY)
void AddRowSumMat ( Real  alpha,
const MatrixBase< Real > &  M,
Real  beta = 1.0 
)

Does *this = alpha * (sum of rows of M) + beta * *this.

Definition at line 716 of file kaldi-vector.cc.

References kaldi::cblas_Xaxpy(), kaldi::cblas_Xscal(), MatrixBase< Real >::Data(), data_, rnnlm::i, KALDI_ASSERT, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), VectorBase< Real >::Set(), and MatrixBase< Real >::Stride().

Referenced by CovarianceStats::AccStats(), PldaStats::AddSamples(), kaldi::nnet2::AverageConstPart(), IvectorExtractorStats::CommitStatsForW(), kaldi::CuVectorUnitTestAddRowSumMat(), LdaEstimate::GetStats(), AmSgmm2::LogLikelihood(), main(), AmSgmm2::SplitSubstatesInGroup(), kaldi::UnitTestAddRowSumMatSpeed(), kaldi::UnitTestCuVectorAddRowSumMat(), kaldi::UnitTestCuVectorAddRowSumMatLarge(), UnitTestEstimateFullGmm(), EbwAmSgmm2Updater::Update(), MleAmSgmm2Updater::Update(), and kaldi::nnet2::UpdateHash().

716  {
717  KALDI_ASSERT(dim_ == M.NumCols());
718  MatrixIndexT num_rows = M.NumRows(), stride = M.Stride(), dim = dim_;
719  Real *data = data_;
720 
721  // implement the function according to a dimension cutoff for computation efficiency
722  if (num_rows <= 64) {
723  cblas_Xscal(dim, beta, data, 1);
724  const Real *m_data = M.Data();
725  for (MatrixIndexT i = 0; i < num_rows; i++, m_data += stride)
726  cblas_Xaxpy(dim, alpha, m_data, 1, data, 1);
727 
728  } else {
729  Vector<Real> ones(M.NumRows());
730  ones.Set(1.0);
731  this->AddMatVec(alpha, M, kTrans, ones, beta);
732  }
733 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
void cblas_Xscal(const int N, const float alpha, float *data, const int inc)
void AddMatVec(const Real alpha, const MatrixBase< Real > &M, const MatrixTransposeType trans, const VectorBase< Real > &v, const Real beta)
Add matrix times vector : this <– beta*this + alpha*M*v.
Definition: kaldi-vector.cc:91
Real * data_
data memory area
Definition: kaldi-vector.h:376
void cblas_Xaxpy(const int N, const float alpha, const float *X, const int incX, float *Y, const int incY)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddSpVec ( const Real  alpha,
const SpMatrix< Real > &  M,
const VectorBase< Real > &  v,
const Real  beta 
)

Add symmetric positive definite matrix times vector: this <– beta*this + alpha*M*v.

Calls BLAS SPMV.

Definition at line 140 of file kaldi-vector.cc.

References kaldi::cblas_Xspmv(), VectorBase< Real >::Data(), PackedMatrix< Real >::Data(), data_, VectorBase< Real >::dim_, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

Referenced by kaldi::CalBasisFmllrStepSize(), AmSgmm2::ComputePerFrameVars(), FullGmmNormal::CopyToFullGmm(), kaldi::CuVectorUnitTestAddSpVec(), kaldi::Debias(), kaldi::FmllrAuxfGradient(), kaldi::FmllrAuxFuncDiagGmm(), kaldi::FmllrInnerUpdate(), IvectorExtractor::GetAcousticAuxfMean(), FullGmm::GetComponentMean(), IvectorExtractor::GetIvectorDistribution(), PldaEstimator::GetStatsFromClassMeans(), kaldi::GpsrBasicAlpha(), kaldi::GpsrBB(), main(), kaldi::MllrAuxFunction(), FullGmm::SetInvCovars(), FullGmm::SetInvCovarsAndMeans(), kaldi::SolveQuadraticProblem(), AmSgmm2::SplitSubstatesInGroup(), SpMatrix< Real >::TopEigs(), kaldi::UnitTestLbfgs(), kaldi::UnitTestLinearCgd(), kaldi::UnitTestMul(), kaldi::UnitTestSolve(), MlltAccs::Update(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), and MleSgmm2SpeakerAccs::UpdateWithU().

143  {
144  KALDI_ASSERT(M.NumRows() == v.dim_ && dim_ == v.dim_);
145  KALDI_ASSERT(&v != this);
146  cblas_Xspmv(alpha, M.NumRows(), M.Data(), v.Data(), 1, beta, data_, 1);
147 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void cblas_Xspmv(const float alpha, const int num_rows, const float *Mdata, const float *v, const int v_inc, const float beta, float *y, const int y_inc)
void AddTpVec ( const Real  alpha,
const TpMatrix< Real > &  M,
const MatrixTransposeType  trans,
const VectorBase< Real > &  v,
const Real  beta 
)

Add triangular matrix times vector: this <– beta*this + alpha*M*v.

Works even if rv == *this.

Definition at line 1242 of file kaldi-vector.cc.

References VectorBase< Real >::dim_, KALDI_ASSERT, VectorBase< Real >::MulTp(), and PackedMatrix< Real >::NumRows().

Referenced by FastNnetCombiner::ComputeCurrentNnet(), FastNnetCombiner::ComputeObjfAndGradient(), FastNnetCombiner::ComputePreconditioner(), kaldi::nnet2::PerturbTrainingExample(), FullGmmNormal::Rand(), kaldi::UnitTestCuVectorAddTp(), kaldi::UnitTestCuVectorAddTpVec(), kaldi::UnitTestMul(), and kaldi::UnitTestTriVecSolver().

1245  {
1246  KALDI_ASSERT(dim_ == v.dim_ && dim_ == M.NumRows());
1247  if (beta == 0.0) {
1248  if (&v != this) CopyFromVec(v);
1249  MulTp(M, trans);
1250  if (alpha != 1.0) Scale(alpha);
1251  } else {
1252  Vector<Real> tmp(v);
1253  tmp.MulTp(M, trans);
1254  if (beta != 1.0) Scale(beta); // *this <-- beta * *this
1255  AddVec(alpha, tmp); // *this += alpha * M * v
1256  }
1257 }
void MulTp(const TpMatrix< Real > &M, const MatrixTransposeType trans)
Multiplies this vector by lower-triangular marix: *this <– *this *M.
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
void Scale(Real alpha)
Multiplies all elements by this constant.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
void AddVec ( const float  alpha,
const VectorBase< float > &  rv 
)
void AddVec< double > ( const double  alpha,
const VectorBase< double > &  rv 
)
void AddVec ( const float  alpha,
const VectorBase< float > &  v 
)

Definition at line 74 of file kaldi-vector.cc.

References kaldi::cblas_Xaxpy(), VectorBase< Real >::Data(), data_, VectorBase< Real >::dim_, and KALDI_ASSERT.

75  {
76  KALDI_ASSERT(dim_ == v.dim_);
77  KALDI_ASSERT(&v != this);
78  cblas_Xaxpy(dim_, alpha, v.Data(), 1, data_, 1);
79 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
void cblas_Xaxpy(const int N, const float alpha, const float *X, const int incX, float *Y, const int incY)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddVec ( const double  alpha,
const VectorBase< double > &  v 
)

Definition at line 83 of file kaldi-vector.cc.

References kaldi::cblas_Xaxpy(), VectorBase< Real >::Data(), data_, VectorBase< Real >::dim_, and KALDI_ASSERT.

84  {
85  KALDI_ASSERT(dim_ == v.dim_);
86  KALDI_ASSERT(&v != this);
87  cblas_Xaxpy(dim_, alpha, v.Data(), 1, data_, 1);
88 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
void cblas_Xaxpy(const int N, const float alpha, const float *X, const int incX, float *Y, const int incY)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddVec ( const Real  alpha,
const VectorBase< OtherReal > &  v 
)

Add vector : *this = *this + alpha * rv (with casting between floats and doubles)

Definition at line 1029 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, rnnlm::i, and KALDI_ASSERT.

Referenced by OptimizeLbfgs< Real >::AcceptStep(), HldaAccsDiagGmm::AccumulateFromPosteriors(), AccumFullGmm::AccumulateFromPosteriors(), FmllrRawAccs::AccumulateFromPosteriors(), AccumDiagGmm::AccumulateFromPosteriors(), MleAmSgmm2Accs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), FmllrDiagGmmAccs::AccumulateFromPosteriorsPreselect(), VectorClusterable::Add(), AccumDiagGmm::Add(), IvectorExtractorStats::Add(), PldaStats::AddSamples(), PldaUnsupervisedAdaptor::AddStats(), Fmpe::ApplyProjection(), VectorBase< Real >::ApproxEqual(), IvectorExtractorStats::CommitStatsForM(), IvectorExtractorStats::CommitStatsForPrior(), AmSgmm2::ComponentLogLikes(), kaldi::ComputeAmGmmFeatureDeriv(), kaldi::ComputeAndSubtractMean(), PitchFrameInfo::ComputeBacktraces(), Fmpe::ComputeC(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeFmllrPreXform(), AmSgmm2::ComputeGammaI(), Sgmm2Project::ComputeLdaStats(), kaldi::ComputeLocalCost(), OptimizeLbfgs< Real >::ComputeNewDirection(), NnetChainCombiner::ComputeObjfAndDerivFromParameters(), NnetCombiner::ComputeObjfAndDerivFromParameters(), PldaEstimator::ComputeObjfPart2(), EbwAmSgmm2Updater::ComputePhoneVecStats(), BasisFmllrEstimate::ComputeTransform(), CompressedAffineXformStats::CopyFromAffineXformStats(), kaldi::Debias(), kaldi::DiagGmmToStats(), kaldi::EBWUpdateGaussian(), kaldi::FmllrInnerUpdate(), kaldi::GenRandStats(), kaldi::GetFeatureMeanAndVariance(), IvectorExtractor::GetIvectorDistribution(), GetLogLikeTest(), NnetChainCombiner::GetNnetParameters(), NnetCombiner::GetNnetParameters(), PldaEstimator::GetStatsFromClassMeans(), AmSgmm2::GetSubstateSpeakerMean(), kaldi::GpsrBasic(), kaldi::GpsrBasicAlpha(), kaldi::GpsrBB(), kaldi::GpsrGradient(), kaldi::GpsrObjective(), FmllrRawAccs::InitSingleFrameStats(), kaldi::LinearCgd(), Plda::LogLikelihoodRatio(), main(), FullGmm::Merge(), DiagGmm::merged_components_logdet(), FullGmm::MergedComponentsLogdet(), SoftmaxComponent::MixUp(), PitchInterpolator::MultiplyObsProb(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), kaldi::nnet3::PrintPriorDiagnostics(), kaldi::nnet2::PrintPriorDiagnostics(), DeltaFeatures::Process(), ShiftedDeltaFeatures::Process(), kaldi::nnet2::ProcessFile(), AccumFullGmm::Read(), LdaEstimate::Read(), OptimizeLbfgs< Real >::Restart(), NnetChainCombiner::SelfTestDerivatives(), NnetCombiner::SelfTestDerivatives(), NnetChainCombiner::SelfTestModelDerivatives(), NnetCombiner::SelfTestModelDerivatives(), kaldi::SlidingWindowCmnInternal(), Plda::SmoothWithinClassCovariance(), kaldi::SolveQuadraticProblem(), VectorClusterable::Sub(), kaldi::TestClusterKMeansVector(), SpMatrix< Real >::TopEigs(), kaldi::TypeOneUsage(), kaldi::UnitTestAddDiagMat2(), kaldi::UnitTestAddDiagMatMat(), kaldi::UnitTestAddDiagVecMat(), kaldi::UnitTestAddVecCross(), kaldi::UnitTestCuVectorAddColSumMat(), kaldi::UnitTestCuVectorAddColSumMatLarge(), kaldi::UnitTestCuVectorAddRowSumMat(), kaldi::UnitTestCuVectorAddRowSumMatLarge(), kaldi::UnitTestCuVectorAddVec(), UnitTestEstimateDiagGmm(), UnitTestEstimateLda(), kaldi::UnitTestEstimateMmieDiagGmm(), kaldi::UnitTestLbfgs(), kaldi::UnitTestLinearCgd(), kaldi::UnitTestSparseVectorAddToVec(), HldaAccsDiagGmm::Update(), kaldi::UpdateEbwDiagGmm(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), PldaUnsupervisedAdaptor::UpdatePlda(), EbwAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateU(), EbwAmSgmm2Updater::UpdateW(), and MleSgmm2SpeakerAccs::UpdateWithU().

1029  {
1030  KALDI_ASSERT(dim_ == v.dim_);
1031  // remove __restrict__ if it causes compilation problems.
1032  Real *__restrict__ data = data_;
1033  OtherReal *__restrict__ other_data = v.data_;
1034  MatrixIndexT dim = dim_;
1035  if (alpha != 1.0)
1036  for (MatrixIndexT i = 0; i < dim; i++)
1037  data[i] += alpha * other_data[i];
1038  else
1039  for (MatrixIndexT i = 0; i < dim; i++)
1040  data[i] += other_data[i];
1041 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddVec2 ( const Real  alpha,
const VectorBase< Real > &  v 
)
void AddVec2 ( const Real  alpha,
const VectorBase< OtherReal > &  v 
)

Add vector : *this = *this + alpha * rv^2 [element-wise squaring], with casting between floats and doubles.

Definition at line 1050 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, rnnlm::i, and KALDI_ASSERT.

1050  {
1051  KALDI_ASSERT(dim_ == v.dim_);
1052  // remove __restrict__ if it causes compilation problems.
1053  Real *__restrict__ data = data_;
1054  OtherReal *__restrict__ other_data = v.data_;
1055  MatrixIndexT dim = dim_;
1056  if (alpha != 1.0)
1057  for (MatrixIndexT i = 0; i < dim; i++)
1058  data[i] += alpha * other_data[i] * other_data[i];
1059  else
1060  for (MatrixIndexT i = 0; i < dim; i++)
1061  data[i] += other_data[i] * other_data[i];
1062 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddVecDivVec ( Real  alpha,
const VectorBase< Real > &  v,
const VectorBase< Real > &  r,
Real  beta 
)

Add element-by-element quotient of two vectors.

this <—- alpha*v/r + beta*this

Definition at line 1019 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, rnnlm::i, and KALDI_ASSERT.

Referenced by main(), and kaldi::UnitTestSimpleForVec().

1020  {
1021  KALDI_ASSERT((dim_ == v.dim_ && dim_ == rr.dim_));
1022  for (MatrixIndexT i = 0; i < dim_; i++) {
1023  data_[i] = alpha * v.data_[i]/rr.data_[i] + beta * data_[i] ;
1024  }
1025 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void AddVecVec ( Real  alpha,
const VectorBase< Real > &  v,
const VectorBase< Real > &  r,
Real  beta 
)

Add element-by-element product of vectlrs:

Definition at line 985 of file kaldi-vector.cc.

References kaldi::cblas_Xgbmv(), VectorBase< Real >::data_, VectorBase< Real >::dim_, KALDI_ASSERT, and kaldi::kNoTrans.

Referenced by FmllrRawAccs::AccumulateFromPosteriors(), MleAmSgmm2Accs::CommitStatsForSpk(), kaldi::ComputeAmGmmFeatureDeriv(), kaldi::ComputeLocalCost(), OptimizeLbfgs< Real >::ComputeNewDirection(), kaldi::CuVectorUnitTestAddVecVec(), kaldi::GetFeatDeriv(), and BatchNormComponent::Info().

986  {
987  KALDI_ASSERT(v.data_ != this->data_ && r.data_ != this->data_);
988  // We pretend that v is a band-diagonal matrix.
989  KALDI_ASSERT(dim_ == v.dim_ && dim_ == r.dim_);
990  cblas_Xgbmv(kNoTrans, dim_, dim_, 0, 0, alpha, v.data_, 1,
991  r.data_, 1, beta, this->data_, 1);
992 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void cblas_Xgbmv(MatrixTransposeType trans, MatrixIndexT num_rows, MatrixIndexT num_cols, MatrixIndexT num_below, MatrixIndexT num_above, float alpha, const float *Mdata, MatrixIndexT stride, const float *xdata, MatrixIndexT incX, float beta, float *ydata, MatrixIndexT incY)
void ApplyAbs ( )

Take absolute value of each of the elements.

Definition at line 809 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by kaldi::nnet2::PrintPriorDiagnostics(), kaldi::nnet3::PrintPriorDiagnostics(), and kaldi::UnitTestTopEigs().

809  {
810  for (MatrixIndexT i = 0; i < dim_; i++) { data_[i] = std::abs(data_[i]); }
811 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT ApplyCeiling ( Real  ceil_val)

Applies ceiling to all elements. Returns number of elements changed.

Definition at line 826 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by kaldi::CuVectorUnitTestApplyCeiling(), and FeatureTransformEstimate::EstimateInternal().

826  {
827  MatrixIndexT num_changed = 0;
828  for (MatrixIndexT i = 0; i < dim_; i++) {
829  if (data_[i] > ceil_val) {
830  data_[i] = ceil_val;
831  num_changed++;
832  }
833  }
834  return num_changed;
835 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT ApplyFloor ( const VectorBase< Real > &  floor_vec)

Applies floor to all elements. Returns number of elements floored.

Definition at line 839 of file kaldi-vector.cc.

References data_, VectorBase< Real >::Dim(), rnnlm::i, and KALDI_ASSERT.

839  {
840  KALDI_ASSERT(floor_vec.Dim() == dim_);
841  MatrixIndexT num_floored = 0;
842  for (MatrixIndexT i = 0; i < dim_; i++) {
843  if (data_[i] < floor_vec(i)) {
844  data_[i] = floor_vec(i);
845  num_floored++;
846  }
847  }
848  return num_floored;
849 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void ApplyLog ( )

Apply natural log to all elements.

Throw if any element of the vector is negative (but doesn't complain about zero; the log will be -infinity

Definition at line 785 of file kaldi-vector.cc.

References data_, rnnlm::i, KALDI_ERR, and kaldi::Log().

Referenced by AmSgmm2::ComponentLogLikes(), MfccComputer::Compute(), FbankComputer::Compute(), IvectorExtractor::GetAcousticAuxfWeight(), NnetChainCombiner::GetInitialParameters(), NnetCombiner::GetInitialParameters(), SpMatrix< Real >::Log(), PdfPrior::PdfPrior(), LogisticRegression::ScalePriors(), and MleSgmm2SpeakerAccs::UpdateWithU().

785  {
786  for (MatrixIndexT i = 0; i < dim_; i++) {
787  if (data_[i] < 0.0)
788  KALDI_ERR << "Trying to take log of a negative number.";
789  data_[i] = Log(data_[i]);
790  }
791 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
double Log(double x)
Definition: kaldi-math.h:100
#define KALDI_ERR
Definition: kaldi-error.h:127
Real * data_
data memory area
Definition: kaldi-vector.h:376
void ApplyLogAndCopy ( const VectorBase< Real > &  v)

Apply natural log to another vector and put result in *this.

Definition at line 794 of file kaldi-vector.cc.

References data_, VectorBase< Real >::Dim(), rnnlm::i, KALDI_ASSERT, and kaldi::Log().

Referenced by kaldi::UnitTestSimple().

794  {
795  KALDI_ASSERT(dim_ == v.Dim());
796  for (MatrixIndexT i = 0; i < dim_; i++) {
797  data_[i] = Log(v(i));
798  }
799 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
double Log(double x)
Definition: kaldi-math.h:100
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real ApplyLogSoftMax ( )

Applies log soft-max to vector and returns normalizer (log sum of exponentials).

This is the same as: $ x(i) = x(i) - log(\sum_i exp(x(i))) $

Definition at line 862 of file kaldi-vector.cc.

References data_, kaldi::Exp(), rnnlm::i, and kaldi::Log().

Referenced by kaldi::UnitTestSimpleForVec().

862  {
863  Real max = this->Max(), sum = 0.0;
864  for (MatrixIndexT i = 0; i < dim_; i++) {
865  sum += Exp((data_[i] -= max));
866  }
867  sum = Log(sum);
868  this->Add(-1.0 * sum);
869  return max + sum;
870 }
double Exp(double x)
Definition: kaldi-math.h:83
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
double Log(double x)
Definition: kaldi-math.h:100
Real * data_
data memory area
Definition: kaldi-vector.h:376
void Add(Real c)
Add a constant to each element of a vector.
void ApplyPow ( Real  power)

Take all elements of vector to a power.

Definition at line 456 of file kaldi-vector.cc.

References data_, rnnlm::i, and KALDI_ERR.

Referenced by AccumDiagGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateFromPosteriors(), SpMatrix< Real >::ApplyFloor(), SpMatrix< Real >::ApplyPow(), DiagGmm::ComponentLogLikelihood(), FbankComputer::Compute(), PlpComputer::Compute(), OnlineNaturalGradient::ComputeEt(), OnlinePreconditioner::ComputeEt(), kaldi::CuVectorUnitTestApplyPow(), Plda::GetNormalizationFactor(), BatchNormComponent::Info(), Plda::LogLikelihoodRatio(), DiagGmm::LogLikelihoods(), DecodableAmDiagGmmUnmapped::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), main(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlineNaturalGradient::PreconditionDirectionsInternal(), OnlinePreconditioner::PreconditionDirectionsInternal(), kaldi::SlidingWindowCmnInternal(), Plda::SmoothWithinClassCovariance(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), MatrixBase< Real >::SymPosSemiDefEig(), UnitTestEstimateDiagGmm(), kaldi::UnitTestEstimateMmieDiagGmm(), kaldi::UnitTestPower(), and IvectorExtractorStats::UpdatePrior().

456  {
457  if (power == 1.0) return;
458  if (power == 2.0) {
459  for (MatrixIndexT i = 0; i < dim_; i++)
460  data_[i] = data_[i] * data_[i];
461  } else if (power == 0.5) {
462  for (MatrixIndexT i = 0; i < dim_; i++) {
463  if (!(data_[i] >= 0.0))
464  KALDI_ERR << "Cannot take square root of negative value "
465  << data_[i];
466  data_[i] = std::sqrt(data_[i]);
467  }
468  } else {
469  for (MatrixIndexT i = 0; i < dim_; i++) {
470  data_[i] = pow(data_[i], power);
471  if (data_[i] == HUGE_VAL) { // HUGE_VAL is what errno returns on error.
472  KALDI_ERR << "Could not raise element " << i << " to power "
473  << power << ": returned value = " << data_[i];
474  }
475  }
476  }
477 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ERR
Definition: kaldi-error.h:127
Real * data_
data memory area
Definition: kaldi-vector.h:376
void ApplyPowAbs ( Real  power,
bool  include_sign = false 
)

Take the absolute value of all elements of a vector to a power.

Include the sign of the input element if include_sign == true. If power is negative and the input value is zero, the output is set zero.

Definition at line 483 of file kaldi-vector.cc.

References data_, rnnlm::i, and KALDI_ERR.

Referenced by kaldi::UnitTestPowerAbs().

483  {
484  if (power == 1.0)
485  for (MatrixIndexT i = 0; i < dim_; i++)
486  data_[i] = (include_sign && data_[i] < 0 ? -1 : 1) * std::abs(data_[i]);
487  if (power == 2.0) {
488  for (MatrixIndexT i = 0; i < dim_; i++)
489  data_[i] = (include_sign && data_[i] < 0 ? -1 : 1) * data_[i] * data_[i];
490  } else if (power == 0.5) {
491  for (MatrixIndexT i = 0; i < dim_; i++) {
492  data_[i] = (include_sign && data_[i] < 0 ? -1 : 1) * std::sqrt(std::abs(data_[i]));
493  }
494  } else if (power < 0.0) {
495  for (MatrixIndexT i = 0; i < dim_; i++) {
496  data_[i] = (data_[i] == 0.0 ? 0.0 : pow(std::abs(data_[i]), power));
497  data_[i] *= (include_sign && data_[i] < 0 ? -1 : 1);
498  if (data_[i] == HUGE_VAL) { // HUGE_VAL is what errno returns on error.
499  KALDI_ERR << "Could not raise element " << i << "to power "
500  << power << ": returned value = " << data_[i];
501  }
502  }
503  } else {
504  for (MatrixIndexT i = 0; i < dim_; i++) {
505  data_[i] = (include_sign && data_[i] < 0 ? -1 : 1) * pow(std::abs(data_[i]), power);
506  if (data_[i] == HUGE_VAL) { // HUGE_VAL is what errno returns on error.
507  KALDI_ERR << "Could not raise element " << i << "to power "
508  << power << ": returned value = " << data_[i];
509  }
510  }
511  }
512 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ERR
Definition: kaldi-error.h:127
Real * data_
data memory area
Definition: kaldi-vector.h:376
Real ApplySoftMax ( )

Apply soft-max to vector and return normalizer (log sum of exponentials).

This is the same as: $ x(i) = exp(x(i)) / \sum_i exp(x(i)) $

Definition at line 852 of file kaldi-vector.cc.

References data_, kaldi::Exp(), rnnlm::i, and kaldi::Log().

Referenced by Fmpe::ApplyProjection(), Fmpe::ApplyProjectionReverse(), IvectorExtractorStats::CommitStatsForWPoint(), FullGmm::ComponentPosteriors(), DiagGmm::ComponentPosteriors(), AmSgmm2::ComputeFmllrPreXform(), kaldi::CuVectorUnitTestApplySoftMax(), IvectorExtractor::GetIvectorDistWeight(), main(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), and kaldi::VectorToPosteriorEntry().

852  {
853  Real max = this->Max(), sum = 0.0;
854  for (MatrixIndexT i = 0; i < dim_; i++) {
855  sum += (data_[i] = Exp(data_[i] - max));
856  }
857  this->Scale(1.0 / sum);
858  return max + Log(sum);
859 }
double Exp(double x)
Definition: kaldi-math.h:83
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
double Log(double x)
Definition: kaldi-math.h:100
void Scale(Real alpha)
Multiplies all elements by this constant.
Real * data_
data memory area
Definition: kaldi-vector.h:376
bool ApproxEqual ( const VectorBase< Real > &  other,
float  tol = 0.01 
) const

Returns true if ((*this)-other).Norm(2.0) <= tol * (*this).Norm(2.0).

Definition at line 560 of file kaldi-vector.cc.

References VectorBase< Real >::AddVec(), data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, rnnlm::i, KALDI_ASSERT, KALDI_ERR, and VectorBase< Real >::Norm().

Referenced by kaldi::ApproxEqual(), AccumDiagGmm::AssertEqual(), kaldi::AssertEqual(), kaldi::CuVectorUnitTestCopyDiagFromPacked(), FmllrRawAccs::DataHasChanged(), FmllrDiagGmmAccs::DataHasChanged(), NnetDiscriminativeSupervision::operator==(), NnetChainSupervision::operator==(), and kaldi::UnitTestNorm().

560  {
561  if (dim_ != other.dim_) KALDI_ERR << "ApproxEqual: size mismatch "
562  << dim_ << " vs. " << other.dim_;
563  KALDI_ASSERT(tol >= 0.0);
564  if (tol != 0.0) {
565  Vector<Real> tmp(*this);
566  tmp.AddVec(-1.0, other);
567  return (tmp.Norm(2.0) <= static_cast<Real>(tol) * this->Norm(2.0));
568  } else { // Test for exact equality.
569  const Real *data = data_;
570  const Real *other_data = other.data_;
571  for (MatrixIndexT dim = dim_, i = 0; i < dim; i++)
572  if (data[i] != other_data[i]) return false;
573  return true;
574  }
575 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ERR
Definition: kaldi-error.h:127
Real Norm(Real p) const
Compute the p-th norm of the vector.
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
template void CopyColFromMat ( const MatrixBase< OtherReal > &  M,
MatrixIndexT  col 
)

Extracts a column of the matrix M.

Definition at line 660 of file kaldi-vector.cc.

References data_, rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by kaldi::ComputeVadEnergy(), FmllrRawAccs::FmllrRawAccs(), kaldi::generate_features(), kaldi::IncreaseTransformDimension(), main(), OnlineTransform::OnlineTransform(), TestSgmm2PreXform(), kaldi::UnitTestAddDiagVecMat(), kaldi::UnitTestRow(), kaldi::UnitTestSimpleForVec(), kaldi::UnitTestSnipEdges(), and kaldi::UnitTestSpliceRows().

660  {
661  KALDI_ASSERT(col < mat.NumCols());
662  KALDI_ASSERT(dim_ == mat.NumRows());
663  for (MatrixIndexT i = 0; i < dim_; i++)
664  data_[i] = mat(i, col);
665  // can't do this very efficiently so don't really bother. could improve this though.
666 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyColsFromMat ( const MatrixBase< Real > &  M)

Performs a column stack of the matrix M.

Definition at line 383 of file kaldi-vector.cc.

References MatrixBase< Real >::Data(), data_, rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Stride().

Referenced by kaldi::UnitTestSpliceRows().

383  {
384  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
385 
386  Real* inc_data = data_;
387  const MatrixIndexT cols = mat.NumCols(), rows = mat.NumRows(), stride = mat.Stride();
388  const Real *mat_inc_data = mat.Data();
389 
390  for (MatrixIndexT i = 0; i < cols; i++) {
391  for (MatrixIndexT j = 0; j < rows; j++) {
392  inc_data[j] = mat_inc_data[j*stride];
393  }
394  mat_inc_data++;
395  inc_data += rows;
396  }
397 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyDiagFromMat ( const MatrixBase< Real > &  M)

Extracts the diagonal of the matrix M.

Definition at line 678 of file kaldi-vector.cc.

References kaldi::cblas_Xcopy(), MatrixBase< Real >::Data(), data_, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::Stride().

Referenced by kaldi::CuVectorUnitTestCopyDiagFromMat(), kaldi::UnitTestAddDiagMat2(), kaldi::UnitTestAddDiagMatMat(), kaldi::UnitTestSpliceRows(), and kaldi::UnitTestTopEigs().

678  {
679  KALDI_ASSERT(dim_ == std::min(M.NumRows(), M.NumCols()));
680  cblas_Xcopy(dim_, M.Data(), M.Stride() + 1, data_, 1);
681 }
void cblas_Xcopy(const int N, const float *X, const int incX, float *Y, const int incY)
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyDiagFromPacked ( const PackedMatrix< Real > &  M)

Extracts the diagonal of a packed matrix M; works for Sp or Tp.

Definition at line 684 of file kaldi-vector.cc.

References data_, rnnlm::i, KALDI_ASSERT, and PackedMatrix< Real >::NumCols().

Referenced by VectorBase< BaseFloat >::CopyDiagFromSp(), VectorBase< BaseFloat >::CopyDiagFromTp(), DiagGmm::CopyFromFullGmm(), kaldi::CuVectorUnitTestCopyDiagFromPacked(), and SpMatrix< Real >::Eig().

684  {
685  KALDI_ASSERT(dim_ == M.NumCols());
686  for (MatrixIndexT i = 0; i < dim_; i++)
687  data_[i] = M(i, i);
688  // could make this more efficient.
689 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyDiagFromSp ( const SpMatrix< Real > &  M)
inline

Extracts the diagonal of a symmetric matrix.

Definition at line 290 of file kaldi-vector.h.

Referenced by kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), and SpMatrix< Real >::TopEigs().

290 { CopyDiagFromPacked(M); }
void CopyDiagFromPacked(const PackedMatrix< Real > &M)
Extracts the diagonal of a packed matrix M; works for Sp or Tp.
void CopyDiagFromTp ( const TpMatrix< Real > &  M)
inline

Extracts the diagonal of a triangular matrix.

Definition at line 293 of file kaldi-vector.h.

293 { CopyDiagFromPacked(M); }
void CopyDiagFromPacked(const PackedMatrix< Real > &M)
Extracts the diagonal of a packed matrix M; works for Sp or Tp.
template void CopyFromPacked ( const PackedMatrix< OtherReal > &  M)

Copy data from a SpMatrix or TpMatrix (must match own size).

Definition at line 236 of file kaldi-vector.cc.

236  {
237  SubVector<OtherReal> v(M);
238  this->CopyFromVec(v);
239 }
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
void CopyFromPtr ( const Real *  Data,
MatrixIndexT  sz 
)
protected

Load data into the vector: sz must match own size.

Load data into the vector.

Definition at line 248 of file kaldi-vector.cc.

References data_, and KALDI_ASSERT.

248  {
249  KALDI_ASSERT(dim_ == sz);
250  std::memcpy(this->data_, data, Dim() * sizeof(Real));
251 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void CopyFromVec ( const VectorBase< Real > &  v)

Copy data from another vector (must match own size).

Copy data from another vector.

Definition at line 227 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::Dim(), and KALDI_ASSERT.

Referenced by OptimizeLbfgs< Real >::AcceptStep(), RegtreeMllrDiagGmmAccs::AccumulateForGaussian(), RegtreeMllrDiagGmmAccs::AccumulateForGmm(), AccumFullGmm::AccumulateFromPosteriors(), kaldi::ApplyAffineTransform(), Fmpe::ApplyC(), kaldi::ClusterGaussiansToUbm(), NnetChainCombiner::Combine(), NnetCombiner::Combine(), kaldi::nnet2::CombineNnets(), kaldi::nnet2::CombineNnetsA(), FullGmm::ComponentPosteriors(), DiagGmm::ComponentPosteriors(), SpectrogramComputer::Compute(), kaldi::ComputeAndSubtractMean(), OnlineNaturalGradient::ComputeEt(), OnlinePreconditioner::ComputeEt(), kaldi::ComputeFeatureNormalizingTransform(), OnlineGenericBaseFeature< C >::ComputeFeatures(), AmSgmm2::ComputePerFrameVars(), AmSgmm2::ComputePerSpkDerivedVars(), EbwAmSgmm2Updater::ComputePhoneVecStats(), OnlineCmvn::ComputeStatsForFrame(), FmllrRawAccs::ConvertToSimpleStats(), kaldi::ConvolveSignals(), DiagGmmNormal::CopyFromDiagGmm(), FullGmm::CopyFromDiagGmm(), DiagGmm::CopyFromDiagGmm(), FullGmmNormal::CopyFromFullGmm(), FullGmm::CopyFromFullGmm(), DiagGmm::CopyFromFullGmm(), DiagGmmNormal::CopyToDiagGmm(), FullGmmNormal::CopyToFullGmm(), CuVectorBase< Real >::CopyToVec(), kaldi::CuVectorUnitTestCopyCross2(), kaldi::Debias(), DiscriminativeExampleSplitter::DoExcise(), kaldi::EBWUpdateGaussian(), DecodableNnetSimple::EnsureFrameIsComputed(), OnlinePitchFeatureImpl::ExtractFrame(), kaldi::ExtractObjectRange(), kaldi::ExtractRowRangeWithPadding(), kaldi::ExtractWaveformRemainder(), FastNnetCombiner::FastNnetCombiner(), kaldi::FFTbasedBlockConvolveSignals(), kaldi::FFTbasedConvolveSignals(), kaldi::FilterMatrixRows(), FullGmm::GetComponentMean(), FullGmm::GetCovarsAndMeans(), kaldi::GetFeatureMeanAndVariance(), OnlineGenericBaseFeature< C >::GetFrame(), OnlineMatrixFeature::GetFrame(), OnlineCmvn::GetFrame(), OnlineTransform::GetFrame(), OnlineCacheFeature::GetFrame(), IvectorExtractor::GetIvectorDistribution(), RegtreeFmllrDiagGmm::GetLogDets(), LogisticRegression::GetLogPosteriors(), FullGmm::GetMeans(), NnetChainCombiner::GetNormalizedWeights(), NnetCombiner::GetNormalizedWeights(), LogisticRegression::GetObjfAndGrad(), DecodableNnetSimple::GetOutputForFrame(), DecodableNnetSimpleLooped::GetOutputForFrame(), SentenceAveragingComponent::GetParams(), NnetChainCombiner::GetParamsDeriv(), NnetCombiner::GetParamsDeriv(), OnlineCmvn::GetState(), AmSgmm2::GetSubstateMean(), NnetChainCombiner::GetUnnormalizedWeightsDeriv(), NnetCombiner::GetUnnormalizedWeightsDeriv(), AmSgmm2::GetVarScaledSubstateSpeakerMean(), NnetChainCombiner::GetWeights(), NnetCombiner::GetWeights(), kaldi::GpsrBasic(), kaldi::GpsrBB(), kaldi::GpsrGradient(), kaldi::GpsrObjective(), FmllrDiagGmmAccs::InitSingleFrameStats(), kaldi::IsmoothStatsDiagGmm(), IvectorExtractor::IvectorExtractor(), kaldi::LinearCgd(), FullGmm::LogLikelihoods(), DiagGmm::LogLikelihoods(), DiagGmm::LogLikelihoodsPreselect(), DecodableAmDiagGmmUnmapped::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), main(), DiagGmm::merged_components_logdet(), FullGmm::MergedComponentsLogdet(), DiagGmm::MergeKmeans(), SoftmaxComponent::MixUp(), Vector< BaseFloat >::operator=(), OnlinePreconditionerSimple::PreconditionDirections(), OnlineNaturalGradientSimple::PreconditionDirections(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradient::PreconditionDirectionsInternal(), OnlinePreconditioner::PreconditionDirectionsInternal(), kaldi::nnet3::ProcessFile(), kaldi::nnet2::ProcessFile(), FullGmmNormal::Rand(), kaldi::RealFftInefficient(), OptimizeLbfgs< Real >::Restart(), kaldi::ReverseFrames(), DiagGmm::SetComponentInvVar(), FullGmm::SetInvCovars(), Sgmm2PerSpkDerivedVars::SetSpeakerVector(), FullGmm::SetWeights(), DiagGmm::SetWeights(), kaldi::SlidingWindowCmnInternal(), kaldi::SolveQuadraticProblem(), SpMatrix< Real >::TopEigs(), Plda::TransformIvector(), kaldi::UnitTestAddDiagVecMat(), kaldi::UnitTestComplexFft(), kaldi::UnitTestCuVectorCopyFromVec(), kaldi::UnitTestDiagGmm(), UnitTestEstimateLda(), UnitTestFullGmm(), kaldi::UnitTestIoCross(), kaldi::UnitTestPower(), kaldi::UnitTestPowerAbs(), UnitTestReadWave(), kaldi::UnitTestRealFft(), kaldi::UnitTestRegtreeFmllrDiagGmm(), kaldi::UnitTestSimpleForVec(), kaldi::UnitTestSplitRadixComplexFft(), kaldi::UnitTestSplitRadixComplexFft2(), kaldi::UnitTestSplitRadixRealFft(), kaldi::UnitTestSubvector(), FmllrRawAccs::Update(), kaldi::UpdateEbwDiagGmm(), kaldi::UpdateEbwWeightsDiagGmm(), MleSgmm2SpeakerAccs::UpdateNoU(), PldaUnsupervisedAdaptor::UpdatePlda(), IvectorExtractorStats::UpdateProjection(), IvectorExtractorStats::UpdateVariances(), IvectorExtractorStats::UpdateWeight(), MleSgmm2SpeakerAccs::UpdateWithU(), VectorRandomizer::Value(), Vector< BaseFloat >::Vector(), ConstantComponent::Vectorize(), PerElementScaleComponent::Vectorize(), PerElementOffsetComponent::Vectorize(), ConstantFunctionComponent::Vectorize(), and NonlinearComponent::Write().

227  {
228  KALDI_ASSERT(Dim() == v.Dim());
229  if (data_ != v.data_) {
230  std::memcpy(this->data_, v.data_, dim_ * sizeof(Real));
231  }
232 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void CopyFromVec ( const VectorBase< OtherReal > &  v)

Copy data from another vector of different type (double vs. float)

Definition at line 255 of file kaldi-vector.cc.

References VectorBase< Real >::Data(), data_, VectorBase< Real >::Dim(), rnnlm::i, and KALDI_ASSERT.

255  {
256  KALDI_ASSERT(dim_ == other.Dim());
257  Real * __restrict__ ptr = data_;
258  const OtherReal * __restrict__ other_ptr = other.Data();
259  for (MatrixIndexT i = 0; i < dim_; i++)
260  ptr[i] = other_ptr[i];
261 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyFromVec ( const CuVectorBase< OtherReal > &  v)

Copy from CuVector. This is defined in ../cudamatrix/cu-vector.h.

Definition at line 349 of file cu-vector.h.

349  {
350  cu.CopyToVec(this);
351 }
void CopyRowFromMat ( const MatrixBase< Real > &  M,
MatrixIndexT  row 
)

Extracts a row of the matrix M.

Could also do this with this->Copy(M[row]).

Definition at line 400 of file kaldi-vector.cc.

References data_, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::RowData().

Referenced by RegtreeFmllrDiagGmmAccs::AccumulateForGaussian(), RegtreeFmllrDiagGmmAccs::AccumulateForGmm(), DiagGmm::GetComponentMean(), DiagGmm::GetComponentVariance(), LdaEstimate::GetStats(), main(), UnitTestEstimateDiagGmm(), kaldi::UnitTestEstimateMmieDiagGmm(), kaldi::UnitTestPosteriors(), kaldi::UnitTestRow(), and kaldi::UnitTestSpliceRows().

400  {
401  KALDI_ASSERT(row < mat.NumRows());
402  KALDI_ASSERT(dim_ == mat.NumCols());
403  const Real *mat_row = mat.RowData(row);
404  memcpy(data_, mat_row, sizeof(Real)*dim_);
405 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyRowFromMat ( const MatrixBase< OtherReal > &  M,
MatrixIndexT  row 
)

Extracts a row of the matrix M with type conversion.

Definition at line 409 of file kaldi-vector.cc.

References data_, rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::RowData().

409  {
410  KALDI_ASSERT(row < mat.NumRows());
411  KALDI_ASSERT(dim_ == mat.NumCols());
412  const OtherReal *mat_row = mat.RowData(row);
413  for (MatrixIndexT i = 0; i < dim_; i++)
414  data_[i] = static_cast<Real>(mat_row[i]);
415 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
template void CopyRowFromSp ( const SpMatrix< OtherReal > &  S,
MatrixIndexT  row 
)

Extracts a row of the symmetric matrix S.

Definition at line 424 of file kaldi-vector.cc.

References PackedMatrix< Real >::Data(), data_, rnnlm::i, KALDI_ASSERT, PackedMatrix< Real >::NumCols(), and PackedMatrix< Real >::NumRows().

Referenced by CompressedAffineXformStats::CopyFromAffineXformStats().

424  {
425  KALDI_ASSERT(row < sp.NumRows());
426  KALDI_ASSERT(dim_ == sp.NumCols());
427 
428  const OtherReal *sp_data = sp.Data();
429 
430  sp_data += (row*(row+1)) / 2; // takes us to beginning of this row.
431  MatrixIndexT i;
432  for (i = 0; i < row; i++) // copy consecutive elements.
433  data_[i] = static_cast<Real>(*(sp_data++));
434  for(; i < dim_; ++i, sp_data += i)
435  data_[i] = static_cast<Real>(*sp_data);
436 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyRowsFromMat ( const MatrixBase< Real > &  M)

Performs a row stack of the matrix M.

Definition at line 341 of file kaldi-vector.cc.

References MatrixBase< Real >::Data(), data_, rnnlm::i, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), MatrixBase< Real >::RowData(), and MatrixBase< Real >::Stride().

Referenced by BasisFmllrAccus::AccuGradientScatter(), FmllrSgmm2Accs::AccumulateForFmllrSubspace(), kaldi::CuVectorUnitTestCopyFromMat(), FmllrRawAccs::GetAuxf(), LinearTransform::GetGradient(), LinearTransform::GetParams(), kaldi::nnet1::MomentStatistics(), kaldi::nnet2::PerturbTrainingExample(), LogisticRegression::TrainParameters(), kaldi::UnitTestSpliceRows(), and LstmNonlinearityComponent::Vectorize().

341  {
342  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
343 
344  Real *inc_data = data_;
345  const MatrixIndexT cols = mat.NumCols(), rows = mat.NumRows();
346 
347  if (mat.Stride() == mat.NumCols()) {
348  memcpy(inc_data, mat.Data(), cols*rows*sizeof(Real));
349  } else {
350  for (MatrixIndexT i = 0; i < rows; i++) {
351  // copy the data to the propper position
352  memcpy(inc_data, mat.RowData(i), cols * sizeof(Real));
353  // set new copy position
354  inc_data += cols;
355  }
356  }
357 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyRowsFromMat ( const MatrixBase< OtherReal > &  M)

Definition at line 361 of file kaldi-vector.cc.

References data_, rnnlm::i, rnnlm::j, KALDI_ASSERT, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and MatrixBase< Real >::RowData().

361  {
362  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
363  Real *vec_data = data_;
364  const MatrixIndexT cols = mat.NumCols(),
365  rows = mat.NumRows();
366 
367  for (MatrixIndexT i = 0; i < rows; i++) {
368  const OtherReal *mat_row = mat.RowData(i);
369  for (MatrixIndexT j = 0; j < cols; j++) {
370  vec_data[j] = static_cast<Real>(mat_row[j]);
371  }
372  vec_data += cols;
373  }
374 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyRowsFromMat ( const CuMatrixBase< Real > &  M)

The following is implemented in ../cudamatrix/cu-matrix.cc.

Definition at line 2393 of file cu-matrix.cc.

References CuMatrixBase< Real >::Data(), data_, KALDI_ASSERT, CuMatrixBase< Real >::Mat(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::RowData(), and CuMatrixBase< Real >::Stride().

2393  {
2394  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
2395 #if HAVE_CUDA == 1
2396  if (CuDevice::Instantiate().Enabled()) {
2397  CuTimer tim;
2398  if (mat.Stride() == mat.NumCols()) {
2399  cudaMemcpy(data_, mat.Data(), sizeof(Real)*dim_, cudaMemcpyDeviceToHost);
2400  } else {
2401  // we could definitely do better than the following.
2402  Real* vec_data = data_;
2403  for (MatrixIndexT r = 0; r < mat.NumRows(); r++) {
2404  cudaMemcpy(vec_data, mat.RowData(r), sizeof(Real) * mat.NumCols(),
2405  cudaMemcpyDeviceToHost);
2406  vec_data += mat.NumCols();
2407  }
2408  }
2409  CuDevice::Instantiate().AccuProfile("CuVectorBase::CopyRowsFromMat", tim);
2410  } else
2411 #endif
2412  {
2413  CopyRowsFromMat(mat.Mat());
2414  }
2415 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void CopyRowsFromMat(const MatrixBase< Real > &M)
Performs a row stack of the matrix M.
Real* Data ( )
inline

Returns a pointer to the start of the vector's data.

Definition at line 68 of file kaldi-vector.h.

Referenced by kaldi::AccCmvnStats(), SpMatrix< Real >::AddDiagVec(), MatrixBase< Real >::AddDiagVecMat(), SpMatrix< Real >::AddMat2Sp(), SpMatrix< Real >::AddMat2Vec(), MatrixBase< Real >::AddMatDiagVec(), VectorBase< Real >::AddMatSvec(), VectorBase< Real >::AddMatVec(), kaldi::AddOuterProductPlusMinus(), VectorBase< Real >::AddSpVec(), SparseVector< Real >::AddToVec(), VectorBase< Real >::AddVec(), SpMatrix< Real >::AddVec2(), SpMatrix< Real >::AddVec2Sp(), MatrixBase< Real >::AddVecToCols(), MatrixBase< Real >::AddVecToRows(), MatrixBase< Real >::AddVecVec(), SpMatrix< Real >::AddVecVec(), PitchInterpolator::Backtrace(), kaldi::ComplexFft(), kaldi::ComplexFftRecursive(), kaldi::ComplexFt(), kaldi::nnet3::ComponentDotProducts(), SpectrogramComputer::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), PlpComputer::Compute(), PitchFrameInfo::ComputeBacktraces(), OnlineNaturalGradient::ComputeEt(), OnlinePreconditioner::ComputeEt(), kaldi::ComputeLpc(), kaldi::ComputeVadEnergy(), MatrixBase< Real >::CopyColFromVec(), MatrixBase< Real >::CopyColsFromVec(), CompressedMatrix::CopyColToVec(), MatrixBase< Real >::CopyDiagFromVec(), SparseVector< Real >::CopyElementsToVec(), SparseMatrix< Real >::CopyElementsToVec(), CuVectorBase< Real >::CopyFromVec(), PackedMatrix< Real >::CopyFromVec(), VectorBase< Real >::CopyFromVec(), MatrixBase< Real >::CopyRowFromVec(), MatrixBase< Real >::CopyRowsFromVec(), CuMatrixBase< Real >::CopyRowsFromVec(), CompressedMatrix::CopyRowToVec(), CuVectorBase< Real >::CopyToVec(), VectorBase< Real >::DivElements(), kaldi::FFTbasedBlockConvolveSignals(), kaldi::FFTbasedConvolveSignals(), FullGmm::GaussianSelection(), DiagGmm::GaussianSelection(), AmSgmm2::GaussianSelection(), FullGmm::GaussianSelectionPreselect(), DiagGmm::GaussianSelectionPreselect(), MatrixBase< Real >::LapackGesvd(), SoftmaxComponent::MixUp(), VectorBase< Real >::MulElements(), SpMatrix< Real >::Qr(), kaldi::nnet3::ReadVectorAsChar(), kaldi::RealFft(), kaldi::SelectLags(), AmSgmm2::SplitSubstatesInGroup(), SubVector< Real >::SubVector(), kaldi::nnet3::SummarizeVector(), SpMatrix< Real >::Tridiagonalize(), kaldi::UnitTestEigSp(), kaldi::UnitTestPldaEstimation(), kaldi::UnitTestSimpleForMat(), kaldi::UnitTestSplitRadixComplexFft(), kaldi::UnitTestSplitRadixRealFft(), kaldi::UnitTestSplitRadixRealFftSpeed(), kaldi::UnitTestTopEigs(), kaldi::VecSpVec(), kaldi::VecSvec(), kaldi::VecVec(), kaldi::nnet3::WriteVectorAsChar(), and kaldi::nnet3::time_height_convolution::ZeroBlankRows().

68 { return data_; }
Real * data_
data memory area
Definition: kaldi-vector.h:376
const Real* Data ( ) const
inline

Returns a pointer to the start of the vector's data (const).

Definition at line 71 of file kaldi-vector.h.

71 { return data_; }
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT Dim ( ) const
inline

Returns the dimension of the vector.

Definition at line 62 of file kaldi-vector.h.

Referenced by kaldi::AccCmvnStats(), kaldi::AccCmvnStatsWrapper(), OnlineGenericBaseFeature< C >::AcceptWaveform(), OnlinePitchFeatureImpl::AcceptWaveform(), NnetLdaStatsAccumulator::AccStatsFromOutput(), LdaEstimate::Accumulate(), AccumFullGmm::AccumulateForComponent(), AccumDiagGmm::AccumulateForComponent(), FmllrRawAccs::AccumulateForGmm(), kaldi::AccumulateForUtterance(), AccumDiagGmm::AccumulateFromDiag(), MlltAccs::AccumulateFromPosteriors(), HldaAccsDiagGmm::AccumulateFromPosteriors(), AccumFullGmm::AccumulateFromPosteriors(), AccumDiagGmm::AccumulateFromPosteriors(), MleAmSgmm2Accs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), FmllrDiagGmmAccs::AccumulateFromPosteriorsPreselect(), AccumulateMultiThreadedClass::AccumulateMultiThreadedClass(), VectorRandomizer::AddData(), SpMatrix< Real >::AddDiagVec(), MatrixBase< Real >::AddDiagVecMat(), SpMatrix< Real >::AddMat2Vec(), MatrixBase< Real >::AddMatDiagVec(), Nnet::AddNnet(), kaldi::nnet3::AddNnetComponents(), kaldi::AddNoise(), kaldi::AddOuterProductPlusMinus(), PldaUnsupervisedAdaptor::AddStats(), SparseVector< Real >::AddToVec(), SpMatrix< Real >::AddVec2(), SpMatrix< Real >::AddVec2Sp(), MatrixBase< Real >::AddVecToCols(), MatrixBase< Real >::AddVecToRows(), kaldi::AddVectorsOfUnequalLength(), kaldi::AddVectorsWithOffset(), MatrixBase< Real >::AddVecVec(), SpMatrix< Real >::AddVecVec(), DecodableNnetSimpleLooped::AdvanceChunk(), kaldi::nnet2::AppendDiscriminativeExamples(), kaldi::AppendVector(), kaldi::AppendVectorToFeats(), kaldi::ApplyAffineTransform(), VectorBase< Real >::ApplyFloor(), SpMatrix< Real >::ApplyFloor(), ApplyFmllrXform(), VectorBase< Real >::ApplyLogAndCopy(), Fmpe::ApplyProjection(), Fmpe::ApplyProjectionReverse(), AssertEqual(), kaldi::nnet2::AverageConstPart(), MleAmSgmm2Accs::Check(), NnetDiscriminativeSupervision::CheckDim(), NnetChainSupervision::CheckDim(), IvectorExtractorStats::CheckDims(), MleSgmm2SpeakerAccs::Clear(), kaldi::nnet2::CombineNnets(), kaldi::nnet2::CombineNnetsA(), IvectorExtractorStats::CommitStatsForM(), MleAmSgmm2Accs::CommitStatsForSpk(), kaldi::ComplexFft(), kaldi::ComplexFftRecursive(), kaldi::ComplexFt(), kaldi::nnet3::ComponentDotProducts(), Nnet::ComponentDotProducts(), FullGmm::ComponentLogLikelihood(), DiagGmm::ComponentLogLikelihood(), AmSgmm2::ComponentLogLikes(), DiagGmm::ComponentPosteriors(), SpectrogramComputer::Compute(), MelBanks::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), OfflineFeatureTpl< F >::Compute(), PlpComputer::Compute(), kaldi::ComputeAndProcessKaldiPitch(), PitchFrameInfo::ComputeBacktraces(), FastNnetCombiner::ComputeCurrentNnet(), kaldi::ComputeEarlyReverbEnergy(), OnlineNaturalGradient::ComputeEt(), OnlinePreconditioner::ComputeEt(), AmSgmm2::ComputeFmllrPreXform(), AmSgmm2::ComputeGammaI(), kaldi::ComputeGconsts(), FullGmm::ComputeGconsts(), DiagGmm::ComputeGconsts(), AmSgmm2::ComputeHsmFromModel(), kaldi::ComputeKaldiPitch(), kaldi::ComputeKaldiPitchFirstPass(), kaldi::ComputeLifterCoeffs(), kaldi::ComputeLocalCost(), kaldi::ComputeLpc(), kaldi::ComputeNccf(), kaldi::nnet2::ComputeObjfAndGradient(), FastNnetCombiner::ComputeObjfAndGradient(), AmSgmm2::ComputePerFrameVars(), AmSgmm2::ComputePerSpkDerivedVars(), kaldi::ComputePowerSpectrum(), OnlineNaturalGradient::ComputeWt1(), OnlinePreconditioner::ComputeWt1(), OnlineNaturalGradient::ComputeZt(), OnlinePreconditioner::ComputeZt(), MatrixBase< Real >::Cond(), kaldi::ConvolveSignals(), MatrixBase< Real >::CopyColFromVec(), MatrixBase< Real >::CopyColsFromVec(), CompressedMatrix::CopyColToVec(), MatrixBase< Real >::CopyDiagFromVec(), SparseVector< Real >::CopyElementsToVec(), SparseMatrix< Real >::CopyElementsToVec(), DiagGmmNormal::CopyFromDiagGmm(), DiagGmm::CopyFromDiagGmm(), CuVectorBase< Real >::CopyFromVec(), PackedMatrix< Real >::CopyFromVec(), VectorBase< Real >::CopyFromVec(), MatrixBase< Real >::CopyRowFromVec(), MatrixBase< Real >::CopyRowsFromVec(), CuMatrixBase< Real >::CopyRowsFromVec(), CompressedMatrix::CopyRowToVec(), DiagGmmNormal::CopyToDiagGmm(), FullGmmNormal::CopyToFullGmm(), CuVectorBase< Real >::CopyToVec(), kaldi::nnet1::CountCorrectFramesWeighted(), kaldi::cu::CpuBackpropLstmNonlinearity(), kaldi::CreateEigenvalueMatrix(), CuVector< BaseFloat >::CuVector(), FmllrRawAccs::DataHasChanged(), FmllrDiagGmmAccs::DataHasChanged(), kaldi::Debias(), DeltaFeatures::DeltaFeatures(), MatrixBase< Real >::DestructiveSvd(), Plda::Dim(), OnlineTransform::Dim(), kaldi::Dither(), VectorBase< Real >::DivElements(), DecodableNnetSimple::DoNnetComputation(), kaldi::EBWUpdateGaussian(), SpMatrix< Real >::Eig(), kaldi::ElementwiseProductOfFft(), Sgmm2PerSpkDerivedVars::Empty(), FeatureTransformEstimate::EstimateInternal(), kaldi::EstimateSgmm2FmllrSubspace(), Xent::Eval(), Mse::Eval(), OnlinePitchFeatureImpl::ExtractFrame(), kaldi::ExtractObjectRange(), kaldi::ExtractWaveformRemainder(), kaldi::ExtractWindow(), FastNnetCombiner::FastNnetCombiner(), kaldi::FFTbasedBlockConvolveSignals(), kaldi::FFTbasedConvolveSignals(), AmSgmm2::GaussianSelection(), DiagGmm::Generate(), FullGmm::GetComponentMean(), DiagGmm::GetComponentMean(), DiagGmm::GetComponentVariance(), kaldi::GetFeatureMeanAndVariance(), OnlineCmvn::GetFrame(), OnlineProcessPitch::GetFrame(), OnlineSpliceFrames::GetFrame(), OnlineDeltaFeature::GetFrame(), OnlineAppendFeature::GetFrame(), OnlinePitchFeatureImpl::GetFrame(), ParametricRelu::GetGradient(), LinearTransform::GetGradient(), AffineTransform::GetGradient(), RecurrentComponent::GetGradient(), ParallelComponent::GetGradient(), LstmProjected::GetGradient(), ConvolutionalComponent::GetGradient(), Convolutional2DComponent::GetGradient(), BlstmProjected::GetGradient(), AddShift::GetGradient(), Rescale::GetGradient(), EigenvalueDecomposition< Real >::GetImagEigenvalues(), NnetChainCombiner::GetInitialParameters(), NnetCombiner::GetInitialParameters(), OnlineIvectorEstimationStats::GetIvector(), DecodableNnetSimple::GetIvectorDim(), DecodableNnetSimpleLooped::GetIvectorDim(), IvectorExtractor::GetIvectorDistribution(), Nnet::GetLearningRates(), RegtreeFmllrDiagGmm::GetLogDets(), LogisticRegression::GetLogPosteriors(), NnetChainCombiner::GetNnetParameters(), NnetCombiner::GetNnetParameters(), kaldi::GetOccs(), ParametricRelu::GetParams(), LinearTransform::GetParams(), AffineTransform::GetParams(), RecurrentComponent::GetParams(), ParallelComponent::GetParams(), FramePoolingComponent::GetParams(), MultiBasisComponent::GetParams(), LstmProjected::GetParams(), ConvolutionalComponent::GetParams(), SentenceAveragingComponent::GetParams(), Convolutional2DComponent::GetParams(), BlstmProjected::GetParams(), AddShift::GetParams(), Rescale::GetParams(), NnetChainCombiner::GetParamsDeriv(), NnetCombiner::GetParamsDeriv(), IvectorExtractor::GetPriorAuxf(), EigenvalueDecomposition< Real >::GetRealEigenvalues(), kaldi::GetSplitTargets(), AmSgmm2::GetSubstateMean(), AmSgmm2::GetSubstateSpeakerMean(), NnetChainCombiner::GetSumToOnePenalty(), NnetCombiner::GetSumToOnePenalty(), AmSgmm2::GetVarScaledSubstateSpeakerMean(), NnetChainCombiner::GetWeights(), NnetCombiner::GetWeights(), NnetChainCombiner::GetWeightsDeriv(), NnetCombiner::GetWeightsDeriv(), kaldi::GpsrBasic(), kaldi::GpsrBasicAlpha(), kaldi::GpsrBB(), kaldi::GpsrCalcLinearCoeff(), kaldi::GpsrGradient(), kaldi::GpsrObjective(), AmNnet::Info(), AmNnetSimple::Info(), AmNnet::Init(), FramePoolingComponent::InitData(), InitRand(), kaldi::InitRand(), FmllrRawAccs::InitSingleFrameStats(), Sgmm2FmllrGlobalParams::IsEmpty(), OnlineIvectorEstimationStats::IvectorDim(), kaldi::nnet2::KlDivergence(), kaldi::nnet3::KlDivergence(), MatrixBase< Real >::LapackGesvd(), NnetDiscriminativeUpdater::LatticeComputations(), FullGmm::LogLikelihoods(), DiagGmm::LogLikelihoods(), FullGmm::LogLikelihoodsPreselect(), DiagGmm::LogLikelihoodsPreselect(), DecodableAmDiagGmmRegtreeFmllr::LogLikelihoodZeroBased(), DecodableAmDiagGmmUnmapped::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), main(), TransitionModel::MapUpdate(), TransitionModel::MapUpdateShared(), DiagGmm::merged_components_logdet(), FullGmm::MergedComponentsLogdet(), kaldi::nnet3::MergeSupervision(), SoftmaxComponent::MixUp(), kaldi::MleDiagGmmUpdate(), TransitionModel::MleUpdate(), TransitionModel::MleUpdateShared(), kaldi::nnet1::MomentStatistics(), MatrixBase< Real >::MulColsVec(), VectorBase< Real >::MulElements(), MatrixBase< Real >::MulRowsVec(), FullGmm::NumGauss(), DiagGmmNormal::NumGauss(), DiagGmm::NumGauss(), OnlinePitchFeatureImpl::OnlinePitchFeatureImpl(), FisherComputationClass::operator()(), CuVector< BaseFloat >::operator=(), Vector< BaseFloat >::operator=(), OptimizeLbfgs< Real >::OptimizeLbfgs(), PdfPrior::PdfPrior(), kaldi::Preemphasize(), TransitionModel::Print(), kaldi::nnet2::PrintPriorDiagnostics(), kaldi::nnet3::PrintPriorDiagnostics(), kaldi::nnet3::PrintVectorPerUpdatableComponent(), IvectorExtractorStats::PriorDiagnostics(), DeltaFeatures::Process(), ShiftedDeltaFeatures::Process(), NnetChainTrainer::ProcessOutputs(), NnetDiscriminativeTrainer::ProcessOutputs(), kaldi::ProcessWindow(), NnetDiscriminativeUpdater::Propagate(), kaldi::unittest::RandDiagGaussFeatures(), kaldi::unittest::RandFullGaussFeatures(), MleAmSgmm2Accs::Read(), FullGmm::Read(), VectorBase< Real >::Read(), Vector< Real >::Read(), PermuteComponent::Read(), kaldi::ReadData(), kaldi::RealFft(), kaldi::RealFftInefficient(), OnlinePitchFeatureImpl::RecomputeBacktraces(), ArbitraryResample::Resample(), LinearResample::Resample(), FullGmmNormal::Resize(), FullGmm::Resize(), DiagGmmNormal::Resize(), DiagGmm::Resize(), Sgmm2PerFrameDerivedVars::Resize(), Nnet::ScaleComponents(), DiagGmm::SetComponentInvVar(), DiagGmm::SetComponentMean(), ArbitraryResample::SetIndexes(), Nnet::SetLearningRates(), PitchFrameInfo::SetNccfPov(), AmNnetSimple::SetNnet(), Nnet::SetParams(), ParametricRelu::SetParams(), LinearTransform::SetParams(), AffineTransform::SetParams(), RecurrentComponent::SetParams(), ParallelComponent::SetParams(), ConvolutionalComponent::SetParams(), Convolutional2DComponent::SetParams(), LstmProjected::SetParams(), AddShift::SetParams(), BlstmProjected::SetParams(), Rescale::SetParams(), kaldi::nnet2::SetPriors(), kaldi::nnet3::SetPriors(), AmNnet::SetPriors(), AmNnetSimple::SetPriors(), LinearResample::SetRemainder(), Sgmm2PerSpkDerivedVars::SetSpeakerVector(), FullGmm::SetWeights(), DiagGmm::SetWeights(), kaldi::SolveQuadraticProblem(), kaldi::SortSvd(), AmSgmm2::SplitSubstates(), SubVector< Real >::SubVector(), kaldi::nnet3::SummarizeVector(), MatrixBase< Real >::SymPosSemiDefEig(), kaldi::nnet3::TestNnetDecodable(), SpMatrix< Real >::TopEigs(), RegtreeFmllrDiagGmm::TransformFeature(), Plda::TransformIvector(), kaldi::TypeOneUsage(), kaldi::TypeTwoUsage(), kaldi::UnitTestCuMatrixSetRandUniform(), kaldi::UnitTestDelay(), UnitTestEstimateLda(), kaldi::UnitTestFFTbasedBlockConvolution(), kaldi::UnitTestFFTbasedConvolution(), UnitTestLinearResample(), UnitTestLinearResample2(), kaldi::UnitTestPieces(), kaldi::UnitTestPldaEstimation(), UnitTestReadWave(), kaldi::UnitTestReplaceValue(), kaldi::UnitTestSetRandUniform(), kaldi::UnitTestSimple(), UnitTestSimple(), kaldi::UnitTestSvdNodestroy(), TimeHeightConvolutionComponent::UnVectorize(), AffineComponent::UnVectorize(), BlockAffineComponent::UnVectorize(), RepeatedAffineComponent::UnVectorize(), ConvolutionComponent::UnVectorize(), LstmNonlinearityComponent::UnVectorize(), CompositeComponent::UnVectorize(), kaldi::nnet3::UnVectorizeNnet(), MleSgmm2SpeakerAccs::Update(), MleSgmm2SpeakerAccs::UpdateNoU(), NnetChainTrainer::UpdateParamsWithMaxChange(), NnetTrainer::UpdateParamsWithMaxChange(), PldaUnsupervisedAdaptor::UpdatePlda(), OnlinePitchFeatureImpl::UpdateRemainder(), EbwAmSgmm2Updater::UpdateSubstateWeights(), MleSgmm2SpeakerAccs::UpdateWithU(), RegtreeFmllrDiagGmm::Validate(), kaldi::VecMatVec(), kaldi::VecSpVec(), kaldi::VecSvec(), Vector< BaseFloat >::Vector(), TimeHeightConvolutionComponent::Vectorize(), AffineComponent::Vectorize(), BlockAffineComponent::Vectorize(), RepeatedAffineComponent::Vectorize(), ConvolutionComponent::Vectorize(), LstmNonlinearityComponent::Vectorize(), CompositeComponent::Vectorize(), kaldi::nnet3::VectorizeNnet(), kaldi::VectorToPosteriorEntry(), kaldi::VecVec(), AccumDiagGmm::Write(), and kaldi::nnet3::WriteVectorAsChar().

62 { return dim_; }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
void DivElements ( const VectorBase< Real > &  v)

Divide element-by-element by a vector.

Definition at line 996 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, rnnlm::i, and KALDI_ASSERT.

Referenced by DiagGmm::GetComponentMean(), main(), and kaldi::SolveQuadraticProblem().

996  {
997  KALDI_ASSERT(dim_ == v.dim_);
998  for (MatrixIndexT i = 0; i < dim_; i++) {
999  data_[i] /= v.data_[i];
1000  }
1001 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void DivElements ( const VectorBase< OtherReal > &  v)

Divide element-by-element by a vector of different type.

Definition at line 1005 of file kaldi-vector.cc.

References VectorBase< Real >::Data(), data_, VectorBase< Real >::Dim(), rnnlm::i, and KALDI_ASSERT.

1005  {
1006  KALDI_ASSERT(dim_ == v.Dim());
1007  const OtherReal *other_ptr = v.Data();
1008  for (MatrixIndexT i = 0; i < dim_; i++) {
1009  data_[i] /= other_ptr[i];
1010  }
1011 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
bool IsZero ( Real  cutoff = 1.0e-06) const

Returns true if matrix is all zeros.

Definition at line 292 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by MleAmSgmm2Accs::Check(), MleAmSgmm2Accs::CommitStatsForSpk(), main(), and kaldi::UnitTestSimpleForVec().

292  {
293  Real abs_max = 0.0;
294  for (MatrixIndexT i = 0; i < Dim(); i++)
295  abs_max = std::max(std::abs(data_[i]), abs_max);
296  return (abs_max <= cutoff);
297 }
int32 MatrixIndexT
Definition: matrix-common.h:96
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
KALDI_DISALLOW_COPY_AND_ASSIGN ( VectorBase< Real >  )
protected
Real LogSumExp ( Real  prune = -1.0) const

Returns log(sum(exp())) without exp overflow If prune > 0.0, ignores terms less than the max - prune.

[Note: in future, if prune = 0.0, it will take the max. For now, use -1 if you don't want it to prune.]

Definition at line 757 of file kaldi-vector.cc.

References data_, kaldi::Exp(), rnnlm::i, kaldi::kLogZeroDouble, kaldi::kLogZeroFloat, kaldi::kMinLogDiffDouble, kaldi::kMinLogDiffFloat, and kaldi::Log().

Referenced by IvectorExtractor::GetAcousticAuxfWeight(), LogisticRegression::GetLogPosteriors(), FullGmm::LogLikelihood(), DiagGmm::LogLikelihood(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), main(), kaldi::UnitTestDiagGmm(), UnitTestFullGmm(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdateW(), MleAmSgmm2Updater::UpdateWGetStats(), and MleSgmm2SpeakerAccs::UpdateWithU().

757  {
758  Real sum;
759  if (sizeof(sum) == 8) sum = kLogZeroDouble;
760  else sum = kLogZeroFloat;
761  Real max_elem = Max(), cutoff;
762  if (sizeof(Real) == 4) cutoff = max_elem + kMinLogDiffFloat;
763  else cutoff = max_elem + kMinLogDiffDouble;
764  if (prune > 0.0 && max_elem - prune > cutoff) // explicit pruning...
765  cutoff = max_elem - prune;
766 
767  double sum_relto_max_elem = 0.0;
768 
769  for (MatrixIndexT i = 0; i < dim_; i++) {
770  BaseFloat f = data_[i];
771  if (f >= cutoff)
772  sum_relto_max_elem += Exp(f - max_elem);
773  }
774  return max_elem + Log(sum_relto_max_elem);
775 }
double Exp(double x)
Definition: kaldi-math.h:83
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
float BaseFloat
Definition: kaldi-types.h:29
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
double Log(double x)
Definition: kaldi-math.h:100
static const double kMinLogDiffDouble
Definition: kaldi-math.h:124
static const float kMinLogDiffFloat
Definition: kaldi-math.h:125
Real * data_
data memory area
Definition: kaldi-vector.h:376
const float kLogZeroFloat
Definition: kaldi-math.h:128
const double kLogZeroDouble
Definition: kaldi-math.h:129
Real Max ( ) const

Returns the maximum value of any element, or -infinity for the empty vector.

Definition at line 578 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by NnetDiscriminativeSupervision::CheckDim(), NnetChainSupervision::CheckDim(), kaldi::nnet3::ComputeAccuracy(), kaldi::ComputeEarlyReverbEnergy(), kaldi::CuVectorUnitTestMax(), OptimizeLbfgs< Real >::DoStep(), FeatureTransformEstimate::EstimateInternal(), AmNnetSimple::Info(), kaldi::InitGmmFromRandomFrames(), SpMatrix< Real >::LimitCond(), main(), CuVectorBase< Real >::Max(), SpMatrix< Real >::MaxAbsEig(), kaldi::MaxAbsolute(), kaldi::nnet1::MomentStatistics(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlineNaturalGradient::PreconditionDirectionsInternal(), OnlinePreconditioner::PreconditionDirectionsInternal(), kaldi::nnet3::PrintPriorDiagnostics(), kaldi::nnet2::PrintPriorDiagnostics(), OnlineNaturalGradient::SelfTest(), OnlinePreconditioner::SelfTest(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), SpMatrix< Real >::SymPosSemiDefEig(), kaldi::TestVectorToPosteriorEntry(), kaldi::UnitTestMaxAbsEig(), kaldi::UnitTestMaxMin(), kaldi::UnitTestSparseVectorMax(), kaldi::UnitTestVectorMax(), and IvectorExtractorStats::UpdatePrior().

578  {
579  Real ans = - std::numeric_limits<Real>::infinity();
580  const Real *data = data_;
581  MatrixIndexT i, dim = dim_;
582  for (i = 0; i + 4 <= dim; i += 4) {
583  Real a1 = data[i], a2 = data[i+1], a3 = data[i+2], a4 = data[i+3];
584  if (a1 > ans || a2 > ans || a3 > ans || a4 > ans) {
585  Real b1 = (a1 > a2 ? a1 : a2), b2 = (a3 > a4 ? a3 : a4);
586  if (b1 > ans) ans = b1;
587  if (b2 > ans) ans = b2;
588  }
589  }
590  for (; i < dim; i++)
591  if (data[i] > ans) ans = data[i];
592  return ans;
593 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
Real Max ( MatrixIndexT index) const

Returns the maximum value of any element, and the associated index.

Error if vector is empty.

Definition at line 596 of file kaldi-vector.cc.

References data_, rnnlm::i, and KALDI_ERR.

596  {
597  if (dim_ == 0) KALDI_ERR << "Empty vector";
598  Real ans = - std::numeric_limits<Real>::infinity();
599  MatrixIndexT index = 0;
600  const Real *data = data_;
601  MatrixIndexT i, dim = dim_;
602  for (i = 0; i + 4 <= dim; i += 4) {
603  Real a1 = data[i], a2 = data[i+1], a3 = data[i+2], a4 = data[i+3];
604  if (a1 > ans || a2 > ans || a3 > ans || a4 > ans) {
605  if (a1 > ans) { ans = a1; index = i; }
606  if (a2 > ans) { ans = a2; index = i + 1; }
607  if (a3 > ans) { ans = a3; index = i + 2; }
608  if (a4 > ans) { ans = a4; index = i + 3; }
609  }
610  }
611  for (; i < dim; i++)
612  if (data[i] > ans) { ans = data[i]; index = i; }
613  *index_out = index;
614  return ans;
615 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ERR
Definition: kaldi-error.h:127
Real * data_
data memory area
Definition: kaldi-vector.h:376
Real Min ( ) const

Returns the minimum value of any element, or +infinity for the empty vector.

Definition at line 618 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by OnlinePitchFeatureImpl::AcceptWaveform(), kaldi::ApplyHessianXformToGradient(), kaldi::ApplyInvHessianXformToChange(), NnetDiscriminativeSupervision::CheckDim(), NnetChainSupervision::CheckDim(), kaldi::CuVectorUnitTestMin(), OptimizeLbfgs< Real >::DoStep(), kaldi::EBWUpdateGaussian(), kaldi::GetFeatureMeanAndVariance(), PldaEstimator::GetOutput(), AmNnet::Info(), AmNnetSimple::Info(), main(), SpMatrix< Real >::MaxAbsEig(), kaldi::MaxAbsolute(), CuVectorBase< Real >::Min(), MatrixBase< BaseFloat >::MinSingularValue(), kaldi::nnet1::MomentStatistics(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlinePitchFeatureImpl::RecomputeBacktraces(), OnlineNaturalGradient::SelfTest(), OnlinePreconditioner::SelfTest(), Nnet::SetLearningRates(), SpMatrix< Real >::SymPosSemiDefEig(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), kaldi::UnitTestFloorUnit(), kaldi::UnitTestMaxAbsEig(), kaldi::UnitTestMaxMin(), kaldi::UnitTestVectorMin(), and IvectorExtractorStats::UpdatePrior().

618  {
619  Real ans = std::numeric_limits<Real>::infinity();
620  const Real *data = data_;
621  MatrixIndexT i, dim = dim_;
622  for (i = 0; i + 4 <= dim; i += 4) {
623  Real a1 = data[i], a2 = data[i+1], a3 = data[i+2], a4 = data[i+3];
624  if (a1 < ans || a2 < ans || a3 < ans || a4 < ans) {
625  Real b1 = (a1 < a2 ? a1 : a2), b2 = (a3 < a4 ? a3 : a4);
626  if (b1 < ans) ans = b1;
627  if (b2 < ans) ans = b2;
628  }
629  }
630  for (; i < dim; i++)
631  if (data[i] < ans) ans = data[i];
632  return ans;
633 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
Real Min ( MatrixIndexT index) const

Returns the minimum value of any element, and the associated index.

Error if vector is empty.

Definition at line 636 of file kaldi-vector.cc.

References data_, rnnlm::i, and KALDI_ERR.

636  {
637  if (dim_ == 0) KALDI_ERR << "Empty vector";
638  Real ans = std::numeric_limits<Real>::infinity();
639  MatrixIndexT index = 0;
640  const Real *data = data_;
641  MatrixIndexT i, dim = dim_;
642  for (i = 0; i + 4 <= dim; i += 4) {
643  Real a1 = data[i], a2 = data[i+1], a3 = data[i+2], a4 = data[i+3];
644  if (a1 < ans || a2 < ans || a3 < ans || a4 < ans) {
645  if (a1 < ans) { ans = a1; index = i; }
646  if (a2 < ans) { ans = a2; index = i + 1; }
647  if (a3 < ans) { ans = a3; index = i + 2; }
648  if (a4 < ans) { ans = a4; index = i + 3; }
649  }
650  }
651  for (; i < dim; i++)
652  if (data[i] < ans) { ans = data[i]; index = i; }
653  *index_out = index;
654  return ans;
655 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_ERR
Definition: kaldi-error.h:127
Real * data_
data memory area
Definition: kaldi-vector.h:376
void MulElements ( const VectorBase< OtherReal > &  v)

Multipy element-by-element by another vector of different type.

Definition at line 970 of file kaldi-vector.cc.

References VectorBase< Real >::Data(), data_, VectorBase< Real >::Dim(), rnnlm::i, and KALDI_ASSERT.

970  {
971  KALDI_ASSERT(dim_ == v.Dim());
972  const OtherReal *other_ptr = v.Data();
973  for (MatrixIndexT i = 0; i < dim_; i++) {
974  data_[i] *= other_ptr[i];
975  }
976 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void MulTp ( const TpMatrix< Real > &  M,
const MatrixTransposeType  trans 
)

Multiplies this vector by lower-triangular marix: *this <– *this *M.

Definition at line 151 of file kaldi-vector.cc.

References kaldi::cblas_Xtpmv(), PackedMatrix< Real >::Data(), data_, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

Referenced by VectorBase< Real >::AddTpVec(), FullGmm::Perturb(), FullGmm::Split(), kaldi::UnitTestCuVectorMulTp(), and kaldi::UnitTestMulTp().

152  {
153  KALDI_ASSERT(M.NumRows() == dim_);
154  cblas_Xtpmv(trans,M.Data(),M.NumRows(),data_,1);
155 }
void cblas_Xtpmv(MatrixTransposeType trans, const float *Mdata, const int num_rows, float *y, const int y_inc)
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real Norm ( Real  p) const

Compute the p-th norm of the vector.

Definition at line 516 of file kaldi-vector.cc.

References data_, rnnlm::i, KALDI_ASSERT, VectorBase< Real >::Norm(), and VectorBase< Real >::Scale().

Referenced by OptimizeLbfgs< Real >::AcceptStep(), VectorBase< Real >::ApproxEqual(), OptimizeLbfgs< Real >::ComputeHifNeeded(), IvectorExtractor::GetIvectorDistribution(), PldaEstimator::GetOutput(), kaldi::GpsrBasic(), kaldi::GpsrBB(), main(), VectorBase< Real >::Norm(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OptimizeLbfgs< Real >::Restart(), Plda::TransformIvector(), kaldi::UnitTestGpsr(), kaldi::UnitTestLbfgs(), kaldi::UnitTestLinearCgd(), kaldi::UnitTestNorm(), kaldi::UnitTestSimpleForVec(), IvectorExtractorStats::UpdatePrior(), and IvectorExtractTask::~IvectorExtractTask().

516  {
517  KALDI_ASSERT(p >= 0.0);
518  Real sum = 0.0;
519  if (p == 0.0) {
520  for (MatrixIndexT i = 0; i < dim_; i++)
521  if (data_[i] != 0.0) sum += 1.0;
522  return sum;
523  } else if (p == 1.0) {
524  for (MatrixIndexT i = 0; i < dim_; i++)
525  sum += std::abs(data_[i]);
526  return sum;
527  } else if (p == 2.0) {
528  for (MatrixIndexT i = 0; i < dim_; i++)
529  sum += data_[i] * data_[i];
530  return std::sqrt(sum);
531  } else if (p == std::numeric_limits<Real>::infinity()){
532  for (MatrixIndexT i = 0; i < dim_; i++)
533  sum = std::max(sum, std::abs(data_[i]));
534  return sum;
535  } else {
536  Real tmp;
537  bool ok = true;
538  for (MatrixIndexT i = 0; i < dim_; i++) {
539  tmp = pow(std::abs(data_[i]), p);
540  if (tmp == HUGE_VAL) // HUGE_VAL is what pow returns on error.
541  ok = false;
542  sum += tmp;
543  }
544  tmp = pow(sum, static_cast<Real>(1.0/p));
545  KALDI_ASSERT(tmp != HUGE_VAL); // should not happen here.
546  if (ok) {
547  return tmp;
548  } else {
549  Real maximum = this->Max(), minimum = this->Min(),
550  max_abs = std::max(maximum, -minimum);
551  KALDI_ASSERT(max_abs > 0); // Or should not have reached here.
552  Vector<Real> tmp(*this);
553  tmp.Scale(1.0 / max_abs);
554  return tmp.Norm(p) * max_abs;
555  }
556  }
557 }
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real operator() ( MatrixIndexT  i) const
inline

Indexing operator (const).

Definition at line 74 of file kaldi-vector.h.

74  {
75  KALDI_PARANOID_ASSERT(static_cast<UnsignedMatrixIndexT>(i) <
76  static_cast<UnsignedMatrixIndexT>(dim_));
77  return *(data_ + i);
78  }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_PARANOID_ASSERT(cond)
Definition: kaldi-error.h:182
Real * data_
data memory area
Definition: kaldi-vector.h:376
Real& operator() ( MatrixIndexT  i)
inline

Indexing operator (non-const).

Definition at line 81 of file kaldi-vector.h.

81  {
82  KALDI_PARANOID_ASSERT(static_cast<UnsignedMatrixIndexT>(i) <
83  static_cast<UnsignedMatrixIndexT>(dim_));
84  return *(data_ + i);
85  }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
#define KALDI_PARANOID_ASSERT(cond)
Definition: kaldi-error.h:182
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT RandCategorical ( ) const

This function returns a random index into this vector, chosen with probability proportional to the corresponding element.

Requires that this->Min() >= 0 and this->Sum() > 0.

Definition at line 318 of file kaldi-vector.cc.

References data_, rnnlm::i, KALDI_ASSERT, and kaldi::RandUniform().

Referenced by FullGmmNormal::Rand(), and kaldi::UnitTestRandCategorical().

318  {
319  kaldi::RandomState rstate;
320  Real sum = this->Sum();
321  KALDI_ASSERT(this->Min() >= 0.0 && sum > 0.0);
322  Real r = RandUniform(&rstate) * sum;
323  Real *data = this->data_;
324  MatrixIndexT dim = this->dim_;
325  Real running_sum = 0.0;
326  for (MatrixIndexT i = 0; i < dim; i++) {
327  running_sum += data[i];
328  if (r < running_sum) return i;
329  }
330  return dim_ - 1; // Should only happen if RandUniform()
331  // returns exactly 1, or due to roundoff.
332 }
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
Definition: kaldi-math.h:151
Real Sum() const
Returns sum of the elements.
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
SubVector<Real> Range ( const MatrixIndexT  o,
const MatrixIndexT  l 
)
inline

Returns a sub-vector of a vector (a range of elements).

Parameters
o[in] Origin, 0 < o < Dim()
l[in] Length 0 < l < Dim()-o
Returns
A SubVector object that aliases the data of the Vector object. See SubVector class for details

Definition at line 92 of file kaldi-vector.h.

Referenced by OnlineGenericBaseFeature< C >::AcceptWaveform(), RegtreeFmllrDiagGmmAccs::AccumulateForGaussian(), RegtreeFmllrDiagGmmAccs::AccumulateForGmm(), FmllrRawAccs::AccumulateFromPosteriors(), FmllrSgmm2Accs::AccumulateFromPosteriors(), VectorRandomizer::AddData(), kaldi::AddVectorsOfUnequalLength(), kaldi::AddVectorsWithOffset(), kaldi::AppendVector(), Fmpe::ApplyProjection(), Fmpe::ApplyProjectionReverse(), FmllrRawAccs::CommitSingleFrameStats(), FmllrDiagGmmAccs::CommitSingleFrameStats(), MelBanks::Compute(), PlpComputer::Compute(), BasisFmllrEstimate::ComputeAmDiagPrecond(), kaldi::ComputeEarlyReverbEnergy(), Sgmm2Project::ComputeLdaTransform(), FmllrRawAccs::DataHasChanged(), OnlinePitchFeatureImpl::ExtractFrame(), kaldi::ExtractObjectRange(), CompressedAffineXformStats::ExtractOneG(), kaldi::ExtractWindow(), kaldi::FFTbasedBlockConvolveSignals(), kaldi::FFTbasedConvolveSignals(), FmllrDiagGmmAccs::FmllrDiagGmmAccs(), kaldi::FmllrInnerUpdate(), ParametricRelu::GetGradient(), Nnet::GetGradient(), AffineTransform::GetGradient(), RecurrentComponent::GetGradient(), ParallelComponent::GetGradient(), LstmProjected::GetGradient(), ConvolutionalComponent::GetGradient(), Convolutional2DComponent::GetGradient(), BlstmProjected::GetGradient(), IvectorExtractor::GetIvectorDistribution(), Nnet::GetParams(), ParametricRelu::GetParams(), AffineTransform::GetParams(), RecurrentComponent::GetParams(), ParallelComponent::GetParams(), FramePoolingComponent::GetParams(), MultiBasisComponent::GetParams(), LstmProjected::GetParams(), ConvolutionalComponent::GetParams(), Convolutional2DComponent::GetParams(), BlstmProjected::GetParams(), kaldi::GpsrCalcLinearCoeff(), kaldi::GpsrGradient(), kaldi::GpsrObjective(), FramePoolingComponent::InitData(), FmllrRawAccs::InitSingleFrameStats(), main(), MelBanks::MelBanks(), kaldi::MergeFullGmm(), SoftmaxComponent::MixUp(), kaldi::RealFftInefficient(), Nnet::SetParams(), ParametricRelu::SetParams(), AffineTransform::SetParams(), RecurrentComponent::SetParams(), ParallelComponent::SetParams(), MultiBasisComponent::SetParams(), ConvolutionalComponent::SetParams(), Convolutional2DComponent::SetParams(), LstmProjected::SetParams(), BlstmProjected::SetParams(), FullGmm::Split(), DiagGmm::Split(), SpMatrix< Real >::TopEigs(), kaldi::UnitTestCuVectorSum(), UnitTestLinearResample(), kaldi::UnitTestRange(), UnitTestVectorRandomizer(), TimeHeightConvolutionComponent::UnVectorize(), Nnet::UnVectorize(), RepeatedAffineComponent::UnVectorize(), AffineComponent::UnVectorize(), BlockAffineComponent::UnVectorize(), ConvolutionComponent::UnVectorize(), VectorRandomizer::Value(), TimeHeightConvolutionComponent::Vectorize(), RepeatedAffineComponent::Vectorize(), AffineComponent::Vectorize(), BlockAffineComponent::Vectorize(), and ConvolutionComponent::Vectorize().

92  {
93  return SubVector<Real>(*this, o, l);
94  }
const SubVector<Real> Range ( const MatrixIndexT  o,
const MatrixIndexT  l 
) const
inline

Returns a const sub-vector of a vector (a range of elements).

Parameters
o[in] Origin, 0 < o < Dim()
l[in] Length 0 < l < Dim()-o
Returns
A SubVector object that aliases the data of the Vector object. See SubVector class for details

Definition at line 101 of file kaldi-vector.h.

102  {
103  return SubVector<Real>(*this, o, l);
104  }
void Read ( std::istream &  in,
bool  binary,
bool  add = false 
)

Reads from C++ stream (option to add to existing contents).

Throws exception on failure

Definition at line 1071 of file kaldi-vector.cc.

References VectorBase< Real >::Dim(), KALDI_ERR, and Vector< Real >::Read().

Referenced by kaldi::operator>>().

1071  {
1072  if (add) {
1073  Vector<Real> tmp(Dim());
1074  tmp.Read(is, binary, false); // read without adding.
1075  if (this->Dim() != tmp.Dim()) {
1076  KALDI_ERR << "VectorBase::Read, size mismatch " << this->Dim()<<" vs. "<<tmp.Dim();
1077  }
1078  this->AddVec(1.0, tmp);
1079  return;
1080  } // now assume add == false.
1081 
1082  // In order to avoid rewriting this, we just declare a Vector and
1083  // use it to read the data, then copy.
1084  Vector<Real> tmp;
1085  tmp.Read(is, binary, false);
1086  if (tmp.Dim() != Dim())
1087  KALDI_ERR << "VectorBase<Real>::Read, size mismatch "
1088  << Dim() << " vs. " << tmp.Dim();
1089  CopyFromVec(tmp);
1090 }
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
#define KALDI_ERR
Definition: kaldi-error.h:127
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void ReplaceValue ( Real  orig,
Real  changed 
)

Set each element to y = (x == orig ? changed : x).

Definition at line 961 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by kaldi::UnitTestCuVectorReplaceValue(), and kaldi::UnitTestReplaceValue().

961  {
962  Real *data = data_;
963  for (MatrixIndexT i = 0; i < dim_; i++)
964  if (data[i] == orig) data[i] = changed;
965 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
void Scale ( Real  alpha)

Multiplies all elements by this constant.

Definition at line 948 of file kaldi-vector.cc.

References kaldi::cblas_Xscal(), and data_.

Referenced by FmllrSgmm2Accs::AccumulateForFmllrSubspace(), FmllrDiagGmmAccs::AccumulateForGmm(), FmllrRawAccs::AccumulateForGmm(), RegtreeMllrDiagGmmAccs::AccumulateForGmm(), RegtreeFmllrDiagGmmAccs::AccumulateForGmm(), AccumAmDiagGmm::AccumulateForGmmTwofeats(), kaldi::AddNoise(), kaldi::AlignUtteranceWrapper(), RegressionTree::BuildTree(), kaldi::ClusterGaussiansToUbm(), PlpComputer::Compute(), kaldi::ComputeAmGmmFeatureDeriv(), Fmpe::ComputeC(), kaldi::ComputeFeatureNormalizingTransform(), AmSgmm2::ComputeFmllrPreXform(), NnetChainCombiner::ComputeObjfAndDerivFromNnet(), NnetCombiner::ComputeObjfAndDerivFromNnet(), EbwAmSgmm2Updater::ComputePhoneVecStats(), FmllrRawAccs::ConvertToSimpleStats(), kaldi::CuVectorUnitTestScale(), kaldi::Debias(), DeltaFeatures::DeltaFeatures(), MatrixBase< Real >::DestructiveSvd(), kaldi::EBWUpdateGaussian(), BasisFmllrEstimate::EstimateFmllrBasis(), kaldi::FFTbasedBlockConvolveSignals(), kaldi::FFTbasedConvolveSignals(), kaldi::FmllrInnerUpdate(), kaldi::GenRandStats(), IvectorExtractor::GetAcousticAuxfVariance(), kaldi::GetFeatDeriv(), kaldi::GetFeatureMeanAndVariance(), PldaEstimator::GetOutput(), LdaEstimate::GetStats(), kaldi::GpsrBB(), NonlinearComponent::Info(), LstmNonlinearityComponent::Info(), BatchNormComponent::Info(), ConstantComponent::InitFromConfig(), ConstantFunctionComponent::InitFromConfig(), kaldi::unittest::InitRandDiagGmm(), kaldi::unittest::InitRandFullGmm(), kaldi::InitRandomGmm(), kaldi::IsmoothStatsDiagGmm(), main(), kaldi::MapDiagGmmUpdate(), FullGmm::Merge(), DiagGmm::merged_components_logdet(), FullGmm::MergedComponentsLogdet(), DiagGmm::MergeKmeans(), kaldi::MleDiagGmmUpdate(), kaldi::MleFullGmmUpdate(), TransitionModel::MleUpdate(), TransitionModel::MleUpdateShared(), VectorBase< Real >::Norm(), PdfPrior::PdfPrior(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlineNaturalGradient::PreconditionDirectionsInternal(), OnlinePreconditioner::PreconditionDirectionsInternal(), DiscriminativeObjectiveInfo::Print(), IvectorExtractorStats::PriorDiagnostics(), rand_diag_gmm(), kaldi::RealFft(), OnlinePitchFeatureImpl::RecomputeBacktraces(), DiagGmm::RemoveComponent(), FullGmm::RemoveComponent(), LdaEstimate::Scale(), IvectorExtractorUtteranceStats::Scale(), AccumFullGmm::Scale(), AccumDiagGmm::Scale(), VectorClusterable::Scale(), OnlineIvectorEstimationStats::Scale(), ShiftedDeltaFeatures::ShiftedDeltaFeatures(), kaldi::SlidingWindowCmnInternal(), AccumDiagGmm::SmoothStats(), kaldi::TestClusterKMeansVector(), kaldi::nnet3::TestNnetComponentUpdatable(), kaldi::TestVectorToPosteriorEntry(), SpMatrix< Real >::TopEigs(), Plda::TransformIvector(), kaldi::UnitTestAddDiagMat2(), kaldi::UnitTestAddDiagMatMat(), kaldi::UnitTestAddDiagVecMat(), kaldi::nnet2::UnitTestAmNnet(), kaldi::UnitTestComplexFft(), kaldi::UnitTestComplexFt(), kaldi::UnitTestCuVectorAddColSumMat(), kaldi::UnitTestCuVectorAddColSumMatLarge(), kaldi::UnitTestCuVectorAddRowSumMat(), kaldi::UnitTestCuVectorAddRowSumMatLarge(), kaldi::UnitTestCuVectorAddVec(), UnitTestEstimateDiagGmm(), UnitTestEstimateFullGmm(), UnitTestEstimateLda(), kaldi::UnitTestEstimateMmieDiagGmm(), kaldi::UnitTestIo(), kaldi::UnitTestIoCross(), kaldi::UnitTestLbfgs(), kaldi::nnet2::UnitTestNnetDecodable(), kaldi::UnitTestNorm(), kaldi::UnitTestPldaEstimation(), kaldi::nnet2::UnitTestPreconditionDirectionsOnline(), kaldi::nnet3::UnitTestPreconditionDirectionsOnline(), kaldi::UnitTestRealFft(), kaldi::UnitTestSimpleForVec(), kaldi::UnitTestSplitRadixComplexFft(), kaldi::UnitTestSplitRadixRealFft(), kaldi::UnitTestVector(), HldaAccsDiagGmm::Update(), NnetChainTrainer::UpdateParamsWithMaxChange(), NnetTrainer::UpdateParamsWithMaxChange(), IvectorExtractorStats::UpdatePrior(), EbwAmSgmm2Updater::UpdateSubstateWeights(), EbwAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateW(), MleSgmm2SpeakerAccs::UpdateWithU(), VectorClusterable::VectorClusterable(), NonlinearComponent::Write(), and LstmNonlinearityComponent::Write().

948  {
949  cblas_Xscal(dim_, alpha, data_, 1);
950 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
void cblas_Xscal(const int N, const float alpha, float *data, const int inc)
Real * data_
data memory area
Definition: kaldi-vector.h:376
void Set ( Real  f)

Set all members of a vector to a specified value.

Definition at line 335 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by VectorBase< Real >::AddColSumMat(), VectorBase< Real >::AddRowSumMat(), MatrixBase< Real >::AddVecToCols(), MatrixBase< Real >::AddVecToRows(), kaldi::nnet2::CombineNnetsA(), kaldi::ComputeLocalCost(), PitchInterpolator::Forward(), kaldi::nnet2::GetInitialModel(), FastNnetCombiner::GetInitialModel(), NnetChainCombiner::GetInitialParameters(), NnetCombiner::GetInitialParameters(), FastNnetCombiner::GetInitialParams(), kaldi::nnet2::GetInitialScaleParams(), LogisticRegression::GetLogPosteriors(), kaldi::nnet2::GetUpdateDirection(), kaldi::GpsrCalcLinearCoeff(), OnlinePreconditionerSimple::InitDefault(), OnlineNaturalGradientSimple::InitDefault(), OnlineNaturalGradient::InitDefault(), OnlinePreconditioner::InitDefault(), main(), kaldi::ReadData(), AmNnet::ResizeOutputLayer(), VectorClusterable::SetZero(), kaldi::SlidingWindowCmnInternal(), Plda::SmoothWithinClassCovariance(), VectorClusterable::Sub(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), TestSgmm2PreXform(), kaldi::TrainOneIter(), kaldi::UnitTestAddVecToCols(), kaldi::UnitTestAddVecToRows(), UnitTestRegressionTree(), kaldi::UnitTestSimpleForVec(), and kaldi::nnet3::time_height_convolution::ZeroBlankRows().

335  {
336  // Why not use memset here?
337  for (MatrixIndexT i = 0; i < dim_; i++) { data_[i] = f; }
338 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
void SetRandn ( )

Set vector to random normally-distributed noise.

Definition at line 300 of file kaldi-vector.cc.

References data_, rnnlm::i, kaldi::RandGauss(), and kaldi::RandGauss2().

Referenced by kaldi::CuVectorUnitTestAddVecVec(), ConstantComponent::InitFromConfig(), ConstantFunctionComponent::InitFromConfig(), main(), LogisticRegression::MixUp(), SoftmaxComponent::MixUp(), PitchInterpolator::MultiplyObsProb(), FullGmm::Perturb(), kaldi::nnet2::PerturbTrainingExample(), FullGmmNormal::Rand(), FullGmm::Split(), kaldi::TestClusterKMeansVector(), kaldi::TestClusterUtilsVector(), kaldi::nnet3::TestNnetDecodable(), kaldi::TestVectorToPosteriorEntry(), SpMatrix< Real >::TopEigs(), kaldi::UnitTestAddDiagMat2(), kaldi::UnitTestAddDiagMatMat(), kaldi::UnitTestAddDiagVecMat(), kaldi::UnitTestAddMatDiagVec(), kaldi::UnitTestAddOuterProductPlusMinus(), kaldi::UnitTestAddVec2Sp(), kaldi::UnitTestAddVecCross(), kaldi::UnitTestAddVecToCols(), kaldi::UnitTestAddVecToColsSpeed(), kaldi::UnitTestAddVecToRows(), kaldi::UnitTestAddVecToRowsSpeed(), kaldi::UnitTestAddVecVec(), kaldi::nnet2::UnitTestAmNnet(), kaldi::UnitTestBackpropLstmNonlinearity(), kaldi::UnitTestCopyRowsAndCols(), kaldi::UnitTestCuMatrixAddVecVec(), kaldi::UnitTestCuSpMatrixAddVec2(), kaldi::UnitTestCuVectorAddTp(), kaldi::UnitTestCuVectorCopyFromVec(), kaldi::UnitTestCuVectorMulTp(), kaldi::UnitTestCuVectorReplaceValue(), kaldi::UnitTestDotprod(), kaldi::UnitTestFFTbasedBlockConvolution(), kaldi::UnitTestFFTbasedConvolution(), kaldi::UnitTestFloorCeiling(), kaldi::UnitTestFloorChol(), kaldi::UnitTestInnerProd(), kaldi::UnitTestIo(), kaldi::UnitTestIoCross(), kaldi::UnitTestLbfgs(), kaldi::UnitTestLinearCgd(), UnitTestLinearResample(), UnitTestLinearResample2(), kaldi::UnitTestMaxMin(), kaldi::UnitTestMul(), kaldi::UnitTestMulTp(), kaldi::nnet2::UnitTestNnetDecodable(), kaldi::UnitTestNorm(), kaldi::UnitTestPldaEstimation(), kaldi::nnet2::UnitTestPreconditionDirectionsOnline(), kaldi::nnet3::UnitTestPreconditionDirectionsOnline(), kaldi::UnitTestRange(), kaldi::UnitTestRemoveRow(), kaldi::UnitTestReplaceValue(), kaldi::UnitTestResize(), kaldi::UnitTestScale(), kaldi::UnitTestSger(), kaldi::UnitTestSimpleForMat(), kaldi::UnitTestSolve(), kaldi::UnitTestSpAddDiagVec(), kaldi::UnitTestSpAddVecVec(), kaldi::UnitTestSparseVectorAddToVec(), kaldi::UnitTestSparseVectorMax(), kaldi::UnitTestSparseVectorSum(), kaldi::UnitTestSparseVectorVecSvec(), kaldi::UnitTestSubvector(), kaldi::nnet3::UnitTestSummarizeVector(), kaldi::UnitTestTriVecSolver(), kaldi::UnitTestVecmul(), kaldi::UnitTestVector(), kaldi::UnitTestVectorMax(), and kaldi::UnitTestVectorMin().

300  {
301  kaldi::RandomState rstate;
302  MatrixIndexT last = (Dim() % 2 == 1) ? Dim() - 1 : Dim();
303  for (MatrixIndexT i = 0; i < last; i += 2) {
304  kaldi::RandGauss2(data_ + i, data_ + i +1, &rstate);
305  }
306  if (Dim() != last) data_[last] = static_cast<Real>(kaldi::RandGauss(&rstate));
307 }
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
int32 MatrixIndexT
Definition: matrix-common.h:96
void RandGauss2(float *a, float *b, RandomState *state)
Definition: kaldi-math.cc:140
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void SetRandUniform ( )

Sets to numbers uniformly distributed on (0,1)

Definition at line 310 of file kaldi-vector.cc.

References data_, rnnlm::i, and kaldi::RandUniform().

310  {
311  kaldi::RandomState rstate;
312  for (MatrixIndexT i = 0; i < Dim(); i++) {
313  *(data_+i) = RandUniform(&rstate);
314  }
315 }
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
Definition: kaldi-math.h:151
int32 MatrixIndexT
Definition: matrix-common.h:96
Real * data_
data memory area
Definition: kaldi-vector.h:376
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void SetZero ( )

Set vector to all zeros.

Definition at line 287 of file kaldi-vector.cc.

References data_.

Referenced by MinimumBayesRisk::AccStats(), MleSgmm2SpeakerAccs::Clear(), FmllrDiagGmmAccs::CommitSingleFrameStats(), MleAmSgmm2Accs::CommitStatsForSpk(), MfccComputer::Compute(), PlpComputer::Compute(), OptimizeLbfgs< Real >::ComputeNewDirection(), kaldi::ConvolveSignals(), SparseVector< Real >::CopyElementsToVec(), kaldi::DiagGmmToStats(), kaldi::EBWUpdateGaussian(), OnlinePitchFeatureImpl::ExtractFrame(), kaldi::FFTbasedBlockConvolveSignals(), FullGmm::GetComponentMean(), OnlineIvectorEstimationStats::GetIvector(), NnetChainCombiner::GetNnetParameters(), NnetCombiner::GetNnetParameters(), NnetChainCombiner::GetParamsDeriv(), NnetCombiner::GetParamsDeriv(), NnetChainCombiner::GetSumToOnePenalty(), NnetCombiner::GetSumToOnePenalty(), kaldi::GpsrBasic(), FmllrRawAccs::InitSingleFrameStats(), FmllrDiagGmmAccs::InitSingleFrameStats(), main(), FullGmm::Merge(), FullGmm::MergePreselect(), DeltaFeatures::Process(), ShiftedDeltaFeatures::Process(), AccumFullGmm::Read(), LdaEstimate::Read(), AccumFullGmm::SetZero(), FmllrRawAccs::SetZero(), AccumDiagGmm::SetZero(), CuMatrixBase< Real >::SetZeroAboveDiag(), kaldi::UnitTestCuVectorAddColSumMat(), kaldi::UnitTestCuVectorAddColSumMatLarge(), kaldi::UnitTestCuVectorAddRowSumMat(), kaldi::UnitTestCuVectorAddRowSumMatLarge(), and LdaEstimate::ZeroAccumulators().

287  {
288  std::memset(data_, 0, dim_ * sizeof(Real));
289 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
void Sigmoid ( const VectorBase< Real > &  src)

Sets each element of *this to the sigmoid function of the corresponding element of "src".

Definition at line 923 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, kaldi::Exp(), rnnlm::i, and KALDI_ASSERT.

Referenced by MatrixBase< Real >::Sigmoid().

923  {
924  KALDI_ASSERT(dim_ == src.dim_);
925  for (MatrixIndexT i = 0; i < dim_; i++) {
926  Real x = src.data_[i];
927  // We aim to avoid floating-point overflow here.
928  if (x > 0.0) {
929  x = 1.0 / (1.0 + Exp(-x));
930  } else {
931  Real ex = Exp(x);
932  x = ex / (ex + 1.0);
933  }
934  data_[i] = x;
935  }
936 }
double Exp(double x)
Definition: kaldi-math.h:83
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT SizeInBytes ( ) const
inline

Returns the size in memory of the vector, in bytes.

Definition at line 65 of file kaldi-vector.h.

65 { return (dim_*sizeof(Real)); }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
void Solve ( const TpMatrix< Real > &  M,
const MatrixTransposeType  trans 
)

If trans == kNoTrans, solves M x = b, where b is the value of *this at input and x is the value of *this at output.

If trans == kTrans, solves M' x = b. Does not test for M being singular or near-singular, so test it before calling this routine.

Definition at line 158 of file kaldi-vector.cc.

References kaldi::cblas_Xtpsv(), PackedMatrix< Real >::Data(), data_, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().

Referenced by kaldi::UnitTestTriVecSolver().

159  {
160  KALDI_ASSERT(M.NumRows() == dim_);
161  cblas_Xtpsv(trans, M.Data(), M.NumRows(), data_, 1);
162 }
void cblas_Xtpsv(MatrixTransposeType trans, const float *Mdata, const int num_rows, float *y, const int y_inc)
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real Sum ( ) const

Returns sum of the elements.

Definition at line 692 of file kaldi-vector.cc.

References data_, and rnnlm::i.

Referenced by OnlinePitchFeatureImpl::AcceptWaveform(), AccumAmDiagGmm::AccumulateFromPosteriors(), FmllrDiagGmmAccs::AccumulateFromPosteriors(), FmllrDiagGmmAccs::AccumulateFromPosteriorsPreselect(), IvectorExtractorStats::AuxfPerFrame(), Nnet::Check(), kaldi::ClusterGaussiansToUbm(), IvectorExtractorStats::CommitStatsForWPoint(), kaldi::nnet3::ComputeAccuracy(), kaldi::ComputeCorrelation(), AmSgmm2::ComputeFmllrPreXform(), NnetChainCombiner::ComputeObjfAndDerivFromNnet(), NnetCombiner::ComputeObjfAndDerivFromNnet(), EbwAmSgmm2Updater::ComputePhoneVecStats(), kaldi::ComputeVadEnergy(), OnlineNaturalGradient::ComputeWt1(), OnlinePreconditioner::ComputeWt1(), kaldi::CuVectorUnitTestCopyDiagFromMat(), Xent::Eval(), Mse::Eval(), DiagGmm::Generate(), kaldi::GenRandStats(), IvectorExtractor::GetAcousticAuxf(), IvectorExtractor::GetAcousticAuxfVariance(), IvectorExtractor::GetAuxf(), IvectorExtractor::GetIvectorDistWeight(), LdaEstimate::GetStats(), AmNnet::Info(), AmNnetSimple::Info(), kaldi::unittest::InitRandDiagGmm(), kaldi::InitRandomGmm(), IvectorExtractorStats::IvectorVarianceDiagnostic(), kaldi::nnet3::KlDivergence(), kaldi::nnet2::KlDivergence(), AffineComponent::LimitRank(), main(), TransitionModel::MapUpdate(), TransitionModel::MapUpdateShared(), kaldi::MleFullGmmUpdate(), TransitionModel::MleUpdate(), TransitionModel::MleUpdateShared(), kaldi::nnet1::MomentStatistics(), IvectorExtractorUtteranceStats::NumFrames(), LimitRankClass::operator()(), PdfPrior::PdfPrior(), BackpropTruncationComponent::PrecomputeIndexes(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradient::PreconditionDirectionsInternal(), OnlinePreconditioner::PreconditionDirectionsInternal(), IvectorExtractorStats::PriorDiagnostics(), kaldi::ProcessWindow(), DiagGmm::RemoveComponent(), FullGmm::RemoveComponent(), MleAmSgmm2Updater::RenormalizeN(), MleAmSgmm2Updater::RenormalizeV(), OnlineNaturalGradient::ReorthogonalizeXt1(), OnlinePreconditioner::ReorthogonalizeXt1(), Xent::Report(), OnlineNaturalGradient::SelfTest(), OnlinePreconditioner::SelfTest(), CuVectorBase< Real >::Sum(), kaldi::nnet3::SummarizeVector(), LdaEstimate::TotCount(), kaldi::TraceMatMat(), kaldi::nnet2::UnitTestAmNnet(), kaldi::UnitTestDiagGmm(), kaldi::UnitTestEigSymmetric(), UnitTestFullGmm(), kaldi::nnet2::UnitTestNnetDecodable(), kaldi::UnitTestPosteriors(), kaldi::UnitTestRandCategorical(), kaldi::UnitTestRange(), kaldi::UnitTestResize(), kaldi::UnitTestSimpleForVec(), kaldi::UnitTestSparseVectorSum(), MleSgmm2SpeakerAccs::Update(), IvectorExtractorStats::Update(), kaldi::UpdateEbwWeightsDiagGmm(), EbwAmSgmm2Updater::UpdateM(), EbwAmSgmm2Updater::UpdateN(), MleSgmm2SpeakerAccs::UpdateNoU(), IvectorExtractorStats::UpdateProjections(), OnlinePitchFeatureImpl::UpdateRemainder(), EbwAmSgmm2Updater::UpdateSubstateWeights(), MleAmSgmm2Updater::UpdateSubstateWeights(), EbwAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateU(), IvectorExtractorStats::UpdateVariances(), EbwAmSgmm2Updater::UpdateVars(), MleAmSgmm2Updater::UpdateVars(), EbwAmSgmm2Updater::UpdateW(), MleAmSgmm2Updater::UpdateW(), IvectorExtractorStats::UpdateWeights(), MleSgmm2SpeakerAccs::UpdateWithU(), and MleAmSgmm2Accs::~MleAmSgmm2Accs().

692  {
693  double sum = 0.0;
694  for (MatrixIndexT i = 0; i < dim_; i++) { sum += data_[i]; }
695  return sum;
696 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
Real SumLog ( ) const

Returns sum of the logs of the elements.

More efficient than just taking log of each. Will return NaN if any elements are negative.

Definition at line 699 of file kaldi-vector.cc.

References data_, rnnlm::i, and kaldi::Log().

Referenced by Plda::LogLikelihoodRatio(), main(), and GaussClusterable::Objf().

699  {
700  double sum_log = 0.0;
701  double prod = 1.0;
702  for (MatrixIndexT i = 0; i < dim_; i++) {
703  prod *= data_[i];
704  // Possible future work (arnab): change these magic values to pre-defined
705  // constants
706  if (prod < 1.0e-10 || prod > 1.0e+10) {
707  sum_log += Log(prod);
708  prod = 1.0;
709  }
710  }
711  if (prod != 1.0) sum_log += Log(prod);
712  return sum_log;
713 }
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
double Log(double x)
Definition: kaldi-math.h:100
Real * data_
data memory area
Definition: kaldi-vector.h:376
void Tanh ( const VectorBase< Real > &  src)

Sets each element of *this to the tanh of the corresponding element of "src".

Definition at line 885 of file kaldi-vector.cc.

References data_, VectorBase< Real >::data_, VectorBase< Real >::dim_, kaldi::Exp(), rnnlm::i, and KALDI_ASSERT.

Referenced by MatrixBase< Real >::Tanh().

885  {
886  KALDI_ASSERT(dim_ == src.dim_);
887  for (MatrixIndexT i = 0; i < dim_; i++) {
888  Real x = src.data_[i];
889  if (x > 0.0) {
890  Real inv_expx = Exp(-x);
891  x = -1.0 + 2.0 / (1.0 + inv_expx * inv_expx);
892  } else {
893  Real expx = Exp(x);
894  x = 1.0 - 2.0 / (1.0 + expx * expx);
895  }
896  data_[i] = x;
897  }
898 }
double Exp(double x)
Definition: kaldi-math.h:83
int32 MatrixIndexT
Definition: matrix-common.h:96
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:378
Real * data_
data memory area
Definition: kaldi-vector.h:376
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Write ( std::ostream &  Out,
bool  binary 
) const

Writes to C++ stream (option to write in binary).

Definition at line 1210 of file kaldi-vector.cc.

References rnnlm::i, KALDI_ASSERT, KALDI_ERR, kaldi::WriteBasicType(), and kaldi::WriteToken().

Referenced by main(), kaldi::UnitTestIo(), kaldi::UnitTestIoCross(), UnitTestRegressionTree(), AmNnet::Write(), NnetExample::Write(), AmNnetSimple::Write(), AccumFullGmm::Write(), LdaEstimate::Write(), Sgmm2FmllrGlobalParams::Write(), Plda::Write(), FullGmm::Write(), TransitionModel::Write(), VectorClusterable::Write(), DiagGmm::Write(), DiscriminativeNnetExample::Write(), IvectorExtractor::Write(), CuVector< Real >::Write(), OnlineIvectorEstimationStats::Write(), IvectorExtractorStats::Write(), NonlinearComponent::Write(), LstmNonlinearityComponent::Write(), and kaldi::nnet3::WriteVectorAsChar().

1210  {
1211  if (!os.good()) {
1212  KALDI_ERR << "Failed to write vector to stream: stream not good";
1213  }
1214  if (binary) {
1215  std::string my_token = (sizeof(Real) == 4 ? "FV" : "DV");
1216  WriteToken(os, binary, my_token);
1217 
1218  int32 size = Dim(); // make the size 32-bit on disk.
1219  KALDI_ASSERT(Dim() == (MatrixIndexT) size);
1220  WriteBasicType(os, binary, size);
1221  os.write(reinterpret_cast<const char*>(Data()), sizeof(Real) * size);
1222  } else {
1223  os << " [ ";
1224  for (MatrixIndexT i = 0; i < Dim(); i++)
1225  os << (*this)(i) << " ";
1226  os << "]\n";
1227  }
1228  if (!os.good())
1229  KALDI_ERR << "Failed to write vector to stream";
1230 }
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ERR
Definition: kaldi-error.h:127
Real * Data()
Returns a pointer to the start of the vector's data.
Definition: kaldi-vector.h:68
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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...
Definition: io-funcs-inl.h:34
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62

Friends And Related Function Documentation

friend class CuVector< Real >
friend

Definition at line 352 of file kaldi-vector.h.

friend class CuVectorBase< Real >
friend

Definition at line 351 of file kaldi-vector.h.

friend class VectorBase< double >
friend

Definition at line 349 of file kaldi-vector.h.

friend class VectorBase< float >
friend

Definition at line 350 of file kaldi-vector.h.

Member Data Documentation


The documentation for this singleton was generated from the following files: