Skip to content

Commit 4c0a3f2

Browse files
Introduce clang-format in pre-commit (#125)
* give a shot at clang-format * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * oops... forgot MANIFEST.in Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f12e4ea commit 4c0a3f2

File tree

4 files changed

+253
-40
lines changed

4 files changed

+253
-40
lines changed

.clang-format

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: Align
6+
AlignArrayOfStructures: None
7+
AlignConsecutiveMacros: None
8+
AlignConsecutiveAssignments: None
9+
AlignConsecutiveBitFields: None
10+
AlignConsecutiveDeclarations: None
11+
AlignEscapedNewlines: Right
12+
AlignOperands: Align
13+
AlignTrailingComments: true
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: true
17+
AllowShortBlocksOnASingleLine: Never
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: All
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLoopsOnASingleLine: false
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: MultiLine
27+
AttributeMacros:
28+
- __capability
29+
BinPackArguments: true
30+
BinPackParameters: true
31+
BraceWrapping:
32+
AfterCaseLabel: false
33+
AfterClass: false
34+
AfterControlStatement: Never
35+
AfterEnum: false
36+
AfterFunction: false
37+
AfterNamespace: false
38+
AfterObjCDeclaration: false
39+
AfterStruct: false
40+
AfterUnion: false
41+
AfterExternBlock: false
42+
BeforeCatch: false
43+
BeforeElse: false
44+
BeforeLambdaBody: false
45+
BeforeWhile: false
46+
IndentBraces: false
47+
SplitEmptyFunction: true
48+
SplitEmptyRecord: true
49+
SplitEmptyNamespace: true
50+
BreakBeforeBinaryOperators: None
51+
BreakBeforeConceptDeclarations: true
52+
BreakBeforeBraces: Attach
53+
BreakBeforeInheritanceComma: false
54+
BreakInheritanceList: BeforeColon
55+
BreakBeforeTernaryOperators: true
56+
BreakConstructorInitializersBeforeComma: false
57+
BreakConstructorInitializers: BeforeColon
58+
BreakAfterJavaFieldAnnotations: false
59+
BreakStringLiterals: true
60+
ColumnLimit: 80
61+
CommentPragmas: '^ IWYU pragma:'
62+
QualifierAlignment: Leave
63+
CompactNamespaces: false
64+
ConstructorInitializerIndentWidth: 4
65+
ContinuationIndentWidth: 4
66+
Cpp11BracedListStyle: true
67+
DeriveLineEnding: true
68+
DerivePointerAlignment: false
69+
DisableFormat: false
70+
EmptyLineAfterAccessModifier: Never
71+
EmptyLineBeforeAccessModifier: LogicalBlock
72+
ExperimentalAutoDetectBinPacking: false
73+
PackConstructorInitializers: BinPack
74+
BasedOnStyle: ''
75+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
76+
AllowAllConstructorInitializersOnNextLine: true
77+
FixNamespaceComments: true
78+
ForEachMacros:
79+
- foreach
80+
- Q_FOREACH
81+
- BOOST_FOREACH
82+
IfMacros:
83+
- KJ_IF_MAYBE
84+
IncludeBlocks: Preserve
85+
IncludeCategories:
86+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
87+
Priority: 2
88+
SortPriority: 0
89+
CaseSensitive: false
90+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
91+
Priority: 3
92+
SortPriority: 0
93+
CaseSensitive: false
94+
- Regex: '.*'
95+
Priority: 1
96+
SortPriority: 0
97+
CaseSensitive: false
98+
IncludeIsMainRegex: '(Test)?$'
99+
IncludeIsMainSourceRegex: ''
100+
IndentAccessModifiers: false
101+
IndentCaseLabels: false
102+
IndentCaseBlocks: false
103+
IndentGotoLabels: true
104+
IndentPPDirectives: None
105+
IndentExternBlock: AfterExternBlock
106+
IndentRequires: false
107+
IndentWidth: 2
108+
IndentWrappedFunctionNames: false
109+
InsertTrailingCommas: None
110+
JavaScriptQuotes: Leave
111+
JavaScriptWrapImports: true
112+
KeepEmptyLinesAtTheStartOfBlocks: true
113+
LambdaBodyIndentation: Signature
114+
MacroBlockBegin: ''
115+
MacroBlockEnd: ''
116+
MaxEmptyLinesToKeep: 1
117+
NamespaceIndentation: None
118+
ObjCBinPackProtocolList: Auto
119+
ObjCBlockIndentWidth: 2
120+
ObjCBreakBeforeNestedBlockParam: true
121+
ObjCSpaceAfterProperty: false
122+
ObjCSpaceBeforeProtocolList: true
123+
PenaltyBreakAssignment: 2
124+
PenaltyBreakBeforeFirstCallParameter: 19
125+
PenaltyBreakComment: 300
126+
PenaltyBreakFirstLessLess: 120
127+
PenaltyBreakOpenParenthesis: 0
128+
PenaltyBreakString: 1000
129+
PenaltyBreakTemplateDeclaration: 10
130+
PenaltyExcessCharacter: 1000000
131+
PenaltyReturnTypeOnItsOwnLine: 60
132+
PenaltyIndentedWhitespace: 0
133+
PointerAlignment: Right
134+
PPIndentWidth: -1
135+
ReferenceAlignment: Pointer
136+
ReflowComments: true
137+
RemoveBracesLLVM: false
138+
SeparateDefinitionBlocks: Leave
139+
ShortNamespaceLines: 1
140+
SortIncludes: CaseSensitive
141+
SortJavaStaticImport: Before
142+
SortUsingDeclarations: true
143+
SpaceAfterCStyleCast: false
144+
SpaceAfterLogicalNot: false
145+
SpaceAfterTemplateKeyword: true
146+
SpaceBeforeAssignmentOperators: true
147+
SpaceBeforeCaseColon: false
148+
SpaceBeforeCpp11BracedList: false
149+
SpaceBeforeCtorInitializerColon: true
150+
SpaceBeforeInheritanceColon: true
151+
SpaceBeforeParens: ControlStatements
152+
SpaceBeforeParensOptions:
153+
AfterControlStatements: true
154+
AfterForeachMacros: true
155+
AfterFunctionDefinitionName: false
156+
AfterFunctionDeclarationName: false
157+
AfterIfMacros: true
158+
AfterOverloadedOperator: false
159+
BeforeNonEmptyParentheses: false
160+
SpaceAroundPointerQualifiers: Default
161+
SpaceBeforeRangeBasedForLoopColon: true
162+
SpaceInEmptyBlock: false
163+
SpaceInEmptyParentheses: false
164+
SpacesBeforeTrailingComments: 1
165+
SpacesInAngles: Never
166+
SpacesInConditionalStatement: false
167+
SpacesInContainerLiterals: true
168+
SpacesInCStyleCastParentheses: false
169+
SpacesInLineCommentPrefix:
170+
Minimum: 1
171+
Maximum: -1
172+
SpacesInParentheses: false
173+
SpacesInSquareBrackets: false
174+
SpaceBeforeSquareBrackets: false
175+
BitFieldColonSpacing: Both
176+
Standard: Latest
177+
StatementAttributeLikeMacros:
178+
- Q_EMIT
179+
StatementMacros:
180+
- Q_UNUSED
181+
- QT_REQUIRE_VERSION
182+
TabWidth: 8
183+
UseCRLF: false
184+
UseTab: Never
185+
WhitespaceSensitiveMacros:
186+
- STRINGIZE
187+
- PP_STRINGIZE
188+
- BOOST_PP_STRINGIZE
189+
- NS_SWIFT_NAME
190+
- CF_SWIFT_NAME
191+
...

.pre-commit-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,9 @@ repos:
4646
hooks:
4747
- id: check-manifest
4848
stages: [manual]
49+
50+
- repo: https://github.com/pre-commit/mirrors-clang-format
51+
rev: "v14.0.6"
52+
hooks:
53+
- id: clang-format
54+
types_or: [c++, c, cuda]

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ graft tests
33
graft fastjet-core
44
graft pybind11
55
global-exclude .git .gitmodules
6-
include LICENSE README.md pyproject.toml setup.py setup.cfg patch.txt
6+
include LICENSE README.md pyproject.toml setup.py setup.cfg patch.txt .clang-format

src/_ext.cpp

+55-39
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,74 @@
1-
// BSD 3-Clause License; see https://github.com/scikit-hep/fastjet/blob/main/LICENSE
1+
// BSD 3-Clause License; see
2+
// https://github.com/scikit-hep/fastjet/blob/main/LICENSE
23

3-
#include <iostream>
4-
#include <cstdlib>
5-
#include <vector>
64
#include <algorithm>
5+
#include <cstdlib>
6+
#include <iostream>
77
#include <unordered_map>
8+
#include <vector>
89

10+
#include <fastjet/AreaDefinition.hh>
911
#include <fastjet/ClusterSequence.hh>
1012
#include <fastjet/ClusterSequenceArea.hh>
13+
#include <fastjet/GhostedAreaSpec.hh>
1114
#include <fastjet/JetDefinition.hh>
1215
#include <fastjet/PseudoJet.hh>
13-
#include <fastjet/AreaDefinition.hh>
14-
#include <fastjet/GhostedAreaSpec.hh>
1516

16-
#include <pybind11/pybind11.h>
17-
#include <pybind11/operators.h>
1817
#include <pybind11/numpy.h>
18+
#include <pybind11/operators.h>
19+
#include <pybind11/pybind11.h>
1920
#include <pybind11/stl.h>
2021

2122
namespace fj = fastjet;
2223
namespace py = pybind11;
2324
using namespace pybind11::literals;
2425

25-
typedef struct{
26-
PyObject_HEAD
27-
void *ptr;
26+
typedef struct {
27+
PyObject_HEAD void *ptr;
2828
void *ty;
2929
int own;
3030
PyObject *next;
3131
} SwigPyObject;
3232

3333
template <typename T>
34-
T swigtocpp(py::object obj) { // unwraps python object to get the cpp pointer from the swig bindings
34+
T swigtocpp(py::object obj) { // unwraps python object to get the cpp pointer
35+
// from the swig bindings
3536
auto upointer = obj.attr("this").ptr();
36-
auto swigpointer = reinterpret_cast<SwigPyObject*>(upointer);
37+
auto swigpointer = reinterpret_cast<SwigPyObject *>(upointer);
3738
auto objpointervoid = swigpointer->ptr;
3839
auto objpointer = reinterpret_cast<T>(objpointervoid);
3940
return objpointer;
4041
}
41-
class output_wrapper{
42-
public:
42+
class output_wrapper {
43+
public:
4344
std::vector<std::shared_ptr<fj::ClusterSequence>> cse;
4445
std::vector<std::shared_ptr<std::vector<fj::PseudoJet>>> parts;
4546

46-
std::shared_ptr<fj::ClusterSequence> getCluster(){
47+
std::shared_ptr<fj::ClusterSequence> getCluster() {
4748
auto a = cse[0];
4849
return a;
4950
}
50-
void setCluster(){}
51+
void setCluster() {}
5152
};
5253

53-
output_wrapper interfacemulti(py::array_t<double, py::array::c_style | py::array::forcecast> pxi, py::array_t<double, py::array::c_style | py::array::forcecast> pyi, py::array_t<double, py::array::c_style | py::array::forcecast> pzi, py::array_t<double, py::array::c_style | py::array::forcecast> Ei,py::array_t<int, py::array::c_style | py::array::forcecast> offsets, py::object jetdef)
54-
{
54+
output_wrapper interfacemulti(
55+
py::array_t<double, py::array::c_style | py::array::forcecast> pxi,
56+
py::array_t<double, py::array::c_style | py::array::forcecast> pyi,
57+
py::array_t<double, py::array::c_style | py::array::forcecast> pzi,
58+
py::array_t<double, py::array::c_style | py::array::forcecast> Ei,
59+
py::array_t<int, py::array::c_style | py::array::forcecast> offsets,
60+
py::object jetdef) {
5561
py::buffer_info infooff = offsets.request();
5662
py::buffer_info infopx = pxi.request();
57-
py::buffer_info infopy = pyi.request(); // requesting buffer information of the input
63+
py::buffer_info infopy =
64+
pyi.request(); // requesting buffer information of the input
5865
py::buffer_info infopz = pzi.request();
5966
py::buffer_info infoE = Ei.request();
6067

6168
auto offptr = static_cast<int *>(infooff.ptr);
6269
auto pxptr = static_cast<double *>(infopx.ptr);
63-
auto pyptr = static_cast<double *>(infopy.ptr); // pointer to the initial value
70+
auto pyptr =
71+
static_cast<double *>(infopy.ptr); // pointer to the initial value
6472
auto pzptr = static_cast<double *>(infopz.ptr);
6573
auto Eptr = static_cast<double *>(infoE.ptr);
6674

@@ -71,31 +79,34 @@ output_wrapper interfacemulti(py::array_t<double, py::array::c_style | py::array
7179
std::vector<double> constphi;
7280
std::vector<double> idx;
7381
std::vector<double> idxo;
74-
for (int i = 0; i < dimoff-1; i++) {
82+
for (int i = 0; i < dimoff - 1; i++) {
7583
std::vector<fj::PseudoJet> particles;
76-
for(int j = *offptr; j < *(offptr+1); j++ ){
77-
particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr));
78-
pxptr++;
79-
pyptr++;
80-
pzptr++;
81-
Eptr++;
84+
for (int j = *offptr; j < *(offptr + 1); j++) {
85+
particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr));
86+
pxptr++;
87+
pyptr++;
88+
pzptr++;
89+
Eptr++;
8290
}
8391

84-
std::vector<fj::PseudoJet> jets;
85-
auto jet_def = swigtocpp<fj::JetDefinition*>(jetdef);
86-
std::shared_ptr<std::vector<fj::PseudoJet>> pj = std::make_shared<std::vector<fj::PseudoJet>>(particles);
87-
std::shared_ptr<fastjet::ClusterSequence> cs = std::make_shared<fastjet::ClusterSequence>(*pj, *jet_def);
88-
auto j = cs->inclusive_jets();
89-
offptr++;
90-
ow.cse.push_back(cs);
91-
ow.parts.push_back(pj);
92+
std::vector<fj::PseudoJet> jets;
93+
auto jet_def = swigtocpp<fj::JetDefinition *>(jetdef);
94+
std::shared_ptr<std::vector<fj::PseudoJet>> pj =
95+
std::make_shared<std::vector<fj::PseudoJet>>(particles);
96+
std::shared_ptr<fastjet::ClusterSequence> cs =
97+
std::make_shared<fastjet::ClusterSequence>(*pj, *jet_def);
98+
auto j = cs->inclusive_jets();
99+
offptr++;
100+
ow.cse.push_back(cs);
101+
ow.parts.push_back(pj);
92102
}
93103
return ow;
94104
}
95105

96106
PYBIND11_MODULE(_ext, m) {
97107
using namespace fastjet;
98-
m.def("interfacemulti", &interfacemulti, py::return_value_policy::take_ownership);
108+
m.def("interfacemulti", &interfacemulti,
109+
py::return_value_policy::take_ownership);
99110
/// Jet algorithm definitions
100111

101112
py::class_<output_wrapper>(m, "output_wrapper")
@@ -1827,6 +1838,11 @@ PYBIND11_MODULE(_ext, m) {
18271838
pt, eta, phi, m of inclusive jets.
18281839
)pbdoc");
18291840
py::class_<ClusterSequence>(m, "ClusterSequence")
1830-
.def(py::init<const std::vector<PseudoJet> &, const JetDefinition &, const bool &>(), "pseudojets"_a, "jet_definition"_a, "write_out_combinations"_a = false, "Create a ClusterSequence, starting from the supplied set of PseudoJets and clustering them with jet definition specified by jet_definition (which also specifies the clustering strategy)");
1831-
1841+
.def(py::init<const std::vector<PseudoJet> &, const JetDefinition &,
1842+
const bool &>(),
1843+
"pseudojets"_a, "jet_definition"_a,
1844+
"write_out_combinations"_a = false,
1845+
"Create a ClusterSequence, starting from the supplied set of "
1846+
"PseudoJets and clustering them with jet definition specified by "
1847+
"jet_definition (which also specifies the clustering strategy)");
18321848
}

0 commit comments

Comments
 (0)