Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17ba652

Browse files
committed
Lint cpp with cpplint
1 parentcf7050a commit17ba652

15 files changed

+244
-180
lines changed

‎.Rbuildignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
LICENSE
55
.travis.yml
66
appveyor.yml
7+
CPPLINT.cfg
8+
^\src\CPPLINT.cfg

‎src/BinaryCount.h‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@
2323
#include<RcppArmadillo.h>
2424

2525
classBinaryCount {
26-
private:
27-
unsignedlong a;
28-
unsignedlong b;
29-
unsignedlong c;
30-
unsignedlong d;
31-
public:
32-
BinaryCount (unsignedlong a,unsignedlong b,unsignedlong c,unsignedlong d) : a(a), b(b), c(c), d(d) {};
33-
~BinaryCount () {};
26+
private:
27+
uint64_t a;
28+
uint64_t b;
29+
uint64_t c;
30+
uint64_t d;
31+
32+
public:
33+
BinaryCount(uint64_t a,uint64_t b,uint64_t c,uint64_t d) : a(a), b(b), c(c), d(d) {}
34+
~BinaryCount() {}
3435
static BinaryCountgetBinaryCount(const arma::mat &A,const arma::mat &B) {
35-
unsignedlong a =0;
36-
unsignedlong b =0;
37-
unsignedlong c =0;
38-
unsignedlong d =0;
36+
uint64_t a =0;
37+
uint64_t b =0;
38+
uint64_t c =0;
39+
uint64_t d =0;
3940

40-
for(arma::uword idx=0; idx < A.size(); ++idx) {
41+
for(arma::uword idx =0; idx < A.size(); ++idx) {
4142
bool aZero = A.at(idx) ==0.0;
4243
bool bZero = B.at(idx) ==0.0;
4344

@@ -54,18 +55,18 @@ class BinaryCount {
5455

5556
returnBinaryCount(a, b, c, d);
5657
}
57-
unsignedlonggetA() {
58+
uint64_tgetA() {
5859
return a;
59-
};
60-
unsignedlonggetB() {
60+
}
61+
uint64_tgetB() {
6162
return b;
62-
};
63-
unsignedlonggetC() {
63+
}
64+
uint64_tgetC() {
6465
return c;
65-
};
66-
unsignedlonggetD() {
66+
}
67+
uint64_tgetD() {
6768
return d;
68-
};
69+
}
6970
};
7071

71-
#endif
72+
#endif// BINARYCOUNT_H_

‎src/CPPLINT.cfg‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set noparent
2+
root=src
3+
filter=-whitespace/indent
4+
filter=-runtime/references
5+
filter=-build/include
6+
linelength=120
7+
exclude_files=(Makevars.*|CPPLINT.cfg|RcppExports.cpp)

‎src/DistanceBinary.h‎

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include<RcppArmadillo.h>
2424
#include<math.h>
2525
#include"IDistance.h"
26-
#include"Utility.h"
26+
#include"Util.h"
2727
#include"BinaryCount.h"
2828

2929
#undef max
@@ -37,8 +37,8 @@ class DistanceBinary : public IDistance {
3737
public:
3838
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
3939
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
40-
unsignedlong denominator = bc.getA() + bc.getB() + bc.getC();
41-
return ((denominator ==0) ?0 :(double)(bc.getB() + bc.getC()) / denominator);
40+
uint64_t denominator = bc.getA() + bc.getB() + bc.getC();
41+
return ((denominator ==0) ?0 :static_cast<double>(bc.getB() + bc.getC()) / denominator);
4242
}
4343
};
4444

@@ -49,8 +49,8 @@ class DistanceBraunblanquet : public IDistance {
4949
public:
5050
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
5151
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
52-
unsignedlong denominator =maxOfPair((bc.getA() + bc.getB()), (bc.getA() + bc.getC()));
53-
returnutility::similarityToDistance((double)bc.getA() / denominator);
52+
uint64_t denominator =maxOfPair((bc.getA() + bc.getB()), (bc.getA() + bc.getC()));
53+
returnutil::similarityToDistance(static_cast<double>(bc.getA()) / denominator);
5454
}
5555
};
5656

@@ -61,8 +61,8 @@ class DistanceDice : public IDistance {
6161
public:
6262
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
6363
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
64-
unsignedlong denominator =2 * bc.getA() + bc.getB() + bc.getC();
65-
returnutility::similarityToDistance((double)(2 * bc.getA()) / denominator);
64+
uint64_t denominator =2 * bc.getA() + bc.getB() + bc.getC();
65+
returnutil::similarityToDistance(static_cast<double>(2 * bc.getA()) / denominator);
6666
}
6767
};
6868

