Skip to content

Commit 55b9b69

Browse files
Quentin62vkubicki
andauthored
fix: clang error and c++17 deprecation #34 #35 #38
* -= method for iterators * boost -> std in multinomial statistics * postfix operators for iterators * prefix ++ -- return the value before application * tests(MixtComp): change tolerance * refactor(MixtComp): refactor deprecated std::iterator #38 * feat(RMixtCompIO): use c++17 as standard * .clang-format added and applied on two sources * doc * doc * corecting the corrections * iterator include removed * Correcting the corrections, once again * missing ref * trivial copy constructors removed * unuglyfying * ConstIterator(Iterator &other) * ConstIterator(const Iterator &other) --------- Co-authored-by: Vincent KUBICKI <vincent.kubicki@laposte.net>
1 parent 5b466dc commit 55b9b69

File tree

13 files changed

+231
-173
lines changed

13 files changed

+231
-173
lines changed

MixtComp/.clang-format

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
2+
# https://llvm.org/docs/CodingStandards.html
3+
4+
BasedOnStyle: LLVM
5+
6+
AccessModifierOffset: -4
7+
AllowShortIfStatementsOnASingleLine: false
8+
ColumnLimit: 0
9+
FixNamespaceComments: false
10+
IndentCaseLabels: false
11+
IndentWidth: 4
12+
NamespaceIndentation: All
13+
TabWidth: 4
14+
UseTab: Always

MixtComp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ brew install cmake boost eigen lcov
2929

3030
## Windows
3131

