]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Expose AD driver methods via ADHelper bass class.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 6 Dec 2018 13:40:50 +0000 (14:40 +0100)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Thu, 24 Jan 2019 07:44:11 +0000 (08:44 +0100)
Further features provided by the drivers are exposed through the base helper class.

include/deal.II/differentiation/ad/ad_helpers.h
source/differentiation/ad/ad_helpers.cc

index 7aad5de7edab5966a916a7e6979a2b39260ecdf8..4d8bcc78a32546e4fa171dbf70ad327b57b94199 100644 (file)
@@ -478,6 +478,50 @@ namespace Differentiation
       activate_recorded_tape(
         const typename Types<ad_type>::tape_index tape_index);
 
+      /**
+       * Return a flag that, when <code>true</code>, indicates that the
+       * retaping of the dependent function is necessary for a reliable
+       * computation to be performed on a tape with the given @p tape_index.
+       * This may be necessary a sign comparison within branched operations
+       * yields different results to those computed at the original tape
+       * evaluation point.
+       *
+       * For the output of this function to be meaningful, it must be called
+       * after the activate_recorded_tape() is called and the new evaluation
+       * point for the tape (i.e. values of the independent variables) have
+       * been set and subsequently used (i.e. in the determination of the values
+       * or derivatives of the dependent variables).
+       */
+      bool
+      recorded_tape_requires_retaping(
+        const typename Types<ad_type>::tape_index tape_index) const;
+
+      /**
+       * Return a flag that, when <code>true</code>, indicates that the
+       * retaping of the dependent function is necessary for a reliable
+       * computation to be performed on the avtive tape. This may be necessary a
+       * sign comparison within branched operations yields different results to
+       * those computed at the original tape evaluation point.
+       *
+       * For the output of this function to be meaningful, it must be called
+       * after the activate_recorded_tape() is called and the new evaluation
+       * point for the tape (i.e. values of the independent variables) have
+       * been set and subsequently used (i.e. in the determination of the values
+       * or derivatives of the dependent variables).
+       */
+      bool
+      active_tape_requires_retaping() const;
+
+      /**
+       * Clears and removes the currently active tape.
+       *
+       * This is typically only necessary when branch switching is detected on
+       * the original tape at evaluation point. This state can be checked using
+       * the active_tape_requires_retaping() function.
+       */
+      void
+      clear_active_tape();
+
       //@}
 
     protected:
index c1a29cb1f38916180a7aad211c6b584324308228..d8a7866ba37703406e2235c46093abc04f7770c8 100644 (file)
@@ -475,6 +475,44 @@ namespace Differentiation
 
 
 
+    template <enum AD::NumberTypes ADNumberTypeCode, typename ScalarType>
+    bool
+    ADHelperBase<ADNumberTypeCode, ScalarType>::recorded_tape_requires_retaping(
+      const typename Types<ad_type>::tape_index tape_index) const
+    {
+      if (ADNumberTraits<ad_type>::is_tapeless == true)
+        return false;
+
+      return taped_driver.requires_retaping(tape_index);
+    }
+
+
+
+    template <enum AD::NumberTypes ADNumberTypeCode, typename ScalarType>
+    bool
+    ADHelperBase<ADNumberTypeCode, ScalarType>::active_tape_requires_retaping()
+      const
+    {
+      if (ADNumberTraits<ad_type>::is_tapeless == true)
+        return false;
+
+      return taped_driver.last_action_requires_retaping();
+    }
+
+
+
+    template <enum AD::NumberTypes ADNumberTypeCode, typename ScalarType>
+    void
+    ADHelperBase<ADNumberTypeCode, ScalarType>::clear_active_tape()
+    {
+      if (ADNumberTraits<ad_type>::is_tapeless == true)
+        return;
+
+      taped_driver.remove_tape(taped_driver.active_tape_index());
+    }
+
+
+
     template <enum AD::NumberTypes ADNumberTypeCode, typename ScalarType>
     void
     ADHelperBase<ADNumberTypeCode, ScalarType>::activate_tape(

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.