From 18ebe7adb6dca146a58b9a74e5eb63ae2af8d987 Mon Sep 17 00:00:00 2001 From: kchristin Date: Thu, 12 Sep 2024 17:24:14 +0300 Subject: [PATCH] Fix format --- include/clad/Differentiator/DiffPlanner.h | 14 ++++---- include/clad/Differentiator/Differentiator.h | 9 ++--- include/clad/Differentiator/FunctionTraits.h | 37 ++++++++++---------- include/clad/Differentiator/KokkosBuiltins.h | 29 +++++++++------ lib/Differentiator/DiffPlanner.cpp | 9 +++-- lib/Differentiator/ReverseModeVisitor.cpp | 7 ++-- lib/Differentiator/VisitorBase.cpp | 3 +- 7 files changed, 57 insertions(+), 51 deletions(-) diff --git a/include/clad/Differentiator/DiffPlanner.h b/include/clad/Differentiator/DiffPlanner.h index ef29b7246..388757ca4 100644 --- a/include/clad/Differentiator/DiffPlanner.h +++ b/include/clad/Differentiator/DiffPlanner.h @@ -169,13 +169,13 @@ struct DiffRequest { // Define the hash function for DiffRequest. template <> struct std::hash { - std::size_t operator()(const clad::DiffRequest& DR) const { - // Use the function pointer as the hash of the DiffRequest, it - // is sufficient to break a reasonable number of collisions. - if (DR.Function->getPreviousDecl()) - return std::hash{}(DR.Function->getPreviousDecl()); - return std::hash{}(DR.Function); - } + std::size_t operator()(const clad::DiffRequest& DR) const { + // Use the function pointer as the hash of the DiffRequest, it + // is sufficient to break a reasonable number of collisions. + if (DR.Function->getPreviousDecl()) + return std::hash{}(DR.Function->getPreviousDecl()); + return std::hash{}(DR.Function); + } }; #endif diff --git a/include/clad/Differentiator/Differentiator.h b/include/clad/Differentiator/Differentiator.h index 26e03f457..621c1a3b5 100644 --- a/include/clad/Differentiator/Differentiator.h +++ b/include/clad/Differentiator/Differentiator.h @@ -365,10 +365,11 @@ CUDA_HOST_DEVICE T push(tape& to, ArgsT... val) { return_type_t execute_helper(ReturnType C::*f, Obj&& obj, Args&&... args) { // `static_cast` is required here for perfect forwarding. - return execute_with_default_args( - DropArgs_t{}, f, static_cast(obj), - TakeNFirstArgs_t{}, - static_cast(args)...); + return execute_with_default_args( + DropArgs_t{}, f, + static_cast(obj), + TakeNFirstArgs_t{}, + static_cast(args)...); } /// If user have not passed object explicitly, then this specialization /// will be used and derived function will be called through the object diff --git a/include/clad/Differentiator/FunctionTraits.h b/include/clad/Differentiator/FunctionTraits.h index c15eeb270..eee83b1cf 100644 --- a/include/clad/Differentiator/FunctionTraits.h +++ b/include/clad/Differentiator/FunctionTraits.h @@ -240,85 +240,84 @@ namespace clad { using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; template - struct function_traits { + struct function_traits { using return_type = ReturnType; using argument_types = list; }; diff --git a/include/clad/Differentiator/KokkosBuiltins.h b/include/clad/Differentiator/KokkosBuiltins.h index 1a6253027..4d87f52df 100644 --- a/include/clad/Differentiator/KokkosBuiltins.h +++ b/include/clad/Differentiator/KokkosBuiltins.h @@ -191,7 +191,8 @@ struct diff_parallel_for_MDP_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { ::Kokkos::parallel_for( - "_diff_" + str, policy, [&functor, &d_functor](auto&&... args) { + "_diff_" + str, policy, + [&functor, &d_functor](auto&&... args) { functor.operator_call_pushforward(args..., &d_functor, 0, 0); }); } @@ -213,7 +214,8 @@ struct diff_parallel_for_MDP_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { ::Kokkos::parallel_for( - "_diff_" + str, policy, [&functor, &d_functor](auto&&... args) { + "_diff_" + str, policy, + [&functor, &d_functor](auto&&... args) { functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0); }); } @@ -235,7 +237,8 @@ struct diff_parallel_for_MDP_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { ::Kokkos::parallel_for( - "_diff_" + str, policy, [&functor, &d_functor](auto&&... args) { + "_diff_" + str, policy, + [&functor, &d_functor](auto&&... args) { functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0, 0); }); } @@ -257,7 +260,8 @@ struct diff_parallel_for_MDP_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { ::Kokkos::parallel_for( - "_diff_" + str, policy, [&functor, &d_functor](auto&&... args) { + "_diff_" + str, policy, + [&functor, &d_functor](auto&&... args) { functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0, 0, 0); }); } @@ -278,11 +282,12 @@ template struct diff_parallel_for_MDP_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { - ::Kokkos::parallel_for("_diff_" + str, policy, - [&functor, &d_functor](auto&&... args) { - functor.operator_call_pushforward( - args..., &d_functor, 0, 0, 0, 0, 0, 0); - }); + ::Kokkos::parallel_for( + "_diff_" + str, policy, + [&functor, &d_functor](auto&&... args) { + functor.operator_call_pushforward(args..., &d_functor, 0, 0, 0, 0, 0, + 0); + }); } }; @@ -321,7 +326,8 @@ struct diff_parallel_for_OP_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { ::Kokkos::parallel_for( - "_diff_" + str, policy, [&functor, &d_functor](auto&&... args) { + "_diff_" + str, policy, + [&functor, &d_functor](auto&&... args) { functor.operator_call_pushforward(args..., &d_functor, {}); }); } @@ -344,7 +350,8 @@ struct diff_parallel_for_int_call_dispatch { static void run(const ::std::string& str, const Policy& policy, const FunctorType& functor, const FunctorType& d_functor) { ::Kokkos::parallel_for( - "_diff_" + str, policy, [&functor, &d_functor](const int i) { + "_diff_" + str, policy, + [&functor, &d_functor](const int i) { functor.operator_call_pushforward(i, &d_functor, 0); }); } diff --git a/lib/Differentiator/DiffPlanner.cpp b/lib/Differentiator/DiffPlanner.cpp index e25cabf40..8b5cd2df2 100644 --- a/lib/Differentiator/DiffPlanner.cpp +++ b/lib/Differentiator/DiffPlanner.cpp @@ -304,12 +304,11 @@ namespace clad { i < e && paramIdx < FD->getNumParams(); ++i) { const auto* param = DVI[i].param; while (paramIdx < FD->getNumParams() && - FD->getParamDecl(paramIdx) != param) { - ++paramIdx; - } + FD->getParamDecl(paramIdx) != param) + ++paramIdx; if (paramIdx != FD->getNumParams()) - // Update the parameter to point to the definition parameter. - DVI[i].param = Function->getParamDecl(paramIdx); + // Update the parameter to point to the definition parameter. + DVI[i].param = Function->getParamDecl(paramIdx); } return; } diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 5cdb07bb0..5113abe40 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -4070,9 +4070,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, Expr* ReverseModeVisitor::BreakContStmtHandler:: CreateCFTapeSizeExprForCurrentCase() { - return m_RMV.BuildOp(BinaryOperatorKind::BO_NE, m_ControlFlowTape->Size(), - ConstantFolder::synthesizeLiteral( - m_RMV.m_Context.IntTy, m_RMV.m_Context, 0)); + return m_RMV.BuildOp( + BinaryOperatorKind::BO_NE, m_ControlFlowTape->Size(), + ConstantFolder::synthesizeLiteral(m_RMV.m_Context.IntTy, + m_RMV.m_Context, /*val=*/0)); } void ReverseModeVisitor::BreakContStmtHandler::UpdateForwAndRevBlocks( diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 2e912c8c5..f3443aa61 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -280,9 +280,8 @@ namespace clad { (isa(ENoCasts) && cast(ENoCasts)->getNumArgs() == 2) || isa(ENoCasts) || - isa(ENoCasts)) { + isa(ENoCasts)) return m_Sema.ActOnParenExpr(E->getBeginLoc(), E->getEndLoc(), E).get(); - } return E; }