Skip to content

Commit

Permalink
[NFC] Reformat with clang-format 18 (#130)
Browse files Browse the repository at this point in the history
* reformat with clang-format 18

* format
  • Loading branch information
anakinxc authored Mar 12, 2024
1 parent dac7ea1 commit 8c1a18a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 49 deletions.
3 changes: 1 addition & 2 deletions heu/library/algorithms/mock/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ void Evaluator::NegateInplace(Ciphertext *a) const { *a = Negate(*a); }
#endif

#ifdef IMPL_VECTORIZED_SPI
void Evaluator::Randomize(Span<Ciphertext>) const { /* nothing to do */
}
void Evaluator::Randomize(Span<Ciphertext>) const { /* nothing to do */ }

#define SIMD_FUNCTION_IMPL(NAME, RET, T1, OP, T2) \
std::vector<RET> Evaluator::NAME(ConstSpan<T1> a, ConstSpan<T2> b) const { \
Expand Down
2 changes: 1 addition & 1 deletion heu/library/algorithms/paillier_gpu/gpulib/paillier.cu
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void cudainit() {
}

//*********************************************gpu
//api*****************************************
// api*****************************************
int gpu_paillier_enc_bk(h_paillier_ciphertext_t* res, h_paillier_pubkey_t* pub,
h_paillier_plaintext_t* pt, h_paillier_random_t* rand,
unsigned int count) {
Expand Down
4 changes: 2 additions & 2 deletions heu/library/numpy/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ using kHasReduceSum = decltype(std::declval<const CLAZZ&>().ReduceSum(
std::array<int64_t, 2> x_stride, \
const DenseMatrix<phe::TY>& y, \
std::array<int64_t, 2> y_stride, RET* out) \
-> std::enable_if_t<std::experimental::is_detected_v< \
->std::enable_if_t<std::experimental::is_detected_v< \
kHasVectorized##OP, CLAZZ, SUB_TX, SUB_TY>> { \
const auto* x_base = x.data(); \
const auto* y_base = y.data(); \
Expand Down Expand Up @@ -146,7 +146,7 @@ using kHasReduceSum = decltype(std::declval<const CLAZZ&>().ReduceSum(
std::array<int64_t, 2> x_stride, \
const DenseMatrix<phe::TY>& y, \
std::array<int64_t, 2> y_stride, RET* out) \
-> std::enable_if_t<!std::experimental::is_detected_v< \
->std::enable_if_t<!std::experimental::is_detected_v< \
kHasVectorized##OP, CLAZZ, SUB_TX, SUB_TY>> { \
const auto* x_base = x.data(); \
const auto* y_base = y.data(); \
Expand Down
92 changes: 48 additions & 44 deletions heu/library/phe/base/predefined_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ namespace heu::lib::phe {

// invoke functions with 0 args //

#define DEFINE_INVOKE_METHOD_RET_0(ret, func) \
template <typename CLAZZ> \
using kHasScalar##func = decltype(std::declval<const CLAZZ&>().func()); \
\
/* Call scalar SPI */ \
template <typename CLAZZ> \
auto DoCall##func(const CLAZZ& sub_clazz) -> std::enable_if_t< \
std::experimental::is_detected_v<kHasScalar##func, CLAZZ>, ret> { \
return ret(sub_clazz.func()); \
} \
\
/* Call vectorized SPI */ \
template <typename CLAZZ> \
auto DoCall##func(const CLAZZ& sub_clazz) -> std::enable_if_t< \
!std::experimental::is_detected_v<kHasScalar##func, CLAZZ>, ret> { \
return ret(sub_clazz.func(1)[0]); \
#define DEFINE_INVOKE_METHOD_RET_0(ret, func) \
template <typename CLAZZ> \
using kHasScalar##func = decltype(std::declval<const CLAZZ&>().func()); \
\
/* Call scalar SPI */ \
template <typename CLAZZ> \
auto DoCall##func(const CLAZZ& sub_clazz) \
->std::enable_if_t< \
std::experimental::is_detected_v<kHasScalar##func, CLAZZ>, ret> { \
return ret(sub_clazz.func()); \
} \
\
/* Call vectorized SPI */ \
template <typename CLAZZ> \
auto DoCall##func(const CLAZZ& sub_clazz) \
->std::enable_if_t< \
!std::experimental::is_detected_v<kHasScalar##func, CLAZZ>, ret> { \
return ret(sub_clazz.func(1)[0]); \
}

// invoke functions with 1 args (with return value) //
Expand All @@ -50,7 +52,7 @@ namespace heu::lib::phe {
/* Call scalar SPI */ \
template <typename CLAZZ, typename TYPE1> \
auto DoCall##func(const CLAZZ& sub_clazz, const TYPE1& in1) \
-> std::enable_if_t< \
->std::enable_if_t< \
std::experimental::is_detected_v<kHasScalar##func, CLAZZ, TYPE1>, \
ret> { \
return ret(sub_clazz.func(in1)); \
Expand All @@ -59,7 +61,7 @@ namespace heu::lib::phe {
/* Call vectorized SPI */ \
template <typename CLAZZ, typename TYPE1> \
auto DoCall##func(const CLAZZ& sub_clazz, const TYPE1& in1) \
-> std::enable_if_t< \
->std::enable_if_t< \
!std::experimental::is_detected_v<kHasScalar##func, CLAZZ, TYPE1>, \
ret> { \
return ret(sub_clazz.func(absl::MakeConstSpan<>({&in1}))[0]); \
Expand All @@ -72,24 +74,26 @@ namespace heu::lib::phe {

// invoke functions with 1 args (no return value) //

#define DEFINE_INVOKE_METHOD_VOID_1(func) \
template <typename CLAZZ, typename TYPE1> \
using kHasScalar##func = \
decltype(std::declval<const CLAZZ&>().func(std::declval<TYPE1*>())); \
\
/* Call scalar SPI */ \
template <typename CLAZZ, typename TYPE1> \
auto DoCall##func(const CLAZZ& sub_clazz, TYPE1* out1) -> std::enable_if_t< \
std::experimental::is_detected_v<kHasScalar##func, CLAZZ, TYPE1>> { \
(sub_clazz.func(out1)); \
} \
\
/* Call vectorized SPI */ \
template <typename CLAZZ, typename TYPE1> \
auto DoCall##func(const CLAZZ& sub_clazz, TYPE1* out1) -> std::enable_if_t< \
!std::experimental::is_detected_v<kHasScalar##func, CLAZZ, TYPE1>> { \
TYPE1* wrap[] = {out1}; \
(sub_clazz.func(absl::MakeSpan<>(wrap))); \
#define DEFINE_INVOKE_METHOD_VOID_1(func) \
template <typename CLAZZ, typename TYPE1> \
using kHasScalar##func = \
decltype(std::declval<const CLAZZ&>().func(std::declval<TYPE1*>())); \
\
/* Call scalar SPI */ \
template <typename CLAZZ, typename TYPE1> \
auto DoCall##func(const CLAZZ& sub_clazz, TYPE1* out1) \
->std::enable_if_t< \
std::experimental::is_detected_v<kHasScalar##func, CLAZZ, TYPE1>> { \
(sub_clazz.func(out1)); \
} \
\
/* Call vectorized SPI */ \
template <typename CLAZZ, typename TYPE1> \
auto DoCall##func(const CLAZZ& sub_clazz, TYPE1* out1) \
->std::enable_if_t< \
!std::experimental::is_detected_v<kHasScalar##func, CLAZZ, TYPE1>> { \
TYPE1* wrap[] = {out1}; \
(sub_clazz.func(absl::MakeSpan<>(wrap))); \
}

#define DO_INVOKE_METHOD_VOID_1(ns, clazz, func, type1, out1) \
Expand All @@ -106,19 +110,19 @@ namespace heu::lib::phe {
template <typename CLAZZ, typename TYPE1, typename TYPE2> \
auto DoCall##func(const CLAZZ& sub_clazz, const TYPE1& in1, \
const TYPE2& in2) \
-> std::enable_if_t<std::experimental::is_detected_v< \
kHasScalar##func, CLAZZ, TYPE1, TYPE2>, \
ret> { \
->std::enable_if_t<std::experimental::is_detected_v< \
kHasScalar##func, CLAZZ, TYPE1, TYPE2>, \
ret> { \
return ret(sub_clazz.func(in1, in2)); \
} \
\
/* Call vectorized SPI */ \
template <typename CLAZZ, typename TYPE1, typename TYPE2> \
auto DoCall##func(const CLAZZ& sub_clazz, const TYPE1& in1, \
const TYPE2& in2) \
-> std::enable_if_t<!std::experimental::is_detected_v< \
kHasScalar##func, CLAZZ, TYPE1, TYPE2>, \
ret> { \
->std::enable_if_t<!std::experimental::is_detected_v< \
kHasScalar##func, CLAZZ, TYPE1, TYPE2>, \
ret> { \
return ret(sub_clazz.func(absl::MakeConstSpan<>({&in1}), \
absl::MakeConstSpan<>({&in2}))[0]); \
}
Expand All @@ -138,15 +142,15 @@ namespace heu::lib::phe {
/* Call scalar SPI */ \
template <typename CLAZZ, typename TYPE1, typename TYPE2> \
auto DoCall##func(const CLAZZ& sub_clazz, TYPE1* in_out1, const TYPE2& in2) \
-> std::enable_if_t<std::experimental::is_detected_v< \
->std::enable_if_t<std::experimental::is_detected_v< \
kHasScalar##func, CLAZZ, TYPE1, TYPE2>> { \
(sub_clazz.func(in_out1, in2)); \
} \
\
/* Call vectorized SPI */ \
template <typename CLAZZ, typename TYPE1, typename TYPE2> \
auto DoCall##func(const CLAZZ& sub_clazz, TYPE1* in_out1, const TYPE2& in2) \
-> std::enable_if_t<!std::experimental::is_detected_v< \
->std::enable_if_t<!std::experimental::is_detected_v< \
kHasScalar##func, CLAZZ, TYPE1, TYPE2>> { \
TYPE1* wrap[] = {in_out1}; \
(sub_clazz.func(absl::MakeSpan<>(wrap), absl::MakeConstSpan<>({&in2}))); \
Expand Down

0 comments on commit 8c1a18a

Please sign in to comment.