Simbody  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SmallMatrix.h File Reference

This file is the user-includeable header to be included in user programs to provide fixed-length Vec & Mat classes. More...

Go to the source code of this file.

Namespaces

 SimTK
 This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with other symbols.
 

Typedefs

typedef Vec< 2 > SimTK::Vec2
 This is the most common 2D vector type: a column of 2 Real values stored consecutively in memory (packed). More...
 
typedef Vec< 3 > SimTK::Vec3
 This is the most common 3D vector type: a column of 3 Real values stored consecutively in memory (packed). More...
 
typedef Vec< 4 > SimTK::Vec4
 This is the most common 4D vector type: a column of 4 Real values stored consecutively in memory (packed). More...
 
typedef Mat< 2, 2 > SimTK::Mat22
 This is the most common 2x2 matrix type: two packed columns of 2 Real values each. More...
 
typedef Mat< 3, 3 > SimTK::Mat33
 This is the most common 3x3 matrix type: three packed columns of 3 Real values each. More...
 
typedef Mat< 4, 4 > SimTK::Mat44
 This is the most common 4x4 matrix type: four packed columns of 4 Real values each. More...
 
typedef SymMat< 2 > SimTK::SymMat22
 A compact, 2x2 Real symmetric matrix; only 3 elements are stored. More...
 
typedef SymMat< 3 > SimTK::SymMat33
 A compact, 3x3 Real symmetric matrix; only 6 elements are stored. More...
 
typedef SymMat< 4 > SimTK::SymMat44
 A compact, 2x2 Real symmetric matrix; only 10 elements are stored. More...
 
typedef Row< 2 > SimTK::Row2
 Packed, 2-element row of Real values. More...
 
typedef Row< 3 > SimTK::Row3
 Packed, 3-element row of Real values. More...
 
typedef Row< 4 > SimTK::Row4
 Packed, 4-element row of Real values. More...
 
typedef Vec< 1 > SimTK::Vec1
 A vector of just one Real element (not too useful). More...
 
typedef Vec< 5 > SimTK::Vec5
 Packed, 5-element vector of Real values. More...
 
typedef Vec< 6 > SimTK::Vec6
 Packed, 6-element vector of Real values. More...
 
typedef Vec< 7 > SimTK::Vec7
 Packed, 7-element vector of Real values. More...
 
typedef Vec< 8 > SimTK::Vec8
 Packed, 8-element vector of Real values. More...
 
typedef Vec< 9 > SimTK::Vec9
 Packed, 9-element vector of Real values. More...
 
typedef Mat< 1, 1 > SimTK::Mat11
 1x1 Real matrix, that is, a scalar. More...
 
typedef Mat< 1, 2 > SimTK::Mat12
 1x2 Real row matrix. More...
 
typedef Mat< 1, 3 > SimTK::Mat13
 1x3 Real row matrix. More...
 
typedef Mat< 1, 4 > SimTK::Mat14
 1x4 Real row matrix. More...
 
typedef Mat< 1, 5 > SimTK::Mat15
 1x5 Real row matrix. More...
 
typedef Mat< 1, 6 > SimTK::Mat16
 1x6 Real row matrix. More...
 
typedef Mat< 1, 7 > SimTK::Mat17
 1x7 Real row matrix. More...
 
typedef Mat< 1, 8 > SimTK::Mat18
 1x8 Real row matrix. More...
 
typedef Mat< 1, 9 > SimTK::Mat19
 1x9 Real row matrix. More...
 
typedef Mat< 2, 1 > SimTK::Mat21
 2x1 Real column matrix. More...
 
typedef Mat< 2, 3 > SimTK::Mat23
 2x3 Real matrix, packed by columns. More...
 
typedef Mat< 2, 4 > SimTK::Mat24
 2x4 Real matrix, packed by columns. More...
 
typedef Mat< 2, 5 > SimTK::Mat25
 2x5 Real matrix, packed by columns. More...
 
typedef Mat< 2, 6 > SimTK::Mat26
 2x6 Real matrix, packed by columns. More...
 
typedef Mat< 2, 7 > SimTK::Mat27
 2x7 Real matrix, packed by columns. More...
 
typedef Mat< 2, 8 > SimTK::Mat28
 2x8 Real matrix, packed by columns. More...
 
typedef Mat< 2, 9 > SimTK::Mat29
 2x9 Real matrix, packed by columns. More...
 
typedef Mat< 3, 1 > SimTK::Mat31
 3x1 Real column matrix. More...
 
typedef Mat< 3, 2 > SimTK::Mat32
 3x2 Real matrix, packed by columns. More...
 
typedef Mat< 3, 4 > SimTK::Mat34
 3x4 Real matrix, packed by columns. More...
 
