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...
 
void ApplyFloor (Real floor_val, MatrixIndexT *floored_count=nullptr)
 Applies floor to all elements. More...
 
void ApplyCeiling (Real ceil_val, MatrixIndexT *ceiled_count=nullptr)
 Applies ceiling to all elements. 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 40 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 360 of file kaldi-vector.h.

360 {}
VectorBase ( )
inlineexplicitprotected

Empty initializer, corresponds to vector of zero size.

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

363  : data_(NULL), dim_(0) {
365  }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
#define KALDI_ASSERT_IS_FLOATING_TYPE(F)
Definition: kaldi-utils.h:133
Real * data_
data memory area
Definition: kaldi-vector.h:379

Member Function Documentation

void Add ( Real  c)

Add a constant to each element of a vector.

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

References data_, and rnnlm::i.

Referenced by AmSgmm2::ComponentLogLikes(), kaldi::ComputeCorrelation(), OnlinePreconditioner::ComputeZt(), OnlineNaturalGradient::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(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), kaldi::ProcessWindow(), AccumDiagGmm::SmoothStats(), AccumDiagGmm::SmoothWithModel(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdateSubstateWeights(), MleAmSgmm2Updater::UpdateW(), MleAmSgmm2Updater::UpdateWGetStats(), and MleSgmm2SpeakerAccs::UpdateWithU().

953  {
954  for (MatrixIndexT i = 0; i < dim_; i++) {
955  data_[i] += c;
956  }
957 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 737 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().

737  {
738  KALDI_ASSERT(dim_ == M.NumRows());
739  MatrixIndexT num_cols = M.NumCols();
740 
741  // implement the function according to a dimension cutoff for computation efficiency
742  if (num_cols <= 64) {
743  for (MatrixIndexT i = 0; i < dim_; i++) {
744  double sum = 0.0;
745  const Real *src = M.RowData(i);
746  for (MatrixIndexT j = 0; j < num_cols; j++)
747  sum += src[j];
748  data_[i] = alpha * sum + beta * data_[i];
749  }
750  } else {
751  Vector<Real> ones(M.NumCols());
752  ones.Set(1.0);
753  this->AddMatVec(alpha, M, kNoTrans, ones, beta);
754  }
755 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
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:92
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1301 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().

1303  {
1304  if (trans == kNoTrans) {
1305  KALDI_ASSERT(this->dim_ == M.NumRows());
1306  MatrixIndexT rows = this->dim_, cols = M.NumCols(),
1307  mat_stride = M.Stride();
1308  Real *data = this->data_;
1309  const Real *mat_data = M.Data();
1310  for (MatrixIndexT i = 0; i < rows; i++, mat_data += mat_stride, data++)
1311  *data = beta * *data + alpha * cblas_Xdot(cols,mat_data,1,mat_data,1);
1312  } else {
1313  KALDI_ASSERT(this->dim_ == M.NumCols());
1314  MatrixIndexT rows = M.NumRows(), cols = this->dim_,
1315  mat_stride = M.Stride();
1316  Real *data = this->data_;
1317  const Real *mat_data = M.Data();
1318  for (MatrixIndexT i = 0; i < cols; i++, mat_data++, data++)
1319  *data = beta * *data + alpha * cblas_Xdot(rows, mat_data, mat_stride,
1320  mat_data, mat_stride);
1321  }
1322 }
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:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1325 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().

1329  {
1330  MatrixIndexT dim = this->dim_,
1331  M_col_dim = (transM == kTrans ? M.NumRows() : M.NumCols()),
1332  N_row_dim = (transN == kTrans ? N.NumCols() : N.NumRows());
1333  KALDI_ASSERT(M_col_dim == N_row_dim); // this is the dimension we sum over
1334  MatrixIndexT M_row_stride = M.Stride(), M_col_stride = 1;
1335  if (transM == kTrans) std::swap(M_row_stride, M_col_stride);
1336  MatrixIndexT N_row_stride = N.Stride(), N_col_stride = 1;
1337  if (transN == kTrans) std::swap(N_row_stride, N_col_stride);
1338 
1339  Real *data = this->data_;
1340  const Real *Mdata = M.Data(), *Ndata = N.Data();
1341  for (MatrixIndexT i = 0; i < dim; i++, Mdata += M_row_stride, Ndata += N_col_stride, data++) {
1342  *data = beta * *data + alpha * cblas_Xdot(M_col_dim, Mdata, M_col_stride, Ndata, N_row_stride);
1343  }
1344 }
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:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 105 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().

109  {
110  KALDI_ASSERT((trans == kNoTrans && M.NumCols() == v.dim_ && M.NumRows() == dim_)
111  || (trans == kTrans && M.NumRows() == v.dim_ && M.NumCols() == dim_));
112  KALDI_ASSERT(&v != this);
113  Xgemv_sparsevec(trans, M.NumRows(), M.NumCols(), alpha, M.Data(), M.Stride(),
114  v.Data(), 1, beta, data_, 1);
115  return;
116  /*
117  MatrixIndexT this_dim = this->dim_, v_dim = v.dim_,
118  M_stride = M.Stride();
119  Real *this_data = this->data_;
120  const Real *M_data = M.Data(), *v_data = v.data_;
121  if (beta != 1.0) this->Scale(beta);
122  if (trans == kNoTrans) {
123  for (MatrixIndexT i = 0; i < v_dim; i++) {
124  Real v_i = v_data[i];
125  if (v_i == 0.0) continue;
126  // Add to *this, the i'th column of the Matrix, times v_i.
127  cblas_Xaxpy(this_dim, v_i * alpha, M_data + i, M_stride, this_data, 1);
128  }
129  } else { // The transposed case is slightly more efficient, I guess.
130  for (MatrixIndexT i = 0; i < v_dim; i++) {
131  Real v_i = v.data_[i];
132  if (v_i == 0.0) continue;
133  // Add to *this, the i'th row of the Matrix, times v_i.
134  cblas_Xaxpy(this_dim, v_i * alpha,
135  M_data + (i * M_stride), 1, this_data, 1);
136  }
137  }*/
138 }
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:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 92 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(), Plda::ApplyTransform(), 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(), FmllrRawAccs::Update(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), IvectorExtractorStats::UpdatePrior(), MleSgmm2SpeakerAccs::UpdateWithU(), and kaldi::VecMatVec().

96  {
97  KALDI_ASSERT((trans == kNoTrans && M.NumCols() == v.dim_ && M.NumRows() == dim_)
98  || (trans == kTrans && M.NumRows() == v.dim_ && M.NumCols() == dim_));
99  KALDI_ASSERT(&v != this);
100  cblas_Xgemv(trans, M.NumRows(), M.NumCols(), alpha, M.Data(), M.Stride(),
101  v.Data(), 1, beta, data_, 1);
102 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 717 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(), kaldi::EstPca(), LdaEstimate::GetStats(), AmSgmm2::LogLikelihood(), main(), AmSgmm2::SplitSubstatesInGroup(), kaldi::UnitTestAddRowSumMatSpeed(), kaldi::UnitTestCuVectorAddRowSumMat(), kaldi::UnitTestCuVectorAddRowSumMatLarge(), UnitTestEstimateFullGmm(), EbwAmSgmm2Updater::Update(), MleAmSgmm2Updater::Update(), and kaldi::nnet2::UpdateHash().

717  {
718  KALDI_ASSERT(dim_ == M.NumCols());
719  MatrixIndexT num_rows = M.NumRows(), stride = M.Stride(), dim = dim_;
720  Real *data = data_;
721 
722  // implement the function according to a dimension cutoff for computation efficiency
723  if (num_rows <= 64) {
724  cblas_Xscal(dim, beta, data, 1);
725  const Real *m_data = M.Data();
726  for (MatrixIndexT i = 0; i < num_rows; i++, m_data += stride)
727  cblas_Xaxpy(dim, alpha, m_data, 1, data, 1);
728 
729  } else {
730  Vector<Real> ones(M.NumRows());
731  ones.Set(1.0);
732  this->AddMatVec(alpha, M, kTrans, ones, beta);
733  }
734 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
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:92
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 141 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().

144  {
145  KALDI_ASSERT(M.NumRows() == v.dim_ && dim_ == v.dim_);
146  KALDI_ASSERT(&v != this);
147  cblas_Xspmv(alpha, M.NumRows(), M.Data(), v.Data(), 1, beta, data_, 1);
148 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1260 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(), FullGmmNormal::Rand(), kaldi::UnitTestCuVectorAddTp(), kaldi::UnitTestCuVectorAddTpVec(), kaldi::UnitTestMul(), and kaldi::UnitTestTriVecSolver().

1263  {
1264  KALDI_ASSERT(dim_ == v.dim_ && dim_ == M.NumRows());
1265  if (beta == 0.0) {
1266  if (&v != this) CopyFromVec(v);
1267  MulTp(M, trans);
1268  if (alpha != 1.0) Scale(alpha);
1269  } else {
1270  Vector<Real> tmp(v);
1271  tmp.MulTp(M, trans);
1272  if (beta != 1.0) Scale(beta); // *this <-- beta * *this
1273  AddVec(alpha, tmp); // *this += alpha * M * v
1274  }
1275 }
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:381
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 75 of file kaldi-vector.cc.

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

76  {
77  KALDI_ASSERT(dim_ == v.dim_);
78  KALDI_ASSERT(&v != this);
79  cblas_Xaxpy(dim_, alpha, v.Data(), 1, data_, 1);
80 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 84 of file kaldi-vector.cc.

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

85  {
86  KALDI_ASSERT(dim_ == v.dim_);
87  KALDI_ASSERT(&v != this);
88  cblas_Xaxpy(dim_, alpha, v.Data(), 1, data_, 1);
89 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 1041 of file kaldi-vector.cc.

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

Referenced by OptimizeLbfgs< Real >::AcceptStep(), AccumFullGmm::AccumulateFromPosteriors(), FmllrRawAccs::AccumulateFromPosteriors(), AccumDiagGmm::AccumulateFromPosteriors(), MleAmSgmm2Accs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), FmllrDiagGmmAccs::AccumulateFromPosteriorsPreselect(), VectorClusterable::Add(), RestrictedAttentionComponent::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(), PldaEstimator::ComputeObjfPart2(), EbwAmSgmm2Updater::ComputePhoneVecStats(), BasisFmllrEstimate::ComputeTransform(), CompressedAffineXformStats::CopyFromAffineXformStats(), kaldi::Debias(), kaldi::DiagGmmToStats(), kaldi::EBWUpdateGaussian(), kaldi::FmllrInnerUpdate(), kaldi::GenRandStats(), kaldi::GetFeatureMeanAndVariance(), IvectorExtractor::GetIvectorDistribution(), GetLogLikeTest(), 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(), kaldi::SlidingWindowCmnInternal(), Plda::SmoothWithinClassCovariance(), kaldi::SolveQuadraticProblem(), RestrictedAttentionComponent::StoreStats(), 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(), kaldi::UpdateEbwDiagGmm(), EbwAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), PldaUnsupervisedAdaptor::UpdatePlda(), EbwAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateU(), EbwAmSgmm2Updater::UpdateW(), and MleSgmm2SpeakerAccs::UpdateWithU().

1041  {
1042  KALDI_ASSERT(dim_ == v.dim_);
1043  // remove __restrict__ if it causes compilation problems.
1044  Real *__restrict__ data = data_;
1045  OtherReal *__restrict__ other_data = v.data_;
1046  MatrixIndexT dim = dim_;
1047  if (alpha != 1.0)
1048  for (MatrixIndexT i = 0; i < dim; i++)
1049  data[i] += alpha * other_data[i];
1050  else
1051  for (MatrixIndexT i = 0; i < dim; i++)
1052  data[i] += other_data[i];
1053 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1062 of file kaldi-vector.cc.

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

1062  {
1063  KALDI_ASSERT(dim_ == v.dim_);
1064  // remove __restrict__ if it causes compilation problems.
1065  Real *__restrict__ data = data_;
1066  OtherReal *__restrict__ other_data = v.data_;
1067  MatrixIndexT dim = dim_;
1068  if (alpha != 1.0)
1069  for (MatrixIndexT i = 0; i < dim; i++)
1070  data[i] += alpha * other_data[i] * other_data[i];
1071  else
1072  for (MatrixIndexT i = 0; i < dim; i++)
1073  data[i] += other_data[i] * other_data[i];
1074 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1031 of file kaldi-vector.cc.

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

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

1032  {
1033  KALDI_ASSERT((dim_ == v.dim_ && dim_ == rr.dim_));
1034  for (MatrixIndexT i = 0; i < dim_; i++) {
1035  data_[i] = alpha * v.data_[i]/rr.data_[i] + beta * data_[i] ;
1036  }
1037 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 997 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().

998  {
999  KALDI_ASSERT(v.data_ != this->data_ && r.data_ != this->data_);
1000  // We pretend that v is a band-diagonal matrix.
1001  KALDI_ASSERT(dim_ == v.dim_ && dim_ == r.dim_);
1002  cblas_Xgbmv(kNoTrans, dim_, dim_, 0, 0, alpha, v.data_, 1,
1003  r.data_, 1, beta, this->data_, 1);
1004 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
#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 810 of file kaldi-vector.cc.

References data_, and rnnlm::i.

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

810  {
811  for (MatrixIndexT i = 0; i < dim_; i++) { data_[i] = std::abs(data_[i]); }
812 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
void ApplyCeiling ( Real  ceil_val,
MatrixIndexT ceiled_count = nullptr 
)

Applies ceiling to all elements.

Returns number of elements changed in ceiled_count if it is non-null.

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

References data_, and rnnlm::i.

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

833  {
834  if (ceiled_count == nullptr) {
835  for (MatrixIndexT i = 0; i < dim_; i++) {
836  data_[i] = std::min(data_[i], ceil_val);
837  }
838  } else {
839  MatrixIndexT num_changed = 0;
840  for (MatrixIndexT i = 0; i < dim_; i++) {
841  if (data_[i] > ceil_val) {
842  data_[i] = ceil_val;
843  num_changed++;
844  }
845  }
846  *ceiled_count = num_changed;
847  }
848 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
void ApplyFloor ( Real  floor_val,
MatrixIndexT floored_count = nullptr 
)

Applies floor to all elements.

Returns number of elements floored in floored_count if it is non-null.

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

References data_, and rnnlm::i.

Referenced by Plda::ApplyTransform(), SpectrogramComputer::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), AmSgmm2::ComputeFmllrPreXform(), kaldi::CuVectorUnitTestApplyFloor(), PldaEstimator::GetOutput(), kaldi::GpsrBasic(), kaldi::GpsrBB(), BatchNormComponent::Info(), NonlinearComponent::Info(), IvectorExtractor::InvertWithFlooring(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), kaldi::SlidingWindowCmnInternal(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), SpMatrix< Real >::SymPosSemiDefEig(), kaldi::UnitTestCuDiffNormalizePerRow(), kaldi::UnitTestFloorCeiling(), IvectorExtractorStats::UpdatePrior(), MleAmSgmm2Updater::UpdateVars(), and NonlinearComponent::Write().

815  {
816  if (floored_count == nullptr) {
817  for (MatrixIndexT i = 0; i < dim_; i++) {
818  data_[i] = std::max(data_[i], floor_val);
819  }
820  } else {
821  MatrixIndexT num_floored = 0;
822  for (MatrixIndexT i = 0; i < dim_; i++) {
823  if (data_[i] < floor_val) {
824  data_[i] = floor_val;
825  num_floored++;
826  }
827  }
828  *floored_count = num_floored;
829  }
830 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
MatrixIndexT ApplyFloor ( const VectorBase< Real > &  floor_vec)

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

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

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

851  {
852  KALDI_ASSERT(floor_vec.Dim() == dim_);
853  MatrixIndexT num_floored = 0;
854  for (MatrixIndexT i = 0; i < dim_; i++) {
855  if (data_[i] < floor_vec(i)) {
856  data_[i] = floor_vec(i);
857  num_floored++;
858  }
859  }
860  return num_floored;
861 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 786 of file kaldi-vector.cc.

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

Referenced by AmSgmm2::ComponentLogLikes(), MfccComputer::Compute(), FbankComputer::Compute(), IvectorExtractor::GetAcousticAuxfWeight(), PdfPrior::PdfPrior(), LogisticRegression::ScalePriors(), and MleSgmm2SpeakerAccs::UpdateWithU().

786  {
787  for (MatrixIndexT i = 0; i < dim_; i++) {
788  if (data_[i] < 0.0)
789  KALDI_ERR << "Trying to take log of a negative number.";
790  data_[i] = Log(data_[i]);
791  }
792 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
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:379
void ApplyLogAndCopy ( const VectorBase< Real > &  v)

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

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

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

Referenced by kaldi::UnitTestSimple().

795  {
796  KALDI_ASSERT(dim_ == v.Dim());
797  for (MatrixIndexT i = 0; i < dim_; i++) {
798  data_[i] = Log(v(i));
799  }
800 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
double Log(double x)
Definition: kaldi-math.h:100
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 874 of file kaldi-vector.cc.

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

Referenced by kaldi::UnitTestSimpleForVec().

874  {
875  Real max = this->Max(), sum = 0.0;
876  for (MatrixIndexT i = 0; i < dim_; i++) {
877  sum += Exp((data_[i] -= max));
878  }
879  sum = Log(sum);
880  this->Add(-1.0 * sum);
881  return max + sum;
882 }
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:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
double Log(double x)
Definition: kaldi-math.h:100
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 457 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(), OnlinePreconditioner::ComputeEt(), OnlineNaturalGradient::ComputeEt(), kaldi::CuVectorUnitTestApplyPow(), SvdApplier::DecomposeComponent(), Plda::GetNormalizationFactor(), BatchNormComponent::Info(), NonlinearComponent::Info(), Plda::LogLikelihoodRatio(), DiagGmm::LogLikelihoods(), DecodableAmDiagGmmUnmapped::LogLikelihoodZeroBased(), DecodableAmDiagGmmRegtreeMllr::LogLikelihoodZeroBased(), main(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), kaldi::SlidingWindowCmnInternal(), Plda::SmoothWithinClassCovariance(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), MatrixBase< Real >::SymPosSemiDefEig(), UnitTestEstimateDiagGmm(), kaldi::UnitTestEstimateMmieDiagGmm(), kaldi::UnitTestPower(), IvectorExtractorStats::UpdatePrior(), and NonlinearComponent::Write().

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

References data_, rnnlm::i, and KALDI_ERR.

Referenced by kaldi::UnitTestPowerAbs().

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

864  {
865  Real max = this->Max(), sum = 0.0;
866  for (MatrixIndexT i = 0; i < dim_; i++) {
867  sum += (data_[i] = Exp(data_[i] - max));
868  }
869  this->Scale(1.0 / sum);
870  return max + Log(sum);
871 }
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:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
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:379
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 561 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().

561  {
562  if (dim_ != other.dim_) KALDI_ERR << "ApproxEqual: size mismatch "
563  << dim_ << " vs. " << other.dim_;
564  KALDI_ASSERT(tol >= 0.0);
565  if (tol != 0.0) {
566  Vector<Real> tmp(*this);
567  tmp.AddVec(-1.0, other);
568  return (tmp.Norm(2.0) <= static_cast<Real>(tol) * this->Norm(2.0));
569  } else { // Test for exact equality.
570  const Real *data = data_;
571  const Real *other_data = other.data_;
572  for (MatrixIndexT dim = dim_, i = 0; i < dim; i++)
573  if (data[i] != other_data[i]) return false;
574  return true;
575  }
576 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
#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:379
#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 661 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().

661  {
662  KALDI_ASSERT(col < mat.NumCols());
663  KALDI_ASSERT(dim_ == mat.NumRows());
664  for (MatrixIndexT i = 0; i < dim_; i++)
665  data_[i] = mat(i, col);
666  // can't do this very efficiently so don't really bother. could improve this though.
667 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 384 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().

384  {
385  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
386 
387  Real* inc_data = data_;
388  const MatrixIndexT cols = mat.NumCols(), rows = mat.NumRows(), stride = mat.Stride();
389  const Real *mat_inc_data = mat.Data();
390 
391  for (MatrixIndexT i = 0; i < cols; i++) {
392  for (MatrixIndexT j = 0; j < rows; j++) {
393  inc_data[j] = mat_inc_data[j*stride];
394  }
395  mat_inc_data++;
396  inc_data += rows;
397  }
398 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 679 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().

679  {
680  KALDI_ASSERT(dim_ == std::min(M.NumRows(), M.NumCols()));
681  cblas_Xcopy(dim_, M.Data(), M.Stride() + 1, data_, 1);
682 }
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:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 685 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().

685  {
686  KALDI_ASSERT(dim_ == M.NumCols());
687  for (MatrixIndexT i = 0; i < dim_; i++)
688  data_[i] = M(i, i);
689  // could make this more efficient.
690 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 293 of file kaldi-vector.h.

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

293 { 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 296 of file kaldi-vector.h.

296 { 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 237 of file kaldi-vector.cc.

237  {
238  SubVector<OtherReal> v(M);
239  this->CopyFromVec(v);
240 }
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 249 of file kaldi-vector.cc.

References data_, and KALDI_ASSERT.

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

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

Copy data from another vector.

Definition at line 228 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(), Plda::ApplyTransform(), kaldi::ClusterGaussiansToUbm(), kaldi::nnet2::CombineNnets(), kaldi::nnet2::CombineNnetsA(), FullGmm::ComponentPosteriors(), DiagGmm::ComponentPosteriors(), SpectrogramComputer::Compute(), kaldi::ComputeAndSubtractMean(), OnlinePreconditioner::ComputeEt(), OnlineNaturalGradient::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(), LogisticRegression::GetObjfAndGrad(), DecodableNnetSimple::GetOutputForFrame(), DecodableNnetSimpleLooped::GetOutputForFrame(), SentenceAveragingComponent::GetParams(), OnlineCmvn::GetState(), AmSgmm2::GetSubstateMean(), AmSgmm2::GetVarScaledSubstateSpeakerMean(), 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=(), OnlineNaturalGradientSimple::PreconditionDirections(), OnlinePreconditionerSimple::PreconditionDirections(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), kaldi::nnet3::ProcessFile(), kaldi::nnet2::ProcessFile(), FullGmmNormal::Rand(), kaldi::RealFftInefficient(), OptimizeLbfgs< Real >::Restart(), kaldi::ReverseFrames(), kaldi::nnet3::RunNnetComputation(), 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().

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

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

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

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

256  {
257  KALDI_ASSERT(dim_ == other.Dim());
258  Real * __restrict__ ptr = data_;
259  const OtherReal * __restrict__ other_ptr = other.Data();
260  for (MatrixIndexT i = 0; i < dim_; i++)
261  ptr[i] = other_ptr[i];
262 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 368 of file cu-vector.h.

368  {
369  cu.CopyToVec(this);
370 }
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 401 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().

401  {
402  KALDI_ASSERT(row < mat.NumRows());
403  KALDI_ASSERT(dim_ == mat.NumCols());
404  const Real *mat_row = mat.RowData(row);
405  memcpy(data_, mat_row, sizeof(Real)*dim_);
406 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 410 of file kaldi-vector.cc.

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

410  {
411  KALDI_ASSERT(row < mat.NumRows());
412  KALDI_ASSERT(dim_ == mat.NumCols());
413  const OtherReal *mat_row = mat.RowData(row);
414  for (MatrixIndexT i = 0; i < dim_; i++)
415  data_[i] = static_cast<Real>(mat_row[i]);
416 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 425 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().

425  {
426  KALDI_ASSERT(row < sp.NumRows());
427  KALDI_ASSERT(dim_ == sp.NumCols());
428 
429  const OtherReal *sp_data = sp.Data();
430 
431  sp_data += (row*(row+1)) / 2; // takes us to beginning of this row.
432  MatrixIndexT i;
433  for (i = 0; i < row; i++) // copy consecutive elements.
434  data_[i] = static_cast<Real>(*(sp_data++));
435  for(; i < dim_; ++i, sp_data += i)
436  data_[i] = static_cast<Real>(*sp_data);
437 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 342 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(), LogisticRegression::TrainParameters(), kaldi::UnitTestSpliceRows(), LinearComponent::Vectorize(), and LstmNonlinearityComponent::Vectorize().

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

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

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

362  {
363  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
364  Real *vec_data = data_;
365  const MatrixIndexT cols = mat.NumCols(),
366  rows = mat.NumRows();
367 
368  for (MatrixIndexT i = 0; i < rows; i++) {
369  const OtherReal *mat_row = mat.RowData(i);
370  for (MatrixIndexT j = 0; j < cols; j++) {
371  vec_data[j] = static_cast<Real>(mat_row[j]);
372  }
373  vec_data += cols;
374  }
375 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 2560 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().

2560  {
2561  KALDI_ASSERT(dim_ == mat.NumCols() * mat.NumRows());
2562 #if HAVE_CUDA == 1
2563  if (CuDevice::Instantiate().Enabled()) {
2564  CuTimer tim;
2565  if (mat.Stride() == mat.NumCols()) {
2566  cudaMemcpy(data_, mat.Data(), sizeof(Real)*dim_, cudaMemcpyDeviceToHost);
2567  } else {
2568  // we could definitely do better than the following.
2569  Real* vec_data = data_;
2570  for (MatrixIndexT r = 0; r < mat.NumRows(); r++) {
2571  cudaMemcpy(vec_data, mat.RowData(r), sizeof(Real) * mat.NumCols(),
2572  cudaMemcpyDeviceToHost);
2573  vec_data += mat.NumCols();
2574  }
2575  }
2576  CuDevice::Instantiate().AccuProfile("CuVectorBase::CopyRowsFromMat", tim);
2577  } else
2578 #endif
2579  {
2580  CopyRowsFromMat(mat.Mat());
2581  }
2582 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 69 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(), SpMatrix< Real >::AddVecVec(), PitchInterpolator::Backtrace(), kaldi::ComplexFft(), kaldi::ComplexFftRecursive(), kaldi::ComplexFt(), kaldi::nnet3::ComponentDotProducts(), SpectrogramComputer::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), PlpComputer::Compute(), PitchFrameInfo::ComputeBacktraces(), OnlinePreconditioner::ComputeEt(), OnlineNaturalGradient::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(), CuMatrixBase< Real >::CopyRowsFromVec(), MatrixBase< Real >::CopyRowsFromVec(), CompressedMatrix::CopyRowToVec(), CuVectorBase< Real >::CopyToVec(), kaldi::Dither(), 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().

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

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

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

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

Returns the dimension of the vector.

Definition at line 63 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(), AccumFullGmm::AccumulateFromPosteriors(), AccumDiagGmm::AccumulateFromPosteriors(), MleAmSgmm2Accs::AccumulateFromPosteriors(), MleSgmm2SpeakerAccs::AccumulateFromPosteriors(), FmllrDiagGmmAccs::AccumulateFromPosteriorsPreselect(), AccumulateMultiThreadedClass::AccumulateMultiThreadedClass(), RestrictedAttentionComponent::Add(), 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(), 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::nnet3::ComputeAccuracy(), kaldi::ComputeAndProcessKaldiPitch(), PitchFrameInfo::ComputeBacktraces(), FastNnetCombiner::ComputeCurrentNnet(), kaldi::ComputeEarlyReverbEnergy(), OnlinePreconditioner::ComputeEt(), OnlineNaturalGradient::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(), OnlinePreconditioner::ComputeWt1(), OnlineNaturalGradient::ComputeWt1(), OnlinePreconditioner::ComputeZt(), OnlineNaturalGradient::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(), CuMatrixBase< Real >::CopyRowsFromVec(), MatrixBase< Real >::CopyRowsFromVec(), CompressedMatrix::CopyRowToVec(), DiagGmmNormal::CopyToDiagGmm(), FullGmmNormal::CopyToFullGmm(), CuVectorBase< Real >::CopyToVec(), kaldi::nnet1::CountCorrectFramesWeighted(), kaldi::cu::CpuBackpropLstmNonlinearity(), 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(), kaldi::EstPca(), 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(), OnlineIvectorEstimationStats::GetIvector(), DecodableNnetSimple::GetIvectorDim(), DecodableNnetSimpleLooped::GetIvectorDim(), IvectorExtractor::GetIvectorDistribution(), Nnet::GetLearningRates(), RegtreeFmllrDiagGmm::GetLogDets(), LogisticRegression::GetLogPosteriors(), 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(), IvectorExtractor::GetPriorAuxf(), EigenvalueDecomposition< Real >::GetRealEigenvalues(), kaldi::GetSplitTargets(), AmSgmm2::GetSubstateMean(), AmSgmm2::GetSubstateSpeakerMean(), AmSgmm2::GetVarScaledSubstateSpeakerMean(), kaldi::GpsrBasic(), kaldi::GpsrBasicAlpha(), kaldi::GpsrBB(), kaldi::GpsrCalcLinearCoeff(), kaldi::GpsrGradient(), kaldi::GpsrObjective(), AmNnet::Info(), AmNnetSimple::Info(), RestrictedAttentionComponent::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(), NnetComputeProb::PrintTotalStats(), kaldi::nnet3::PrintVectorPerUpdatableComponent(), IvectorExtractorStats::PriorDiagnostics(), DeltaFeatures::Process(), ShiftedDeltaFeatures::Process(), NnetChainTrainer::ProcessOutputs(), NnetDiscriminativeTrainer::ProcessOutputs(), NnetComputeProb::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(), DiagGmmNormal::Resize(), FullGmm::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(), AmSgmm2::SplitSubstates(), RestrictedAttentionComponent::StoreStats(), 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(), LinearComponent::UnVectorize(), ConvolutionComponent::UnVectorize(), LstmNonlinearityComponent::UnVectorize(), CompositeComponent::UnVectorize(), kaldi::nnet3::UnVectorizeNnet(), MleSgmm2SpeakerAccs::Update(), kaldi::nnet3::UpdateNnetWithMaxChange(), MleSgmm2SpeakerAccs::UpdateNoU(), 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(), LinearComponent::Vectorize(), ConvolutionComponent::Vectorize(), LstmNonlinearityComponent::Vectorize(), CompositeComponent::Vectorize(), kaldi::nnet3::VectorizeNnet(), kaldi::VectorToPosteriorEntry(), kaldi::VecVec(), AccumDiagGmm::Write(), and kaldi::nnet3::WriteVectorAsChar().

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

Divide element-by-element by a vector.

Definition at line 1008 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().

1008  {
1009  KALDI_ASSERT(dim_ == v.dim_);
1010  for (MatrixIndexT i = 0; i < dim_; i++) {
1011  data_[i] /= v.data_[i];
1012  }
1013 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1017 of file kaldi-vector.cc.

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

1017  {
1018  KALDI_ASSERT(dim_ == v.Dim());
1019  const OtherReal *other_ptr = v.Data();
1020  for (MatrixIndexT i = 0; i < dim_; i++) {
1021  data_[i] /= other_ptr[i];
1022  }
1023 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 293 of file kaldi-vector.cc.

References data_, and rnnlm::i.

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

293  {
294  Real abs_max = 0.0;
295  for (MatrixIndexT i = 0; i < Dim(); i++)
296  abs_max = std::max(std::abs(data_[i]), abs_max);
297  return (abs_max <= cutoff);
298 }
int32 MatrixIndexT
Definition: matrix-common.h:98
Real * data_
data memory area
Definition: kaldi-vector.h:379
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:63
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 758 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().

758  {
759  Real sum;
760  if (sizeof(sum) == 8) sum = kLogZeroDouble;
761  else sum = kLogZeroFloat;
762  Real max_elem = Max(), cutoff;
763  if (sizeof(Real) == 4) cutoff = max_elem + kMinLogDiffFloat;
764  else cutoff = max_elem + kMinLogDiffDouble;
765  if (prune > 0.0 && max_elem - prune > cutoff) // explicit pruning...
766  cutoff = max_elem - prune;
767 
768  double sum_relto_max_elem = 0.0;
769 
770  for (MatrixIndexT i = 0; i < dim_; i++) {
771  BaseFloat f = data_[i];
772  if (f >= cutoff)
773  sum_relto_max_elem += Exp(f - max_elem);
774  }
775  return max_elem + Log(sum_relto_max_elem);
776 }
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:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
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:379
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 579 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(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), kaldi::nnet3::PrintPriorDiagnostics(), kaldi::nnet2::PrintPriorDiagnostics(), OnlinePreconditioner::SelfTest(), OnlineNaturalGradient::SelfTest(), kaldi::SolveQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), SpMatrix< Real >::SymPosSemiDefEig(), kaldi::TestVectorToPosteriorEntry(), kaldi::UnitTestMaxAbsEig(), kaldi::UnitTestMaxMin(), kaldi::UnitTestSparseVectorMax(), kaldi::UnitTestVectorMax(), and IvectorExtractorStats::UpdatePrior().

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

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

Error if vector is empty.

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

References data_, rnnlm::i, and KALDI_ERR.

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

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

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

References data_, and rnnlm::i.

Referenced by OnlinePitchFeatureImpl::AcceptWaveform(), kaldi::ApplyHessianXformToGradient(), kaldi::ApplyInvHessianXformToChange(), Plda::ApplyTransform(), 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(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePitchFeatureImpl::RecomputeBacktraces(), OnlinePreconditioner::SelfTest(), OnlineNaturalGradient::SelfTest(), Nnet::SetLearningRates(), SpMatrix< Real >::SymPosSemiDefEig(), TestSgmm2FmllrAccsIO(), TestSgmm2FmllrSubspace(), kaldi::UnitTestFloorUnit(), kaldi::UnitTestMaxAbsEig(), kaldi::UnitTestMaxMin(), kaldi::UnitTestVectorMin(), and IvectorExtractorStats::UpdatePrior().

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

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

Error if vector is empty.

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

References data_, rnnlm::i, and KALDI_ERR.

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

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

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

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

982  {
983  KALDI_ASSERT(dim_ == v.Dim());
984  const OtherReal *other_ptr = v.Data();
985  for (MatrixIndexT i = 0; i < dim_; i++) {
986  data_[i] *= other_ptr[i];
987  }
988 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 152 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().

153  {
154  KALDI_ASSERT(M.NumRows() == dim_);
155  cblas_Xtpmv(trans,M.Data(),M.NumRows(),data_,1);
156 }
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:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 517 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().

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

Indexing operator (const).

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

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

Indexing operator (non-const).

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

82  {
83  KALDI_PARANOID_ASSERT(static_cast<UnsignedMatrixIndexT>(i) <
84  static_cast<UnsignedMatrixIndexT>(dim_));
85  return *(data_ + i);
86  }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
#define KALDI_PARANOID_ASSERT(cond)
Definition: kaldi-error.h:182
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 319 of file kaldi-vector.cc.

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

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

319  {
320  kaldi::RandomState rstate;
321  Real sum = this->Sum();
322  KALDI_ASSERT(this->Min() >= 0.0 && sum > 0.0);
323  Real r = RandUniform(&rstate) * sum;
324  Real *data = this->data_;
325  MatrixIndexT dim = this->dim_;
326  Real running_sum = 0.0;
327  for (MatrixIndexT i = 0; i < dim; i++) {
328  running_sum += data[i];
329  if (r < running_sum) return i;
330  }
331  return dim_ - 1; // Should only happen if RandUniform()
332  // returns exactly 1, or due to roundoff.
333 }
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:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 93 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(), ScaleAndOffsetComponent::UnVectorize(), ConvolutionComponent::UnVectorize(), VectorRandomizer::Value(), TimeHeightConvolutionComponent::Vectorize(), RepeatedAffineComponent::Vectorize(), AffineComponent::Vectorize(), BlockAffineComponent::Vectorize(), ScaleAndOffsetComponent::Vectorize(), and ConvolutionComponent::Vectorize().

93  {
94  return SubVector<Real>(*this, o, l);
95  }
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 102 of file kaldi-vector.h.

103  {
104  return SubVector<Real>(*this, o, l);
105  }
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 1083 of file kaldi-vector.cc.

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

Referenced by kaldi::operator>>().

1083  {
1084  if (add) {
1085  Vector<Real> tmp(Dim());
1086  tmp.Read(is, binary, false); // read without adding.
1087  if (this->Dim() != tmp.Dim()) {
1088  KALDI_ERR << "VectorBase::Read, size mismatch " << this->Dim()<<" vs. "<<tmp.Dim();
1089  }
1090  this->AddVec(1.0, tmp);
1091  return;
1092  } // now assume add == false.
1093 
1094  // In order to avoid rewriting this, we just declare a Vector and
1095  // use it to read the data, then copy.
1096  Vector<Real> tmp;
1097  tmp.Read(is, binary, false);
1098  if (tmp.Dim() != Dim())
1099  KALDI_ERR << "VectorBase<Real>::Read, size mismatch "
1100  << Dim() << " vs. " << tmp.Dim();
1101  CopyFromVec(tmp);
1102 }
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:63
void ReplaceValue ( Real  orig,
Real  changed 
)

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

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

References data_, and rnnlm::i.

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

973  {
974  Real *data = data_;
975  for (MatrixIndexT i = 0; i < dim_; i++)
976  if (data[i] == orig) data[i] = changed;
977 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
void Scale ( Real  alpha)

Multiplies all elements by this constant.

Definition at line 960 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(), EbwAmSgmm2Updater::ComputePhoneVecStats(), FmllrRawAccs::ConvertToSimpleStats(), kaldi::CuVectorUnitTestScale(), kaldi::Debias(), DeltaFeatures::DeltaFeatures(), MatrixBase< Real >::DestructiveSvd(), kaldi::EBWUpdateGaussian(), BasisFmllrEstimate::EstimateFmllrBasis(), kaldi::EstPca(), kaldi::FFTbasedBlockConvolveSignals(), kaldi::FFTbasedConvolveSignals(), kaldi::FmllrInnerUpdate(), kaldi::GenRandStats(), IvectorExtractor::GetAcousticAuxfVariance(), kaldi::GetFeatDeriv(), kaldi::GetFeatureMeanAndVariance(), PldaEstimator::GetOutput(), LdaEstimate::GetStats(), kaldi::GpsrBB(), BatchNormComponent::Info(), NonlinearComponent::Info(), LstmNonlinearityComponent::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(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::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(), RestrictedAttentionComponent::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(), kaldi::nnet3::UpdateNnetWithMaxChange(), IvectorExtractorStats::UpdatePrior(), EbwAmSgmm2Updater::UpdateSubstateWeights(), EbwAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateU(), MleAmSgmm2Updater::UpdateW(), MleSgmm2SpeakerAccs::UpdateWithU(), VectorClusterable::VectorClusterable(), NonlinearComponent::Write(), and LstmNonlinearityComponent::Write().

960  {
961  cblas_Xscal(dim_, alpha, data_, 1);
962 }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
void cblas_Xscal(const int N, const float alpha, float *data, const int inc)
Real * data_
data memory area
Definition: kaldi-vector.h:379
void Set ( Real  f)

Set all members of a vector to a specified value.

Definition at line 336 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::nnet3::ComputeAccuracy(), kaldi::ComputeLocalCost(), PitchInterpolator::Forward(), kaldi::nnet2::GetInitialModel(), FastNnetCombiner::GetInitialModel(), FastNnetCombiner::GetInitialParams(), kaldi::nnet2::GetInitialScaleParams(), LogisticRegression::GetLogPosteriors(), kaldi::nnet2::GetUpdateDirection(), kaldi::GpsrCalcLinearCoeff(), OnlinePreconditionerSimple::InitDefault(), OnlineNaturalGradientSimple::InitDefault(), OnlinePreconditioner::InitDefault(), OnlineNaturalGradient::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().

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

Set vector to random normally-distributed noise.

Definition at line 301 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(), 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().

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

Sets to numbers uniformly distributed on (0,1)

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

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

311  {
312  kaldi::RandomState rstate;
313  for (MatrixIndexT i = 0; i < Dim(); i++) {
314  *(data_+i) = RandUniform(&rstate);
315  }
316 }
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:98
Real * data_
data memory area
Definition: kaldi-vector.h:379
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:63
void Sigmoid ( const VectorBase< Real > &  src)

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

Definition at line 935 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().

935  {
936  KALDI_ASSERT(dim_ == src.dim_);
937  for (MatrixIndexT i = 0; i < dim_; i++) {
938  Real x = src.data_[i];
939  // We aim to avoid floating-point overflow here.
940  if (x > 0.0) {
941  x = 1.0 / (1.0 + Exp(-x));
942  } else {
943  Real ex = Exp(x);
944  x = ex / (ex + 1.0);
945  }
946  data_[i] = x;
947  }
948 }
double Exp(double x)
Definition: kaldi-math.h:83
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 66 of file kaldi-vector.h.

66 { return (dim_*sizeof(Real)); }
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
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 159 of file kaldi-vector.cc.

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

Referenced by kaldi::UnitTestTriVecSolver().

160  {
161  KALDI_ASSERT(M.NumRows() == dim_);
162  cblas_Xtpsv(trans, M.Data(), M.NumRows(), data_, 1);
163 }
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:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real Sum ( ) const

Returns sum of the elements.

Definition at line 693 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(), EbwAmSgmm2Updater::ComputePhoneVecStats(), kaldi::ComputeVadEnergy(), OnlinePreconditioner::ComputeWt1(), OnlineNaturalGradient::ComputeWt1(), kaldi::CuVectorUnitTestCopyDiagFromMat(), SvdApplier::DecomposeComponent(), kaldi::EstPca(), 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(), OnlinePreconditioner::PreconditionDirectionsInternal(), OnlineNaturalGradient::PreconditionDirectionsInternal(), IvectorExtractorStats::PriorDiagnostics(), kaldi::ProcessWindow(), DiagGmm::RemoveComponent(), FullGmm::RemoveComponent(), MleAmSgmm2Updater::RenormalizeN(), MleAmSgmm2Updater::RenormalizeV(), OnlinePreconditioner::ReorthogonalizeXt1(), OnlineNaturalGradient::ReorthogonalizeXt1(), Xent::Report(), OnlinePreconditioner::SelfTest(), OnlineNaturalGradient::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().

693  {
694  double sum = 0.0;
695  for (MatrixIndexT i = 0; i < dim_; i++) { sum += data_[i]; }
696  return sum;
697 }
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
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 700 of file kaldi-vector.cc.

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

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

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

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

Definition at line 897 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().

897  {
898  KALDI_ASSERT(dim_ == src.dim_);
899  for (MatrixIndexT i = 0; i < dim_; i++) {
900  Real x = src.data_[i];
901  if (x > 0.0) {
902  Real inv_expx = Exp(-x);
903  x = -1.0 + 2.0 / (1.0 + inv_expx * inv_expx);
904  } else {
905  Real expx = Exp(x);
906  x = 1.0 - 2.0 / (1.0 + expx * expx);
907  }
908  data_[i] = x;
909  }
910 }
double Exp(double x)
Definition: kaldi-math.h:83
int32 MatrixIndexT
Definition: matrix-common.h:98
MatrixIndexT dim_
dimension of vector
Definition: kaldi-vector.h:381
Real * data_
data memory area
Definition: kaldi-vector.h:379
#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 1228 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(), FullGmm::Write(), TransitionModel::Write(), VectorClusterable::Write(), Plda::Write(), RestrictedAttentionComponent::Write(), DiagGmm::Write(), DiscriminativeNnetExample::Write(), IvectorExtractor::Write(), CuVector< Real >::Write(), OnlineIvectorEstimationStats::Write(), IvectorExtractorStats::Write(), NonlinearComponent::Write(), LstmNonlinearityComponent::Write(), and kaldi::nnet3::WriteVectorAsChar().

1228  {
1229  if (!os.good()) {
1230  KALDI_ERR << "Failed to write vector to stream: stream not good";
1231  }
1232  if (binary) {
1233  std::string my_token = (sizeof(Real) == 4 ? "FV" : "DV");
1234  WriteToken(os, binary, my_token);
1235 
1236  int32 size = Dim(); // make the size 32-bit on disk.
1237  KALDI_ASSERT(Dim() == (MatrixIndexT) size);
1238  WriteBasicType(os, binary, size);
1239  os.write(reinterpret_cast<const char*>(Data()), sizeof(Real) * size);
1240  } else {
1241  os << " [ ";
1242  for (MatrixIndexT i = 0; i < Dim(); i++)
1243  os << (*this)(i) << " ";
1244  os << "]\n";
1245  }
1246  if (!os.good())
1247  KALDI_ERR << "Failed to write vector to stream";
1248 }
int32 MatrixIndexT
Definition: matrix-common.h:98
#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:69
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:63

Friends And Related Function Documentation

friend class CuVector< Real >
friend

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

friend class CuVectorBase< Real >
friend

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

friend class VectorBase< double >
friend

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

friend class VectorBase< float >
friend

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

Member Data Documentation


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