AGX Dynamics  2.37.3.2
MatrixTypes.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef MATRIX_TYPES_H
18 #define MATRIX_TYPES_H
19 
20 namespace agx
21 {
22 
48  class MatrixType {
49  public:
50 
56  enum Storage {
57  DENSE = 2,
60  };
61 
67  enum Type {
68  GENERIC = 0,
69  SQUARE = 2,
70  SYMMETRIC = 4,
75  };
76 
77  MatrixType() : m_storage(DENSE), m_type(GENERIC) { }
78 
79 
80  MatrixType(int type, int storage) {
81  m_storage = storage;
82  m_type = type;
83  }
84 
85  MatrixType & setSymmetric (bool t = true) {
86  (t)? m_type |= SYMMETRIC
87  : m_type &= ~SYMMETRIC;
88  return setGeneric(false);
89  }
90 
91  MatrixType & setSquare (bool t = true) {
92  (t)? m_type |= SQUARE
93  : m_type &= ~SQUARE;
94  return setGeneric(false);
95  }
96 
97  MatrixType & setSaddlePoint(bool t = true) {
98  (t)? m_type |= SADDLE_POINT
99  : m_type &= ~SADDLE_POINT;
100  return setGeneric(false).setSquare(true);
101  }
102 
103  MatrixType & setPositiveDefinite (bool t = true) {
104  (t)? m_type |= POSITIVE_DEFINITE
105  : m_type &= ~POSITIVE_DEFINITE;
106  return setGeneric(!t).setSquare(true);
107  }
108 
109  MatrixType & setGeneric (bool t = true ) {
110  if (t) { m_type = GENERIC ; }
111  return *this;
112  }
113 
114  MatrixType &setDense(bool t = true ) {
115  (t)? m_storage |= DENSE
116  : m_storage &= ~DENSE;
117  return *this;
118  }
119 
120  MatrixType &setSparse(bool t = true ) {
121  return setDense(!t);
122  }
123 
124  MatrixType &setUpperTriangle(bool t = true ) {
125  (t)? m_storage |= UPPER_TRIANGLE
126  : m_storage &= ~UPPER_TRIANGLE;
127  return setLowerTriangle(!t);
128  }
129 
130  MatrixType &setLowerTriangle(bool t = true ) {
131  (t)? m_storage |= LOWER_TRIANGLE
132  : m_storage &= ~LOWER_TRIANGLE;
133  return this->setSquare(true);
134  }
135 
136  bool isGeneric() const { return m_type == GENERIC ; }
137  bool isPositiveDefinite () const { return (m_type&POSITIVE_DEFINITE) != 0; }
138  bool isSaddlePoint () const { return (m_type&SADDLE_POINT) != 0; }
139  bool isSymmetric () const { return (m_type&SYMMETRIC) != 0; }
140  bool isDense() const { return (m_storage&DENSE) != 0; }
141  bool isSparse() const { return ! isDense() ; }
142  bool isUpperTriangle() const { return (m_storage&UPPER_TRIANGLE) != 0; }
143  bool isLowerTriangle() const { return (m_storage&LOWER_TRIANGLE) != 0; }
144  bool isSquare() const { return (m_type&SQUARE) != 0; }
145 
146  private:
147  int m_storage;
148  int m_type;
149  };
150 
151 }
152 #endif
bool isDense() const
Definition: MatrixTypes.h:140
Storage
How the matrix is stored.
Definition: MatrixTypes.h:56
MatrixType & setSymmetric(bool t=true)
Definition: MatrixTypes.h:85
MatrixType & setGeneric(bool t=true)
Definition: MatrixTypes.h:109
bool isSparse() const
Definition: MatrixTypes.h:141
bool isLowerTriangle() const
Definition: MatrixTypes.h:143
MatrixType(int type, int storage)
Definition: MatrixTypes.h:80
bool isSquare() const
Definition: MatrixTypes.h:144
Saddle point matrices, which may be symmetric or not, and positive definite or not.
Definition: MatrixTypes.h:72
bool isSymmetric() const
Definition: MatrixTypes.h:139
bool isUpperTriangle() const
Definition: MatrixTypes.h:142
MatrixType & setPositiveDefinite(bool t=true)
Definition: MatrixTypes.h:103
MatrixType & setSaddlePoint(bool t=true)
Definition: MatrixTypes.h:97
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
MatrixType & setLowerTriangle(bool t=true)
Definition: MatrixTypes.h:130
MatrixType & setSparse(bool t=true)
Definition: MatrixTypes.h:120
No special property.
Definition: MatrixTypes.h:68
Positive definite matrices.
Definition: MatrixTypes.h:71
MatrixType & setUpperTriangle(bool t=true)
Definition: MatrixTypes.h:124
bool isGeneric() const
Definition: MatrixTypes.h:136
MatrixType & setSquare(bool t=true)
Definition: MatrixTypes.h:91
Only upper triangle is stored, dense or sparse.
Definition: MatrixTypes.h:58
Only lower triangle is stored, dense or sparse.
Definition: MatrixTypes.h:59
A class to distinguish between various types of matrices, both in terms of storage properties...
Definition: MatrixTypes.h:48
MatrixType & setDense(bool t=true)
Definition: MatrixTypes.h:114
Type
The kind of matrix we are dealing with.
Definition: MatrixTypes.h:67
bool isSaddlePoint() const
Definition: MatrixTypes.h:138
bool isPositiveDefinite() const
Definition: MatrixTypes.h:137
Symmetric matrices.
Definition: MatrixTypes.h:70
The entire matrix is stored, or it is sparse.
Definition: MatrixTypes.h:57