typedef Mat< 3, 5 > SimTK::Mat35
 3x5 Real matrix, packed by columns. More...
 
typedef Mat< 3, 6 > SimTK::Mat36
 3x6 Real matrix, packed by columns. More...
 
typedef Mat< 3, 7 > SimTK::Mat37
 3x7 Real matrix, packed by columns. More...
 
typedef Mat< 3, 8 > SimTK::Mat38
 3x8 Real matrix, packed by columns. More...
 
typedef Mat< 3, 9 > SimTK::Mat39
 3x9 Real matrix, packed by columns. More...
 
typedef Mat< 4, 1 > SimTK::Mat41
 4x1 Real column matrix. More...
 
typedef Mat< 4, 2 > SimTK::Mat42
 4x2 Real matrix, packed by columns. More...
 
typedef Mat< 4, 3 > SimTK::Mat43
 4x3 Real matrix, packed by columns. More...
 
typedef Mat< 4, 5 > SimTK::Mat45
 4x5 Real matrix, packed by columns. More...
 
typedef Mat< 4, 6 > SimTK::Mat46
 4x6 Real matrix, packed by columns. More...
 
typedef Mat< 4, 7 > SimTK::Mat47
 4x7 Real matrix, packed by columns. More...
 
typedef Mat< 4, 8 > SimTK::Mat48
 4x8 Real matrix, packed by columns. More...
 
typedef Mat< 4, 9 > SimTK::Mat49
 4x9 Real matrix, packed by columns. More...
 
typedef Mat< 5, 1 > SimTK::Mat51
 5x1 Real column matrix. More...
 
typedef Mat< 5, 2 > SimTK::Mat52
 5x2 Real matrix, packed by columns. More...
 
typedef Mat< 5, 3 > SimTK::Mat53
 5x3 Real matrix, packed by columns. More...
 
typedef Mat< 5, 4 > SimTK::Mat54
 5x4 Real matrix, packed by columns. More...
 
typedef Mat< 5, 5 > SimTK::Mat55
 5x5 Real matrix, packed by columns. More...
 
typedef Mat< 5, 6 > SimTK::Mat56
 5x6 Real matrix, packed by columns. More...
 
typedef Mat< 5, 7 > SimTK::Mat57
 5x7 Real matrix, packed by columns. More...
 
typedef Mat< 5, 8 > SimTK::Mat58
 5x8 Real matrix, packed by columns. More...
 
typedef Mat< 5, 9 > SimTK::Mat59
 5x9 Real matrix, packed by columns. More...
 
typedef Mat< 6, 1 > SimTK::Mat61
 6x1 Real column matrix. More...
 
typedef Mat< 6, 2 > SimTK::Mat62
 6x2 Real matrix, packed by columns. More...
 
typedef Mat< 6, 3 > SimTK::Mat63
 6x3 Real matrix, packed by columns. More...
 
typedef Mat< 6, 4 > SimTK::Mat64
 6x4 Real matrix, packed by columns. More...
 
typedef Mat< 6, 5 > SimTK::Mat65
 6x5 Real matrix, packed by columns. More...
 
typedef Mat< 6, 6 > SimTK::Mat66
 6x6 Real matrix, packed by columns. More...
 
typedef Mat< 6, 7 > SimTK::Mat67
 6x7 Real matrix, packed by columns. More...
 
typedef Mat< 6, 8 > SimTK::Mat68
 6x8 Real matrix, packed by columns. More...
 
typedef Mat< 6, 9 > SimTK::Mat69
 6x9 Real matrix, packed by columns. More...
 
typedef Mat< 7, 1 > SimTK::Mat71
 7x1 Real column matrix. More...
 
typedef Mat< 7, 2 > SimTK::Mat72
 7x2 Real matrix, packed by columns. More...
 
typedef Mat< 7, 3 > SimTK::Mat73
 7x3 Real matrix, packed by columns. More...
 
typedef Mat< 7, 4 > SimTK::Mat74
 7x4 Real matrix, packed by columns. More...
 
typedef Mat< 7, 5 > SimTK::Mat75
 7x5 Real matrix, packed by columns. More...
 
typedef Mat< 7, 6 > SimTK::Mat76
 7x6 Real matrix, packed by columns. More...
 
typedef Mat< 7, 7 > SimTK::Mat77
 7x7 Real matrix, packed by columns. More...
 
typedef Mat< 7, 8 > SimTK::Mat78
 7x8 Real matrix, packed by columns. More...
 
typedef Mat< 7, 9 > SimTK::Mat79
 7x9 Real matrix, packed by columns. More...
 
typedef Mat< 8, 1 > SimTK::Mat81
 8x1 Real column matrix. More...
 
