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 385 of file sp-matrix.h.

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

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

References VectorBase< Real >::ApproxEqual().

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

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

References MatrixBase< Real >::ApproxEqual().

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

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

References kaldi::ApproxEqual(), and KALDI_ASSERT.

392  {
393  KALDI_ASSERT(ApproxEqual(A, B, tol));
394 }
bool ApproxEqual(const SpMatrix< Real > &A, const SpMatrix< Real > &B, Real tol=0.01)
Definition: sp-matrix.h:385
#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 560 of file kaldi-vector.h.

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

561  {
562  KALDI_ASSERT(a.ApproxEqual(b, tol));
563 }
#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 953 of file kaldi-matrix.h.

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

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

Returns trace of matrix.

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

References MatrixBase< Real >::Trace().

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

960 { 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 2277 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().

2279  {
2280  MatrixIndexT ARows = A.NumRows(), ACols = A.NumCols(), BRows = B.NumRows(), BCols = B.NumCols(),
2281  CRows = C.NumRows(), CCols = C.NumCols();
2282  if (transA == kTrans) std::swap(ARows, ACols);
2283  if (transB == kTrans) std::swap(BRows, BCols);
2284  if (transC == kTrans) std::swap(CRows, CCols);
2285  KALDI_ASSERT( CCols == ARows && ACols == BRows && BCols == CRows && "TraceMatMatMat: args have mismatched dimensions.");
2286  if (ARows*BCols < std::min(BRows*CCols, CRows*ACols)) {
2287  Matrix<Real> AB(ARows, BCols);
2288  AB.AddMatMat(1.0, A, transA, B, transB, 0.0); // AB = A * B.
2289  return TraceMatMat(AB, C, transC);
2290  } else if ( BRows*CCols < CRows*ACols) {
2291  Matrix<Real> BC(BRows, CCols);
2292  BC.AddMatMat(1.0, B, transB, C, transC, 0.0); // BC = B * C.
2293  return TraceMatMat(BC, A, transA);
2294  } else {
2295  Matrix<Real> CA(CRows, ACols);
2296  CA.AddMatMat(1.0, C, transC, A, transA, 0.0); // CA = C * A
2297  return TraceMatMat(CA, B, transB);
2298  }
2299 }
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 2313 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().

2316  {
2317  MatrixIndexT ARows = A.NumRows(), ACols = A.NumCols(), BRows = B.NumRows(), BCols = B.NumCols(),
2318  CRows = C.NumRows(), CCols = C.NumCols(), DRows = D.NumRows(), DCols = D.NumCols();
2319  if (transA == kTrans) std::swap(ARows, ACols);
2320  if (transB == kTrans) std::swap(BRows, BCols);
2321  if (transC == kTrans) std::swap(CRows, CCols);
2322  if (transD == kTrans) std::swap(DRows, DCols);
2323  KALDI_ASSERT( DCols == ARows && ACols == BRows && BCols == CRows && CCols == DRows && "TraceMatMatMat: args have mismatched dimensions.");
2324  if (ARows*BCols < std::min(BRows*CCols, std::min(CRows*DCols, DRows*ACols))) {
2325  Matrix<Real> AB(ARows, BCols);
2326  AB.AddMatMat(1.0, A, transA, B, transB, 0.0); // AB = A * B.
2327  return TraceMatMatMat(AB, kNoTrans, C, transC, D, transD);
2328  } else if ((BRows*CCols) < std::min(CRows*DCols, DRows*ACols)) {
2329  Matrix<Real> BC(BRows, CCols);
2330  BC.AddMatMat(1.0, B, transB, C, transC, 0.0); // BC = B * C.
2331  return TraceMatMatMat(BC, kNoTrans, D, transD, A, transA);
2332  } else if (CRows*DCols < DRows*ACols) {
2333  Matrix<Real> CD(CRows, DCols);
2334  CD.AddMatMat(1.0, C, transC, D, transD, 0.0); // CD = C * D
2335  return TraceMatMatMat(CD, kNoTrans, A, transA, B, transB);
2336  } else {
2337  Matrix<Real> DA(DRows, ACols);
2338  DA.AddMatMat(1.0, D, transD, A, transA, 0.0); // DA = D * A
2339  return TraceMatMatMat(DA, kNoTrans, B, transB, C, transC);
2340  }
2341 }
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 439 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().

441  {
442  KALDI_ASSERT((transA == kTrans?A.NumCols():A.NumRows()) ==
443  (transC == kTrans?C.NumRows():C.NumCols()) &&
444  (transA == kTrans?A.NumRows():A.NumCols()) == B.NumRows() &&
445  (transC == kTrans?C.NumCols():C.NumRows()) == B.NumRows() &&
446  "TraceMatSpMat: arguments have wrong dimension.");
447  Matrix<Real> tmp(B.NumRows(), B.NumRows());
448  tmp.AddMatMat(1.0, C, transC, A, transA, 0.0); // tmp = C * A.
449  return TraceSpMat(B, tmp);
450 }
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 462 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().

464  {
465  KALDI_ASSERT((transA == kTrans ?A.NumCols():A.NumRows() == D.NumCols()) &&
466  (transA == kTrans ? A.NumRows():A.NumCols() == B.NumRows()) &&
467  (transC == kTrans ? A.NumCols():A.NumRows() == B.NumCols()) &&
468  (transC == kTrans ? A.NumRows():A.NumCols() == D.NumRows()) &&
469  "KALDI_ERR: TraceMatSpMatSp: arguments have mismatched dimension.");
470  // Could perhaps optimize this more depending on dimensions of quantities.
471  Matrix<Real> tmpAB(transA == kTrans ? A.NumCols():A.NumRows(), B.NumCols());
472  tmpAB.AddMatSp(1.0, A, transA, B, 0.0);
473  Matrix<Real> tmpCD(transC == kTrans ? C.NumCols():C.NumRows(), D.NumCols());
474  tmpCD.AddMatSp(1.0, C, transC, D, 0.0);
475  return TraceMatMat(tmpAB, tmpCD, kNoTrans);
476 }
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 413 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().

413  {
414  KALDI_ASSERT(A.NumRows() == B.NumRows() && A.NumCols() == B.NumCols() &&
415  "KALDI_ERR: TraceSpMat: arguments have mismatched dimension");
416  MatrixIndexT R = A.NumRows();
417  Real ans = (Real)0.0;
418  const Real *Aptr = A.Data(), *Bptr = B.Data();
419  MatrixIndexT bStride = B.Stride();
420  for (MatrixIndexT r = 0;r < R;r++) {
421  for (MatrixIndexT c = 0;c < r;c++) {
422  // ans += A(r, c) * (B(r, c) + B(c, r));
423  ans += *(Aptr++) * (Bptr[r*bStride + c] + Bptr[c*bStride + r]);
424  }
425  // ans += A(r, r) * B(r, r);
426  ans += *(Aptr++) * Bptr[r*bStride + r];
427  }
428  return ans;
429 }
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 350 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().

350  {
351  KALDI_ASSERT(A.NumRows() == B.NumRows());
352  const double *Aptr = A.Data();
353  const double *Bptr = B.Data();
354  MatrixIndexT R = A.NumRows();
355  MatrixIndexT RR = (R * (R + 1)) / 2;
356  double all_twice = 2.0 * cblas_Xdot(RR, Aptr, 1, Bptr, 1);
357  // "all_twice" contains twice the vector-wise dot-product... this is
358  // what we want except the diagonal elements are represented
359  // twice.
360  double diag_once = 0.0;
361  for (MatrixIndexT row_plus_two = 2; row_plus_two <= R + 1; row_plus_two++) {
362  diag_once += *Aptr * *Bptr;
363  Aptr += row_plus_two;
364  Bptr += row_plus_two;
365  }
366  return all_twice - diag_once;
367 }
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 370 of file sp-matrix.cc.

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

370  {
371  KALDI_ASSERT(A.NumRows() == B.NumRows());
372  const float *Aptr = A.Data();
373  const float *Bptr = B.Data();
374  MatrixIndexT R = A.NumRows();
375  MatrixIndexT RR = (R * (R + 1)) / 2;
376  float all_twice = 2.0 * cblas_Xdot(RR, Aptr, 1, Bptr, 1);
377  // "all_twice" contains twice the vector-wise dot-product... this is
378  // what we want except the diagonal elements are represented
379  // twice.
380  float diag_once = 0.0;
381  for (MatrixIndexT row_plus_two = 2; row_plus_two <= R + 1; row_plus_two++) {
382  diag_once += *Aptr * *Bptr;
383  Aptr += row_plus_two;
384  Bptr += row_plus_two;
385  }
386  return all_twice - diag_once;
387 }
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 391 of file sp-matrix.cc.

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

391  {
392  KALDI_ASSERT(A.NumRows() == B.NumRows());
393  Real ans = 0.0;
394  const Real *Aptr = A.Data();
395  const OtherReal *Bptr = B.Data();
396  MatrixIndexT row, col, R = A.NumRows();
397  for (row = 0; row < R; row++) {
398  for (col = 0; col < row; col++)
399  ans += 2.0 * *(Aptr++) * *(Bptr++);
400  ans += *(Aptr++) * *(Bptr++); // Diagonal.
401  }
402  return ans;
403 }
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 1195 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().

1195  {
1196  MatrixIndexT adim = A.NumRows();
1197  KALDI_ASSERT(adim == B.NumRows());
1198  MatrixIndexT dim = (adim*(adim+1))/2;
1199  return cblas_Xdot(dim, A.Data(), 1, B.Data(), 1);
1200 }
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 1252 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().

1253  {
1254  KALDI_ASSERT(v1.Dim() == M.NumRows() && v2.Dim() == M.NumCols());
1255  Vector<Real> vtmp(M.NumRows());
1256  vtmp.AddMatVec(1.0, M, kNoTrans, v2, 0.0);
1257  return VecVec(v1, vtmp);
1258 }
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 988 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().

989  {
990  MatrixIndexT D = M.NumRows();
991  KALDI_ASSERT(v1.Dim() == D && v1.Dim() == v2.Dim());
992  Vector<Real> tmp_vec(D);
993  cblas_Xspmv(D, 1.0, M.Data(), v1.Data(), 1, 0.0, tmp_vec.Data(), 1);
994  return VecVec(tmp_vec, v2);
995 }
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(), RepeatedAffineComponent::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