All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Matrix-vector functions returning scalars
Collaboration diagram for Matrix-vector functions returning scalars:

Functions

template<typename Real >
bool ApproxEqual (const MatrixBase< Real > &A, const MatrixBase< Real > &B, Real tol=0.01)
 
template<typename Real >
void AssertEqual (const MatrixBase< Real > &A, const MatrixBase< Real > &B, float tol=0.01)
 
template<typename Real >
double TraceMat (const MatrixBase< Real > &A)
 Returns trace of matrix. More...
 
template<typename Real >
Real TraceMatMatMat (const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const MatrixBase< Real > &C, MatrixTransposeType transC)
 Returns tr(A B C) More...
 
template<typename Real >
Real TraceMatMatMatMat (const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const MatrixBase< Real > &C, MatrixTransposeType transC, const MatrixBase< Real > &D, MatrixTransposeType transD)
 Returns tr(A B C D) More...
 
template<typename Real >
bool ApproxEqual (const VectorBase< Real > &a, const VectorBase< Real > &b, Real tol=0.01)
 
template<typename Real >
void AssertEqual (VectorBase< Real > &a, VectorBase< Real > &b, float tol=0.01)
 
template<typename Real >
Real VecVec (const VectorBase< Real > &v1, const VectorBase< Real > &v2)
 Returns dot product between v1 and v2. More...
 
template<typename Real , typename OtherReal >
Real VecVec (const VectorBase< Real > &ra, const VectorBase< OtherReal > &rb)
 
template<typename Real >
Real VecMatVec (const VectorBase< Real > &v1, const MatrixBase< Real > &M, const VectorBase< Real > &v2)
 Returns $ v_1^T M v_2 $ . More...
 
float TraceSpSp (const SpMatrix< float > &A, const SpMatrix< float > &B)
 Returns tr(A B). More...
 
double TraceSpSp (const SpMatrix< double > &A, const SpMatrix< double > &B)
 
template<typename Real >
bool ApproxEqual (const SpMatrix< Real > &A, const SpMatrix< Real > &B, Real tol=0.01)
 
template<typename Real >
void AssertEqual (const SpMatrix< Real > &A, const SpMatrix< Real > &B, Real tol=0.01)
 
template<typename Real , typename OtherReal >
Real TraceSpSp (const SpMatrix< Real > &A, const SpMatrix< OtherReal > &B)
 Returns tr(A B). More...
 
template<typename Real >
Real TraceSpSpLower (const SpMatrix< Real > &A, const SpMatrix< Real > &B)
 
template<typename Real >
Real TraceSpMat (const SpMatrix< Real > &A, const MatrixBase< Real > &B)
 Returns tr(A B). More...
 
template<typename Real >
Real TraceMatSpMat (const MatrixBase< Real > &A, MatrixTransposeType transA, const SpMatrix< Real > &B, const MatrixBase< Real > &C, MatrixTransposeType transC)
 Returns tr(A B C) (A and C may be transposed as specified by transA and transC). More...
 
template<typename Real >
Real TraceMatSpMatSp (const MatrixBase< Real > &A, MatrixTransposeType transA, const SpMatrix< Real > &B, const MatrixBase< Real > &C, MatrixTransposeType transC, const SpMatrix< Real > &D)
 Returns tr (A B C D) (A and C may be transposed as specified by transA and transB). More...
 
template<typename Real >
Real VecSpVec (const VectorBase< Real > &v1, const SpMatrix< Real > &M, const VectorBase< Real > &v2)
 Computes v1^T * M * v2. More...
 

Detailed Description

Function Documentation

bool kaldi::ApproxEqual ( const SpMatrix< Real > &  A,
const SpMatrix< Real > &  B,
Real  tol = 0.01 
)
inline

Definition at line 375 of file sp-matrix.h.

376  {
377  return A.ApproxEqual(B, tol);
378 }
bool kaldi::ApproxEqual ( const VectorBase< Real > &  a,
const VectorBase< Real > &  b,
Real  tol = 0.01 
)

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

References VectorBase< Real >::ApproxEqual().