typedef Mat< 8, 2 > SimTK::Mat82
 8x2 Real matrix, packed by columns. More...
 
typedef Mat< 8, 3 > SimTK::Mat83
 8x3 Real matrix, packed by columns. More...
 
typedef Mat< 8, 4 > SimTK::Mat84
 8x4 Real matrix, packed by columns. More...
 
typedef Mat< 8, 5 > SimTK::Mat85
 8x5 Real matrix, packed by columns. More...
 
typedef Mat< 8, 6 > SimTK::Mat86
 8x6 Real matrix, packed by columns. More...
 
typedef Mat< 8, 7 > SimTK::Mat87
 8x7 Real matrix, packed by columns. More...
 
typedef Mat< 8, 8 > SimTK::Mat88
 8x8 Real matrix, packed by columns. More...
 
typedef Mat< 8, 9 > SimTK::Mat89
 8x9 Real matrix, packed by columns. More...
 
typedef Mat< 9, 1 > SimTK::Mat91
 9x1 Real column matrix. More...
 
typedef Mat< 9, 2 > SimTK::Mat92
 9x2 Real matrix, packed by columns. More...
 
typedef Mat< 9, 3 > SimTK::Mat93
 9x3 Real matrix, packed by columns. More...
 
typedef Mat< 9, 4 > SimTK::Mat94
 9x4 Real matrix, packed by columns. More...
 
typedef Mat< 9, 5 > SimTK::Mat95
 9x5 Real matrix, packed by columns. More...
 
typedef Mat< 9, 6 > SimTK::Mat96
 9x6 Real matrix, packed by columns. More...
 
typedef Mat< 9, 7 > SimTK::Mat97
 9x7 Real matrix, packed by columns. More...
 
typedef Mat< 9, 8 > SimTK::Mat98
 9x8 Real matrix, packed by columns. More...
 
typedef Mat< 9, 9 > SimTK::Mat99
 9x9 Real matrix, packed by columns. More...
 
typedef SymMat< 1 > SimTK::SymMat11
 1x1 Real symmetric matrix, that is, a scalar. More...
 
typedef SymMat< 5 > SimTK::SymMat55
 5x5 compact Real symmetric matrix. More...
 
typedef SymMat< 6 > SimTK::SymMat66
 6x6 compact Real symmetric matrix. More...
 
typedef SymMat< 7 > SimTK::SymMat77
 7x7 compact Real symmetric matrix. More...
 
typedef SymMat< 8 > SimTK::SymMat88
 8x8 compact Real symmetric matrix. More...
 
typedef SymMat< 9 > SimTK::SymMat99
 9x9 compact Real symmetric matrix. More...
 
typedef Row< 1 > SimTK::Row1
 A row vector of one Real element (not too useful). More...
 
typedef Row< 5 > SimTK::Row5
 Packed, 5-element row of Real values. More...
 
typedef Row< 6 > SimTK::Row6
 Packed, 6-element row of Real values. More...
 
typedef Row< 7 > SimTK::Row7
 Packed, 7-element row of Real values. More...
 
typedef Row< 8 > SimTK::Row8
 Packed, 8-element row of Real values. More...
 
typedef Row< 9 > SimTK::Row9
 Packed, 9-element row of Real values. More...
 
typedef Vec< 1, float > SimTK::fVec1
 A vector of one float element (not too useful). More...
 
typedef Vec< 2, float > SimTK::fVec2
 Packed, 2-element vector of float values. More...
 
typedef Vec< 3, float > SimTK::fVec3
 Packed, 3-element vector of float values. More...
 
typedef Vec< 4, float > SimTK::fVec4
 Packed, 4-element vector of float values. More...
 
typedef Vec< 5, float > SimTK::fVec5
 Packed, 5-element vector of float values. More...
 
typedef Vec< 6, float > SimTK::fVec6
 Packed, 6-element vector of float values. More...
 
typedef Vec< 7, float > SimTK::fVec7
 Packed, 7-element vector of float values. More...
 
typedef Vec< 8, float > SimTK::fVec8
 Packed, 8-element vector of float values. More...
 
typedef Vec< 9, float > SimTK::fVec9
 Packed, 9-element vector of float values. More...
 
typedef Mat< 1, 1, float > SimTK::fMat11
 1x1 float matrix, that is, a scalar. More...
 
typedef Mat< 2, 2, float > SimTK::fMat22
 2x2 float matrix, packed by columns. More...
 
typedef Mat< 3, 3, float > SimTK::fMat33
 3x3 float matrix, packed by columns. More...
 
typedef Mat< 3, 4, float > SimTK::fMat34
 3x4 float matrix, packed by columns. More...
 
typedef Mat< 4, 3, float > SimTK::fMat43
 4x3 float matrix, packed by columns. More...
 
