Audacity 3.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
31class Matrix;
32
33class 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
57class 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
81bool InvertMatrix(const Matrix& input, Matrix& Minv);
82
84
85Matrix IdentityMatrix(unsigned N);
86
87Vector operator+(const Vector &left, const Vector &right);
88Vector operator-(const Vector &left, const Vector &right);
89Vector operator*(const Vector &left, const Vector &right);
90Vector operator*(const Vector &left, double right);
91
92Vector VectorSubset(const Vector &other, unsigned start, unsigned len);
93Vector VectorConcatenate(const Vector& left, const Vector& right);
94
95Vector operator*(const Vector &left, const Matrix &right);
96Vector operator*(const Matrix &left, const Vector &right);
97
98Matrix operator+(const Matrix &left, const Matrix &right);
99Matrix operator*(const Matrix &left, const double right);
100
101// No operator* on matrices due to ambiguity
102Matrix ScalarMultiply(const Matrix &left, const Matrix &right);
103Matrix MatrixMultiply(const Matrix &left, const Matrix &right);
104
105Matrix MatrixSubset(const Matrix &M,
106 unsigned startRow, unsigned numRows,
107 unsigned startCol, unsigned numCols);
108
109Matrix MatrixConcatenateCols(const Matrix& left, const Matrix& right);
110
111bool InvertMatrix(const Matrix& M, Matrix& Minv);
112
113#endif // __AUDACITY_MATRIX__
Matrix TransposeMatrix(const Matrix &M)
Definition: Matrix.cpp:280
Matrix IdentityMatrix(unsigned N)
Definition: Matrix.cpp:127
Vector VectorConcatenate(const Vector &left, const Vector &right)
Definition: Matrix.cpp:178
Vector operator-(const Vector &left, const Vector &right)
Definition: Matrix.cpp:144
Vector operator+(const Vector &left, const Vector &right)
Definition: Matrix.cpp:135
bool InvertMatrix(const Matrix &input, Matrix &Minv)
Definition: Matrix.cpp:289
Matrix MatrixConcatenateCols(const Matrix &left, const Matrix &right)
Definition: Matrix.cpp:267
Vector operator*(const Vector &left, const Vector &right)
Definition: Matrix.cpp:153
Vector VectorSubset(const Vector &other, unsigned start, unsigned len)
Definition: Matrix.cpp:170
Matrix ScalarMultiply(const Matrix &left, const Matrix &right)
Definition: Matrix.cpp:232
Matrix MatrixSubset(const Matrix &M, unsigned startRow, unsigned numRows, unsigned startCol, unsigned numCols)
Definition: Matrix.cpp:256
Matrix MatrixMultiply(const Matrix &left, const Matrix &right)
Definition: Matrix.cpp:243
Holds a matrix of doubles and supports arithmetic, subsetting, and matrix inversion....
Definition: Matrix.h:58
unsigned Cols() const
Definition: Matrix.h:69
Matrix(const Matrix &copyFrom)
Definition: Matrix.cpp:102
Matrix & operator=(const Matrix &other)
Definition: Matrix.cpp:96
unsigned Rows() const
Definition: Matrix.h:68
ArrayOf< Vector > mRowVec
Definition: Matrix.h:78
void SwapRows(unsigned i, unsigned j)
Definition: Matrix.cpp:122
Vector & operator[](unsigned i) const
Definition: Matrix.h:67
~Matrix()
Definition: Matrix.cpp:118
unsigned mRows
Definition: Matrix.h:76
void CopyFrom(const Matrix &other)
Definition: Matrix.cpp:107
Vector & operator[](unsigned i)
Definition: Matrix.h:66
unsigned mCols
Definition: Matrix.h:77
Holds a matrix of doubles and supports arithmetic operations, including Vector-Matrix operations....
Definition: Matrix.h:34
double operator[](unsigned i) const
Definition: Matrix.h:47
void Reinit(unsigned len)
Definition: Matrix.cpp:60
~Vector()
Definition: Matrix.cpp:56
Vector & operator=(const Vector &other)
Definition: Matrix.cpp:42
Doubles mData
Definition: Matrix.h:54
unsigned Len() const
Definition: Matrix.h:48
void Swap(Vector &that)
Definition: Matrix.cpp:66
double Sum() const
Definition: Matrix.cpp:72
Vector()
Definition: Matrix.cpp:18
unsigned mN
Definition: Matrix.h:53
double & operator[](unsigned i)
Definition: Matrix.h:46