32-
To install the necessary tools, user needs to install [cygwin](https://www.cygwin.com/). gcc, cmake, boost and eigen must be installed through the cygwin packages installer.
32+
To install the necessary tools, user needs to install [cygwin](https://www.cygwin.com/). gcc, cmake, boost and eigen must be installed through the cygwin packages installer. Note: WSL might be a better solution, but does it allows to compare with CRAN builds for example ?
3333

3434
## Compilation & tests
3535

MixtComp/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
## Performances
3232

3333
- remove regex in data parsing. Will be faster but less tolerant to data format.
34-
- Statistics object generate a boost::variate_generator each time a variable is sampled. It should be possible to generate a vector of value, when the parameters do not vary.
34+
- Statistics object generate a boost::variate_generator each time a variable is sampled. It should be possible to generate a vector of value, when the parameters do not vary. -> Use standard library for sampling, as in Multinomial Statistics.
3535

3636
## Long Term
3737

MixtComp/docs/Graph.md

Lines changed: 59 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,93 +6,88 @@ Inputs and outputs are given as Graph objects. MixtComp methods are templated wi
66
- R objects (*RGraph* class, cf. [RMixtCompIO](../../RMixtCompIO/src/RGraph.h))
77
- python objects (*PyGraph* class, cf. [pyMixtComp](../../pyMixtComp/src/lib/PyGraph.h))
88

9-
109
The different *Graph* classes must implement the following method:
1110

1211
- `void getSubGraph(const std::vector<std::string>& path, Graph& j) const;`: get the Graph at the given path. It modifies the `j` argument.
1312
- `template<typename Type> void add_payload(const std::vector<std::string>& path, const std::string& name, const Type& p);`: add an object in the Graph and create the complete path to it if it does not exist yet.
14-
- `void addSubGraph(const std::vector<std::string>& path, const std::string& name, const Graph& p);`: add an other Graph in the Graph and create the complete path to it if it does not exist yet.
13+
- `void addSubGraph(const std::vector<std::string>& path, const std::string& name, const Graph& p);`: add an other Graph in the Graph and create the complete path to it if it does not exist yet.
1514
- `template<typename Type> Type get_payload(const std::vector<std::string>& path, const std::string& name) const;`: get the element named `name` in `path`
1615
- `template<typename Type> void get_payload(const std::vector<std::string>& path, const std::string& name, Type& p);`: get the element named `name` in `path`. This version modifies the `p` argument.
1716
- `bool exist_payload(const std::vector<std::string>& path, const std::string& name) const;`: test if an element named `name` exists in `path`.
1817
- `void name_payload(const std::vector<std::string>& path, std::list<std::string>& l) const;`: get the names of all the elements in `path` It modifies the `l` argument.
1918

20-
with `path` a vector containing the path of the element to reach or save an element (e.g. ["variable", "param", "var1", "stat"] the element in the following path: variable/param/var1/stat). `Type` can be `int`, `double`, `bool`, `vector<T>`, `vector<vector<T> >`, `NamedVector<T>`, `NamedMatrix<T>`. `NamedMatrix<T>` is a struct containing an Eigen Matrix `mat_` and two vector<string> named `colnames_` and `rownames_`. `NamedVector<T>` is a struct containing an Eigen Matrix with 1 column `vec_` and a vector<string> named `rownames_` (see [NamedAlgebra](../src/lib/IO/NamedAlgebra.h) and [LinAlg](../src/lib/LinAlg/LinAlg.h) for mode details about `NamedVector` and `NamedMatrix`).
21-
19+
with `path` a vector containing the path of the element to reach or save an element (e.g. ["variable", "param", "var1", "stat"] the element in the following path: variable/param/var1/stat). `Type` can be `int`, `double`, `bool`, `vector<T>`, `vector<vector<T> >`, `NamedVector<T>`, `NamedMatrix<T>`. `NamedMatrix<T>` is a struct containing an Eigen Matrix `mat_` and two `vector<string>` named `colnames_` and `rownames_`. `NamedVector<T>` is a struct containing an Eigen Matrix with 1 column `vec_` and a `vector<string>` named `rownames_` (see [NamedAlgebra](../src/lib/IO/NamedAlgebra.h) and [LinAlg](../src/lib/LinAlg/LinAlg.h) for mode details about `NamedVector` and `NamedMatrix`).
2220

23-
24-
# Structure of input Graphs
21+
## Structure of input Graphs
2522

2623
Three Graphs for learning (and four for prediction) (see [file](./dataFormat.md) for mdoe details):
2724

2825
- algo
29-
- nClass
30-
- nInd
31-
- nbBurnInIter
32-
- nbIter
33-
- nbGibbsBurnInIter
34-
- nbGibbsIter
35-
- nInitPerClass
36-
- nSemTry
37-
- ratioStableCriterion
38-
- nStableCriterion
39-
- confidenceLevel
40-
- mode ("learn" or "predict")
26+
- nClass
27+
- nInd
28+
- nbBurnInIter
29+
- nbIter
30+
- nbGibbsBurnInIter
31+
- nbGibbsIter
32+
- nInitPerClass
33+
- nSemTry
34+
- ratioStableCriterion
35+
- nStableCriterion
36+
- confidenceLevel
37+
- mode ("learn" or "predict")
4138

4239
- data
43-
- var1 (array of string)
44-
- var2
45-
- ...
40+
- var1 (array of string)
41+
- var2
42+
- ...
4643

4744
- desc
48-
- var1
49-
- type
50-
- paramStr
51-
- var2
52-
- ...
45+
- var1
46+
- type
47+
- paramStr
48+
- var2
49+
- ...
5350

5451
- param (output Graph of a MixtComp run. Only for prediction, see below)
5552

56-
57-
# Structure of output Graph
53+
## Structure of output Graph
5854

5955
An unique Graph containing: (see [file](./objectOutput.md) for more details)
6056

6157
- algo (copy of algo input)
62-
- mixture
58+
- mixture
6359
- variable
64-
- type
65-
- var1: type of var1
66-
- var2: type of var2
67-
- data
68-
- var1
69-
- completed
70-
- stat (to be implemented, except for LatentClass -> immediate implementation)
71-
- var2
72-
- ...
73-
- param
74-
- var1 (case 1: simple model)
75-
- log
76-
- stat
77-
- paramStr
78-
- var2 (case 2: functional)
79-
- alpha
80-
- log
81-
- stat
82-
- beta
83-
- log
84-
- stat
85-
- sd
86-
- log
87-
- stat
88-
- paramStr
89-
- var3 (case 2: rank)
90-
- mu
91-
- log
92-
- stat
93-
- pi
94-
- log
95-
- stat
96-
- paramStr
97-
- ...
98-
60+
- type
61+
- var1: type of var1
62+
- var2: type of var2
63+
- data
64+
- var1
65+
- completed
66+
- stat (to be implemented, except for LatentClass -> immediate implementation)
67+
- var2
68+
- ...
69+
- param
70+
- var1 (case 1: simple model)
71+
- log
72+
- stat
73+
- paramStr
74+
- var2 (case 2: functional)
75+
- alpha
76+
- log
77+
- stat
78+
- beta
79+
- log
80+
- stat
81+
- sd
82+
- log
83+
- stat
84+
- paramStr
85+
- var3 (case 2: rank)
86+
- mu
87+
- log
88+
- stat
89+
- pi
90+
- log
91+
- stat
92+
- paramStr
93+
- ...
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Development environment
2+
3+
## Current
4+
5+
VS Code with the the following extensions:
6+
7+
- clangd
8+
- Disable Intellisense from Microsoft C++ extension. The formatting should be automatically handled upon detection of the `.clang-format` file at the root of the project.
9+
- markdownlint
10+
11+
Enable the "Format on save" option to ensure everything is properly formatted.
12+
13+
## Previous
14+
15+
The general style used is K&R from Eclipse, modified for a line wrap at 200 characters.

MixtComp/docs/styleguide.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

MixtComp/src/lib/LinAlg/ConstIterator.h

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,31 @@
2828
//#include <iostream>
2929
//#include <iterator>
3030

31-
class ConstIterator: public std::iterator<std::random_access_iterator_tag,
32-
Scalar, int, Scalar*, Scalar&> {
31+
class ConstIterator {
32+
3333
public:
34-
ConstIterator(int i, int j, const Derived& mat) :
35-
i_(i), j_(j), rows_(mat.rows()), p_mat_(&mat) {
36-
}
34+
// iterator traits
35+
using iterator_category = std::random_access_iterator_tag;
36+
using value_type = Scalar;
37+
using difference_type = int;
38+
using pointer = Scalar *;
39+
using reference = Scalar &;
3740

38-
ConstIterator(const Iterator& it) :
39-
i_(it.i_), j_(it.j_), rows_(it.rows_), p_mat_(it.p_mat_) {
41+
int i_;
42+
int j_;
43+
int rows_;
44+
const Derived *p_mat_;
45+
46+
ConstIterator(int i, int j, const Derived &mat)
47+
: i_(i), j_(j), rows_(mat.rows()), p_mat_(&mat) {
4048
}
4149

50+
ConstIterator(const Iterator &other)
51+
: i_(other.i_),
52+
j_(other.j_),
53+
rows_(other.rows_),
54+
p_mat_(other.p_mat_) {}
55+
4256
ConstIterator operator+(int i) {
4357
int posP, iP, jP;
4458
posP = pos();
@@ -47,11 +61,16 @@ class ConstIterator: public std::iterator<std::random_access_iterator_tag,
4761
return ConstIterator(iP, jP, *p_mat_);
4862
}
4963

50-
ConstIterator& operator+=(int i) {
64+
ConstIterator operator+=(int i) {
5165
posToIn(pos() + i, i_, j_);
5266
return *this;
5367
}
5468

69+
ConstIterator operator-=(int i) {
70+
posToIn(pos() - i, i_, j_);
71+
return *this;
72+
}
73+
5574
ConstIterator operator-(int i) {
5675
int posP, iP, jP;
5776
posP = pos();
@@ -60,52 +79,50 @@ class ConstIterator: public std::iterator<std::random_access_iterator_tag,
6079
return ConstIterator(iP, jP, *p_mat_);
6180
}
6281

63-
int operator-(const ConstIterator& it) {
82+
int operator-(const ConstIterator &it) {
6483
return pos() - it.pos();
6584
}
6685

67-
bool operator<(const ConstIterator& it) {
86+
bool operator<(const ConstIterator &it) {
6887
if (j_ < it.j_) {
6988
return true;
7089
} else if (j_ > it.j_) {
7190
return false;
72-
} else if (i_ < it.i_) // in this case, j_ == it.j_, hence comparison must be done on i_
73-
{
91+
} else if (i_ < it.i_) { // in this case, j_ == it.j_, hence comparison must be done on i_
7492
return true;
7593
}
7694

7795
return false;
7896
}
7997

80-
bool operator==(const ConstIterator& it) {
98+
bool operator==(const ConstIterator &it) {
8199
if (i_ == it.i_ && j_ == it.j_)
82100
return true;
83101
else
84102
return false;
85103
}
86104

87-
bool operator>(const ConstIterator& it) {
105+
bool operator>(const ConstIterator &it) {
88106
if (j_ > it.j_) {
89107
return true;
90108
} else if (j_ > it.j_) {
91109
return false;
92-
} else if (i_ > it.i_) // in this case, j_ == it.j_, hence comparison must be done on i_
93-
{
110+
} else if (i_ > it.i_) { // in this case, j_ == it.j_, hence comparison must be done on i_
94111
return true;
95112
}
96113

97114
return false;
98115
}
99116

100-
bool operator>=(const ConstIterator& it) {
117+
bool operator>=(const ConstIterator &it) {
101118
if (!(*this < it)) {
102119
return true;
103120
}
104121

105122
return false;
106123
}
107124

108-
bool operator!=(const ConstIterator& it) {
125+
bool operator!=(const ConstIterator &it) {
109126
if (i_ != it.i_ || j_ != it.j_)
110127
return true;
111128
else
@@ -115,17 +132,17 @@ class ConstIterator: public std::iterator<std::random_access_iterator_tag,
115132
/**
116133
* returns const Scalar instead of const Scalar& to avoid error with temporaries
117134
*/
118-
const Scalar& operator*() const {
135+
const Scalar &operator*() const {
119136
return (*p_mat_)(i_, j_);
120137
}
121138

122-
const Scalar* operator->() const {
139+
const Scalar *operator->() const {
123140
return &(*p_mat_)(i_, j_);
124141
}
125142

126-
const ConstIterator& operator++() {
143+
const ConstIterator &operator++() {
127144
if (i_ < rows_ - 1) // row increment
128-
{
145+
{
129146
++i_;
130147
} else // column increment
131148
{
@@ -135,7 +152,20 @@ class ConstIterator: public std::iterator<std::random_access_iterator_tag,
135152
return *this;
136153
}
137154

138-
const ConstIterator& operator--() {
155+
const ConstIterator operator++(int) {
156+
ConstIterator temp(*this);
157+
if (i_ < rows_ - 1) // row increment
158+
{
159+
++i_;
160+
} else // column increment
161+
{
162+
i_ = 0;
163+
++j_;
164+
}
165+
return temp;
166+
}
167+
168+
const ConstIterator &operator--() {
139169
if (i_ > 0) {
140170
--i_;
141171
} else {
@@ -145,12 +175,7 @@ class ConstIterator: public std::iterator<std::random_access_iterator_tag,
145175
return *this;
146176
}
147177

148-
int i_;
149-
int j_;
150-
int rows_;
151-
const Derived* p_mat_;
152-
153-
void posToIn(int pos, int& i, int& j) const {
178+
void posToIn(int pos, int &i, int &j) const {
154179
std::div_t divresult;
155180
divresult = std::div(pos, rows_);
156181

0 commit comments

Comments
 (0)