558  {
559  return a.ApproxEqual(b, tol);
560 }
bool kaldi::ApproxEqual ( const MatrixBase< Real > &  A,
const MatrixBase< Real > &  B,
Real  tol = 0.01 
)

Definition at line 949 of file kaldi-matrix.h.

References MatrixBase< Real >::ApproxEqual().

950  {
951  return A.ApproxEqual(B, tol);
952 }
void kaldi::AssertEqual ( const SpMatrix< Real > &  A,
const SpMatrix< Real > &  B,
Real  tol = 0.01 
)
inline

Definition at line 381 of file sp-matrix.h.

References kaldi::ApproxEqual(), and KALDI_ASSERT.

382  {
383  KALDI_ASSERT(ApproxEqual(A, B, tol));
384 }
bool ApproxEqual(const SpMatrix< Real > &A, const SpMatrix< Real > &B, Real tol=0.01)
Definition: sp-matrix.h:375
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void kaldi::AssertEqual ( VectorBase< Real > &  a,
VectorBase< Real > &  b,
float  tol = 0.01 
)
inline

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

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

564  {
565  KALDI_ASSERT(a.ApproxEqual(b, tol));
566 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void kaldi::AssertEqual ( const MatrixBase< Real > &  A,
const MatrixBase< Real > &  B,
float  tol = 0.01 
)
inline

Definition at line 955 of file kaldi-matrix.h.

References MatrixBase< Real >::ApproxEqual(), and KALDI_ASSERT.

956  {
957  KALDI_ASSERT(A.ApproxEqual(B, tol));
958 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
double kaldi::TraceMat ( const MatrixBase< Real > &  A)

Returns trace of matrix.

Definition at line 962 of file kaldi-matrix.h.

References MatrixBase< Real >::Trace().

Referenced by kaldi::CalBasisFmllrStepSize(), kaldi::CalcFmllrStepSize(), and kaldi::UnitTestTrace().

962 { return A.Trace(); }
Real TraceMatMatMat ( const MatrixBase< Real > &  A,
MatrixTransposeType  transA,
const MatrixBase< Real > &  B,
MatrixTransposeType  transB,
const MatrixBase< Real > &  C,
MatrixTransposeType  transC 
)

Returns tr(A B C)

Definition at line 2292 of file kaldi-matrix.cc.

References MatrixBase< Real >::AddMatMat(), KALDI_ASSERT, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), kaldi::swap(), and kaldi::TraceMatMat().

Referenced by kaldi::TraceMatMatMatMat(), and kaldi::UnitTestTrace().

2294  {
2295  MatrixIndexT ARows = A.NumRows(), ACols = A.NumCols(), BRows = B.NumRows(), BCols = B.NumCols(),
2296  CRows = C.NumRows(), CCols = C.NumCols();
2297  if (transA == kTrans) std::swap(ARows, ACols);
2298  if (transB == kTrans) std::swap(BRows, BCols);
2299  if (transC == kTrans) std::swap(CRows, CCols);
2300  KALDI_ASSERT( CCols == ARows && ACols == BRows && BCols == CRows && "TraceMatMatMat: args have mismatched dimensions.");
2301  if (ARows*BCols < std::min(BRows*CCols, CRows*ACols)) {
2302  Matrix<Real> AB(ARows, BCols);
2303  AB.AddMatMat(1.0, A, transA, B, transB, 0.0); // AB = A * B.
2304  return TraceMatMat(AB, C, transC);
2305  } else if ( BRows*CCols < CRows*ACols) {
2306  Matrix<Real> BC(BRows, CCols);
2307  BC.AddMatMat(1.0, B, transB, C, transC, 0.0); // BC = B * C.
2308  return TraceMatMat(BC, A, transA);
2309  } else {
2310  Matrix<Real> CA(CRows, ACols);
2311  CA.AddMatMat(1.0, C, transC, A, transA, 0.0); // CA = C * A
2312  return TraceMatMat(CA, B, transB);
2313  }
2314 }
template double TraceMatMat(const MatrixBase< double > &A, const MatrixBase< double > &B, MatrixTransposeType trans)
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real TraceMatMatMatMat ( const MatrixBase< Real > &  A,
MatrixTransposeType  transA,
const MatrixBase< Real > &  B,
MatrixTransposeType  transB,
const MatrixBase< Real > &  C,
MatrixTransposeType  transC,
const MatrixBase< Real > &  D,
MatrixTransposeType  transD 
)

Returns tr(A B C D)

Definition at line 2328 of file kaldi-matrix.cc.

References MatrixBase< Real >::AddMatMat(), KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), kaldi::swap(), and kaldi::TraceMatMatMat().

