Ravelin
MatrixN.h
1 /****************************************************************************
2  * Copyright 2013 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef MATRIXN
8 #error This class is not to be included by the user directly. Use MatrixNd.h or MatrixNf.h instead.
9 #endif
10 
11 class MATRIX2;
12 class MATRIX3;
13 
15 
18 class MATRIXN
19 {
20  friend class SHAREDMATRIXN;
21 
22  public:
23  MATRIXN();
24  MATRIXN(unsigned rows, unsigned columns);
25  MATRIXN(unsigned rows, unsigned columns, const REAL* array);
26  MATRIXN(const VECTORN& v, Transposition trans = eNoTranspose);
27  MATRIXN(const SHAREDVECTORN& v, Transposition trans = eNoTranspose);
28  MATRIXN(const CONST_SHAREDVECTORN& v, Transposition trans = eNoTranspose);
29 // MATRIXN(const POSE& m);
30  MATRIXN(const MATRIX2& m);
31  MATRIXN(const MATRIX3& m);
32  MATRIXN(const MATRIXN& m);
34  MATRIXN(const CONST_SHAREDMATRIXN& m);
36  MATRIXN& set_identity(unsigned sz);
37  bool is_symmetric(REAL tolerance = -1.0) const;
38  static MATRIXN identity(unsigned dim);
39  REAL norm_inf() const;
40  static MATRIXN construct_variable(unsigned rows, unsigned cols, ...);
41  virtual ~MATRIXN() { }
44  MATRIXN& set(const VECTORN& v, Transposition trans = eNoTranspose);
45  MATRIXN& set(const SHAREDVECTORN& v, Transposition trans = eNoTranspose);
46  MATRIXN& set(const CONST_SHAREDVECTORN& v, Transposition trans = eNoTranspose);
47 // MATRIXN& set(const POSE& m);
48  unsigned rows() const { return _rows; }
49  unsigned columns() const { return _columns; }
50  virtual MATRIXN& resize(unsigned rows, unsigned columns, bool preserve = false);
51  MATRIXN& remove_row(unsigned i);
52  MATRIXN& remove_column(unsigned i);
53 
54  static MATRIXN zero(unsigned rows, unsigned columns);
55  MATRIXN& negate();
56  MATRIXN& set_zero();
57  virtual MATRIXN& transpose();
58  virtual MATRIXN& operator=(const MATRIXN& source);
59  MATRIXN& operator=(const MATRIX2& source);
60  MATRIXN& operator=(const MATRIX3& source);
61  MATRIXN& operator=(const SHAREDMATRIXN& source);
62  MATRIXN& operator=(const CONST_SHAREDMATRIXN& source);
63  MATRIXN& operator=(const VECTORN& v) { return set(v, eNoTranspose); }
64  MATRIXN& operator=(const SHAREDVECTORN& v) { return set(v, eNoTranspose); }
65  MATRIXN& operator=(const CONST_SHAREDVECTORN& v) { return set(v, eNoTranspose); }
66  static MATRIXN& mult(const MATRIXN& m1, const MATRIXN& m2, MATRIXN& result) { return m1.mult(m2, result); }
67  MATRIXN& operator+=(const MATRIXN& m);
69  MATRIXN& operator/=(REAL scalar);
70  MATRIXN& operator*=(REAL scalar);
71  REAL* data() { return _data.get(); }
72  const REAL* data() const { return _data.get(); }
73  void free_memory() { resize(0,0); compress(); }
74  void compress() { _data.compress(); }
75  unsigned leading_dim() const { return _rows; }
76  unsigned inc() const { return 1; }
77 
79  unsigned size() const { return _rows * _columns; }
80 
81  const REAL& operator()(unsigned i, unsigned j) const;
82  REAL& operator()(const unsigned i, const unsigned j);
83 
84  #define MATRIXX MATRIXN
85  #include "MatrixCommon.inl"
86  #undef MATRIXX
87  #define XMATRIXN MATRIXN
88  #include "XMatrixN.inl"
89  #undef XMATRIXN
90 
91  protected:
92  #ifndef REENTRANT
93  static FastThreadable<MATRIXN> _n;
94  static FastThreadable<VECTORN> _workv;
95  #endif
96 
97  SharedResizable<REAL> _data;
98  unsigned _rows;
99  unsigned _columns;
100 }; // end class
101 
102 std::ostream& operator<<(std::ostream& out, const MATRIXN& m);
103 std::istream& operator>>(std::istream& in, MATRIXN& m);
104 
MATRIXN & negate()
Negates this matrix in place.
Definition: MatrixN.cpp:359
MATRIXN & operator-=(const MATRIXN &m)
Subtracts m from this.
Definition: MatrixN.cpp:473
virtual MATRIXN & resize(unsigned rows, unsigned columns, bool preserve=false)
Resizes this matrix, optionally preserving its existing elements.
Definition: MatrixN.cpp:274
A general 2x2 matrix.
Definition: Matrix2.h:16
MATRIXN & set(const VECTORN &v, Transposition trans=eNoTranspose)
Sets this matrix from a vector.
Definition: MatrixN.cpp:123
MATRIXN & zero_upper_triangle()
Zeros the upper triangle of the matrix.
Definition: MatrixN.cpp:390
U & mult(const T &x, U &y, REAL alpha=(REAL) 1.0, REAL beta=(REAL) 0.0) const
Does the operation y = beta*y + alpha*this*x.
Definition: SharedMatrixN.h:222
static MATRIXN construct_variable(unsigned rows, unsigned cols,...)
Constructs a MATRIXN using a variable number of double values.
Definition: MatrixN.cpp:193
MATRIXN()
Default constructor - constructs an empty matrix.
Definition: MatrixN.cpp:7
A generic, possibly non-square matrix.
Definition: MatrixN.h:18
A generic N-dimensional floating point vector.
Definition: SharedVectorN.h:77
A generic, possibly non-square matrix using shared data.
Definition: SharedMatrixN.h:59
MATRIXN & operator*=(REAL scalar)
Multiplies this matrix by another in place.
Definition: MatrixN.cpp:341
A generic N-dimensional floating point vector.
Definition: SharedVectorN.h:15
MATRIXN & set_identity()
Sets this matrix to the identity matrix.
Definition: MatrixN.cpp:455
MATRIXN & operator/=(REAL scalar)
Divides this matrix by a scalar in place.
Definition: MatrixN.cpp:350
MATRIXN & set_zero()
Sets the matrix to the zero matrix.
Definition: MatrixN.cpp:297
A generic N-dimensional floating point vector.
Definition: VectorN.h:16
MATRIXN & remove_row(unsigned i)
Removes a row from the matrix.
Definition: MatrixN.cpp:209
MATRIXN & remove_column(unsigned i)
Removes a column from the matrix.
Definition: MatrixN.cpp:230
unsigned size() const
Gets the total number of elements in this matrix.
Definition: MatrixN.h:79
bool is_symmetric(REAL tolerance=-1.0) const
Checks whether the given matrix is symmetric to the specified tolerance.
Definition: MatrixN.cpp:368
const REAL & operator()(unsigned i, unsigned j) const
Gets the desired entry.
Definition: MatrixN.cpp:435
A generic, possibly non-square matrix using constant shared data.
Definition: SharedMatrixN.h:19
MATRIXN & zero_lower_triangle()
Zeros the lower triangle of the matrix.
Definition: MatrixN.cpp:405
MATRIXN & operator+=(const MATRIXN &m)
Adds m to this.
Definition: MatrixN.cpp:487
static MATRIXN identity(unsigned dim)
Returns an identity matrix.
Definition: MatrixN.cpp:420
A 3x3 matrix that may be used for orientation, inertia tensors, etc.
Definition: Matrix3.h:20
virtual MATRIXN & operator=(const MATRIXN &source)
Sets this to m.
Definition: MatrixN.cpp:501
virtual MATRIXN & transpose()
Sets this matrix to its transpose.
Definition: MatrixN.cpp:304