Audacity  2.2.0
Matrix.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  Matrix.h
6 
7  Dominic Mazzoni
8 
9 *******************************************************************//*******************************************************************/
25 
26 #ifndef __AUDACITY_MATRIX__
27 #define __AUDACITY_MATRIX__
28 
29 #include "SampleFormat.h"
30 
31 class Matrix;
32 
33 class Vector
34 {
35  public:
36  Vector();
37  Vector(const Vector& copyFrom);
38  Vector(unsigned len, double *data=NULL);
39  Vector(unsigned len, float *data);
40  Vector& operator=(const Vector &other);
41  ~Vector();
42 
43  void Reinit(unsigned len);
44  void Swap(Vector &that);
45 
46  inline double& operator[](unsigned i) { return mData[i]; }
47  inline double operator[](unsigned i) const { return mData[i]; }
48  inline unsigned Len() const { return mN; }
49 
50  double Sum() const;
51 
52  private:
53  unsigned mN{ 0 };
55 };
56 
57 class Matrix
58 {
59  public:
60  Matrix(const Matrix& copyFrom);
61  Matrix(unsigned rows, unsigned cols, double **data=NULL);
62  ~Matrix();
63 
64  Matrix& operator=(const Matrix& other);
65 
66  inline Vector& operator[](unsigned i) { return mRowVec[i]; }
67  inline Vector& operator[](unsigned i) const { return mRowVec[i]; }
68  inline unsigned Rows() const { return mRows; }
69  inline unsigned Cols() const { return mCols; }
70 
71  void SwapRows(unsigned i, unsigned j);
72 
73  private:
74  void CopyFrom(const Matrix& other);
75 
76  unsigned mRows;
77  unsigned mCols;
79 };
80 
81 bool InvertMatrix(const Matrix& input, Matrix& Minv);
82 
83 Matrix TransposeMatrix(const Matrix& M);
84 
85 Matrix IdentityMatrix(unsigned N);
86 
87 Vector operator+(const Vector &left, const Vector &right);
88 Vector operator-(const Vector &left, const Vector &right);
89 Vector operator*(const Vector &left, const Vector &right);
90 Vector operator*(const Vector &left, double right);
91 
92 Vector VectorSubset(const Vector &other, unsigned start, unsigned len);
93 Vector VectorConcatenate(const Vector& left, const Vector& right);
94 
95 Vector operator*(const Vector &left, const Matrix &right);
96 Vector operator*(const Matrix &left, const Vector &right);
97 
98 Matrix operator+(const Matrix &left, const Matrix &right);
99 Matrix operator*(const Matrix &left, const double right);
100 
101 // No operator* on matrices due to ambiguity
102 Matrix ScalarMultiply(const Matrix &left, const Matrix &right);
103 Matrix MatrixMultiply(const Matrix &left, const Matrix &right);
104 
105 Matrix MatrixSubset(const Matrix &M,
106  unsigned startRow, unsigned numRows,
107  unsigned startCol, unsigned numCols);
108 
109 Matrix MatrixConcatenateCols(const Matrix& left, const Matrix& right);
110 
111 bool InvertMatrix(const Matrix& M, Matrix& Minv);
112 
113 #endif // __AUDACITY_MATRIX__
Matrix MatrixMultiply(const Matrix &left, const Matrix &right)
Definition: Matrix.cpp:243
Vector operator+(const Vector &left, const Vector &right)
Definition: Matrix.cpp:135
unsigned mN
Definition: Matrix.h:53
Matrix & operator=(const Matrix &other)
Definition: Matrix.cpp:96
Matrix IdentityMatrix(unsigned N)
Definition: Matrix.cpp:127
void SwapRows(unsigned i, unsigned j)
Definition: Matrix.cpp:122
unsigned Len() const
Definition: Matrix.h:48
Matrix ScalarMultiply(const Matrix &left, const Matrix &right)
Definition: Matrix.cpp:232
Vector operator-(const Vector &left, const Vector &right)
Definition: Matrix.cpp:144
Vector VectorSubset(const Vector &other, unsigned start, unsigned len)
Definition: Matrix.cpp:170
unsigned mRows
Definition: Matrix.h:76
double & operator[](unsigned i)
Definition: Matrix.h:46
unsigned Rows() const
Definition: Matrix.h:68
Matrix MatrixConcatenateCols(const Matrix &left, const Matrix &right)
Definition: Matrix.cpp:267
Vector & operator[](unsigned i)
Definition: Matrix.h:66
Vector()
Definition: Matrix.cpp:18
double operator[](unsigned i) const
Definition: Matrix.h:47
double Sum() const
Definition: Matrix.cpp:72
~Matrix()
Definition: Matrix.cpp:118
void Swap(Vector &that)
Definition: Matrix.cpp:66
Vector VectorConcatenate(const Vector &left, const Vector &right)
Definition: Matrix.cpp:178
Holds a matrix of doubles and supports arithmetic, subsetting, and matrix inversion. Used by InterpolateAudio.
Definition: Matrix.h:57
void Reinit(unsigned len)
Definition: Matrix.cpp:60
Matrix(const Matrix &copyFrom)
Definition: Matrix.cpp:102
bool InvertMatrix(const Matrix &input, Matrix &Minv)
Definition: Matrix.cpp:289
Doubles mData
Definition: Matrix.h:54
~Vector()
Definition: Matrix.cpp:56
Vector operator*(const Vector &left, const Vector &right)
Definition: Matrix.cpp:153
ArrayOf< Vector > mRowVec
Definition: Matrix.h:78
unsigned Cols() const
Definition: Matrix.h:69
Holds a matrix of doubles and supports arithmetic operations, including Vector-Matrix operations...
Definition: Matrix.h:33
Matrix TransposeMatrix(const Matrix &M)
Definition: Matrix.cpp:280
Matrix MatrixSubset(const Matrix &M, unsigned startRow, unsigned numRows, unsigned startCol, unsigned numCols)
Definition: Matrix.cpp:256
Vector & operator=(const Vector &other)
Definition: Matrix.cpp:42
unsigned mCols
Definition: Matrix.h:77
void CopyFrom(const Matrix &other)
Definition: Matrix.cpp:107
Vector & operator[](unsigned i) const
Definition: Matrix.h:67