From 3dffa935282d6248bcd3fe86913aad7d34ee12c6 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Fri, 5 Oct 2018 17:40:12 +0200 Subject: [PATCH] Move special AD numbers related to taping from namespaces to structs. Refer to #7117 --- .../deal.II/differentiation/ad/ad_drivers.h | 333 +++++++++++------- .../deal.II/differentiation/ad/ad_helpers.h | 48 ++- source/differentiation/ad/ad_helpers.cc | 63 ++-- 3 files changed, 269 insertions(+), 175 deletions(-) diff --git a/include/deal.II/differentiation/ad/ad_drivers.h b/include/deal.II/differentiation/ad/ad_drivers.h index 0d02f189bc..51fa63dc4d 100644 --- a/include/deal.II/differentiation/ad/ad_drivers.h +++ b/include/deal.II/differentiation/ad/ad_drivers.h @@ -92,56 +92,46 @@ namespace Differentiation /** - * A collection of types used within the context of auto-differentiable - * numbers. + * A struct defining a collection of types used within the context of + * auto-differentiable numbers. */ - namespace types + template + struct Types { /** - * Typedef for tape indices. ADOL-C uses short integers, so - * we restrict ourselves to similar types. + * Typedef for tape indices. */ - using tape_index = unsigned short; + using tape_index = unsigned int; /** * Typedef for tape buffer sizes. */ using tape_buffer_sizes = unsigned int; - } // namespace types + }; // struct Types /** - * A collection of special numbers used within the context of - * auto-differentiable numbers. + * A struct defining a collection of special numbers used within the + * context of auto-differentiable numbers. */ - namespace numbers + template + struct Numbers { /** * A tape index that is unusable and can be used to invalidate recording * operations. - * - * @note ADOL-C doesn't allow us to record to this reserved tape (i.e. can't - * write it to file), so we can safely use it as an invalidation case. In - * general, we want the user to be able to record to a tape if they'd - * like. */ - static const types::tape_index invalid_tape_index = 0; + // Note: We stipulate in the documentation for the helper classes that the + // valid tape index range is (invalid_tape_index,max_tape_index). + static const typename Types::tape_index invalid_tape_index = + 0u; /** * The maximum number of tapes that can be written on one process. */ -#ifdef DEAL_II_WITH_ADOLC - // Note: This value is a limitation of ADOL-C, and not something that we - // have control over. See test adolc/helper_tape_index_01.cc for - // verification that we cannot use or exceed this value. This value is - // defined as TBUFNUM; see - // https://gitlab.com/adol-c/adol-c/blob/master/ADOL-C/include/adolc/internal/usrparms.h#L34 - static const types::tape_index max_tape_index = TBUFNUM; -#else - static const types::tape_index max_tape_index = - std::numeric_limits::max(); -#endif // DEAL_II_WITH_ADOLC - } // namespace numbers + static const typename Types::tape_index max_tape_index = + std::numeric_limits::tape_index>::max(); + }; // struct Numbers /** @@ -184,7 +174,7 @@ namespace Differentiation * Returns the tape number which is currently activated for recording or * reading. */ - types::tape_index + typename Types::tape_index active_tape_index() const; /** @@ -192,7 +182,8 @@ namespace Differentiation * or registered. */ bool - is_registered_tape(const types::tape_index tape_index) const; + is_registered_tape( + const typename Types::tape_index tape_index) const; /** * Returns whether or not the numerical values of all independent @@ -227,10 +218,19 @@ namespace Differentiation * @param[in] tbufsize ADOL-C Taylor buffer size */ void - set_tape_buffer_sizes(const types::tape_buffer_sizes obufsize = 67108864, - const types::tape_buffer_sizes lbufsize = 67108864, - const types::tape_buffer_sizes vbufsize = 67108864, - const types::tape_buffer_sizes tbufsize = 67108864); + set_tape_buffer_sizes( + const typename Types::tape_buffer_sizes obufsize = 64 * + 1024 * + 1024, + const typename Types::tape_buffer_sizes lbufsize = 64 * + 1024 * + 1024, + const typename Types::tape_buffer_sizes vbufsize = 64 * + 1024 * + 1024, + const typename Types::tape_buffer_sizes tbufsize = 64 * + 1024 * + 1024); /** * Enable the recording mode for a given tape. @@ -241,8 +241,8 @@ namespace Differentiation * tape buffer. */ void - start_taping(const types::tape_index tape_index, - const bool keep_independent_values); + start_taping(const typename Types::tape_index tape_index, + const bool keep_independent_values); /** * Disable the recording mode for a given tape. @@ -253,8 +253,9 @@ namespace Differentiation * should be written to file or kept in memory. */ void - stop_taping(const types::tape_index active_tape_index, - const bool write_tapes_to_file); + stop_taping( + const typename Types::tape_index active_tape_index, + const bool write_tapes_to_file); /** * Select a tape to record to or read from. @@ -267,10 +268,11 @@ namespace Differentiation * from. * * @note The chosen tape index must be greater than - * numbers::invalid_tape_index and less than numbers::max_tape_index. + * Numbers::invalid_tape_index and less than + * Numbers::max_tape_index. */ void - activate_tape(const types::tape_index tape_index); + activate_tape(const typename Types::tape_index tape_index); /** * Reset the state of the class. @@ -300,8 +302,9 @@ namespace Differentiation * written. */ static void - print_tape_stats(const types::tape_index tape_index, - std::ostream & stream); + print_tape_stats( + const typename Types::tape_index tape_index, + std::ostream & stream); //@} @@ -321,7 +324,7 @@ namespace Differentiation * @return The scalar value of the function. */ static ScalarType - value(const types::tape_index active_tape_index, + value(const typename Types::tape_index active_tape_index, const std::vector &independent_variables); /** @@ -338,7 +341,7 @@ namespace Differentiation * n_independent_variables). */ static void - gradient(const types::tape_index active_tape_index, + gradient(const typename Types::tape_index active_tape_index, const std::vector &independent_variables, Vector & gradient); @@ -356,7 +359,7 @@ namespace Differentiation * n_independent_variables$\times$n_independent_variables). */ static void - hessian(const types::tape_index active_tape_index, + hessian(const typename Types::tape_index active_tape_index, const std::vector &independent_variables, FullMatrix & hessian); @@ -380,7 +383,7 @@ namespace Differentiation * (with length n_dependent_variables). */ static void - values(const types::tape_index active_tape_index, + values(const typename Types::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector &independent_variables, Vector & values); @@ -404,7 +407,7 @@ namespace Differentiation * n_dependent_variables$\times$n_independent_variables). */ static void - jacobian(const types::tape_index active_tape_index, + jacobian(const typename Types::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector &independent_variables, FullMatrix & jacobian); @@ -617,18 +620,18 @@ namespace Differentiation template - types::tape_index + typename Types::tape_index TapedDrivers::active_tape_index() const { AssertThrow(false, ExcRequiresADNumberSpecialization()); - return numbers::invalid_tape_index; + return Numbers::invalid_tape_index; } template bool TapedDrivers::is_registered_tape( - const types::tape_index) const + const typename Types::tape_index) const { AssertThrow(false, ExcRequiresADNumberSpecialization()); return false; @@ -647,10 +650,10 @@ namespace Differentiation template void TapedDrivers::set_tape_buffer_sizes( - const types::tape_buffer_sizes, - const types::tape_buffer_sizes, - const types::tape_buffer_sizes, - const types::tape_buffer_sizes) + const typename Types::tape_buffer_sizes, + const typename Types::tape_buffer_sizes, + const typename Types::tape_buffer_sizes, + const typename Types::tape_buffer_sizes) { AssertThrow(false, ExcRequiresADNumberSpecialization()); } @@ -659,7 +662,7 @@ namespace Differentiation template void TapedDrivers::start_taping( - const types::tape_index, + const typename Types::tape_index, const bool) { AssertThrow(false, ExcRequiresADNumberSpecialization()); @@ -669,7 +672,7 @@ namespace Differentiation template void TapedDrivers::stop_taping( - const types::tape_index, + const typename Types::tape_index, const bool) { AssertThrow(false, ExcRequiresADNumberSpecialization()); @@ -679,7 +682,7 @@ namespace Differentiation template void TapedDrivers::activate_tape( - const types::tape_index) + const typename Types::tape_index) { AssertThrow(false, ExcRequiresADNumberSpecialization()); } @@ -704,7 +707,7 @@ namespace Differentiation template void TapedDrivers::print_tape_stats( - const types::tape_index, + const typename Types::tape_index, std::ostream &) { AssertThrow(false, ExcRequiresADNumberSpecialization()); @@ -714,7 +717,7 @@ namespace Differentiation template ScalarType TapedDrivers::value( - const types::tape_index, + const typename Types::tape_index, const std::vector &) { AssertThrow(false, ExcRequiresADNumberSpecialization()); @@ -725,7 +728,7 @@ namespace Differentiation template void TapedDrivers::gradient( - const types::tape_index, + const typename Types::tape_index, const std::vector &, Vector &) { @@ -736,7 +739,7 @@ namespace Differentiation template void TapedDrivers::hessian( - const types::tape_index, + const typename Types::tape_index, const std::vector &, FullMatrix &) { @@ -747,7 +750,7 @@ namespace Differentiation template void TapedDrivers::values( - const types::tape_index, + const typename Types::tape_index, const unsigned int, const std::vector &, Vector &) @@ -759,7 +762,7 @@ namespace Differentiation template void TapedDrivers::jacobian( - const types::tape_index, + const typename Types::tape_index, const unsigned int, const std::vector &, FullMatrix &) @@ -770,6 +773,62 @@ namespace Differentiation # ifdef DEAL_II_WITH_ADOLC + /** + * Specialization for taped ADOL-C auto-differentiable numbers. + */ + template + struct Types< + ADNumberType, + typename std::enable_if::type_code == + NumberTypes::adolc_taped>::type> + { + /** + * Typedef for tape indices. ADOL-C uses short integers, so + * we restrict ourselves to similar types. + */ + using tape_index = unsigned short; + + /** + * Typedef for tape buffer sizes. + */ + using tape_buffer_sizes = unsigned int; + }; // struct Types + + + /** + * Specialization for taped ADOL-C auto-differentiable numbers. + */ + template + struct Numbers< + ADNumberType, + typename std::enable_if::type_code == + NumberTypes::adolc_taped>::type> + { + /** + * A tape index that is unusable and can be used to invalidate recording + * operations. + * + * @note ADOL-C doesn't allow us to record to this reserved tape (i.e. can't + * write it to file), so we can safely use it as an invalidation case. In + * general, we want the user to be able to record to a tape if they'd + * like. + */ + static const typename Types::tape_index invalid_tape_index = + 0; + + /** + * The maximum number of tapes that can be written on one process. + */ + // Note: This value is a limitation of ADOL-C, and not something that we + // have control over. See test adolc/helper_tape_index_01.cc for + // verification that we cannot use or exceed this value. This value is + // defined as TBUFNUM; see + // https://gitlab.com/adol-c/adol-c/blob/master/ADOL-C/include/adolc/internal/usrparms.h#L34 + static const typename Types::tape_index max_tape_index = + TBUFNUM; + }; // struct Numbers + + /** * Specialization for taped ADOL-C auto-differentiable numbers. * @@ -787,7 +846,7 @@ namespace Differentiation using scalar_type = double; TapedDrivers() - : active_tape(numbers::invalid_tape_index) + : active_tape(Numbers::invalid_tape_index) , keep_values(true) , is_recording_flag(false) , use_stored_taped_buffer_sizes(false) @@ -805,7 +864,7 @@ namespace Differentiation return is_recording_flag; } - types::tape_index + typename Types::tape_index active_tape_index() const { return active_tape; @@ -818,7 +877,8 @@ namespace Differentiation } bool - is_registered_tape(const types::tape_index tape_index) const + is_registered_tape( + const typename Types::tape_index tape_index) const { // Sigh... This is a mess :-/ // The most succinct way to get this piece of information, would be to @@ -851,8 +911,8 @@ namespace Differentiation // see if the tape REALLY exists (i.e. has been touched, even if nothing // has been written to it) before trying to access it. It'll only take // an O(n) search, but at this point who really cares about efficiency? - const std::vector registered_tape_indices = - get_registered_tape_indices(); + const std::vector::tape_index> + registered_tape_indices = get_registered_tape_indices(); const auto it = std::find(registered_tape_indices.begin(), registered_tape_indices.end(), tape_index); @@ -866,10 +926,11 @@ namespace Differentiation } void - set_tape_buffer_sizes(const types::tape_buffer_sizes in_obufsize, - const types::tape_buffer_sizes in_lbufsize, - const types::tape_buffer_sizes in_vbufsize, - const types::tape_buffer_sizes in_tbufsize) + set_tape_buffer_sizes( + const typename Types::tape_buffer_sizes in_obufsize, + const typename Types::tape_buffer_sizes in_lbufsize, + const typename Types::tape_buffer_sizes in_vbufsize, + const typename Types::tape_buffer_sizes in_tbufsize) { // When valid for the chosen AD number type, these values will be used // the next time start_recording_operations() is called. @@ -881,8 +942,8 @@ namespace Differentiation } void - start_taping(const types::tape_index tape_index, - const bool keep_independent_values) + start_taping(const typename Types::tape_index tape_index, + const bool keep_independent_values) { if (use_stored_taped_buffer_sizes) trace_on(tape_index, @@ -900,8 +961,9 @@ namespace Differentiation } void - stop_taping(const types::tape_index active_tape_index, - const bool write_tapes_to_file) + stop_taping( + const typename Types::tape_index active_tape_index, + const bool write_tapes_to_file) { if (write_tapes_to_file) trace_off(active_tape_index); // Slow @@ -917,11 +979,11 @@ namespace Differentiation // invalidate it. However, there is now also no way to double-check // that the newly recorded tape is indeed the active tape. if (keep_independent_values() == false) - active_tape = numbers::invalid_tape_index; + active_tape = Numbers::invalid_tape_index; } void - activate_tape(const types::tape_index tape_index) + activate_tape(const typename Types::tape_index tape_index) { active_tape = tape_index; } @@ -929,12 +991,12 @@ namespace Differentiation void reset(const bool clear_registered_tapes) { - active_tape = numbers::invalid_tape_index; + active_tape = Numbers::invalid_tape_index; is_recording_flag = false; if (clear_registered_tapes) { - const std::vector registered_tape_indices = - get_registered_tape_indices(); + const std::vector::tape_index> + registered_tape_indices = get_registered_tape_indices(); for (const auto &tape_index : registered_tape_indices) removeTape(tape_index, TapeRemovalType::ADOLC_REMOVE_COMPLETELY); } @@ -943,8 +1005,8 @@ namespace Differentiation void print(std::ostream &stream) const { - const std::vector registered_tape_indices = - get_registered_tape_indices(); + const std::vector::tape_index> + registered_tape_indices = get_registered_tape_indices(); stream << "Registered tapes: "; auto it_registered_tape = registered_tape_indices.begin(); for (unsigned int i = 0; i < registered_tape_indices.size(); @@ -959,7 +1021,9 @@ namespace Differentiation } static void - print_tape_stats(const types::tape_index tape_index, std::ostream &stream) + print_tape_stats( + const typename Types::tape_index tape_index, + std::ostream & stream) { // See ADOL-C manual section 2.1 // and adolc/taping.h @@ -997,7 +1061,7 @@ namespace Differentiation // === Scalar drivers === static scalar_type - value(const types::tape_index active_tape_index, + value(const typename Types::tape_index active_tape_index, const std::vector &independent_variables) { scalar_type value = 0.0; @@ -1012,7 +1076,7 @@ namespace Differentiation } static void - gradient(const types::tape_index active_tape_index, + gradient(const typename Types::tape_index active_tape_index, const std::vector &independent_variables, Vector & gradient) { @@ -1035,7 +1099,7 @@ namespace Differentiation } static void - hessian(const types::tape_index active_tape_index, + hessian(const typename Types::tape_index active_tape_index, const std::vector &independent_variables, FullMatrix & hessian) { @@ -1071,7 +1135,7 @@ namespace Differentiation // === Vector drivers === static void - values(const types::tape_index active_tape_index, + values(const typename Types::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector &independent_variables, Vector & values) @@ -1090,7 +1154,7 @@ namespace Differentiation } static void - jacobian(const types::tape_index active_tape_index, + jacobian(const typename Types::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector &independent_variables, FullMatrix & jacobian) @@ -1123,7 +1187,7 @@ namespace Differentiation * be recorded to or read from when performing computations using "taped" * auto-differentiable numbers. */ - types::tape_index active_tape; + typename Types::tape_index active_tape; /** * Mark whether we're going to inform taped data structures to retain @@ -1149,27 +1213,27 @@ namespace Differentiation /** * ADOL-C operations buffer size. */ - types::tape_buffer_sizes obufsize; + typename Types::tape_buffer_sizes obufsize; /** * ADOL-C locations buffer size. */ - types::tape_buffer_sizes lbufsize; + typename Types::tape_buffer_sizes lbufsize; /** * ADOL-C value buffer size. */ - types::tape_buffer_sizes vbufsize; + typename Types::tape_buffer_sizes vbufsize; /** * ADOL-C Taylor buffer size. */ - types::tape_buffer_sizes tbufsize; + typename Types::tape_buffer_sizes tbufsize; /** * Return a list of registered tape indices */ - std::vector + std::vector::tape_index> get_registered_tape_indices() const { // We've chosen to use unsigned shorts for the tape @@ -1179,8 +1243,8 @@ namespace Differentiation std::vector registered_tape_indices_s; cachedTraceTags(registered_tape_indices_s); - std::vector registered_tape_indices( - registered_tape_indices_s.size()); + std::vector::tape_index> + registered_tape_indices(registered_tape_indices_s.size()); std::copy(registered_tape_indices_s.begin(), registered_tape_indices_s.end(), registered_tape_indices.begin()); @@ -1216,11 +1280,11 @@ namespace Differentiation return false; } - types::tape_index + typename Types::tape_index active_tape_index() const { AssertThrow(false, ExcRequiresADOLC()); - return numbers::invalid_tape_index; + return Numbers::invalid_tape_index; } bool @@ -1231,35 +1295,37 @@ namespace Differentiation } bool - is_registered_tape(const types::tape_index tape_index) const + is_registered_tape( + const typename Types::tape_index tape_index) const { AssertThrow(false, ExcRequiresADOLC()); return false; } void - set_tape_buffer_sizes(const types::tape_buffer_sizes, - const types::tape_buffer_sizes, - const types::tape_buffer_sizes, - const types::tape_buffer_sizes) + set_tape_buffer_sizes( + const typename Types::tape_buffer_sizes, + const typename Types::tape_buffer_sizes, + const typename Types::tape_buffer_sizes, + const typename Types::tape_buffer_sizes) { AssertThrow(false, ExcRequiresADOLC()); } void - start_taping(const types::tape_index, const bool) + start_taping(const typename Types::tape_index, const bool) { AssertThrow(false, ExcRequiresADOLC()); } void - stop_taping(const types::tape_index, const bool) + stop_taping(const typename Types::tape_index, const bool) { AssertThrow(false, ExcRequiresADOLC()); } void - activate_tape(const types::tape_index) + activate_tape(const typename Types::tape_index) { AssertThrow(false, ExcRequiresADOLC()); } @@ -1277,7 +1343,8 @@ namespace Differentiation } static void - print_tape_stats(const types::tape_index, std::ostream &) + print_tape_stats(const typename Types::tape_index, + std::ostream &) { AssertThrow(false, ExcRequiresADOLC()); } @@ -1286,14 +1353,15 @@ namespace Differentiation // === Scalar drivers === static scalar_type - value(const types::tape_index, const std::vector &) + value(const typename Types::tape_index, + const std::vector &) { AssertThrow(false, ExcRequiresADOLC()); return 0.0; } static void - gradient(const types::tape_index, + gradient(const typename Types::tape_index, const std::vector &, Vector &) { @@ -1301,7 +1369,7 @@ namespace Differentiation } static void - hessian(const types::tape_index, + hessian(const typename Types::tape_index, const std::vector &, FullMatrix &) { @@ -1311,7 +1379,7 @@ namespace Differentiation // === Vector drivers === static void - values(const types::tape_index, + values(const typename Types::tape_index, const unsigned int, const std::vector &, Vector &) @@ -1320,7 +1388,7 @@ namespace Differentiation } static void - jacobian(const types::tape_index, + jacobian(const typename Types::tape_index, const unsigned int, const std::vector &, FullMatrix &) @@ -1359,7 +1427,7 @@ namespace Differentiation return taped_driver.is_recording(); } - types::tape_index + typename Types::tape_index active_tape_index() const { // ADOL-C only supports 'double', not 'float', so we can forward to @@ -1374,7 +1442,8 @@ namespace Differentiation } bool - is_registered_tape(const types::tape_index tape_index) const + is_registered_tape( + const typename Types::tape_index tape_index) const { // ADOL-C only supports 'double', not 'float', so we can forward to // the 'double' implementation of this function @@ -1382,10 +1451,11 @@ namespace Differentiation } void - set_tape_buffer_sizes(const types::tape_buffer_sizes obufsize, - const types::tape_buffer_sizes lbufsize, - const types::tape_buffer_sizes vbufsize, - const types::tape_buffer_sizes tbufsize) + set_tape_buffer_sizes( + const typename Types::tape_buffer_sizes obufsize, + const typename Types::tape_buffer_sizes lbufsize, + const typename Types::tape_buffer_sizes vbufsize, + const typename Types::tape_buffer_sizes tbufsize) { // ADOL-C only supports 'double', not 'float', so we can forward to // the 'double' implementation of this function @@ -1396,8 +1466,8 @@ namespace Differentiation } void - start_taping(const types::tape_index tape_index, - const bool keep_independent_values) + start_taping(const typename Types::tape_index tape_index, + const bool keep_independent_values) { // ADOL-C only supports 'double', not 'float', so we can forward to // the 'double' implementation of this function @@ -1405,8 +1475,9 @@ namespace Differentiation } void - stop_taping(const types::tape_index active_tape_index, - const bool write_tapes_to_file) + stop_taping( + const typename Types::tape_index active_tape_index, + const bool write_tapes_to_file) { // ADOL-C only supports 'double', not 'float', so we can forward to // the 'double' implementation of this function @@ -1414,7 +1485,7 @@ namespace Differentiation } void - activate_tape(const types::tape_index tape_index) + activate_tape(const typename Types::tape_index tape_index) { taped_driver.activate_tape(tape_index); } @@ -1432,7 +1503,9 @@ namespace Differentiation } static void - print_tape_stats(const types::tape_index tape_index, std::ostream &stream) + print_tape_stats( + const typename Types::tape_index tape_index, + std::ostream & stream) { // ADOL-C only supports 'double', not 'float', so we can forward to // the 'double' implementation of this function @@ -1443,7 +1516,7 @@ namespace Differentiation // === Scalar drivers === static scalar_type - value(const types::tape_index active_tape_index, + value(const typename Types::tape_index active_tape_index, const std::vector &independent_variables) { // ADOL-C only supports 'double', not 'float', so we can forward to @@ -1453,7 +1526,7 @@ namespace Differentiation } static void - gradient(const types::tape_index active_tape_index, + gradient(const typename Types::tape_index active_tape_index, const std::vector &independent_variables, Vector & gradient) { @@ -1468,7 +1541,7 @@ namespace Differentiation } static void - hessian(const types::tape_index active_tape_index, + hessian(const typename Types::tape_index active_tape_index, const std::vector &independent_variables, FullMatrix & hessian) { @@ -1485,7 +1558,7 @@ namespace Differentiation // === Vector drivers === static void - values(const types::tape_index active_tape_index, + values(const typename Types::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector &independent_variables, Vector & values) @@ -1502,7 +1575,7 @@ namespace Differentiation } static void - jacobian(const types::tape_index active_tape_index, + jacobian(const typename Types::tape_index active_tape_index, const unsigned int n_dependent_variables, const std::vector &independent_variables, FullMatrix & jacobian) diff --git a/include/deal.II/differentiation/ad/ad_helpers.h b/include/deal.II/differentiation/ad/ad_helpers.h index 1ec78b6b7e..c131f31fdc 100644 --- a/include/deal.II/differentiation/ad/ad_helpers.h +++ b/include/deal.II/differentiation/ad/ad_helpers.h @@ -107,7 +107,7 @@ namespace Differentiation * ad_helper.set_tape_buffer_sizes(); * * // Select a tape number to record to - * const types::tape_index tape_index = ...; + * const typename Types::tape_index tape_index = ...; * * // Indicate that we are about to start tracing the operations for * // function evaluation on the tape. If this tape has already been used @@ -261,8 +261,8 @@ namespace Differentiation * is a taped auto-differentiable number. */ void - print_tape_stats(const types::tape_index tape_index, - std::ostream & stream) const; + print_tape_stats(const typename Types::tape_index tape_index, + std::ostream & stream) const; //@} @@ -350,7 +350,7 @@ namespace Differentiation * Returns the tape index which is currently activated for recording or * reading. */ - types::tape_index + typename Types::tape_index active_tape_index() const; /** @@ -358,7 +358,8 @@ namespace Differentiation * or registered. */ bool - is_registered_tape(const types::tape_index tape_index) const; + is_registered_tape( + const typename Types::tape_index tape_index) const; /** * Set the buffer sizes for the next active tape. @@ -386,10 +387,15 @@ namespace Differentiation * @param[in] tbufsize ADOL-C Taylor buffer size */ void - set_tape_buffer_sizes(const types::tape_buffer_sizes obufsize = 67108864, - const types::tape_buffer_sizes lbufsize = 67108864, - const types::tape_buffer_sizes vbufsize = 67108864, - const types::tape_buffer_sizes tbufsize = 67108864); + set_tape_buffer_sizes( + const typename Types::tape_buffer_sizes obufsize = 64 * 1024 * + 1024, + const typename Types::tape_buffer_sizes lbufsize = 64 * 1024 * + 1024, + const typename Types::tape_buffer_sizes vbufsize = 64 * 1024 * + 1024, + const typename Types::tape_buffer_sizes tbufsize = 64 * 1024 * + 1024); /** * Enable recording mode for a given tape. The use of this function is @@ -433,12 +439,14 @@ namespace Differentiation * or jacobian() operations can be performed. * * @note The chosen tape index must be greater than - * numbers::invalid_tape_index and less than numbers::max_tape_index. + * Numbers::invalid_tape_index and less than + * Numbers::max_tape_index. */ bool - start_recording_operations(const types::tape_index tape_index, - const bool overwrite_tape = false, - const bool keep_independent_values = true); + start_recording_operations( + const typename Types::tape_index tape_index, + const bool overwrite_tape = false, + const bool keep_independent_values = true); /** * Disable recording mode for a given tape. The use of this function is @@ -460,10 +468,12 @@ namespace Differentiation * @param[in] tape_index The index of the tape to be read from. * * @note The chosen tape index must be greater than - * numbers::invalid_tape_index and less than numbers::max_tape_index. + * Numbers::invalid_tape_index and less than + * Numbers::max_tape_index. */ void - activate_recorded_tape(const types::tape_index tape_index); + activate_recorded_tape( + const typename Types::tape_index tape_index); //@} @@ -502,10 +512,12 @@ namespace Differentiation * read data from a preexisting tape. * * @note The chosen tape index must be greater than - * numbers::invalid_tape_index and less than numbers::max_tape_index. + * Numbers::invalid_tape_index and less than + * Numbers::max_tape_index. */ void - activate_tape(const types::tape_index tape_index, const bool read_mode); + activate_tape(const typename Types::tape_index tape_index, + const bool read_mode); //@} @@ -1031,7 +1043,7 @@ namespace Differentiation * // material combination: * * // Select a tape number to record to - * const types::tape_index tape_index = ...; + * const typename Types::tape_index tape_index = ...; * * // Indicate that we are about to start tracing the operations for * // function evaluation on the tape. If this tape has already been diff --git a/source/differentiation/ad/ad_helpers.cc b/source/differentiation/ad/ad_helpers.cc index 7437d82fdb..ea732e626a 100644 --- a/source/differentiation/ad/ad_helpers.cc +++ b/source/differentiation/ad/ad_helpers.cc @@ -113,7 +113,8 @@ namespace Differentiation } if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); } Assert( @@ -147,7 +148,7 @@ namespace Differentiation if (ADNumberTraits::is_taped == true) { - Assert(active_tape_index() != numbers::invalid_tape_index, + Assert(active_tape_index() != Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); Assert(is_recording() == true, ExcMessage( @@ -197,7 +198,7 @@ namespace Differentiation { if (ADNumberTraits::is_taped == true) { - Assert(active_tape_index() != numbers::invalid_tape_index, + Assert(active_tape_index() != Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); } Assert(is_recording() == false, @@ -269,7 +270,8 @@ namespace Differentiation template - types::tape_index + typename Types< + typename ADHelperBase::ad_type>::tape_index ADHelperBase::active_tape_index() const { if (AD::is_taped_ad_number::value) @@ -283,7 +285,7 @@ namespace Differentiation template bool ADHelperBase::is_registered_tape( - const types::tape_index tape_index) const + const typename Types::tape_index tape_index) const { if (AD::is_taped_ad_number::value) return taped_driver.is_registered_tape(tape_index); @@ -366,8 +368,8 @@ namespace Differentiation template void ADHelperBase::print_tape_stats( - const types::tape_index tape_index, - std::ostream & stream) const + const typename Types::tape_index tape_index, + std::ostream & stream) const { if (ADNumberTraits::is_tapeless == true) return; @@ -466,7 +468,7 @@ namespace Differentiation template void ADHelperBase::activate_recorded_tape( - const types::tape_index tape_index) + const typename Types::tape_index tape_index) { activate_tape(tape_index, true /*read_mode*/); } @@ -476,14 +478,14 @@ namespace Differentiation template void ADHelperBase::activate_tape( - const types::tape_index tape_index, - const bool read_mode) + const typename Types::tape_index tape_index, + const bool read_mode) { if (ADNumberTraits::is_taped == true) { - Assert(tape_index != numbers::invalid_tape_index, + Assert(tape_index != Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); - Assert(tape_index < numbers::max_tape_index, + Assert(tape_index < Numbers::max_tape_index, ExcMessage("Tape index exceeds maximum allowable value")); taped_driver.activate_tape(tape_index); reset_registered_independent_variables(); @@ -513,10 +515,10 @@ namespace Differentiation template void ADHelperBase::set_tape_buffer_sizes( - const types::tape_buffer_sizes obufsize, - const types::tape_buffer_sizes lbufsize, - const types::tape_buffer_sizes vbufsize, - const types::tape_buffer_sizes tbufsize) + const typename Types::tape_buffer_sizes obufsize, + const typename Types::tape_buffer_sizes lbufsize, + const typename Types::tape_buffer_sizes vbufsize, + const typename Types::tape_buffer_sizes tbufsize) { // When valid for the chosen AD number type, these values will be used the // next time start_recording_operations() is called. @@ -532,9 +534,9 @@ namespace Differentiation template bool ADHelperBase::start_recording_operations( - const types::tape_index tape_index, - const bool overwrite_tape, - const bool keep_independent_values) + const typename Types::tape_index tape_index, + const bool overwrite_tape, + const bool keep_independent_values) { // Define this here for clarity when this flag is used later. const bool read_mode = false; @@ -566,7 +568,8 @@ namespace Differentiation else { Assert(is_recording() == false, - ExcMessage("Tape recording is unexpectedly still enabled.")); + ExcMessage( + "Tape recording is unexpectedly still enabled.")); // Now we activate the pre-recorded tape so that its immediately // available for use @@ -642,7 +645,7 @@ namespace Differentiation if (ADNumberTraits::is_taped == true) { - Assert(active_tape_index() != numbers::invalid_tape_index, + Assert(active_tape_index() != Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); Assert(is_recording() == true, ExcMessage( @@ -701,7 +704,8 @@ namespace Differentiation { if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); } @@ -725,7 +729,8 @@ namespace Differentiation { if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); } @@ -747,7 +752,8 @@ namespace Differentiation { if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); } Assert(values.size() == this->n_independent_variables(), @@ -812,7 +818,8 @@ namespace Differentiation if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); Assert(this->is_recording() == false, ExcMessage( @@ -872,7 +879,8 @@ namespace Differentiation if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); Assert(this->is_recording() == false, ExcMessage( @@ -940,7 +948,8 @@ namespace Differentiation if (ADNumberTraits::is_taped == true) { - Assert(this->active_tape_index() != numbers::invalid_tape_index, + Assert(this->active_tape_index() != + Numbers::invalid_tape_index, ExcMessage("Invalid tape index")); Assert(this->is_recording() == false, ExcMessage( -- 2.39.5