@@ -73,7 +73,8 @@ class DistanceFager : public IDistance {
7373
public:
7474
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
7575
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
76-
returnutility::similarityToDistance(((double) bc.getA() /sqrt((bc.getA() + bc.getB()) * (bc.getA() + bc.getC()))) - ((sqrt(bc.getA() + bc.getC())) /2.0));
76+
returnutil::similarityToDistance((static_cast<double>(bc.getA()) /
77+
sqrt((bc.getA() + bc.getB()) * (bc.getA() + bc.getC()))) - ((sqrt(bc.getA() + bc.getC())) /2.0));
7778
}
7879
};
7980

@@ -84,7 +85,7 @@ class DistanceFaith : public IDistance {
8485
public:
8586
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
8687
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
87-
returnutility::similarityToDistance((bc.getA() +(double)bc.getD() /2.0) / A.n_cols);
88+
returnutil::similarityToDistance((bc.getA() +static_cast<double>(bc.getD()) /2.0) / A.n_cols);
8889
}
8990
};
9091

@@ -95,7 +96,8 @@ class DistanceHamman : public IDistance {
9596
public:
9697
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
9798
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
98-
returnutility::similarityToDistance(((double) bc.getA() + bc.getD() - bc.getB() - bc.getC()) / A.n_cols);
99+
returnutil::similarityToDistance(
100+
(static_cast<double>(bc.getA()) + bc.getD() - bc.getB() - bc.getC()) / A.n_cols);
99101
}
100102
};
101103

@@ -106,7 +108,7 @@ class DistanceKulczynski1 : public IDistance {
106108
public:
107109
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
108110
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
109-
returnutility::similarityToDistance((double)bc.getA() / (bc.getB() + bc.getC()));
111+
returnutil::similarityToDistance(static_cast<double>(bc.getA()) / (bc.getB() + bc.getC()));
110112
}
111113
};
112114

@@ -117,9 +119,9 @@ class DistanceKulczynski2 : public IDistance {
117119
public:
118120
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
119121
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
120-
double div1 =(double)bc.getA() / (bc.getA() + bc.getB());
121-
double div2 =(double)bc.getA() / (bc.getA() + bc.getC());
122-
returnutility::similarityToDistance((div1 + div2) /2.0);
122+
double div1 =static_cast<double>(bc.getA()) / (bc.getA() + bc.getB());
123+
double div2 =static_cast<double>(bc.getA()) / (bc.getA() + bc.getC());
124+
returnutil::similarityToDistance((div1 + div2) /2.0);
123125
}
124126
};
125127

@@ -131,7 +133,8 @@ class DistanceMichael : public IDistance {
131133
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
132134
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
133135
double denominator =pow(bc.getA() + bc.getD(),2) +pow(bc.getB() + bc.getC(),2);
134-
returnutility::similarityToDistance((4.0 * ((double)(bc.getA() * bc.getD()) - (bc.getB() * bc.getC()))) / denominator);
136+
returnutil::similarityToDistance((4.0 * (static_cast<double>(bc.getA() * bc.getD()) -
137+
(bc.getB() * bc.getC()))) / denominator);
135138
}
136139
};
137140

@@ -142,8 +145,8 @@ class DistanceMountford : public IDistance {
142145
public:
143146
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
144147
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
145-
unsignedlong denominator = bc.getA() * (bc.getB() + bc.getC()) +2 * bc.getB() * bc.getC();
146-
returnutility::similarityToDistance((double)(2 * bc.getA()) / denominator);
148+
uint64_t denominator = bc.getA() * (bc.getB() + bc.getC()) +2 * bc.getB() * bc.getC();
149+
returnutil::similarityToDistance(static_cast<double>(2 * bc.getA()) / denominator);
147150
}
148151
};
149152