Referenced by kaldi::UnitTestTrace().

2331  {
2332  MatrixIndexT ARows = A.NumRows(), ACols = A.NumCols(), BRows = B.NumRows(), BCols = B.NumCols(),
2333  CRows = C.NumRows(), CCols = C.NumCols(), DRows = D.NumRows(), DCols = D.NumCols();
2334  if (transA == kTrans) std::swap(ARows, ACols);
2335  if (transB == kTrans) std::swap(BRows, BCols);
2336  if (transC == kTrans) std::swap(CRows, CCols);
2337  if (transD == kTrans) std::swap(DRows, DCols);
2338  KALDI_ASSERT( DCols == ARows && ACols == BRows && BCols == CRows && CCols == DRows && "TraceMatMatMat: args have mismatched dimensions.");
2339  if (ARows*BCols < std::min(BRows*CCols, std::min(CRows*DCols, DRows*ACols))) {
2340  Matrix<Real> AB(ARows, BCols);
2341  AB.AddMatMat(1.0, A, transA, B, transB, 0.0); // AB = A * B.
2342  return TraceMatMatMat(AB, kNoTrans, C, transC, D, transD);
2343  } else if ((BRows*CCols) < std::min(CRows*DCols, DRows*ACols)) {
2344  Matrix<Real> BC(BRows, CCols);
2345  BC.AddMatMat(1.0, B, transB, C, transC, 0.0); // BC = B * C.
2346  return TraceMatMatMat(BC, kNoTrans, D, transD, A, transA);
2347  } else if (CRows*DCols < DRows*ACols) {
2348  Matrix<Real> CD(CRows, DCols);
2349  CD.AddMatMat(1.0, C, transC, D, transD, 0.0); // CD = C * D
2350  return TraceMatMatMat(CD, kNoTrans, A, transA, B, transB);
2351  } else {
2352  Matrix<Real> DA(DRows, ACols);
2353  DA.AddMatMat(1.0, D, transD, A, transA, 0.0); // DA = D * A
2354  return TraceMatMatMat(DA, kNoTrans, B, transB, C, transC);
2355  }
2356 }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
template double TraceMatMatMat(const MatrixBase< double > &A, MatrixTransposeType transA, const MatrixBase< double > &B, MatrixTransposeType transB, const MatrixBase< double > &C, MatrixTransposeType transC)
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real TraceMatSpMat ( const MatrixBase< Real > &  A,
MatrixTransposeType  transA,
const SpMatrix< Real > &  B,
const MatrixBase< Real > &  C,
MatrixTransposeType  transC 
)

Returns tr(A B C) (A and C may be transposed as specified by transA and transC).

Definition at line 415 of file sp-matrix.cc.

References MatrixBase< Real >::AddMatMat(), KALDI_ASSERT, kaldi::kTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), PackedMatrix< Real >::NumRows(), and kaldi::TraceSpMat().

Referenced by kaldi::UnitTestSolve(), and kaldi::UnitTestTrace().

417  {
418  KALDI_ASSERT((transA == kTrans?A.NumCols():A.NumRows()) ==
419  (transC == kTrans?C.NumRows():C.NumCols()) &&
420  (transA == kTrans?A.NumRows():A.NumCols()) == B.NumRows() &&
421  (transC == kTrans?C.NumCols():C.NumRows()) == B.NumRows() &&
422  "TraceMatSpMat: arguments have wrong dimension.");
423  Matrix<Real> tmp(B.NumRows(), B.NumRows());
424  tmp.AddMatMat(1.0, C, transC, A, transA, 0.0); // tmp = C * A.
425  return TraceSpMat(B, tmp);
426 }
template double TraceSpMat(const SpMatrix< double > &A, const MatrixBase< double > &B)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real TraceMatSpMatSp ( const MatrixBase< Real > &  A,
MatrixTransposeType  transA,
const SpMatrix< Real > &  B,
const MatrixBase< Real > &  C,
MatrixTransposeType  transC,
const SpMatrix< Real > &  D 
)

