From c8da83696b8b3178b02626962188f3bbd61406d4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 11 Jan 2024 17:53:59 -0700 Subject: [PATCH] Simplify a function's implementation for tensors. Specifically, now that we can use 'if constexpr', we can avoid using template dispatch which almost certainly is slower to compile and leads to larger libraries. --- include/deal.II/base/tensor.h | 65 +++++++++-------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 56eaa02ef5..0f2ff7de51 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -2103,54 +2103,6 @@ DEAL_II_HOST_DEVICE constexpr inline DEAL_II_ALWAYS_INLINE } -namespace internal -{ - namespace TensorImplementation - { - template ::type>::value, - int> = 0> - constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE - Tensor::type> - division_operator(const Tensor &t, - const OtherNumber &factor) - { - Tensor::type> tt; - const Number inverse_factor = Number(1.) / factor; - // recurse over the base objects - for (unsigned int d = 0; d < dim; ++d) - tt[d] = t[d] * inverse_factor; - return tt; - } - - - template ::type>::value, - int> = 0> - constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE - Tensor::type> - division_operator(const Tensor &t, - const OtherNumber &factor) - { - Tensor::type> tt; - // recurse over the base objects - for (unsigned int d = 0; d < dim; ++d) - tt[d] = t[d] / factor; - return tt; - } - } // namespace TensorImplementation -} // namespace internal - /** * Division of a tensor of general rank with a scalar number. See the @@ -2169,7 +2121,22 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE typename EnableIfScalar::type>::type> operator/(const Tensor &t, const OtherNumber &factor) { - return internal::TensorImplementation::division_operator(t, factor); + Tensor::type> tt; + if constexpr (std::is_integral< + typename ProductType::type>::value) + { + // recurse over the base objects + for (unsigned int d = 0; d < dim; ++d) + tt[d] = t[d] / factor; + } + else + { + const Number inverse_factor = Number(1.) / factor; + // recurse over the base objects + for (unsigned int d = 0; d < dim; ++d) + tt[d] = t[d] * inverse_factor; + } + return tt; } -- 2.39.5