85 static void*
operator new(
size_t size) {
89 static void operator delete(
void* p) {
115 void setSize(
int newRows,
int newCols);
123 inline Impl(
int r,
int c) : elt(
NULL), data(
NULL), R(0), C(0), dataSize(0) {
136 inline void set(
int r,
int c, T v) {
142 inline const T&
get(
int r,
int c)
const {
155 void add(T B,
Impl& out)
const;
161 void sub(T B,
Impl& out)
const;
170 void mul(T B,
Impl& out)
const;
176 void div(T B,
Impl& out)
const;
220 void mulRow(
int r,
const T& v);
231 void setRow(
int r,
const T* vals);
233 void setCol(
int c,
const T* vals);
298 for (
int i = 0; i < d.
length(); ++i) {
370 Matrix C(impl->R, impl->C);
371 impl->mul(B, *C.
impl);
377 Matrix C(impl->R, impl->C);
384 Matrix C(impl->R, impl->C);
391 Matrix C(impl->R, impl->C);
392 impl->add(v, *C.
impl);
398 Matrix C(impl->R, impl->C);
399 impl->sub(v, *C.
impl);
418 Matrix C(impl->R, impl->C);
419 impl->lsub(B, *C.
impl);
424 Matrix C(impl->R, impl->C);
446 # define DECLARE_METHODS_1(method)\
447 inline Matrix method() const {\
448 Matrix C(impl->R, impl->C);\
449 impl->method(*C.impl);\
452 void method(Matrix& out) const;
463 # undef DECLARE_METHODS_1
482 return impl->determinant();
523 return (trans * (*
this)).inverse() * trans;
538 void set(
int r,
int c, T v);
548 T
get(
int r,
int c)
const;
563 void mulRow(
int r,
const T& v);
582 std::string
toString(
const std::string& name)
const;
585 static const std::string name =
"";
614 static const char*
svdCore(
float** U,
int rows,
int cols,
float* D,
float** V);
Matrix operator>(const T &scalar) const
Matrix(int R, int C)
Definition: Matrix.h:307
G3D::Matrix abs(const G3D::Matrix &M)
Definition: Matrix.h:632
bool allNonZero() const
Definition: Matrix.cpp:420
Matrix operator==(const T &scalar) const
Matrix(Impl *i)
Definition: Matrix.h:242
Matrix & operator/=(const T &B)
Definition: Matrix.cpp:107
static const char * svdCore(float **U, int rows, int cols, float *D, float **V)
Definition: Matrix.cpp:1505
Matrix vectorPseudoInverse() const
Definition: Matrix.cpp:1012
Matrix(ImplRef i)
Definition: Matrix.h:241
void setCol(int c, const T *vals)
Definition: Matrix.cpp:816
void inverseInPlaceGaussJordan()
Definition: Matrix.cpp:1353
void arrayDiv(const Impl &B, Impl &out) const
double norm() const
Definition: Matrix.cpp:523
Matrix3 toMatrix3() const
Definition: Matrix.cpp:310
Matrix col(int c) const
Definition: Matrix.cpp:217
Matrix & operator*=(const T &B)
Definition: Matrix.cpp:89
void div(T B, Impl &out) const
Matrix operator*(const T &B) const
Definition: Matrix.h:369
Matrix operator-() const
Definition: Matrix.h:465
Vector2int16
Definition: Vector2int16.h:28
Matrix row3PseudoInverse(const Matrix &B) const
Definition: Matrix.cpp:1262
int rows() const
Definition: Matrix.h:324
void sub(const Impl &B, Impl &out) const
double abs(double fValue)
Definition: g3dmath.h:617
void adjoint(Impl &out) const
Definition: Matrix.cpp:776
bool allZero() const
Definition: Matrix.h:571
int dataSize
Definition: Matrix.h:110
void setZero()
Definition: Matrix.cpp:595
void setRow(int r, const T *vals)
Definition: Matrix.cpp:810
Dynamic 1D array tuned for performance.
Definition: Array.h:95
int col
Definition: Matrix.h:248
G3D::Matrix operator+(const G3D::Matrix::T &v, const G3D::Matrix &M)
Definition: Matrix.h:628
arena_t NULL
Definition: jemalloc_internal.h:624
int numElements() const
Definition: Matrix.h:554
static Matrix fromDiagonal(const Array< S > &d)
Definition: Matrix.h:296
void arrayExp(Impl &out) const
static G3D::Matrix::T negate(G3D::Matrix::T x)
Definition: Matrix.cpp:8
void set(int r, int c, T v)
Definition: Matrix.cpp:159
int length() const
Definition: Array.h:438
void setRow(int r, const Matrix &vec)
Definition: Matrix.cpp:168
void mulRow(int r, const T &v)
Definition: Matrix.cpp:289
Impl & operator=(const Impl &m)
Definition: Matrix.cpp:587
void cofactor(Impl &out) const
Definition: Matrix.cpp:783
T determinant() const
Definition: Matrix.h:481
bool operator>(const SortRank &x) const
Definition: Matrix.h:250
int R
Definition: Matrix.h:105
void swapRows(int r0, int r1)
Definition: Matrix.cpp:600
Matrix pseudoInverse(float tolerance=-1) const
Computes the Moore-Penrose pseudo inverse, equivalent to (ATA)-1AT). The SVD method is used for perfo...
Definition: Matrix.cpp:885
T * data
Definition: Matrix.h:102
void swapAndNegateCols(int c0, int c1)
Definition: Matrix.cpp:612
T determinant() const
Definition: Matrix.cpp:823
std::string toString() const
Definition: Matrix.h:584
void inverseViaAdjoint(Impl &out) const
Definition: Matrix.cpp:734
static void * malloc(size_t bytes)
Definition: System.cpp:1441
static Matrix identity(int N)
Definition: Matrix.cpp:262
Matrix colPartPseudoInverse() const
Definition: Matrix.cpp:1073
void arraySqrt(Impl &out) const
Matrix inverse() const
Definition: Matrix.h:475
Definition: ReferenceCount.h:24
T ** elt
Definition: Matrix.h:99
ImplRef impl
Definition: Matrix.h:239
Matrix subMatrix(int r1, int r2, int c1, int c2) const
Definition: Matrix.cpp:395
bool allNonZero() const
Definition: Matrix.cpp:1474
bool anyNonZero() const
Definition: Matrix.cpp:1463
Impl(const Impl &B)
Definition: Matrix.h:129
Matrix lsub(const T &B) const
Definition: Matrix.h:417
void mulRow(int r, const T &v)
Definition: Matrix.cpp:623
void arrayCos(Impl &out) const
void setSize(int newRows, int newCols)
Definition: Matrix.cpp:550
Matrix & operator-=(const T &B)
Definition: Matrix.cpp:95
void serialize(TextOutput &t) const
Definition: Matrix.cpp:17
#define debugAssert(exp)
Definition: debugAssert.h:160
Matrix4 toMatrix4() const
Definition: Matrix.cpp:320
Vector2 toVector2() const
Definition: Matrix.cpp:331
Matrix operator-(const Matrix &B) const
Definition: Matrix.h:383
Impl()
Definition: Matrix.h:117
Matrix col4PseudoInverse(const Matrix &B) const
Definition: Matrix.cpp:1188
Matrix operator-(const T &v) const
Definition: Matrix.h:397
static int debugNumCopyOps
Definition: Matrix.h:69
bool operator==(const SortRank &x) const
Definition: Matrix.h:266
Matrix row(int r) const
Definition: Matrix.cpp:208
Matrix operator<=(const T &scalar) const
static Matrix one(int R, int C)
Definition: Matrix.cpp:244
void arrayLog(Impl &out) const
void setCol(int c, const Matrix &vec)
Definition: Matrix.cpp:185
Matrix col2PseudoInverse(const Matrix &B) const
Definition: Matrix.cpp:1111
void swapRows(int r0, int r1)
Definition: Matrix.cpp:364
Vector2int16 size() const
Definition: Matrix.h:550
Matrix operator!=(const T &scalar) const
T value
Definition: Matrix.h:247
Matrix operator*(const Matrix &B) const
Definition: Matrix.h:362
Matrix partitionPseudoInverse() const
Definition: Matrix.cpp:1334
void set(int r, int c, T v)
Definition: Matrix.h:136
Definition: TextOutput.h:60
void arrayMulInPlace(const Matrix &B)
Definition: Matrix.cpp:134
Matrix(const Matrix4 &M)
Definition: Matrix.h:293
Matrix operator+(const Matrix &B) const
Definition: Matrix.h:376
void abs(Impl &out) const
Vector3 toVector3() const
Definition: Matrix.cpp:341
int cols() const
Definition: Matrix.h:329
static void free(void *p)
Definition: System.cpp:1473
#define DECLARE_METHODS_1(method)
Definition: Matrix.h:446
G3D::Matrix operator-(const G3D::Matrix::T &v, const G3D::Matrix &M)
Definition: Matrix.h:620
void mul(const Impl &B, Impl &out) const
Definition: Matrix.cpp:632
bool anyZero() const
Definition: Matrix.h:575
Matrix operator+(const T &v) const
Definition: Matrix.h:390
static int debugNumAllocOps
Definition: Matrix.h:73
float T
Definition: Matrix.h:65
Matrix adjoint() const
Definition: Matrix.h:497
void transpose(Impl &out) const
Definition: Matrix.cpp:753
bool anyNonZero() const
Definition: Matrix.cpp:415
Matrix & operator+=(const T &B)
Definition: Matrix.cpp:101
G3D::Matrix operator*(const G3D::Matrix::T &v, const G3D::Matrix &M)
Definition: Matrix.h:624
Matrix row4PseudoInverse(const Matrix &B) const
Definition: Matrix.cpp:1297
Matrix operator>=(const T &scalar) const
Impl(int r, int c)
Definition: Matrix.h:123
Matrix(const Matrix3 &M)
Definition: Matrix.h:291
bool operator<(const SortRank &x) const
Definition: Matrix.h:254
Matrix()
Definition: Matrix.h:289
double normSquared() const
Definition: Matrix.cpp:508
void arrayMul(const Impl &B, Impl &out) const
void lsub(T B, Impl &out) const
Definition: Matrix.cpp:722
Matrix operator<(const T &scalar) const
Matrix row2PseudoInverse(const Matrix &B) const
Definition: Matrix.cpp:1224
void svd(Matrix &U, Array< T > &d, Matrix &V, bool sort=true) const
Definition: Matrix.cpp:425
void add(const Impl &B, Impl &out) const
shared_ptr< Impl > ImplRef
Definition: Matrix.h:237
void negate(Impl &out) const
void swapAndNegateCols(int c0, int c1)
Definition: Matrix.cpp:380
G3D::int16 x
Definition: Vector2int16.h:37
static Matrix zero(int R, int C)
Definition: Matrix.cpp:237
void withoutRowAndCol(int excludeRow, int excludeCol, Impl &out) const
Definition: Matrix.cpp:873
Matrix rowPartPseudoInverse() const
Definition: Matrix.cpp:1033
bool operator>=(const SortRank &x) const
Definition: Matrix.h:258
static Matrix random(int R, int C)
Definition: Matrix.cpp:253
void arrayDivInPlace(const Matrix &B)
Definition: Matrix.cpp:140
Definition: Vector2int16.h:22
Matrix arrayMul(const Matrix &B) const
Definition: Matrix.h:423
Matrix svdPseudoInverse(float tolerance=-1) const
Definition: Matrix.cpp:900
Matrix transpose() const
Definition: Matrix.h:488
Vector4 toVector4() const
Definition: Matrix.cpp:351
~Impl()
Definition: Matrix.cpp:580
int C
Definition: Matrix.h:108
bool operator!=(const SortRank &x) const
Definition: Matrix.h:270
Matrix col3PseudoInverse(const Matrix &B) const
Definition: Matrix.cpp:1152
bool operator<=(const SortRank &x) const
Definition: Matrix.h:262
Matrix gaussJordanPseudoInverse() const
Definition: Matrix.h:521
void arraySin(Impl &out) const