Returns tr (A B C D) (A and C may be transposed as specified by transA and transB).

Definition at line 438 of file sp-matrix.cc.

References MatrixBase< Real >::AddMatSp(), KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, MatrixBase< Real >::NumCols(), PackedMatrix< Real >::NumCols(), MatrixBase< Real >::NumRows(), PackedMatrix< Real >::NumRows(), and kaldi::TraceMatMat().

Referenced by kaldi::CalcFmllrStepSize(), kaldi::UnitTestSolve(), and kaldi::UnitTestTrace().

440  {
441  KALDI_ASSERT((transA == kTrans ?A.NumCols():A.NumRows() == D.NumCols()) &&
442  (transA == kTrans ? A.NumRows():A.NumCols() == B.NumRows()) &&
443  (transC == kTrans ? A.NumCols():A.NumRows() == B.NumCols()) &&
444  (transC == kTrans ? A.NumRows():A.NumCols() == D.NumRows()) &&
445  "KALDI_ERR: TraceMatSpMatSp: arguments have mismatched dimension.");
446  // Could perhaps optimize this more depending on dimensions of quantities.
447  Matrix<Real> tmpAB(transA == kTrans ? A.NumCols():A.NumRows(), B.NumCols());
448  tmpAB.AddMatSp(1.0, A, transA, B, 0.0);
449  Matrix<Real> tmpCD(transC == kTrans ? C.NumCols():C.NumRows(), D.NumCols());
450  tmpCD.AddMatSp(1.0, C, transC, D, 0.0);
451  return TraceMatMat(tmpAB, tmpCD, kNoTrans);
452 }
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real TraceSpMat ( const SpMatrix< Real > &  A,
const MatrixBase< Real > &  B 
)

Returns tr(A B).

No option to transpose B because would make no difference.

Definition at line 389 of file sp-matrix.cc.

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

Referenced by kaldi::TraceMatSpMat(), and kaldi::UnitTestTrace().

389  {
390  KALDI_ASSERT(A.NumRows() == B.NumRows() && A.NumCols() == B.NumCols() &&
391  "KALDI_ERR: TraceSpMat: arguments have mismatched dimension");
392  MatrixIndexT R = A.NumRows();
393  Real ans = (Real)0.0;
394  const Real *Aptr = A.Data(), *Bptr = B.Data();
395  MatrixIndexT bStride = B.Stride();
396  for (MatrixIndexT r = 0;r < R;r++) {
397  for (MatrixIndexT c = 0;c < r;c++) {
398  // ans += A(r, c) * (B(r, c) + B(c, r));
399  ans += *(Aptr++) * (Bptr[r*bStride + c] + Bptr[c*bStride + r]);
400  }
401  // ans += A(r, r) * B(r, r);
402  ans += *(Aptr++) * Bptr[r*bStride + r];
403  }
404  return ans;
405 }
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
double TraceSpSp ( const SpMatrix< double > &  A,
const SpMatrix< double > &  B 
)

Definition at line 326 of file sp-matrix.cc.

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