@@ -154,8 +157,8 @@ class DistanceMozley : public IDistance {
154157
public:
155158
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
156159
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
157-
unsignedlong denominator = (bc.getA() + bc.getB()) * (bc.getA() + bc.getC());
158-
returnutility::similarityToDistance(((double)bc.getA() * A.n_cols) / denominator);
160+
uint64_t denominator = (bc.getA() + bc.getB()) * (bc.getA() + bc.getC());
161+
returnutil::similarityToDistance((static_cast<double>(bc.getA() * A.n_cols)) / denominator);
159162
}
160163
};
161164

@@ -167,7 +170,7 @@ class DistanceOchiai : public IDistance {
167170
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
168171
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
169172
double denominator =sqrt((bc.getA() + bc.getB()) * (bc.getA() + bc.getC()));
170-
returnutility::similarityToDistance((double)bc.getA() / denominator);
173+
returnutil::similarityToDistance(static_cast<double>(bc.getA()) / denominator);
171174
}
172175
};
173176

@@ -178,8 +181,10 @@ class DistancePhi : public IDistance {
178181
public:
179182
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
180183
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
181-
double denominator = (sqrt(bc.getA() + bc.getB()) *sqrt(bc.getC() + bc.getD()) *sqrt(bc.getA() + bc.getC()) *sqrt(bc.getB() + bc.getD()));
182-
returnutility::similarityToDistance(((double) (bc.getA() * bc.getD()) - (bc.getB() * bc.getC())) / denominator);
184+
double denominator = (sqrt(bc.getA() + bc.getB()) *sqrt(bc.getC() + bc.getD()) *
185+
sqrt(bc.getA() + bc.getC()) *sqrt(bc.getB() + bc.getD()));
186+
returnutil::similarityToDistance(
187+
(static_cast<double>(bc.getA() * bc.getD()) - (bc.getB() * bc.getC()))/ denominator);
183188
}
184189
};
185190

@@ -190,7 +195,7 @@ class DistanceRussel : public IDistance {
190195
public:
191196
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
192197
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
193-
returnutility::similarityToDistance((double)bc.getA() / A.n_cols);
198+
returnutil::similarityToDistance(static_cast<double>(bc.getA()) / A.n_cols);
194199
}
195200
};
196201

@@ -201,7 +206,7 @@ class DistanceSimplematching : public IDistance {
201206
public:
202207
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
203208
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
204-
returnutility::similarityToDistance((double)(bc.getA() + bc.getD()) / A.n_cols);
209+
returnutil::similarityToDistance(static_cast<double>(bc.getA() + bc.getD()) / A.n_cols);
205210
}
206211
};
207212

@@ -212,8 +217,8 @@ class DistanceSimpson : public IDistance {
212217
public:
213218
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
214219
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
215-
unsignedlong denominator =minOfPair((bc.getA() + bc.getB()), (bc.getA() + bc.getC()));
216-
returnutility::similarityToDistance((double)bc.getA() / denominator);
220+
uint64_t denominator =minOfPair((bc.getA() + bc.getB()), (bc.getA() + bc.getC()));
221+
returnutil::similarityToDistance(static_cast<double>(bc.getA()) / denominator);
217222
}
218223
};
219224

@@ -225,7 +230,10 @@ class DistanceStiles : public IDistance {
225230
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
226231
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
227232
unsignedint n = A.n_cols;
228-
returnutility::similarityToDistance((log(n) +2 *log(abs((double) bc.getA() * bc.getD() - bc.getB() * bc.getC()) - n /2.0) -log(bc.getA() + bc.getB()) -log(bc.getC() + bc.getD()) -log(bc.getA() + bc.getC()) -log(bc.getB() + bc.getD())));
233+
returnutil::similarityToDistance(
234+
(log(n) +2 *log(fabs(static_cast<double>(bc.getA() * bc.getD()) - bc.getB() * bc.getC()) - n /2.0) -
235+
log(bc.getA() + bc.getB()) -log(bc.getC() + bc.getD()) -
236+
log(bc.getA() + bc.getC()) -log(bc.getB() + bc.getD())));
229237
}
230238
};
231239

