Ravelin
SharedMatrixN.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 SHAREDMATRIXN
8 #error This class is not to be included by the user directly. Use SharedMatrixNd.h or SharedMatrixNf.h instead.
9 #endif
10 
11 class MATRIXN;
14 
16 
20 {
21  friend class MATRIXN;
22  friend class SHAREDMATRIXN;
23 
24  public:
26  CONST_SHAREDMATRIXN(const SHAREDMATRIXN& source);
28  CONST_SHAREDMATRIXN(unsigned rows, unsigned cols, unsigned leading_dim, unsigned start, SharedResizable<REAL> data);
29  const SHAREDMATRIXN get() const;
30  void reset_from(const CONST_SHAREDMATRIXN& source);
31  void reset_from(const SHAREDMATRIXN& source);
32  bool is_symmetric(REAL tolerance = (REAL) -1.0) const;
33  REAL norm_inf() const;
34  unsigned rows() const { return _rows; }
35  unsigned columns() const { return _columns; }
36  unsigned leading_dim() const { return _ld; }
37  CONST_SHAREDMATRIXN& resize(unsigned rows, unsigned columns, bool preserve = false);
38  const REAL& operator()(unsigned i, unsigned j) const;
39  const REAL* data() const { return _data.get()+_start; }
40 
42  void reset() { _data.reset(); _rows = _start = _columns = _ld = 0; }
43 
44  #include "ConstMatrixCommon.inl"
45  #include "ConstMatrixN.inl"
46 
47  protected:
48  SharedResizable<REAL> _data;
49  unsigned _rows;
50  unsigned _start;
51  unsigned _columns;
52  unsigned _ld; // the leading dimension of the matrix
53 }; // end class
54 
56 
60 {
61  friend class MATRIXN;
62  friend class CONST_SHAREDMATRIXN;
63 
64  public:
65  SHAREDMATRIXN();
66  SHAREDMATRIXN(const SHAREDMATRIXN& source);
67  SHAREDMATRIXN(unsigned rows, unsigned cols, unsigned leading_dim, unsigned start, SharedResizable<REAL> data);
68  void reset_from(const SHAREDMATRIXN& source);
70  bool is_symmetric(REAL tolerance = (REAL) -1.0) const;
71  REAL norm_inf() const;
74  unsigned rows() const { return _rows; }
75  unsigned columns() const { return _columns; }
76  unsigned leading_dim() const { return _ld; }
77  SHAREDMATRIXN& resize(unsigned rows, unsigned columns, bool preserve = false);
80  SHAREDMATRIXN& operator/=(REAL scalar);
81  SHAREDMATRIXN& operator*=(REAL scalar);
82  SHAREDMATRIXN& operator=(const MATRIX3& m);
83  SHAREDMATRIXN& operator=(const MATRIXN& source);
84  SHAREDMATRIXN& operator=(const SHAREDMATRIXN& source);
86  REAL& operator()(unsigned i, unsigned j);
87  const REAL& operator()(unsigned i, unsigned j) const;
88  REAL* data() { return _data.get()+_start; }
89  const REAL* data() const { return _data.get()+_start; }
90 
92  void reset() { _data.reset(); _rows = _start = _columns = _ld = 0; }
93 
94  #define XMATRIXN SHAREDMATRIXN
95  #include "XMatrixN.inl"
96  #undef XMATRIXN
97  #define MATRIXX SHAREDMATRIXN
98  #include "MatrixCommon.inl"
99  #undef MATRIXX
100 
101  protected:
102  SharedResizable<REAL> _data;
103  unsigned _rows;
104  unsigned _start;
105  unsigned _columns;
106  unsigned _ld; // the leading dimension of the matrix
107 }; // end class
108 
109 
110 std::ostream& operator<<(std::ostream& out, const SHAREDMATRIXN& m);
111 std::ostream& operator<<(std::ostream& out, const CONST_SHAREDMATRIXN& m);
112 std::istream& operator>>(std::istream& in, SHAREDMATRIXN& m);
113 
const REAL & operator()(unsigned i, unsigned j) const
Accesses the given element.
Definition: SharedMatrixN.cpp:325
void reset_from(const SHAREDMATRIXN &source)
Resets this from another shared matrix.
Definition: SharedMatrixN.cpp:23
void reset_from(const CONST_SHAREDMATRIXN &source)
Resets this from another shared matrix.
Definition: SharedMatrixN.cpp:288
A generic, possibly non-square matrix.
Definition: MatrixN.h:18
SHAREDMATRIXN & resize(unsigned rows, unsigned columns, bool preserve=false)
Resizes this matrix, optionally preserving its existing elements.
Definition: SharedMatrixN.cpp:119
SHAREDMATRIXN & operator/=(REAL scalar)
Divides this matrix by a scalar in place.
Definition: SharedMatrixN.cpp:157
bool is_symmetric(REAL tolerance=(REAL)-1.0) const
Checks whether the given matrix is symmetric to the specified tolerance.
Definition: SharedMatrixN.cpp:180
A generic, possibly non-square matrix using shared data.
Definition: SharedMatrixN.h:59
void reset()
Resets the shared matrix.
Definition: SharedMatrixN.h:92
void reset()
Resets the shared matrix.
Definition: SharedMatrixN.h:42
REAL & operator()(unsigned i, unsigned j)
Accesses the given element.
Definition: SharedMatrixN.cpp:33
SHAREDMATRIXN & zero_lower_triangle()
Zeros the lower triangle of the matrix.
Definition: SharedMatrixN.cpp:217
SHAREDMATRIXN & set_zero()
Sets the matrix to the zero matrix.
Definition: SharedMatrixN.cpp:131
A generic, possibly non-square matrix using constant shared data.
Definition: SharedMatrixN.h:19
SHAREDMATRIXN & operator*=(REAL scalar)
Multiplies this matrix by another in place.
Definition: SharedMatrixN.cpp:140
SHAREDMATRIXN & negate()
Negates this matrix in place.
Definition: SharedMatrixN.cpp:174
SHAREDMATRIXN & operator=(const MATRIX3 &m)
Sets a matrix from a MATRIX3.
Definition: SharedMatrixN.cpp:53
SHAREDMATRIXN & set_identity()
Sets this matrix to the identity matrix.
Definition: SharedMatrixN.cpp:232
A 3x3 matrix that may be used for orientation, inertia tensors, etc.
Definition: Matrix3.h:20
SHAREDMATRIXN & zero_upper_triangle()
Zeros the upper triangle of the matrix.
Definition: SharedMatrixN.cpp:202