3 #include <matrix-types.h>
15 float* m_data{
nullptr};
17 size_t rows()
const noexcept {
return m_rows; }
18 size_t cols()
const noexcept {
return m_cols; }
19 size_t stride()
const noexcept {
return m_stride; }
20 float* data()
const noexcept {
return m_data; }
21 float* data(
size_t row)
const noexcept {
return m_data + (row * stride()); }
22 float& operator()(
size_t row,
size_t col)
const noexcept {
return m_data[row * m_stride + col]; }
23 bool empty()
const noexcept {
return rows() == 0 || cols() == 0; }
25 void AddMat(
float alpha,
const MatrixBase& A, MatrixTransposeType transA);
26 void AddMatMat(
float,
const MatrixBase&, MatrixTransposeType,
const MatrixBase&, MatrixTransposeType,
float);
29 void ApplyFloor(
float);
31 void CopyColFromVec(
const VectorBase&,
size_t);
32 void CopyCols(
const MatrixBase&,
const std::vector<ssize_t>&);
35 void CopyFromMat(
const MatrixBase&, MatrixTransposeType transposeType);
36 void CopyRowFromVec(
const VectorBase&,
size_t);
37 void CopyRows(
const MatrixBase&,
const std::vector<ssize_t>&);
39 bool IsDiagonal(
float)
const;
40 bool IsSymmetric(
float)
const;
41 bool IsUnit(
float)
const;
44 bool IsZero(
float cutoff = 0.00001)
const;
47 SubMatrix Range(
size_t,
size_t,
size_t,
size_t)
const;
48 void Read(
bool,
bool, std::istream*);
49 void Read(
bool, std::istream*);
51 void Scale(
float factor);
52 void Set(
float value);
53 void SetRandomGaussian();
54 void SetRandomUniform();
57 void Write(
bool, std::ostream*)
const;
59 bool HasInfinity()
const;
64 Resize(other.m_rows, other.m_cols, MatrixResizeType::kUndefined);
65 CopyFromMat(other, MatrixTransposeType::kNoTrans);
68 Resize(other.m_rows, other.m_cols, MatrixResizeType::kUndefined);
69 CopyFromMat(other, MatrixTransposeType::kNoTrans);
72 m_rows = other.m_rows;
73 m_cols = other.m_cols;
74 m_stride = other.m_stride;
75 m_data = other.m_data;
77 other.m_data =
nullptr;
81 void Resize(
size_t rows,
size_t cols, MatrixResizeType resize = MatrixResizeType::kSetZero);
82 void AllocateMatrixMemory(
size_t rows,
size_t cols);
83 void ReleaseMatrixMemory();
84 ~
Matrix() { ReleaseMatrixMemory(); }
93 void RemoveRow(
size_t row);
94 void Read(
bool,
bool, std::istream*);
95 void Read(
bool, std::istream*);
99 static void PrintAllocStats(std::ostream&);
100 static void ResetAllocStats();
103 SubMatrix(
const MatrixBase& parent,
size_t rowoffset,
size_t rows,
size_t coloffset,
size_t cols);
106 std::ostream& operator<<(std::ostream&,
const MatrixBase&);
Definition: vector-wrapper.h:11
Definition: matrix-wrapper.h:11
Definition: matrix-wrapper.h:61
Definition: matrix-wrapper.h:102