cu-test.cc
Go to the documentation of this file.
1 // cudamatrix/cu-test.cc
2 
3 // Copyright 2013 Karel Vesely
4 // 2014 LINSE/UFSC; Augusto Henrique Hentz
5 // 2013-2015 Johns Hopkins University (author: Daniel Povey)
6 
7 // See ../../COPYING for clarification regarding multiple authors
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
17 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
18 // MERCHANTABLITY OR NON-INFRINGEMENT.
19 // See the Apache 2 License for the specific language governing permissions and
20 // limitations under the License.
21 
22 #include <iostream>
23 #include <vector>
24 #include <cstdlib>
25 #include <ctime>
26 
27 #include "base/kaldi-common.h"
28 #include "cudamatrix/cu-device.h"
32 #include "cudamatrix/cu-vector.h"
33 #include <numeric>
34 #include <time.h>
35 
36 namespace kaldi {
37 
38 /*
39  * INITIALIZERS
40  */
41 template<typename Real>
42 static void InitRand(SpMatrix<Real> *M) {
43  do {
44  for (MatrixIndexT i = 0; i < M->NumRows(); i++) {
45  for (MatrixIndexT j = 0; j <= i; j++ ) {
46  (*M)(i,j) = RandGauss();
47  }
48  }
49  } while (M->NumRows() != 0 && M->Cond() > 100);
50 }
51 
52 template<typename Real>
53 static void InitRand(VectorBase<Real> *v) {
54  for (MatrixIndexT i = 0; i < v->Dim(); i++) {
55  (*v)(i) = RandGauss();
56  }
57 }
58 
59 template<typename Real>
60 static void UnitTestSetZeroAboveDiag() {
61  for (MatrixIndexT i = 1; i < 10; i++) {
62  MatrixIndexT dim = 10 * i;
63  Matrix<Real> A(dim,dim);
64  A.SetRandn();
65  CuMatrix<Real> B(A);
66 
67  B.SetZeroAboveDiag();
68 
69  Real sum = 0.0;
70  for (MatrixIndexT i = 0; i < dim; i++) {
71  for (MatrixIndexT j = i + 1; j < dim; j++)
72  sum += A(i,j);
73  }
74 
75  KALDI_LOG << "the upper diaganoal sum for A is : " << sum;
76  B.CopyToMat(&A);
77  sum = 0.0;
78  for (MatrixIndexT i = 0; i < dim; i++) {
79  for (MatrixIndexT j = i + 1; j < dim; j++)
80  sum += A(i,j);
81  }
82  KALDI_LOG << "the upper diaganoal sum for B is : " << sum;
83  }
84 }
85 
86 
87 template<typename Real> static void UnitTestCholesky() {
88  for (MatrixIndexT iter = 0; iter < 3; iter++) {
89  MatrixIndexT dim = 300 + Rand() % 200;
90  // set dimension
91  // computing the matrix for cholesky input
92  // CuMatrix is cuda matrix class while Matrix is cpu matrix class
93  CuMatrix<Real> A(dim, dim);
94  Matrix<Real> B(dim, dim);
95  Vector<Real> C(dim);
96  for (MatrixIndexT i = 0; i < dim; i++) {
97  B(i, i) = 1;
98  C(i) = 1 + Rand() % 4;
99  }
100  B.AddVecVec(1.0, C, C);
101  // copy the matrix to cudamatrix object
102  A.CopyFromMat(B);
103  A.CopyToMat(&B);
104  //KALDI_LOG << B;
105  // doing cholesky
106  A.Cholesky();
107 
108  Matrix<Real> D(dim,dim);
109  A.CopyToMat(&D);
110 
111  //KALDI_LOG << "D is: " << D;
112  Matrix<Real> E(dim,dim);
113  E.AddMatMat(1.0, D, kNoTrans, D, kTrans, 0.0);
114  // check if the D'D is equal to B or not!
115  AssertEqual(B, E);
116  }
117 }
118 
119 template<typename Real> static void UnitTestTrace() {
120  for (MatrixIndexT iter = 1; iter < 18; iter++) {
121  MatrixIndexT dim = iter;
122  KALDI_LOG << "dim is : " << iter;
123  SpMatrix<Real> A(dim);
124  A.SetRandn();
125  CuSpMatrix<Real> B(A);
126  KALDI_LOG << "cpu trace is : " << A.Trace();
127  KALDI_LOG << "gpu trace is : " << B.Trace();
128  }
129  /*
130  Vector<Real> tim(100);
131  Vector<Real> d(100);
132  for (MatrixIndexT iter = 0; iter < 100; iter++) {
133  MatrixIndexT dim = 10000 + Rand() % 400;
134  Matrix<Real> A(dim,dim);
135  A.SetRandn();
136  CuMatrix<Real> B(A);
137  CuSpMatrix<Real> C(B,kTakeLower);
138  clock_t t1 = clock();
139  tim(iter) = C.Trace();
140  clock_t t2 = clock();
141  //tim(iter) = t2 - t1;
142  d(iter) = dim;
143  KALDI_LOG << tim(iter) << iter;
144  KALDI_LOG << d(iter) << iter;
145  }
146  KALDI_LOG << "tim is " << tim;
147  KALDI_LOG << "dim is " << d;
148  */
149 }
150 
151 template<typename Real> static void UnitInvert() {
152  //MatrixIndexT dim = 15 + Rand() % 40;;
153  MatrixIndexT dim = 8;
154  CuMatrix<Real> A(dim,dim);
155  Matrix<Real> B(dim,dim);
156  Vector<Real> C(dim);
157  for (MatrixIndexT i = 0; i < dim; i++) {
158  B(i,i) = 1;
159  C(i) = i + 1;
160  }
161  B.AddVecVec(1.0,C,C);
162  CuMatrix<Real> tmp(dim,dim);
163  A.CopyFromMat(B);
164  //A.Cholesky();
165  A.CopyToMat(&B);
166  KALDI_LOG << "B is : ";
167  KALDI_LOG << B;
168  A.SymInvertPosDef();
169  Matrix<Real> D(dim,dim);
170  A.CopyToMat(&D);
171  KALDI_LOG << "D is : ";
172  KALDI_LOG << D;
173  Matrix<Real> X(dim,dim);
174  X.AddMatMat(1,B,kNoTrans,D,kNoTrans,0);
175  KALDI_LOG << X;
176  //for (MatrixIndexT i = 0; i < dim; i++) {
177  // for (MatrixIndexT j = i+1; j < dim; j++)
178  // D(i,j) = 0;
179  //}
180  //Matrix<Real> E(dim,dim);
181  //E.AddMatMat(1,D,kNoTrans,D,kTrans,0);
182  //AssertEqual(B,E);
183 }
184 
185 template<typename Real> static void UnitTestInvert() {
186  for (MatrixIndexT iter = 0; iter < 3; iter++) {
187  MatrixIndexT dim = 500 + Rand() % 400;
188 
189  KALDI_LOG << "dim is : ";
190  KALDI_LOG << dim;
191  CuMatrix<Real> A(dim,dim);
192  Matrix<Real> B(dim,dim);
193  Vector<Real> C(dim);
194  for (MatrixIndexT i = 0; i < dim; i++) {
195  B(i,i) = 1;
196  C(i) = (i/(1.0*dim)) + 1;
197  }
198  Matrix<Real> Identity(B);
199  B.AddVecVec(1.0, C, C);
200  // Now we have a positive-definite B (inversion would
201  // fail if it were not positive definite).
202 
203  A.CopyFromMat(B);
204 
205  A.SymInvertPosDef();
206  Matrix<Real> D(dim,dim);
207  A.CopyToMat(&D);
208 
209  Matrix<Real> X(dim,dim);
210  X.AddMatMat(1.0, B, kNoTrans, D, kNoTrans, 0.0);
211  // KALDI_LOG << "X is (should be identity): " << X;
212  AssertEqual(Identity, X, (sizeof(Real) == 4 ? 0.1 : 0.001));
213  }
214 }
215 
216 template<typename Real> static void UnitTestConstructor() {
217  MatrixIndexT dim = 8;
218  CuMatrix<Real> A(dim,dim);
219  Matrix<Real> B(dim,dim);
220  for (MatrixIndexT i = 0; i < dim; i++) {
221  for (MatrixIndexT j = 0; j <=i; j++)
222  B(i,j) = i+j;
223  for (MatrixIndexT j = i+1; j < dim; j++)
224  B(i,j) = i+j+4;
225  }
226  KALDI_LOG << "A is : ";
227  KALDI_LOG << B;
228  A.CopyFromMat(B);
229  //CuSpMatrix<Real> C(dim);
230  //C.CopyFromMat(A,kTakeLower);
232  SpMatrix<Real> D(dim);
233  C.CopyToSp(&D);
234  KALDI_LOG << "C is : ";
235  for (MatrixIndexT i = 0; i < dim; i++) {
236  for (MatrixIndexT j = 0; j <= i; j++)
237  std::cout << D(i,j) << " ";
238  std::cout << '\n';
239  }
240 }
241 
242 template<typename Real> static void UnitTestCopySp() {
243  // Checking that the various versions of copying
244  // matrix to SpMatrix work the same in the symmetric case.
245  for (MatrixIndexT iter = 0;iter < 5;iter++) {
246  int32 dim = 5 + Rand() % 10;
247  SpMatrix<Real> A(dim), B(dim);
248  A.SetRandn();
249  Matrix<Real> C(A);
250  //CuMatrix<Real> D(C);
251 
252  {
253  CuMatrix<Real> D2(dim,dim);
254  D2.CopyFromMat(C);
255  KALDI_LOG << "D2 is " << D2;
256  CuSpMatrix<Real> E(D2.NumRows(), kUndefined);
257  KALDI_LOG << "D2 is " << D2;
258  E.CopyFromMat(D2, kTakeLower);
259  KALDI_LOG << "D2 is " << D2;
260  }
261 
262  CuMatrix<Real> D(dim,dim);
263  D.CopyFromMat(C);
264  KALDI_LOG << "D stride is : " << D.Stride() <<'\n';
265 
268  //E.CopyFromMat(D,kTakeLower);
269  /*
270  KALDI_LOG << D.NumRows();
271  //E.CopyFromMat(D, kTakeMean);
272  //E(D, kTakeMean);
273  //KALDI_LOG << E.NumRows();
274 
275  E.CopyToMat(&B);
276  AssertEqual(A, B);
277  B.SetZero();
278  //E.CopyFromMat(D, kTakeLower);
279  CuSpMatrix<Real> F(D,kTakeLower);
280  //F(D, kTakeLower);
281  F.CopyToMat(&B);
282  AssertEqual(A, B);
283  B.SetZero();
284  //E.CopyFromMat(D, kTakeUpper);
285  //E(D, kTakeUpper);
286  CuSpMatrix<Real> G(D, kTakeUpper);
287  G.CopyToMat(&B);
288  AssertEqual(A, B);
289  */
290  }
291 
292 }
293 
294 template<typename Real> static void UnitTestCopyFromMat() {
295  MatrixIndexT dim = 8;
296  CuMatrix<Real> A(dim,dim);
297  Matrix<Real> B(dim,dim);
298  for (MatrixIndexT i = 0; i < dim; i++) {
299  for (MatrixIndexT j = 0; j <=i; j++)
300  B(i,j) = i+j;
301  for (MatrixIndexT j = i+1; j < dim; j++)
302  B(i,j) = i+j+4;
303  }
304  KALDI_LOG << "A is : ";
305  KALDI_LOG << B;
306  A.CopyFromMat(B);
307  CuSpMatrix<Real> C(dim);
308  C.CopyFromMat(A,kTakeLower);
309  SpMatrix<Real> D(dim);
310  C.CopyToSp(&D);
311  KALDI_LOG << "C is : ";
312  for (MatrixIndexT i = 0; i < dim; i++) {
313  for (MatrixIndexT j = 0; j <= i; j++)
314  std::cout << D(i,j) << " ";
315  std::cout << '\n';
316  }
317  C.CopyFromMat(A,kTakeUpper);
318  C.CopyToSp(&D);
319  KALDI_LOG << "C is : ";
320  for (MatrixIndexT i = 0; i < dim; i++) {
321  for (MatrixIndexT j = 0; j <= i; j++)
322  std::cout << D(i,j) << " ";
323  std::cout << '\n';
324  }
325 
326  C.CopyFromMat(A,kTakeMean);
327  C.CopyToSp(&D);
328  KALDI_LOG << "C is : ";
329  for (MatrixIndexT i = 0; i < dim; i++) {
330  for (MatrixIndexT j = 0; j <= i; j++)
331  std::cout << D(i,j) << " ";
332  std::cout << '\n';
333  }
334 
335  //KALDI_LOG << D;
336 }
337 
338 template<typename Real> static void UnitTestMatrix() {
339  //operator()
340  for (MatrixIndexT iter = 0; iter < 2; iter++) {
341  int32 dim1 = 6 + Rand() % 10;
342  int32 dim2 = 8 + Rand() % 10;
343  Matrix<Real> A(dim1,dim2);
344  A.SetRandn();
345  CuMatrix<Real> B(A);
346  KALDI_ASSERT(A(3, 4) == B(3, 4));
347  B(3, 4) = 2.0;
348  A(3, 4) = B(3, 4);
349  KALDI_ASSERT(A(3, 4) == B(3, 4));
350 
351  SpMatrix<Real> As(dim1);
352  CuSpMatrix<Real> Bs(As);
353  KALDI_ASSERT(As(3, 4) == Bs(3, 4));
354  Bs(3, 4) = 2.0;
355  if (Rand() % 2 == 0)
356  As(3, 4) = Bs(3, 4);
357  else
358  As(3, 4) = (const_cast<const CuSpMatrix<Real>&>(Bs))(3, 4);
359 
360  KALDI_ASSERT(As(3, 4) == Bs(3, 4));
361 
362  Vector<Real> v(dim1);
363  CuVector<Real> w(v);
364  KALDI_ASSERT(w(2) == v(2));
365  w(2) = 3.0;
366  v(2) = w(2);
367  KALDI_ASSERT(w(2) == v(2));
368  }
369 
370  //SetRandn
371  for (MatrixIndexT iter = 0; iter < 10; iter++) {
372  int32 dim1 = 15 + Rand() % 10;
373  int32 dim2 = dim1;//10 + Rand() % 14;
374  //KALDI_LOG << "dimension is " << dim1
375  // << " " << dim2 << '\n';
376  CuMatrix<Real> A(dim1,dim2);
377  A.SetRandn();
378  Matrix<Real> A1(dim1,dim2);
379  A.CopyToMat(&A1);
380  //KALDI_LOG << "gpu sum is: " << A.Sum();
381  //KALDI_LOG << "cpu sum is: " << A1.Sum();
382  }
383 }
384 
385 template<typename Real> static void UnitTestMulTp() {
386  for (MatrixIndexT iter = 0; iter < 10; iter++) {
387  int32 dim = 1 + Rand() % 30;
388  Vector<Real> v(dim);
389  v.SetRandn();
390  TpMatrix<Real> M(dim);
391  M.SetRandn();
392  CuVector<Real> cv(v);
393  CuTpMatrix<Real> cM(M);
394 
395  Vector<Real> v2(dim);
396  cv.CopyToVec(&v2);
397  AssertEqual(v, v2);
398  v.MulTp(M, iter % 2 == 0 ? kTrans:kNoTrans);
399  cv.MulTp(cM, iter % 2 == 0 ? kTrans:kNoTrans);
400  cv.CopyToVec(&v2);
401  // KALDI_LOG << "v is " << v << ", v2 is " << v2;
402  AssertEqual(v, v2);
403  }
404 }
405 
406 template<typename Real> static void UnitTestVector() {
407  // Scale
408  for (MatrixIndexT iter = 0; iter < 10; iter++) {
409  int32 dim = 24 + Rand() % 10;
410  Vector<Real> A(dim);
411  A.SetRandn();
412  CuVector<Real> B(A);
413  Vector<Real> C(dim);
414  Real r = 1.43;
415  B.Scale(r);
416  B.CopyToVec(&C);
417  A.Scale(r);
418  //KALDI_LOG << A;
419  //KALDI_LOG << (A.Scale(r));
420  //KALDI_LOG << C;
421  AssertEqual(A, C);
422  }
423 
424  for (MatrixIndexT iter = 0; iter < 10; iter++) {
425  int32 dim = 15 + Rand() % 10;
426  CuVector<Real> A(dim);
427  CuVector<Real> B(dim);
428  Vector<Real> A1(dim);
429  Vector<Real> B1(dim);
430  A.SetRandn();
431  B.SetRandn();
432  A.CopyToVec(&A1);
433  B.CopyToVec(&B1);
434  A.MulElements(B);
435  A1.MulElements(B1);
436  Vector<Real> A2(dim);
437  A.CopyToVec(&A2);
438  AssertEqual(A1,A2);
439  }
440  /*
441  for (MatrixIndexT iter = 0; iter < 10; iter++) {
442  int32 dim = 72;
443  CuVector<Real> A(dim);
444  Vector<Real> A1(dim);
445  CuMatrix<Real> B(9,8);
446  Matrix<Real> B1(9,8);
447  B.SetRandn();
448  B.CopyToMat(&B1);
449  A.CopyRowsFromMat(B);
450  A1.CopyRowsFromMat(B1);
451  Vector<Real> A2(dim);
452  A.CopyToVec(&A2);
453  AssertEqual(A1,A2);
454  }
455 
456  for (MatrixIndexT iter = 0; iter < 10; iter++) {
457  int32 dim = 15 + Rand() % 10;
458  CuVector<Real> A(dim);
459  A.SetRandn();
460  Vector<Real> A1(dim);
461  A.CopyToVec(&A1);
462  KALDI_LOG << "cpu min is : " << A1.Min();
463  KALDI_LOG << "gpu min is : " << A.Min();
464  }
465 
466  for (MatrixIndexT iter = 0; iter < 10; iter++) {
467  int32 dim = 15 + Rand() % 10;
468  CuVector<Real> A(dim);
469  A.SetRandn();
470  Vector<Real> A1(dim);
471  A.CopyToVec(&A1);
472  CuVector<Real> B(dim);
473  B.SetRandn();
474  Vector<Real> B1(dim);
475  B.CopyToVec(&B1);
476  CuVector<Real> C(dim);
477  C.SetRandn();
478  Vector<Real> C1(dim);
479  C.CopyToVec(&C1);
480  Real alpha = 2;
481  Real beta = 3;
482  A.AddVecVec(alpha, B, C, beta);
483  A1.AddVecVec(alpha,B1,C1,beta);
484  Vector<Real> D(dim);
485  A.CopyToVec(&D);
486  AssertEqual(D,A1);
487  }
488 
489  for (MatrixIndexT iter = 0; iter < 10; iter++) {
490  int32 dim1 = 15 + Rand() % 10;
491  int32 dim2 = 10 + Rand() % 10;
492  Matrix<Real> A(dim1,dim2);
493  for (MatrixIndexT i = 0; i < dim1; i++) {
494  for (MatrixIndexT j = 0; j < dim2; j++)
495  A(i,j) = i + 2 * j + 1;
496  }
497  KALDI_LOG << A;
498  CuMatrix<Real> B(dim1,dim2);
499  B.CopyFromMat(A);
500  CuVector<Real> C(dim1);
501  C.SetZero();
502  Real alpha = 1;
503  Real beta = 1;
504  C.AddDiagMat2(alpha, B, kNoTrans, beta);
505  Vector<Real> D(dim1);
506  C.CopyToVec(&D);
507  KALDI_LOG << D;
508  Vector<Real> E(dim1);
509  E.AddDiagMat2(alpha, A, kNoTrans, beta);
510  KALDI_LOG << E;
511  AssertEqual(D,E);
512  }
513 
514  for (MatrixIndexT iter = 0; iter < 10; iter++) {
515  int32 dim1 = 15 + Rand() % 10;
516  int32 dim2 = 10 + Rand() % 10;
517  Matrix<Real> A(dim1,dim2);
518  for (MatrixIndexT i = 0; i < dim1; i++) {
519  for (MatrixIndexT j = 0; j < dim2; j++)
520  A(i,j) = i + 2 * j + 1;
521  }
522  KALDI_LOG << A;
523  CuMatrix<Real> B(dim1,dim2);
524  B.CopyFromMat(A);
525  CuSubVector<Real> C(B,1);
526  Vector<Real> D(dim2);
527  C.CopyToVec(&D);
528  KALDI_LOG << D;
529  }
530 
531  for (MatrixIndexT iter = 0; iter < 10; iter++) {
532  int32 dim = 15 + Rand() % 10;
533  CuVector<Real> A(dim);
534  A.SetRandn();
535  Vector<Real> A1(dim);
536  A.CopyToVec(&A1);
537  CuVector<Real> B(dim);
538  B.SetRandn();
539  Vector<Real> B1(dim);
540  B.CopyToVec(&B1);
541  Real dot = VecVec(A,B);
542  KALDI_LOG << "dot product in gpu: " << dot;
543  dot = VecVec(A1,B1);
544  KALDI_LOG << "dot product in cpu: " << dot;
545  }
546 
547  for (MatrixIndexT iter = 0; iter < 10; iter++) {
548  int32 dim = 15 + Rand() % 10;
549  CuVector<Real> A(dim);
550  Vector<Real> A1(dim);
551  for (MatrixIndexT i = 0; i < dim; i++)
552  A1(i) = i;
553  A.CopyFromVec(A1);
554  KALDI_LOG << A(dim-2);
555  KALDI_LOG << A1(dim-2);
556  }
557  */
558 }
559 
560 template<typename Real>
561 static void CuMatrixUnitTest() {
562  UnitTestTrace<Real>();
563  UnitTestCholesky<Real>();
564  UnitTestInvert<Real>();
565  UnitInvert<Real>();
566  UnitTestCopyFromMat<Real>();
567  UnitTestCopySp<Real>();
568  UnitTestConstructor<Real>();
569  UnitTestVector<Real>();
570  UnitTestMulTp<Real>();
571  UnitTestMatrix<Real>();
572  UnitTestSetZeroAboveDiag<Real>();
573 }
574 } //namespace
575 
576 int main() {
577  using namespace kaldi;
578  SetVerboseLevel(1);
579 #if HAVE_CUDA == 1
580  for (int32 loop = 0; loop < 2; loop++) {
581  if (loop == 0)
582  CuDevice::Instantiate().SelectGpuId("no");
583  else
584  CuDevice::Instantiate().SelectGpuId("yes");
585 #endif
586  kaldi::CuMatrixUnitTest<float>();
587 
588 #if HAVE_CUDA == 1
589  if (!kaldi::CuDevice::Instantiate().DoublePrecisionSupported()) {
590  KALDI_WARN << "Double precision not supported, not testing that code";
591  } else
592 #endif
593  {
594  kaldi::CuMatrixUnitTest<double>();
595  }
596 #if HAVE_CUDA == 1
597  }
598  kaldi::CuDevice::Instantiate().PrintProfile();
599 #endif
600 
601  KALDI_LOG << "Tests succeeded.";
602  return 0;
603 }
void MulElements(const CuVectorBase< Real > &v)
Definition: cu-vector.cc:838
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
Definition: cu-matrix.cc:344
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
MatrixIndexT Stride() const
Definition: cu-matrix.h:217
static void UnitTestCopyFromMat()
Definition: cu-test.cc:294
Packed symetric matrix class.
Definition: matrix-common.h:62
static void UnitTestConstructor()
Definition: cu-test.cc:216
void MulTp(const CuTpMatrix< Real > &M, const MatrixTransposeType trans)
Multiplies this vector by lower-triangular marix: *this <– *this *M.
Definition: cu-vector.cc:727
void CopyToMat(MatrixBase< OtherReal > *dst, MatrixTransposeType trans=kNoTrans) const
Definition: cu-matrix.cc:447
static void UnitTestSetZeroAboveDiag()
Definition: cu-test.cc:60
static void UnitTestVector()
Definition: cu-test.cc:406
static void UnitTestInvert()
Definition: cu-test.cc:185
Real Trace() const
Definition: sp-matrix.cc:171
float RandGauss(struct RandomState *state=NULL)
Definition: kaldi-math.h:155
kaldi::int32 int32
void MulTp(const TpMatrix< Real > &M, const MatrixTransposeType trans)
Multiplies this vector by lower-triangular matrix: *this <– *this *M.
A class for storing matrices.
Definition: kaldi-matrix.h:823
This class represents a matrix that&#39;s stored on the GPU if we have one, and in memory if not...
Definition: matrix-common.h:71
MatrixIndexT NumRows() const
static void UnitTestMatrix()
Definition: cu-test.cc:338
static void InitRand(VectorBase< Real > *v)
void SetRandn()
< Set to unit matrix.
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
Definition: kaldi-error.h:64
void SymInvertPosDef()
Inversion for positive definite symmetric matrices.
Definition: cu-matrix.cc:2111
int32 MatrixIndexT
Definition: matrix-common.h:98
static void UnitTestMulTp()
Definition: cu-test.cc:385
static void UnitTestCholesky()
Definition: cu-test.cc:87
void MulElements(const VectorBase< Real > &v)
Multiply element-by-element by another vector.
static void UnitInvert()
Definition: cu-test.cc:151
void SetRandn()
Sets to random values of a normal distribution.
void AddMatMat(const Real alpha, const MatrixBase< Real > &A, MatrixTransposeType transA, const MatrixBase< Real > &B, MatrixTransposeType transB, const Real beta)
static void CuMatrixUnitTest()
Definition: cu-test.cc:561
Packed symetric matrix class.
Definition: matrix-common.h:63
void Cholesky(CuMatrixBase< Real > *inv_cholesky=NULL)
This function does sets *this to the Cholesky factor of *this (i.e.
Definition: cu-matrix.cc:1987
#define KALDI_WARN
Definition: kaldi-error.h:150
static void UnitTestTrace()
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
void Scale(Real alpha)
Multiplies all elements by this constant.
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
void SetRandn()
Set vector to random normally-distributed noise.
int main()
Definition: cu-test.cc:576
void CopyFromMat(const CuMatrixBase< Real > &orig, SpCopyType copy_type=kTakeLower)
Definition: cu-sp-matrix.cc:39
void CopyToSp(SpMatrix< Real > *dst) const
Definition: cu-sp-matrix.h:95
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Real Cond() const
Returns maximum ratio of singular values.
Definition: sp-matrix.h:145
void AddVecVec(const Real alpha, const VectorBase< OtherReal > &a, const VectorBase< OtherReal > &b)
*this += alpha * a * b^T
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
void Scale(Real value)
Definition: cu-vector.cc:1216
static void UnitTestCopySp()
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
#define KALDI_LOG
Definition: kaldi-error.h:153
void CopyToVec(VectorBase< OtherReal > *dst) const
Definition: cu-vector.cc:938
void SetZeroAboveDiag()
Zeroes all elements for which col > row.
Definition: cu-matrix.cc:554