From: Martin Kronbichler Date: Tue, 20 Aug 2019 19:13:16 +0000 (+0200) Subject: Avoid superfluous zero + add-into in tensor contraction X-Git-Tag: v9.2.0-rc1~1202^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8609%2Fhead;p=dealii.git Avoid superfluous zero + add-into in tensor contraction --- diff --git a/include/deal.II/base/tensor_accessors.h b/include/deal.II/base/tensor_accessors.h index b08d048709..a82c4027ed 100644 --- a/include/deal.II/base/tensor_accessors.h +++ b/include/deal.II/base/tensor_accessors.h @@ -714,12 +714,22 @@ namespace TensorAccessors { // Some auto-differentiable numbers need explicit // zero initialization. - T1 result = dealii::internal::NumberType::value(0.0); - for (unsigned int i = 0; i < dim; ++i) - result += - Contract2::template contract2(left[i], - right[i]); - return result; + if (dim == 0) + { + T1 result = dealii::internal::NumberType::value(0.0); + return result; + } + else + { + T1 result = + Contract2::template contract2(left[0], + right[0]); + for (unsigned int i = 1; i < dim; ++i) + result += + Contract2::template contract2(left[i], + right[i]); + return result; + } } };