Referenced by MleAmSgmm2Updater::ComputeMPrior(), PldaEstimator::ComputeObjfPart1(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::GetAcousticAuxfVariance(), IvectorExtractor::GetAcousticAuxfWeight(), CuSpMatrix< Real >::IsUnit(), kaldi::MlObjective(), kaldi::SolveQuadraticMatrixProblem(), kaldi::TraceSpSp(), kaldi::UnitTestCuSpMatrixTraceSpSp(), kaldi::UnitTestDeterminant(), kaldi::UnitTestTraceSpSpLower(), IvectorExtractorStats::UpdateVariances(), EbwAmSgmm2Updater::UpdateVars(), and MleAmSgmm2Updater::UpdateVars().

326  {
327  KALDI_ASSERT(A.NumRows() == B.NumRows());
328  const double *Aptr = A.Data();
329  const double *Bptr = B.Data();
330  MatrixIndexT R = A.NumRows();
331  MatrixIndexT RR = (R * (R + 1)) / 2;
332  double all_twice = 2.0 * cblas_Xdot(RR, Aptr, 1, Bptr, 1);
333  // "all_twice" contains twice the vector-wise dot-product... this is
334  // what we want except the diagonal elements are represented
335  // twice.
336  double diag_once = 0.0;
337  for (MatrixIndexT row_plus_two = 2; row_plus_two <= R + 1; row_plus_two++) {
338  diag_once += *Aptr * *Bptr;
339  Aptr += row_plus_two;
340  Bptr += row_plus_two;
341  }
342  return all_twice - diag_once;
343 }
MatrixIndexT NumRows() const
float cblas_Xdot(const int N, const float *const X, const int incX, const float *const Y, const int incY)
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
float TraceSpSp ( const SpMatrix< float > &  A,
const SpMatrix< float > &  B 
)

Returns tr(A B).

Definition at line 346 of file sp-matrix.cc.

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

346  {
347  KALDI_ASSERT(A.NumRows() == B.NumRows());
348  const float *Aptr = A.Data();
349  const float *Bptr = B.Data();
350  MatrixIndexT R = A.NumRows();
351  MatrixIndexT RR = (R * (R + 1)) / 2;
352  float all_twice = 2.0 * cblas_Xdot(RR, Aptr, 1, Bptr, 1);
353  // "all_twice" contains twice the vector-wise dot-product... this is
354  // what we want except the diagonal elements are represented
355  // twice.
356  float diag_once = 0.0;
357  for (MatrixIndexT row_plus_two = 2; row_plus_two <= R + 1; row_plus_two++) {
358  diag_once += *Aptr * *Bptr;
359  Aptr += row_plus_two;
360  Bptr += row_plus_two;
361  }
362  return all_twice - diag_once;
363 }
float cblas_Xdot(const int N, const float *const X, const int incX, const float *const Y, const int incY)
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real TraceSpSp ( const SpMatrix< Real > &  A,
const SpMatrix< OtherReal > &  B 
)

Returns tr(A B).

Definition at line 367 of file sp-matrix.cc.

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

367  {
368  KALDI_ASSERT(A.NumRows() == B.NumRows());
369  Real ans = 0.0;
370  const Real *Aptr = A.Data();
371  const OtherReal *Bptr = B.Data();
372  MatrixIndexT row, col, R = A.NumRows();
373  for (row = 0; row < R; row++) {
374  for (col = 0; col < row; col++)
375  ans += 2.0 * *(Aptr++) * *(Bptr++);
376  ans += *(Aptr++) * *(Bptr++); // Diagonal.
377  }
378  return ans;
379 }
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real TraceSpSpLower ( const SpMatrix< Real > &  A,
const SpMatrix< Real > &  B 
)

Definition at line 1171 of file sp-matrix.cc.

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

Referenced by FullGmm::LogLikelihoods(), FullGmm::LogLikelihoodsPreselect(), and kaldi::UnitTestTraceSpSpLower().

1171  {
1172  MatrixIndexT adim = A.NumRows();
1173  KALDI_ASSERT(adim == B.NumRows());
1174  MatrixIndexT dim = (adim*(adim+1))/2;
1175  return cblas_Xdot(dim, A.Data(), 1, B.Data(), 1);
1176 }
float cblas_Xdot(const int N, const float *const X, const int incX, const float *const Y, const int incY)
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real VecMatVec ( const VectorBase< Real > &  v1,
const MatrixBase< Real > &  M,
const VectorBase< Real > &  v2 
)

Returns $ v_1^T M v_2 $ .

Not as efficient as it could be where v1 == v2.

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

References VectorBase< Real >::AddMatVec(), VectorBase< Real >::Dim(), KALDI_ASSERT, kaldi::kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), and kaldi::VecVec().

