From: Wolfgang Bangerth Date: Fri, 12 Jan 2024 00:53:59 +0000 (-0700) Subject: Simplify a function's implementation for tensors. X-Git-Tag: relicensing~172^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16460%2Fhead;p=dealii.git 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. --- 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; }