@@ -236,8 +244,8 @@ class DistanceTanimoto : public IDistance {
236244
public:
237245
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
238246
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
239-
unsignedlong denominator = bc.getA() +2 * bc.getB() +2 * bc.getC() + bc.getD();
240-
returnutility::similarityToDistance((double)(bc.getA() + bc.getD()) / denominator);
247+
uint64_t denominator = bc.getA() +2 * bc.getB() +2 * bc.getC() + bc.getD();
248+
returnutil::similarityToDistance(static_cast<double>(bc.getA() + bc.getD()) / denominator);
241249
}
242250
};
243251

@@ -248,8 +256,9 @@ class DistanceYule : public IDistance {
248256
public:
249257
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
250258
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
251-
unsignedlong denominator = (bc.getA() * bc.getD()) + (bc.getB() * bc.getC());
252-
returnutility::similarityToDistance(((double) (bc.getA() * bc.getD()) - (bc.getB() * bc.getC())) / denominator);
259+
uint64_t denominator = (bc.getA() * bc.getD()) + (bc.getB() * bc.getC());
260+
returnutil::similarityToDistance((static_cast<double>(bc.getA() * bc.getD()) -
261+
(bc.getB() * bc.getC())) / denominator);
253262
}
254263
};
255264

@@ -261,8 +270,9 @@ class DistanceYule2 : public IDistance {
261270
doublecalcDistance(const arma::mat &A,const arma::mat &B) {
262271
BinaryCount bc =BinaryCount::getBinaryCount(A, B);
263272
double denominator =sqrt(bc.getA() * bc.getD()) +sqrt(bc.getB() * bc.getC());
264-
returnutility::similarityToDistance((double) (sqrt(bc.getA() * bc.getD()) -sqrt(bc.getB() * bc.getC())) / denominator);
273+
returnutil::similarityToDistance((static_cast<double>(sqrt(bc.getA() * bc.getD())) -
274+
sqrt(bc.getB() * bc.getC())) / denominator);
265275
}
266276
};
267277

268-
#endif
278+
#endif// DISTANCEBINARY_H_

‎src/DistanceDTWFactory.cpp‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// DistanceDTWFactory.cpp
22
//
3-
// Copyright (C) 2017 Alexander Eckert
3+
// Copyright (C) 2017, 2018 Alexander Eckert
44
//
55
// This file is part of parallelDist.
66
//
@@ -19,9 +19,12 @@
1919