1261  {
1262  KALDI_ASSERT(v1.Dim() == M.NumRows() && v2.Dim() == M.NumCols());
1263  Vector<Real> vtmp(M.NumRows());
1264  vtmp.AddMatVec(1.0, M, kNoTrans, v2, 0.0);
1265  return VecVec(v1, vtmp);
1266 }
template double VecVec(const VectorBase< double > &ra, const VectorBase< float > &rb)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real VecSpVec ( const VectorBase< Real > &  v1,
const SpMatrix< Real > &  M,
const VectorBase< Real > &  v2 
)

Computes v1^T * M * v2.

Not as efficient as it could be where v1 == v2 (but no suitable blas routines available).Returns $ v_1^T M v_2 $ Not as efficient as it could be where v1 == v2.

Definition at line 964 of file sp-matrix.cc.

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

Referenced by FullGmm::ComponentLogLikelihood(), FullGmm::ComputeGconsts(), PldaEstimator::ComputeObjfPart2(), IvectorExtractor::GetAcousticAuxfMean(), FmllrRawAccs::GetAuxf(), GetLogLikeTest(), main(), OnlineIvectorEstimationStats::Objf(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), kaldi::UnitTestFloorChol(), UnitTestFullGmm(), kaldi::UnitTestGpsr(), kaldi::UnitTestInnerProd(), kaldi::UnitTestLbfgs(), kaldi::UnitTestSolve(), MlltAccs::Update(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), MleAmSgmm2Updater::UpdateW(), and MleSgmm2SpeakerAccs::UpdateWithU().

965  {
966  MatrixIndexT D = M.NumRows();
967  KALDI_ASSERT(v1.Dim() == D && v1.Dim() == v2.Dim());
968  Vector<Real> tmp_vec(D);
969  cblas_Xspmv(D, 1.0, M.Data(), v1.Data(), 1, 0.0, tmp_vec.Data(), 1);
970  return VecVec(tmp_vec, v2);
971 }
int32 MatrixIndexT
Definition: matrix-common.h:96
#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)
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:36
Real VecVec ( const VectorBase< Real > &  a,
const VectorBase< Real > &  b 
)

Returns dot product between v1 and v2.

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

References kaldi::cblas_Xdot(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), and KALDI_ASSERT.

