G3D::Matrix Class ReferenceN x M matrix.
More...
#include <Matrix.h>
List of all members.
|
Public Types |
| typedef float | T |
Public Member Functions |
| void | abs (Matrix &out) const |
| Matrix | abs () const |
| Matrix | adjoint () const |
| bool | allNonZero () const |
| bool | allZero () const |
| bool | anyNonZero () const |
| bool | anyZero () const |
| void | arrayCos (Matrix &out) const |
| Matrix | arrayCos () const |
| void | arrayDivInPlace (const Matrix &B) |
| void | arrayExp (Matrix &out) const |
| Matrix | arrayExp () const |
| void | arrayLog (Matrix &out) const |
| Matrix | arrayLog () const |
| Matrix | arrayMul (const Matrix &B) const |
| void | arrayMulInPlace (const Matrix &B) |
| void | arraySin (Matrix &out) const |
| Matrix | arraySin () const |
| void | arraySqrt (Matrix &out) const |
| Matrix | arraySqrt () const |
| Matrix | col (int c) const |
| int | cols () const |
| T | determinant () const |
| Matrix | gaussJordanPseudoInverse () const |
| T | get (int r, int c) const |
| Matrix | inverse () const |
| Matrix | lsub (const T &B) const |
| | Matrix (int R, int C) |
| | Matrix (const Matrix4 &M) |
| | Matrix (const Matrix3 &M) |
| | Matrix () |
| void | mulRow (int r, const T &v) |
| void | negate (Matrix &out) const |
| Matrix | negate () const |
| double | norm () const |
| int | numElements () const |
| Matrix | operator * (const T &B) const |
| Matrix | operator * (const Matrix &B) const |
| Matrix & | operator *= (const Matrix &B) |
| Matrix & | operator *= (const T &B) |
| Matrix | operator!= (const T &scalar) const |
| Matrix | operator+ (const T &v) const |
| Matrix | operator+ (const Matrix &B) const |
| Matrix & | operator+= (const Matrix &B) |
| Matrix & | operator+= (const T &B) |
| Matrix | operator- () const |
| Matrix | operator- (const T &v) const |
| Matrix | operator- (const Matrix &B) const |
| Matrix & | operator-= (const Matrix &B) |
| Matrix & | operator-= (const T &B) |
| Matrix & | operator/= (const T &B) |
| Matrix | operator< (const T &scalar) const |
| Matrix | operator<= (const T &scalar) const |
| Matrix | operator== (const T &scalar) const |
| Matrix | operator> (const T &scalar) const |
| Matrix | operator>= (const T &scalar) const |
| Matrix | pseudoInverse (float tolerance=-1) const |
| Matrix | row (int r) const |
| int | rows () const |
| void | serialize (TextOutput &t) const |
| void | set (int r, int c, T v) |
| void | setCol (int c, const Matrix &vec) |
| void | setRow (int r, const Matrix &vec) |
| Vector2int16 | size () const |
| Matrix | subMatrix (int r1, int r2, int c1, int c2) const |
| void | svd (Matrix &U, Array< T > &d, Matrix &V, bool sort=true) const |
| void | swapAndNegateCols (int c0, int c1) |
| void | swapRows (int r0, int r1) |
| Matrix3 | toMatrix3 () const |
| Matrix4 | toMatrix4 () const |
| std::string | toString () const |
| std::string | toString (const std::string &name) const |
| Vector2 | toVector2 () const |
| Vector3 | toVector3 () const |
| Vector4 | toVector4 () const |
| void | transpose (Matrix &out) const |
| Matrix | transpose () const |
Static Public Member Functions |
| static Matrix | fromDiagonal (const Matrix &d) |
| template<class S> |
| static Matrix | fromDiagonal (const Array< S > &d) |
| static Matrix | identity (int N) |
| static Matrix | one (int R, int C) |
| static Matrix | random (int R, int C) |
| static const char * | svdCore (float **U, int rows, int cols, float *D, float **V) |
| static Matrix | zero (int R, int C) |
Static Public Attributes |
| static int | debugNumAllocOps |
| static int | debugNumCopyOps |
Classes |
| class | Impl |
| | Does not throw exceptions-- assumes the caller has taken care of argument checking.
|
| class | SortRank |
| | Used by SVD.
|
Detailed Description
N x M matrix.
The actual data is tracked internally by a reference counted pointer; it is efficient to pass and assign Matrix objects because no data is actually copied. This avoids the headache of pointers and allows natural math notation:
Matrix A, B, C;
...
C = A * f(B);
C = C.inverse();
A = Matrix::identity(4);
C = A;
C.set(0, 0, 2.0); // Triggers a copy of the data so that A remains unchanged.
etc.
The Matrix::debugNumCopyOps and Matrix::debugNumAllocOps counters increment every time an operation forces the copy and allocation of matrices. You can use these to detect slow operations when efficiency is a major concern.
Some methods accept an output argument instead of returning a value. For example, A = B.transpose() can also be invoked as B.transpose(A). The latter may be more efficient, since Matrix may be able to re-use the storage of A (if it has approximatly the right size and isn't currently shared with another matrix).
- See also:
- G3D::Matrix3, G3D::Matrix4, G3D::Vector2, G3D::Vector3, G3D::Vector4, G3D::CoordinateFrame
- BETA API Likely to receive incompatible changes in future releases.
Member Typedef Documentation
Internal precision.
Currently float, but this may become a templated class in the future to allow operations like Matrix<double> and Matrix<ComplexFloat>.
Not necessarily a plain-old-data type (e.g., could ComplexFloat), but must be something with no constructor, that can be safely memcpyd, and that has a bit pattern of all zeros when zero.
Constructor & Destructor Documentation
| G3D::Matrix::Matrix |
( |
|
) |
[inline] |
| G3D::Matrix::Matrix |
( |
const Matrix3 & |
M |
) |
[inline] |
| G3D::Matrix::Matrix |
( |
const Matrix4 & |
M |
) |
[inline] |
| G3D::Matrix::Matrix |
( |
int |
R, |
|
|
int |
C | |
|
) |
| | [inline] |
Returns a new matrix that is all zero.
Member Function Documentation
| void G3D::Matrix::abs |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::abs |
( |
|
) |
const [inline] |
| Matrix G3D::Matrix::adjoint |
( |
|
) |
const [inline] |
| bool G3D::Matrix::allNonZero |
( |
|
) |
const |
Returns true if all elements are non-zero.
| bool G3D::Matrix::allZero |
( |
|
) |
const [inline] |
| bool G3D::Matrix::anyNonZero |
( |
|
) |
const |
Returns true if any element is non-zero.
| bool G3D::Matrix::anyZero |
( |
|
) |
const [inline] |
| void G3D::Matrix::arrayCos |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::arrayCos |
( |
|
) |
const [inline] |
| void G3D::Matrix::arrayDivInPlace |
( |
const Matrix & |
B |
) |
|
| void G3D::Matrix::arrayExp |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::arrayExp |
( |
|
) |
const [inline] |
| void G3D::Matrix::arrayLog |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::arrayLog |
( |
|
) |
const [inline] |
| Matrix G3D::Matrix::arrayMul |
( |
const Matrix & |
B |
) |
const [inline] |
| void G3D::Matrix::arrayMulInPlace |
( |
const Matrix & |
B |
) |
|
| void G3D::Matrix::arraySin |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::arraySin |
( |
|
) |
const [inline] |
| void G3D::Matrix::arraySqrt |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::arraySqrt |
( |
|
) |
const [inline] |
| Matrix G3D::Matrix::col |
( |
int |
c |
) |
const |
| int G3D::Matrix::cols |
( |
|
) |
const [inline] |
| T G3D::Matrix::determinant |
( |
|
) |
const [inline] |
| static Matrix G3D::Matrix::fromDiagonal |
( |
const Matrix & |
d |
) |
[static] |
template<class S>
| static Matrix G3D::Matrix::fromDiagonal |
( |
const Array< S > & |
d |
) |
[inline, static] |
| Matrix G3D::Matrix::gaussJordanPseudoInverse |
( |
|
) |
const [inline] |
(ATA)-1AT) computed using Gauss-Jordan elimination.
| T G3D::Matrix::get |
( |
int |
r, |
|
|
int |
c | |
|
) |
| | const |
| static Matrix G3D::Matrix::identity |
( |
int |
N |
) |
[static] |
Returns a new identity matrix.
| Matrix G3D::Matrix::inverse |
( |
|
) |
const [inline] |
| Matrix G3D::Matrix::lsub |
( |
const T & |
B |
) |
const [inline] |
| void G3D::Matrix::mulRow |
( |
int |
r, |
|
|
const T & |
v | |
|
) |
| | |
| void G3D::Matrix::negate |
( |
Matrix & |
out |
) |
const |
| Matrix G3D::Matrix::negate |
( |
|
) |
const [inline] |
| double G3D::Matrix::norm |
( |
|
) |
const |
2-norm (sqrt(sum(squares))
| int G3D::Matrix::numElements |
( |
|
) |
const [inline] |
| static Matrix G3D::Matrix::one |
( |
int |
R, |
|
|
int |
C | |
|
) |
| | [static] |
Returns a new matrix that is all one.
| Matrix G3D::Matrix::operator * |
( |
const T & |
B |
) |
const [inline] |
See also A *= B, which is more efficient in many cases.
| Matrix G3D::Matrix::operator * |
( |
const Matrix & |
B |
) |
const [inline] |
Matrix multiplication.
To perform element-by-element multiplication, see arrayMul.
No performance advantage over A * B because matrix multiplication requires intermediate storage.
| Matrix& G3D::Matrix::operator *= |
( |
const T & |
B |
) |
|
Generally more efficient than A * B.
| Matrix G3D::Matrix::operator!= |
( |
const T & |
scalar |
) |
const |
| Matrix G3D::Matrix::operator+ |
( |
const T & |
v |
) |
const [inline] |
See also A += B, which is more efficient in many cases.
| Matrix G3D::Matrix::operator+ |
( |
const Matrix & |
B |
) |
const [inline] |
See also A += B, which is more efficient in many cases.
Generally more efficient than A + B.
| Matrix& G3D::Matrix::operator+= |
( |
const T & |
B |
) |
|
Generally more efficient than A + B.
| Matrix G3D::Matrix::operator- |
( |
|
) |
const [inline] |
| Matrix G3D::Matrix::operator- |
( |
const T & |
v |
) |
const [inline] |
See also A -= B, which is more efficient in many cases.
| Matrix G3D::Matrix::operator- |
( |
const Matrix & |
B |
) |
const [inline] |
See also A -= B, which is more efficient in many cases.
Generally more efficient than A - B.
| Matrix& G3D::Matrix::operator-= |
( |
const T & |
B |
) |
|
Generally more efficient than A - B.
| Matrix& G3D::Matrix::operator/= |
( |
const T & |
B |
) |
|
Generally more efficient than A / B.
| Matrix G3D::Matrix::operator< |
( |
const T & |
scalar |
) |
const |
| Matrix G3D::Matrix::operator<= |
( |
const T & |
scalar |
) |
const |
| Matrix G3D::Matrix::operator== |
( |
const T & |
scalar |
) |
const |
| Matrix G3D::Matrix::operator> |
( |
const T & |
scalar |
) |
const |
| Matrix G3D::Matrix::operator>= |
( |
const T & |
scalar |
) |
const |
| Matrix G3D::Matrix::pseudoInverse |
( |
float |
tolerance = -1 |
) |
const |
(ATA)-1AT) computed using SVD.
- Parameters:
-
| tolerance | Use -1 for automatic tolerance. |
| static Matrix G3D::Matrix::random |
( |
int |
R, |
|
|
int |
C | |
|
) |
| | [static] |
Uniformly distributed values between zero and one.
| Matrix G3D::Matrix::row |
( |
int |
r |
) |
const |
| int G3D::Matrix::rows |
( |
|
) |
const [inline] |
| void G3D::Matrix::serialize |
( |
TextOutput & |
t |
) |
const |
Serializes in Matlab source format.
| void G3D::Matrix::set |
( |
int |
r, |
|
|
int |
c, |
|
|
T |
v | |
|
) |
| | |
| void G3D::Matrix::setCol |
( |
int |
c, |
|
|
const Matrix & |
vec | |
|
) |
| | |
| void G3D::Matrix::setRow |
( |
int |
r, |
|
|
const Matrix & |
vec | |
|
) |
| | |
| Matrix G3D::Matrix::subMatrix |
( |
int |
r1, |
|
|
int |
r2, |
|
|
int |
c1, |
|
|
int |
c2 | |
|
) |
| | const |
Returns a new matrix that is a subset of this one, from r1:r2 to c1:c2, inclusive.
Singular value decomposition.
Factors into three matrices such that this = U * fromDiagonal(d) * V.transpose().
The matrix must have at least as many rows as columns.
- Parameters:
-
| sort | If true (default), the singular values are arranged so that D is sorted from largest to smallest. |
| static const char* G3D::Matrix::svdCore |
( |
float ** |
U, |
|
|
int |
rows, |
|
|
int |
cols, |
|
|
float * |
D, |
|
|
float ** |
V | |
|
) |
| | [static] |
Low-level SVD functionality.
Useful for applications that do not want to construct a Matrix but need to perform the SVD operation.
this = U * D * V'
Assumes that rows >= cols
- Returns:
- NULL on success, a string describing the error on failure.
- Parameters:
-
| U | rows x cols matrix to be decomposed, gets overwritten with U, a rows x cols matrix with orthogonal columns. |
| D | vector of singular values of a (diagonal of the D matrix). Length cols. |
| V | returns the right orthonormal transformation matrix, size cols x cols |
- Referenced Code:
- Based on Dianne Cook's implementation, which is adapted from svdecomp.c in XLISP-STAT 2.1, which is code from Numerical Recipes adapted by Luke Tierney and David Betz. The Numerical Recipes code is adapted from Forsythe et al, who based their code on Golub and Reinsch's original implementation.
| void G3D::Matrix::swapAndNegateCols |
( |
int |
c0, |
|
|
int |
c1 | |
|
) |
| | |
Swaps columns c0 and c1 and negates both.
| void G3D::Matrix::swapRows |
( |
int |
r0, |
|
|
int |
r1 | |
|
) |
| | |
| Matrix3 G3D::Matrix::toMatrix3 |
( |
|
) |
const |
| Matrix4 G3D::Matrix::toMatrix4 |
( |
|
) |
const |
| std::string G3D::Matrix::toString |
( |
|
) |
const [inline] |
| std::string G3D::Matrix::toString |
( |
const std::string & |
name |
) |
const |
| Vector2 G3D::Matrix::toVector2 |
( |
|
) |
const |
| Vector3 G3D::Matrix::toVector3 |
( |
|
) |
const |
| Vector4 G3D::Matrix::toVector4 |
( |
|
) |
const |
| void G3D::Matrix::transpose |
( |
Matrix & |
out |
) |
const |
Transpose in place; more efficient than transpose.
| Matrix G3D::Matrix::transpose |
( |
|
) |
const [inline] |
| static Matrix G3D::Matrix::zero |
( |
int |
R, |
|
|
int |
C | |
|
) |
| | [static] |
Returns a new matrix that is all zero.
Member Data Documentation
Incremented every time a new matrix object is allocated.
Useful for profiling your own code that uses Matrix to determine when it is slow due to allocation.
Incremented every time the elements of a matrix are copied.
Useful for profiling your own code that uses Matrix to determine when it is slow due to copying.
The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:46 2007 for G3D by
1.5.2
Hosted by
|