matrix-functions.h
Go to the documentation of this file.
1 // matrix/matrix-functions.h
2 
3 // Copyright 2009-2011 Microsoft Corporation; Go Vivace Inc.; Jan Silovsky;
4 // Yanmin Qian; 1991 Henrique (Rico) Malvar (*)
5 //
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 // (*) incorporates, with permission, FFT code from his book
22 // "Signal Processing with Lapped Transforms", Artech, 1992.
23 
24 
25 
26 #ifndef KALDI_MATRIX_MATRIX_FUNCTIONS_H_
27 #define KALDI_MATRIX_MATRIX_FUNCTIONS_H_
28 
29 #include "matrix/kaldi-vector.h"
30 #include "matrix/kaldi-matrix.h"
31 
32 namespace kaldi {
33 
36 
64 template<typename Real> void ComplexFft (VectorBase<Real> *v, bool forward, Vector<Real> *tmp_work = NULL);
65 
69 template<typename Real> void ComplexFt (const VectorBase<Real> &in,
70  VectorBase<Real> *out, bool forward);
71 
83 
84 template<typename Real> void RealFft (VectorBase<Real> *v, bool forward);
85 
86 
89 template<typename Real> void RealFftInefficient (VectorBase<Real> *v, bool forward);
90 
104 
105 template<typename Real> void ComputeDctMatrix(Matrix<Real> *M);
106 
107 
109 template<typename Real> inline void ComplexMul(const Real &a_re, const Real &a_im,
110  Real *b_re, Real *b_im);
111 
113 template<typename Real> inline void ComplexAddProduct(const Real &a_re, const Real &a_im,
114  const Real &b_re, const Real &b_im,
115  Real *c_re, Real *c_im);
116 
117 
119 template<typename Real> inline void ComplexImExp(Real x, Real *a_re, Real *a_im);
120 
121 
122 
142 template<typename Real>
143 void ComputePca(const MatrixBase<Real> &X,
144  MatrixBase<Real> *U,
145  MatrixBase<Real> *A,
146  bool print_eigs = false,
147  bool exact = true);
148 
149 
150 
151 // This function does: *plus += max(0, a b^T),
152 // *minus += max(0, -(a b^T)).
153 template<typename Real>
154 void AddOuterProductPlusMinus(Real alpha,
155  const VectorBase<Real> &a,
156  const VectorBase<Real> &b,
157  MatrixBase<Real> *plus,
158  MatrixBase<Real> *minus);
159 
160 template<typename Real1, typename Real2>
161 inline void AssertSameDim(const MatrixBase<Real1> &mat1, const MatrixBase<Real2> &mat2) {
162  KALDI_ASSERT(mat1.NumRows() == mat2.NumRows()
163  && mat1.NumCols() == mat2.NumCols());
164 }
165 
166 
168 
169 } // end namespace kaldi
170 
172 
173 
174 #endif
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void RealFftInefficient(VectorBase< Real > *v, bool forward)
Inefficient version of Fourier transform, for testing purposes.
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
Base class which provides matrix operations not involving resizing or allocation. ...
Definition: kaldi-matrix.h:49
void ComputeDctMatrix(Matrix< Real > *M)
ComputeDctMatrix computes a matrix corresponding to the DCT, such that M * v equals the DCT of vector...
void ComplexFt(const VectorBase< Real > &in, VectorBase< Real > *out, bool forward)
ComplexFt is the same as ComplexFft but it implements the Fourier transform in an inefficient way...
void ComplexAddProduct(const Real &a_re, const Real &a_im, const Real &b_re, const Real &b_im, Real *c_re, Real *c_im)
ComplexMul implements, inline, the complex operation c += (a * b).
void AssertSameDim(const MatrixBase< Real1 > &mat1, const MatrixBase< Real2 > &mat2)
void ComputePca(const MatrixBase< Real > &X, MatrixBase< Real > *U, MatrixBase< Real > *A, bool print_eigs, bool exact)
ComputePCA does a PCA computation, using either outer products or inner products, whichever is more e...
void ComplexMul(const Real &a_re, const Real &a_im, Real *b_re, Real *b_im)
ComplexMul implements, inline, the complex multiplication b *= a.
void AddOuterProductPlusMinus(Real alpha, const VectorBase< Real > &a, const VectorBase< Real > &b, MatrixBase< Real > *plus, MatrixBase< Real > *minus)
void ComplexFft(VectorBase< Real > *v, bool forward, Vector< Real > *tmp_in)
The function ComplexFft does an Fft on the vector argument v.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void ComplexImExp(Real x, Real *a_re, Real *a_im)
ComplexImExp implements a <– exp(i x), inline.
void RealFft(VectorBase< Real > *v, bool forward)
RealFft is a fourier transform of real inputs.