Referenced by OptimizeLbfgs< Real >::AcceptStep(), OnlinePitchFeatureImpl::AcceptWaveform(), FmllrRawAccs::AccumulateForGmm(), kaldi::AddNoise(), kaldi::CalBasisFmllrStepSize(), FullGmm::ComponentLogLikelihood(), DiagGmm::ComponentLogLikelihood(), SpectrogramComputer::Compute(), MelBanks::Compute(), MfccComputer::Compute(), FbankComputer::Compute(), PlpComputer::Compute(), kaldi::ComputeCorrelation(), kaldi::ComputeEarlyReverbEnergy(), OptimizeLbfgs< Real >::ComputeHifNeeded(), OptimizeLbfgs< Real >::ComputeNewDirection(), AmSgmm2::ComputeNormalizersInternal(), AmSgmm2::ComputePerFrameVars(), EbwAmSgmm2Updater::ComputePhoneVecStats(), kaldi::CuVectorUnitTestInvertElements(), kaldi::CuVectorUnitTestSum(), kaldi::CuVectorUnitTestVecVec(), kaldi::Debias(), TimeHeightConvolutionComponent::DotProduct(), RepeatedAffineComponent::DotProduct(), ConstantComponent::DotProduct(), AffineComponent::DotProduct(), BlockAffineComponent::DotProduct(), PerElementScaleComponent::DotProduct(), PerElementOffsetComponent::DotProduct(), ConstantFunctionComponent::DotProduct(), ConvolutionComponent::DotProduct(), Convolutional1dComponent::DotProduct(), kaldi::FmllrAuxfGradient(), kaldi::FmllrAuxFuncDiagGmm(), kaldi::FmllrInnerUpdate(), IvectorExtractor::GetAcousticAuxfGconst(), IvectorExtractor::GetAcousticAuxfMean(), IvectorExtractor::GetAcousticAuxfWeight(), FmllrRawAccs::GetAuxf(), Plda::GetNormalizationFactor(), IvectorExtractor::GetPriorAuxf(), AffineComponentPreconditioned::GetScalingFactor(), NnetChainCombiner::GetWeightsDeriv(), NnetCombiner::GetWeightsDeriv(), kaldi::GpsrBasic(), kaldi::GpsrBasicAlpha(), kaldi::GpsrBB(), kaldi::GpsrObjective(), AffineComponent::Info(), AffineComponentPreconditioned::Info(), AffineComponentPreconditionedOnline::Info(), FixedAffineComponent::Info(), FixedScaleComponent::Info(), FixedBiasComponent::Info(), Convolutional1dComponent::Info(), kaldi::LinearCgd(), AmSgmm2::LogLikelihood(), Plda::LogLikelihoodRatio(), FullGmm::LogLikelihoodsPreselect(), DiagGmm::LogLikelihoodsPreselect(), DecodableAmDiagGmmRegtreeFmllr::LogLikelihoodZeroBased(), main(), kaldi::MllrAuxFunction(), kaldi::MlObjective(), VectorClusterable::Objf(), OnlineIvectorEstimationStats::Objf(), MatrixBase< Real >::OrthogonalizeRows(), kaldi::nnet2::PreconditionDirections(), OnlineNaturalGradientSimple::PreconditionDirectionsCpu(), OnlinePreconditionerSimple::PreconditionDirectionsCpu(), kaldi::nnet3::PrintParameterStats(), kaldi::ProcessWindow(), ArbitraryResample::Resample(), LinearResample::Resample(), NnetChainCombiner::SelfTestDerivatives(), NnetCombiner::SelfTestDerivatives(), NnetChainCombiner::SelfTestModelDerivatives(), NnetCombiner::SelfTestModelDerivatives(), kaldi::SolveDoubleQuadraticMatrixProblem(), kaldi::SolveQuadraticProblem(), OptimizeLbfgs< Real >::StepSizeIteration(), kaldi::nnet3::SummarizeVector(), kaldi::TestCuVectorVecVecOne(), kaldi::nnet3::TestNnetComponentUpdatable(), SpMatrix< Real >::TopEigs(), kaldi::TraceSpSp(), kaldi::UnitTestDotprod(), kaldi::UnitTestGpsr(), kaldi::UnitTestLbfgs(), UnitTestLinearResample2(), kaldi::UnitTestSnipEdges(), kaldi::UnitTestSolve(), kaldi::UnitTestSparseVectorVecSvec(), MlltAccs::Update(), MleAmSgmm2Updater::UpdatePhoneVectorsInternal(), OnlinePitchFeatureImpl::UpdateRemainder(), MleAmSgmm2Updater::UpdateW(), MleAmSgmm2Updater::UpdateWGetStats(), MleSgmm2SpeakerAccs::UpdateWithU(), kaldi::VecMatVec(), kaldi::VecSpVec(), VectorClusterable::VectorClusterable(), and kaldi::VecVec().

37  {
38  MatrixIndexT adim = a.Dim();
39  KALDI_ASSERT(adim == b.Dim());
40  return cblas_Xdot(adim, a.Data(), 1, b.Data(), 1);
41 }
float cblas_Xdot(const int N, const float *const X, const int incX, const float *const Y, const int incY)
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Real VecVec ( const VectorBase< Real > &  ra,
const VectorBase< OtherReal > &  rb 
)

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

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

52  {
53  MatrixIndexT adim = ra.Dim();
54  KALDI_ASSERT(adim == rb.Dim());
55  const Real *a_data = ra.Data();
56  const OtherReal *b_data = rb.Data();
57  Real sum = 0.0;
58  for (MatrixIndexT i = 0; i < adim; i++)
59  sum += a_data[i]*b_data[i];
60  return sum;
61 }
int32 MatrixIndexT
Definition: matrix-common.h:96
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169