typedef Mat< 4, 4, float > SimTK::fMat44
 4x4 float matrix, packed by columns. More...
 
typedef Mat< 5, 5, float > SimTK::fMat55
 5x5 float matrix, packed by columns. More...
 
typedef Mat< 6, 6, float > SimTK::fMat66
 6x6 float matrix, packed by columns. More...
 
typedef Mat< 7, 7, float > SimTK::fMat77
 7x7 float matrix, packed by columns. More...
 
typedef Mat< 8, 8, float > SimTK::fMat88
 8x8 float matrix, packed by columns. More...
 
typedef Mat< 9, 9, float > SimTK::fMat99
 9x9 float matrix, packed by columns. More...
 
typedef SymMat< 1, float > SimTK::fSymMat11
 A 1x1 float symmetric matrix, that is, a scalar. More...
 
typedef SymMat< 2, float > SimTK::fSymMat22
 2x2 compact float symmetric matrix. More...
 
typedef SymMat< 3, float > SimTK::fSymMat33
 3x3 compact float symmetric matrix. More...
 
typedef SymMat< 4, float > SimTK::fSymMat44
 4x4 compact float symmetric matrix. More...
 
typedef SymMat< 5, float > SimTK::fSymMat55
 5x5 compact float symmetric matrix. More...
 
typedef SymMat< 6, float > SimTK::fSymMat66
 6x6 compact float symmetric matrix. More...
 
typedef SymMat< 7, float > SimTK::fSymMat77
 7x7 compact float symmetric matrix. More...
 
typedef SymMat< 8, float > SimTK::fSymMat88
 8x8 compact float symmetric matrix. More...
 
typedef SymMat< 9, float > SimTK::fSymMat99
 9x9 compact float symmetric matrix. More...
 
typedef Row< 1, float > SimTK::fRow1
 A row vector of one float element (not too useful). More...
 
typedef Row< 2, float > SimTK::fRow2
 Packed, 2-element row vector of float values. More...
 
typedef Row< 3, float > SimTK::fRow3
 Packed, 3-element row vector of float values. More...
 
typedef Row< 4, float > SimTK::fRow4
 Packed, 4-element row vector of float values. More...
 
typedef Row< 5, float > SimTK::fRow5
 Packed, 5-element row vector of float values. More...
 
typedef Row< 6, float > SimTK::fRow6
 Packed, 6-element row vector of float values. More...
 
typedef Row< 7, float > SimTK::fRow7
 Packed, 7-element row vector of float values. More...
 
typedef Row< 8, float > SimTK::fRow8
 Packed, 8-element row vector of float values. More...
 
typedef Row< 9, float > SimTK::fRow9
 Packed, 9-element row vector of float values. More...
 

Detailed Description

This file is the user-includeable header to be included in user programs to provide fixed-length Vec & Mat classes.

The included internal headers declare templates needed for zero-overhead handling of small vectors and matrices. The idea is to convey all needed information, including the size, at compile time through the templatized types. These classes have well-defined minimal storage layouts and can be easily interconverted to/from arrays of scalar types, with zero conversion overhead.

There are three generic types required: a column vector Vec, a row vector (a.k.a. "covector") Row, and a matrix Mat. Real and Complex elements at single, double, and quad precision are supported. Almost all operations are inline – this package is intended to provide performance as good as one could achieve by special-purpose C code.

When the element type is a "basic numerical type" then the resulting Vec, Row or Mat is also a basic numerical type, so these can be built up with structured elements so that Vec< 2,Vec<3> > for example is a 2-element vector whose elements are Vec<3>'s.

These classes are designed so that many operations that look like computations are free. These include: negation, conjugation, extraction of real and imaginary parts from complex numerical types, and hermitian or positional transpose. These are performed by type casting rather than computation. That is, these operations can be viewed as a change in perspective rather than an actual computation.

To achieve zero overhead, separate types are needed to convey special matrix structure, although appropriate interconversions are defined. So symmetric matrices are SymMat's and diagonal matrices are DiagMat's. Note that symmetric matrices are more properly called Hermitian in that the reflected elements are conjugates of one another.

Supported operations

Class member functions for Vec<M>: Unary: -, +, ~ (Hermitian transpose) Assignment: copy assignment of identical object elementwise assignment from any M-row Vec or Mat scalar assignment to each element TODO

Global operations involving only Vecs or Vec and scalar, yielding a vector result. (Row has the same set.) v+s, s+v, v+v v-s, s-v, v-v v*s, s*v (can't multiply a vector by another vector) v/s v==s, s==v, v==v (same for !=)

Global operations mixing Row, Vec, Mat s=r*v (dot product) m=v*r (outer product) v=m*v, r=r*m m=m*m (with compatible dimensions)