28 #ifndef KALDI_CUDAMATRIX_CU_VECTOR_H_ 29 #define KALDI_CUDAMATRIX_CU_VECTOR_H_ 38 template<
typename Real>
class CuMatrixBase;
40 template<
typename Real>
41 Real
VecVec(
const CuVectorBase<Real> &v1,
const CuVectorBase<Real> &v2);
43 template<
typename Real,
typename OtherReal>
44 Real
VecVec(
const CuVectorBase<Real> &v1,
const CuVectorBase<OtherReal> &v2);
49 template<
typename Real>
60 template <
typename OtherReal>
81 template<
typename OtherReal>
84 template<
typename OtherReal>
87 template<
typename OtherReal>
98 void Scale(Real value);
102 template<
typename OtherReal>
140 this ->
Floor(*
this, floor_val, floored_count);
144 this ->
Ceiling(*
this, ceiling_val, ceiled_count);
148 this ->
Pow(*
this, power);
171 template<
typename OtherReal>
198 static_cast<UnsignedMatrixIndexT>(
dim_));
206 static_cast<UnsignedMatrixIndexT>(
dim_));
256 template<
typename Real>
277 template<
typename OtherReal>
283 template<
typename OtherReal>
315 void Read(std::istream &is,
bool binary);
316 void Write(std::ostream &is,
bool binary)
const;
324 template<
typename Real>
330 static_cast<UnsignedMatrixIndexT>(length) <=
331 static_cast<UnsignedMatrixIndexT>(t.Dim()));
332 this->
data_ =
const_cast<Real*
>(t.Data()+origin);
345 this->
data_ =
const_cast<Real*
>(data);
359 template<
typename Real>
360 std::ostream &operator << (std::ostream &out, const CuVectorBase<Real> &vec);
363 template<
typename Real>
366 return a.ApproxEqual(b, tol);
369 template<
typename Real>
375 template<
typename Real>
376 template<
typename OtherReal>
381 template<
typename Real>
382 template<
typename OtherReal>
396 template<
typename Real>
397 template<
typename OtherReal>
404 template<
typename Real>
void MulElements(const CuVectorBase< Real > &v)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
friend OtherReal VecVec(const CuVectorBase< OtherReal > &v1, const CuVectorBase< OtherReal > &v2)
This class provides a way for switching between double and float types.
VectorBase< Real > & Vec()
void SetZero()
Math operations.
void CopyDiagFromPacked(const CuPackedMatrix< Real > &M)
Extracts the diagonal of a packed matrix M; works for Sp or Tp.
void MulTp(const CuTpMatrix< Real > &M, const MatrixTransposeType trans)
Multiplies this vector by lower-triangular marix: *this <– *this *M.
const CuSubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l) const
void ApplyCeiling(Real ceiling_val, MatrixIndexT *ceiled_count=NULL)
Base class which provides matrix operations not involving resizing or allocation. ...
void CopyColFromMat(const CuMatrixBase< Real > &mat, MatrixIndexT col)
Real * data_
GPU data pointer (or regular data pointer if CUDA is not compiled in or we have no GPU)...
KALDI_DISALLOW_COPY_AND_ASSIGN(CuVectorBase)
void CopyDiagFromMat(const CuMatrix< Real > &M)
Extracts the diagonal of a matrix.
void AddDiagMat2(Real alpha, const CuMatrixBase< Real > &M, MatrixTransposeType trans, Real beta)
Add the diagonal of a matrix times itself: *this = diag(M M^T) + beta * *this (if trans == kNoTrans)...
CuValue< Real > operator()(MatrixIndexT i)
Real VecMatVec(const VectorBase< Real > &v1, const MatrixBase< Real > &M, const VectorBase< Real > &v2)
Returns .
CuVector(const VectorBase< OtherReal > &v)
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void ApplyFloor(Real floor_val, MatrixIndexT *floored_count=NULL)
The following class is used to simulate non-const references to Real, e.g.
void ReplaceValue(Real orig, Real changed)
void AddDiagMatMat(Real alpha, const CuMatrixBase< Real > &M, MatrixTransposeType transM, const CuMatrixBase< 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 kNoT...
void CopyElements(const CuMatrixBase< Real > &mat, const MatrixTransposeType trans, const CuArrayBase< int32 > &elements)
Copies selected elements from 'mat' to *this.
const Real * Data() const
Returns a pointer to the start of the vector's data (const).
void Pow(const CuVectorBase< Real > &src, Real power)
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
void Ceiling(const CuVectorBase< Real > &src, Real ceiling_val, MatrixIndexT *ceiled_count=NULL)
void AddMatVec(const Real alpha, const CuMatrixBase< Real > &M, MatrixTransposeType trans, const CuVectorBase< Real > &v, const Real beta)
void CopyFromVec(const CuVectorBase< Real > &src)
Copy functions; these will crash if the dimension do not match.
void AddColSumMat(Real alpha, const CuMatrixBase< Real > &mat, Real beta=1.0)
Sum the columns of the matrix, add to vector.
void DivElements(const CuVectorBase< Real > &v)
CuSubVector(const CuVectorBase< Real > &t, const MatrixIndexT origin, const MatrixIndexT length)
void AddSpVec(const Real alpha, const CuSpMatrix< Real > &S, const CuVectorBase< Real > &v, const Real beta)
void ApplyPow(Real power)
#define KALDI_PARANOID_ASSERT(cond)
MatrixIndexT Dim() const
Returns the dimension of the vector.
CuSubVector(const CuMatrixBase< Real > &matrix, MatrixIndexT row)
This operation does not preserve const-ness, so be careful.
Real Max() const
Returns the maximum value of any element, or -infinity for the empty vector.
void AddVec(Real alpha, const CuVectorBase< Real > &vec, Real beta=1.0)
CuSubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Vector()
Constructor that takes no arguments. Initializes to empty.
Matrix for CUDA computing.
CuVector(const CuVectorBase< OtherReal > &v)
MatrixIndexT NumCols() const
CuSubVector(const CuSubVector &other)
Copy constructor this constructor needed for Range() to work in base class.
MatrixIndexT dim_
dimension of the vector
A class representing a vector.
void Floor(const CuVectorBase< Real > &src, Real floor_val, MatrixIndexT *floored_count=NULL)
const VectorBase< Real > & Vec() const
#define KALDI_ASSERT(cond)
Matrix for CUDA computing.
void AddVecVec(Real alpha, const CuVectorBase< Real > &v, const CuVectorBase< Real > &r, Real beta)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Real * Data()
Returns a pointer to the start of the vector's data.
bool ApproxEqual(const CuVectorBase< Real > &other, float tol=0.01) const
CuVector(MatrixIndexT dim, MatrixResizeType t=kSetZero)
Provides a vector abstraction class.
void AddTpVec(const Real alpha, const CuTpMatrix< Real > &M, const MatrixTransposeType trans, const CuVectorBase< Real > &v, const Real beta)
Add triangular matrix times vector: this <– beta*this + alpha*M*v.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
void CopyToVec(VectorBase< OtherReal > *dst) const
CuSubVector(const Real *data, MatrixIndexT length)
void CopyRowsFromMat(const CuMatrixBase< Real > &M)
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
void AddRowSumMat(Real alpha, const CuMatrixBase< Real > &mat, Real beta=1.0)
Sum the rows of the matrix, add to vector.
CuVector(const CuVector< Real > &v)
MatrixIndexT Dim() const
Dimensions.
Vector for CUDA computing.
const Real * RowData(MatrixIndexT r) const
Get raw row pointer (const).