]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid superfluous zero + add-into in tensor contraction 8609/head
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 20 Aug 2019 19:13:16 +0000 (21:13 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 21 Aug 2019 20:23:41 +0000 (22:23 +0200)
include/deal.II/base/tensor_accessors.h

index b08d048709a1324e3909be5e3115a47838147fe5..a82c4027ede34e397c7c654cbaafd21a96ed7188 100644 (file)
@@ -714,12 +714,22 @@ namespace TensorAccessors
       {
         // Some auto-differentiable numbers need explicit
         // zero initialization.
-        T1 result = dealii::internal::NumberType<T1>::value(0.0);
-        for (unsigned int i = 0; i < dim; ++i)
-          result +=
-            Contract2<no_contr - 1, dim>::template contract2<T1>(left[i],
-                                                                 right[i]);
-        return result;
+        if (dim == 0)
+          {
+            T1 result = dealii::internal::NumberType<T1>::value(0.0);
+            return result;
+          }
+        else
+          {
+            T1 result =
+              Contract2<no_contr - 1, dim>::template contract2<T1>(left[0],
+                                                                   right[0]);
+            for (unsigned int i = 1; i < dim; ++i)
+              result +=
+                Contract2<no_contr - 1, dim>::template contract2<T1>(left[i],
+                                                                     right[i]);
+            return result;
+          }
       }
     };
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.