Skip to content

Commit

Permalink
Introduce clang-format in pre-commit (#125)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
chrispap95 and pre-commit-ci[bot] authored Oct 28, 2022
1 parent f12e4ea commit 4c0a3f2
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 40 deletions.
191 changes: 191 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ repos:
hooks:
- id: check-manifest
stages: [manual]

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v14.0.6"
hooks:
- id: clang-format
types_or: [c++, c, cuda]
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ graft tests
graft fastjet-core
graft pybind11
global-exclude .git .gitmodules
include LICENSE README.md pyproject.toml setup.py setup.cfg patch.txt
include LICENSE README.md pyproject.toml setup.py setup.cfg patch.txt .clang-format
94 changes: 55 additions & 39 deletions src/_ext.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,74 @@
// BSD 3-Clause License; see https://github.com/scikit-hep/fastjet/blob/main/LICENSE
// BSD 3-Clause License; see
// https://github.com/scikit-hep/fastjet/blob/main/LICENSE

#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <unordered_map>
#include <vector>

#include <fastjet/AreaDefinition.hh>
#include <fastjet/ClusterSequence.hh>
#include <fastjet/ClusterSequenceArea.hh>
#include <fastjet/GhostedAreaSpec.hh>
#include <fastjet/JetDefinition.hh>
#include <fastjet/PseudoJet.hh>
#include <fastjet/AreaDefinition.hh>
#include <fastjet/GhostedAreaSpec.hh>

#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/numpy.h>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace fj = fastjet;
namespace py = pybind11;
using namespace pybind11::literals;

typedef struct{
PyObject_HEAD
void *ptr;
typedef struct {
PyObject_HEAD void *ptr;
void *ty;
int own;
PyObject *next;
} SwigPyObject;

template <typename T>
T swigtocpp(py::object obj) { // unwraps python object to get the cpp pointer from the swig bindings
T swigtocpp(py::object obj) { // unwraps python object to get the cpp pointer
// from the swig bindings
auto upointer = obj.attr("this").ptr();
auto swigpointer = reinterpret_cast<SwigPyObject*>(upointer);
auto swigpointer = reinterpret_cast<SwigPyObject *>(upointer);
auto objpointervoid = swigpointer->ptr;
auto objpointer = reinterpret_cast<T>(objpointervoid);
return objpointer;
}
class output_wrapper{
public:
class output_wrapper {
public:
std::vector<std::shared_ptr<fj::ClusterSequence>> cse;
std::vector<std::shared_ptr<std::vector<fj::PseudoJet>>> parts;

std::shared_ptr<fj::ClusterSequence> getCluster(){
std::shared_ptr<fj::ClusterSequence> getCluster() {
auto a = cse[0];
return a;
}
void setCluster(){}
void setCluster() {}
};

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)
{
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) {
py::buffer_info infooff = offsets.request();
py::buffer_info infopx = pxi.request();
py::buffer_info infopy = pyi.request(); // requesting buffer information of the input
py::buffer_info infopy =
pyi.request(); // requesting buffer information of the input
py::buffer_info infopz = pzi.request();
py::buffer_info infoE = Ei.request();

auto offptr = static_cast<int *>(infooff.ptr);
auto pxptr = static_cast<double *>(infopx.ptr);
auto pyptr = static_cast<double *>(infopy.ptr); // pointer to the initial value
auto pyptr =
static_cast<double *>(infopy.ptr); // pointer to the initial value
auto pzptr = static_cast<double *>(infopz.ptr);
auto Eptr = static_cast<double *>(infoE.ptr);

Expand All @@ -71,31 +79,34 @@ output_wrapper interfacemulti(py::array_t<double, py::array::c_style | py::array
std::vector<double> constphi;
std::vector<double> idx;
std::vector<double> idxo;
for (int i = 0; i < dimoff-1; i++) {
for (int i = 0; i < dimoff - 1; i++) {
std::vector<fj::PseudoJet> particles;
for(int j = *offptr; j < *(offptr+1); j++ ){
particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr));
pxptr++;
pyptr++;
pzptr++;
Eptr++;
for (int j = *offptr; j < *(offptr + 1); j++) {
particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr));
pxptr++;
pyptr++;
pzptr++;
Eptr++;
}

std::vector<fj::PseudoJet> jets;
auto jet_def = swigtocpp<fj::JetDefinition*>(jetdef);
std::shared_ptr<std::vector<fj::PseudoJet>> pj = std::make_shared<std::vector<fj::PseudoJet>>(particles);
std::shared_ptr<fastjet::ClusterSequence> cs = std::make_shared<fastjet::ClusterSequence>(*pj, *jet_def);
auto j = cs->inclusive_jets();
offptr++;
ow.cse.push_back(cs);
ow.parts.push_back(pj);
std::vector<fj::PseudoJet> jets;
auto jet_def = swigtocpp<fj::JetDefinition *>(jetdef);
std::shared_ptr<std::vector<fj::PseudoJet>> pj =
std::make_shared<std::vector<fj::PseudoJet>>(particles);
std::shared_ptr<fastjet::ClusterSequence> cs =
std::make_shared<fastjet::ClusterSequence>(*pj, *jet_def);
auto j = cs->inclusive_jets();
offptr++;
ow.cse.push_back(cs);
ow.parts.push_back(pj);
}
return ow;
}

PYBIND11_MODULE(_ext, m) {
using namespace fastjet;
m.def("interfacemulti", &interfacemulti, py::return_value_policy::take_ownership);
m.def("interfacemulti", &interfacemulti,
py::return_value_policy::take_ownership);
/// Jet algorithm definitions

py::class_<output_wrapper>(m, "output_wrapper")
Expand Down Expand Up @@ -1827,6 +1838,11 @@ PYBIND11_MODULE(_ext, m) {
pt, eta, phi, m of inclusive jets.
)pbdoc");
py::class_<ClusterSequence>(m, "ClusterSequence")
.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)");

.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)");
}

0 comments on commit 4c0a3f2

Please sign in to comment.