2020
#include"DistanceDTWFactory.h"
2121
#include"StepPattern.h"
22-
#include"Utility.h"
22+
#include"Util.h"
23+
24+
std::shared_ptr<IDistance>DistanceDTWFactory::createDistanceFunction(
25+
const std::string& distName,const Rcpp::List& arguments) {
26+
using util::isEqualStr;
2327

24-
std::shared_ptr<IDistance>DistanceDTWFactory::createDistanceFunction(std::string& distName, Rcpp::List& arguments) {
2528
std::shared_ptr<IDistance> distanceFunction =NULL;
2629
unsignedint windowSize =0;
2730
NormMethod normMethod = NormMethod::NoNorm;
@@ -34,35 +37,38 @@ std::shared_ptr<IDistance> DistanceDTWFactory::createDistanceFunction(std::strin
3437
}
3538
if (arguments.containsElementNamed("norm.method")) {
3639
std::string normMethodStr = Rcpp::as<std::string >(arguments["norm.method"]);
37-
if (utility::isEqualStr(normMethodStr,"n")) {
40+
if (isEqualStr(normMethodStr,"n")) {
3841
normMethod = NormMethod::ALength;
39-
}elseif (utility::isEqualStr(normMethodStr,"n+m")) {
42+
}elseif (isEqualStr(normMethodStr,"n+m")) {
4043
normMethod = NormMethod::ABLength;
41-
}elseif (utility::isEqualStr(normMethodStr,"path.length")) {
44+
}elseif (isEqualStr(normMethodStr,"path.length")) {
4245
normMethod = NormMethod::PathLength;
4346
}
4447
}
4548
if (arguments.containsElementNamed("step.pattern")) {
4649
stepPatternName = Rcpp::as<std::string >(arguments["step.pattern"]);
4750
}
4851

49-
if (utility::isEqualStr(stepPatternName,"asymmetric")) {
52+
if (isEqualStr(stepPatternName,"asymmetric")) {
5053
distanceFunction = std::make_shared<StepPatternAsymmetric>(warpingWindow, windowSize, normMethod);
51-
}elseif (utility::isEqualStr(stepPatternName,"asymmetricP0")) {
54+
}elseif (isEqualStr(stepPatternName,"asymmetricP0")) {
5255
distanceFunction = std::make_shared<StepPatternAsymmetricP0>(warpingWindow, windowSize, normMethod);
53-
}elseif (utility::isEqualStr(stepPatternName,"asymmetricP05")) {
56+
}elseif (isEqualStr(stepPatternName,"asymmetricP05")) {
5457
distanceFunction = std::make_shared<StepPatternAsymmetricP05>(warpingWindow, windowSize, normMethod);
55-
}elseif (utility::isEqualStr(stepPatternName,"asymmetricP1")) {
58+
}elseif (isEqualStr(stepPatternName,"asymmetricP1")) {
5659
distanceFunction = std::make_shared<StepPatternAsymmetricP1>(warpingWindow, windowSize, normMethod);
57-
}elseif (utility::isEqualStr(stepPatternName,"asymmetricP2")) {
60+
}elseif (isEqualStr(stepPatternName,"asymmetricP2")) {
5861
distanceFunction = std::make_shared<StepPatternAsymmetricP2>(warpingWindow, windowSize, normMethod);
59-
}elseif (utility::isEqualStr(stepPatternName,"symmetric2") ||utility::isEqualStr(stepPatternName,"symmetricP0")) {
62+
}elseif (
63+
isEqualStr(stepPatternName,"symmetric2") ||
64+
isEqualStr(stepPatternName,"symmetricP0")
65+
) {
6066
distanceFunction = std::make_shared<StepPatternSymmetric2>(warpingWindow, windowSize, normMethod);
61-
}elseif (utility::isEqualStr(stepPatternName,"symmetricP05")) {
67+
}elseif (isEqualStr(stepPatternName,"symmetricP05")) {
6268
distanceFunction = std::make_shared<StepPatternSymmetricP05>(warpingWindow, windowSize, normMethod);
63-
}elseif (utility::isEqualStr(stepPatternName,"symmetricP1")) {
69+
}elseif (isEqualStr(stepPatternName,"symmetricP1")) {
6470
distanceFunction = std::make_shared<StepPatternSymmetricP1>(warpingWindow, windowSize, normMethod);
65-
}elseif (utility::isEqualStr(stepPatternName,"symmetricP2")) {
71+
}elseif (isEqualStr(stepPatternName,"symmetricP2")) {
6672
distanceFunction = std::make_shared<StepPatternSymmetricP2>(warpingWindow, windowSize, normMethod);
6773
}else {
6874
distanceFunction = std::make_shared<StepPatternSymmetric1>(warpingWindow, windowSize, normMethod);

‎src/DistanceDTWFactory.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222

2323
#include"IDistance.h"
2424
#include<memory>
25+
#include<string>
2526

2627
//==============================
2728
// Distance DTW Factory
2829
//==============================
2930
classDistanceDTWFactory {
3031
public:
31-
std::shared_ptr<IDistance>createDistanceFunction(std::string& distName, Rcpp::List& arguments);
32+
std::shared_ptr<IDistance>createDistanceFunction(conststd::string& distName,const Rcpp::List& arguments);
3233
};
3334

34-
#endif
35+
#endif// DISTANCEDTWFACTORY_H_

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp