Skip to content

Commit e92cf36

Browse files
author
Marc Geilen
committed
Merge branch 'clang-tidy' into main
2 parents c5d2baf + 45ba45c commit e92cf36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3372
-3672
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build:
1010
script:
1111
- cmake -DCODE_COVERAGE=ON .
1212
- make
13-
- ctest
13+
- ctest --output-on-failure
1414
- make maxpluslibcoverage
1515
artifacts:
1616
expire_in: 14d

documentation/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/html/
1+
/html/
2+
Doxyfile.doc

include/maxplus/algebra/mpmatrix.h

Lines changed: 53 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include <unordered_set>
4848
#include <vector>
4949

50-
5150
class CString;
5251

5352
namespace MaxPlus {
@@ -66,7 +65,7 @@ class Vector {
6665
~Vector();
6766

6867
Vector(Vector &&) = default;
69-
Vector &operator=(Vector &&) = default;
68+
Vector &operator=(Vector &&) = delete;
7069

7170
[[nodiscard]] inline unsigned int getSize() const {
7271
return static_cast<unsigned int>(this->table.size());
@@ -76,42 +75,42 @@ class Vector {
7675

7776
void put(unsigned int row, MPTime value);
7877

79-
void toString(CString &outString, double scale = 1.0) const;
78+
void toString(CString &outString, CDouble scale = 1.0) const;
8079

8180
Vector(const Vector &);
8281

8382
Vector &operator=(const Vector &);
8483

85-
MPTime norm();
84+
[[nodiscard]] MPTime norm() const;
8685

8786
void negate();
8887
MPTime normalize();
8988

90-
[[nodiscard]] Vector *add(MPTime increase) const;
89+
[[nodiscard]] Vector add(MPTime increase) const;
9190

92-
void add(MPTime increase, Vector *result) const;
91+
void add(MPTime increase, Vector& result) const;
9392

94-
void maximum(const Vector *matB, Vector *result) const;
93+
void maximum(const Vector& vecB, Vector& result) const;
9594

96-
Vector *add(const Vector *vecB) const;
95+
[[nodiscard]] Vector add(const Vector& vecB) const;
9796

98-
void add(const Vector *vecB, Vector *res) const;
97+
void add(const Vector& vecB, Vector& res) const;
9998

10099
Vector &operator+=(MPTime increase) {
101-
this->add(increase, this);
100+
this->add(increase, *this);
102101
return *this;
103102
}
104103

105104
Vector &operator-=(MPTime decrease) {
106105
assert(!decrease.isMinusInfinity());
107-
this->add(-decrease, this);
106+
this->add(-decrease, *this);
108107
return *this;
109108
}
110109

111-
bool compare(const Vector &v);
110+
[[nodiscard]] bool compare(const Vector &v) const;
112111

113-
Vector &incrementalMaximum(const Vector *vec) {
114-
this->maximum(vec, this);
112+
Vector &incrementalMaximum(const Vector& vec) {
113+
this->maximum(vec, *this);
115114
return *this;
116115
}
117116

@@ -125,7 +124,7 @@ class Vector {
125124
MPTime minimalFiniteElement(unsigned int *itsPosition_Ptr = nullptr) const;
126125

127126
private:
128-
vector<MPTime> table;
127+
std::vector<MPTime> table;
129128
};
130129

131130
enum class MatrixFill { MinusInfinity, Zero, Identity };
@@ -146,10 +145,13 @@ class Matrix {
146145
*/
147146
Matrix(unsigned int nr_rows, unsigned int nr_cols, MatrixFill fill = MatrixFill::MinusInfinity);
148147

149-
Matrix(unsigned int nrows, unsigned int nr_cols, unsigned int nr_el);
148+
Matrix(unsigned int nr_rows, unsigned int nr_cols, unsigned int nr_el);
150149

151150
Matrix(Matrix &&) = default;
152151
Matrix &operator=(Matrix &&) = default;
152+
Matrix(const Matrix &)=default;
153+
154+
Matrix &operator=(const Matrix &);
153155

154156
virtual ~Matrix();
155157

@@ -168,42 +170,42 @@ class Matrix {
168170

169171
void pasteRowVector(unsigned int top_row, unsigned int left_column, const Vector *pastedVector);
170172

171-
[[nodiscard]] virtual Matrix *createCopy() const;
173+
// [[nodiscard]] virtual Matrix *createCopy() const;
172174

173-
[[nodiscard]] Matrix *getTransposedCopy() const;
175+
[[nodiscard]] Matrix transpose() const;
174176

175-
[[nodiscard]] virtual Matrix *getSubMatrix(const list<unsigned int> &rowIndices,
176-
const list<unsigned int> &colIndices) const;
177+
[[nodiscard]] virtual Matrix getSubMatrix(const std::list<unsigned int> &rowIndices,
178+
const std::list<unsigned int> &colIndices) const;
177179

178-
[[nodiscard]] Matrix *getSubMatrix(const list<unsigned int> &indices) const;
180+
[[nodiscard]] Matrix getSubMatrix(const std::list<unsigned int> &indices) const;
179181

180-
[[nodiscard]] Matrix *getSubMatrixNonSquare(const list<unsigned int> &indices) const;
182+
[[nodiscard]] Matrix getSubMatrixNonSquare(const std::list<unsigned int> &indices) const;
181183

182184
/**
183185
* Increases the number of rows of the matrix by n and fills the new elements with -\infty.
184186
*/
185187
void addRows(uint n);
186188

187-
void toString(CString &outString, double scale = 1.0) const;
188-
void toMatlabString(CString &outString, double scale = 1.0) const;
189-
void toLaTeXString(CString &outString, double scale = 1.0) const;
189+
void toString(CString &outString, CDouble scale = 1.0) const;
190+
void toMatlabString(CString &outString, CDouble scale = 1.0) const;
191+
void toLaTeXString(CString &outString, CDouble scale = 1.0) const;
190192

191193
// Algebraic operations.
192-
[[nodiscard]] Matrix *add(MPTime increase) const;
194+
[[nodiscard]] Matrix add(MPTime increase) const;
193195

194-
void add(MPTime increase, Matrix *result) const;
196+
void add(MPTime increase, Matrix& result) const;
195197

196-
[[nodiscard]] Matrix *mp_sub(const Matrix &m) const;
198+
[[nodiscard]] Matrix mp_sub(const Matrix &m) const;
197199

198-
[[nodiscard]] Matrix *mp_maximum(const Matrix &m) const;
200+
[[nodiscard]] Matrix mp_maximum(const Matrix &m) const;
199201

200-
void maximum(const Matrix *matB, Matrix *result) const;
202+
void maximum(const Matrix& matB, Matrix& result) const;
201203

202-
[[nodiscard]] Vector *mp_multiply(const Vector &v) const;
204+
[[nodiscard]] Vector mp_multiply(const Vector &v) const;
203205

204-
[[nodiscard]] Matrix *mp_multiply(const Matrix &m) const;
206+
[[nodiscard]] Matrix mp_multiply(const Matrix &m) const;
205207

206-
[[nodiscard]] Matrix *mp_power(unsigned int p) const;
208+
[[nodiscard]] Matrix mp_power(unsigned int p) const;
207209

208210
[[nodiscard]] CDouble mp_eigenvalue() const;
209211

@@ -214,19 +216,18 @@ class Matrix {
214216
[[nodiscard]] EigenvectorList mpEigenvectors() const;
215217

216218
Matrix &operator+=(MPTime increase) {
217-
this->add(increase, this);
219+
this->add(increase, *this);
218220
return *this;
219221
}
220222

221223
Matrix &operator-=(MPTime decrease) {
222224
assert(!decrease.isMinusInfinity());
223-
this->add(-decrease, this);
225+
this->add(-decrease, *this);
224226
return *this;
225227
}
226228

227-
Matrix &incrementalMaximum(const Matrix *matrix) {
228-
this->maximum(matrix, this);
229-
return *this;
229+
void incrementalMaximum(const Matrix& matrix) {
230+
this->maximum(matrix, *this);
230231
}
231232

232233
bool operator==(const Matrix &other);
@@ -238,75 +239,32 @@ class Matrix {
238239
[[nodiscard]] MPTime largestFiniteElement() const;
239240
[[nodiscard]] MPTime minimalFiniteElement() const;
240241

241-
[[nodiscard]] Matrix *plusClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
242+
[[nodiscard]] Matrix plusClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
242243

243-
[[nodiscard]] Matrix *starClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
244+
[[nodiscard]] Matrix starClosureMatrix(MPTime posCycleThreshold = MP_EPSILON) const;
244245

245-
[[nodiscard]] Matrix *allPairLongestPathMatrix(MPTime posCycleThreshold,
246+
[[nodiscard]] Matrix allPairLongestPathMatrix(MPTime posCycleThreshold,
246247
bool implyZeroSelfEdges) const;
247248
bool
248249
allPairLongestPathMatrix(MPTime posCycleThreshold, bool implyZeroSelfEdges, Matrix &res) const;
249250

250251
[[nodiscard]] MCMgraph mpMatrixToPrecedenceGraph() const;
251252

252-
// factory methods
253-
[[nodiscard]] virtual Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const;
253+
// // factory methods
254+
// [[nodiscard]] virtual Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const;
254255

255256
private:
256-
// Implicit copying is not allowed
257-
// => Intentionally private and not implemented
258-
Matrix(const Matrix &);
259-
260-
Matrix &operator=(const Matrix &);
261257

262258
void init(MatrixFill fill);
263259
void init();
264260

265261
Matrix();
266262

267-
vector<MPTime> table;
263+
std::vector<MPTime> table;
268264
unsigned int szRows;
269265
unsigned int szCols;
270266
};
271267

272-
class ExtendedMatrix : public Matrix {
273-
public:
274-
ExtendedMatrix(unsigned int nrows, unsigned int nr_cols) : Matrix(nrows, nr_cols) {
275-
unsigned int nr_els = this->getRows() * this->getCols();
276-
this->bufferSets.resize(nr_els);
277-
}
278-
279-
// Creates a matrix with reserved memory for nr_el expected entities
280-
ExtendedMatrix(unsigned int nrows, unsigned int nr_cols, unsigned int nr_el) :
281-
Matrix(nrows, nr_cols, nr_el) {
282-
this->bufferSets.reserve(nr_el);
283-
}
284-
explicit ExtendedMatrix(unsigned int N) : Matrix(N) {}
285-
286-
[[nodiscard]] Matrix *createCopy() const override {
287-
Matrix *newMatrix = Matrix::createCopy();
288-
auto *newExtendedMatrix = dynamic_cast<ExtendedMatrix *>(newMatrix);
289-
290-
unsigned int nr_els = this->getRows() * this->getCols();
291-
for (unsigned int pos = 0; pos < nr_els; pos++) {
292-
newExtendedMatrix->bufferSets[pos] = this->bufferSets[pos];
293-
}
294-
295-
return newExtendedMatrix;
296-
}
297-
298-
void put(unsigned int row, unsigned int column, MPTime value, std::unordered_set<int> &);
299-
[[nodiscard]] Matrix *getSubMatrix(const list<unsigned int> &rowIndices,
300-
const list<unsigned int> &colIndices) const override;
301-
302-
// factory methods
303-
[[nodiscard]] Matrix *makeMatrix(unsigned int nr_rows, unsigned int nr_cols) const override;
304-
305-
[[nodiscard]] std::unordered_set<int> getBufferSet(unsigned int row, unsigned int column) const;
306-
307-
private:
308-
vector<std::unordered_set<int>> bufferSets;
309-
};
310268

311269
/****************************************************
312270
* VectorList: usually represents a set of eigenvectors
@@ -320,11 +278,11 @@ class VectorList : private std::vector<std::unique_ptr<Vector>> {
320278

321279
VectorList(VectorList &&) = default;
322280
VectorList &operator=(VectorList &&) = delete;
323-
281+
324282
// Implicit copying is not allowed
325283
// => Intentionally private and not implemented
326-
VectorList(const VectorList &)=delete;
327-
VectorList &operator=(const VectorList &)=delete;
284+
VectorList(const VectorList &) = delete;
285+
VectorList &operator=(const VectorList &) = delete;
328286

329287
[[nodiscard]] const Vector &vectorRefAt(unsigned int n) const; // vector at index 'n'
330288
Vector &vectorRefAt(unsigned int n);
@@ -337,9 +295,9 @@ class VectorList : private std::vector<std::unique_ptr<Vector>> {
337295

338296
void grow(); // append one vector place
339297

340-
void toString(CString &outString, double scale = 1.0) const;
298+
void toString(CString &outString, CDouble scale = 1.0) const;
341299

342-
// bool findSimilar(const Vector& vec, double threshold) const;
300+
// bool findSimilar(const Vector& vec, CDouble threshold) const;
343301
// similar - differs by a constant within a threshold
344302

345303
private:
@@ -358,14 +316,12 @@ inline const Vector &VectorList::lastVectorRef() const { return *this->at(this->
358316

359317
inline Vector &VectorList::lastVectorRef() { return *this->at(this->size() - 1); }
360318

361-
inline unsigned int VectorList::getSize() const {
362-
return static_cast<unsigned int>(this->size());
363-
}
319+
inline unsigned int VectorList::getSize() const { return static_cast<unsigned int>(this->size()); }
364320

365321
inline void VectorList::grow() {
366322
auto last = static_cast<unsigned int>(this->size());
367-
this->resize(last + 1);
368-
this->insert(this->begin()+last, std::make_unique<Vector>(oneVectorSize, MP_MINUSINFINITY));
323+
this->resize(static_cast<size_t>(last + 1));
324+
this->insert(this->begin() + last, std::make_unique<Vector>(oneVectorSize, MP_MINUSINFINITY));
369325
}
370326

371327
} // namespace MaxPlus

0 commit comments

Comments
 (0)