668 Assert(is_registered_tape(active_tape_index),
669 ExcMessage(
"This tape has not yet been recorded."));
671 scalar_type value = 0.0;
673 status[active_tape_index] =
674 ::function(active_tape_index,
676 independent_variables.size(),
677 const_cast<double *
>(independent_variables.data()),
684 template <
typename ADNumberType>
688 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
689 NumberTypes::adolc_taped>>::
691 const std::vector<scalar_type> &independent_variables,
696 ExcSupportedDerivativeLevels(
699 Assert(gradient.size() == independent_variables.size(),
701 independent_variables.size()));
702 Assert(is_registered_tape(active_tape_index),
703 ExcMessage(
"This tape has not yet been recorded."));
708 status[active_tape_index] =
709 ::gradient(active_tape_index,
710 independent_variables.size(),
711 const_cast<scalar_type *
>(independent_variables.data()),
716 template <
typename ADNumberType>
718 TapedDrivers<ADNumberType,
720 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
721 NumberTypes::adolc_taped>>::
722 hessian(
const typename Types<ADNumberType>::tape_index active_tape_index,
723 const std::vector<scalar_type> &independent_variables,
728 ExcSupportedDerivativeLevels(
731 Assert(hessian.m() == independent_variables.size(),
733 Assert(hessian.n() == independent_variables.size(),
735 Assert(is_registered_tape(active_tape_index),
736 ExcMessage(
"This tape has not yet been recorded."));
738 const unsigned int n_independent_variables = independent_variables.size();
739 std::vector<scalar_type *> H(n_independent_variables);
740 for (
unsigned int i = 0; i < n_independent_variables; ++i)
741 H[i] = &hessian[i][0];
743 status[active_tape_index] =
744 ::hessian(active_tape_index,
745 n_independent_variables,
746 const_cast<scalar_type *
>(independent_variables.data()),
752 for (
unsigned int i = 0; i < n_independent_variables; ++i)
753 for (
unsigned int j = 0; j < i; ++j)
754 hessian[j][i] = hessian[i][j];
758 template <
typename ADNumberType>
760 TapedDrivers<ADNumberType,
762 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
763 NumberTypes::adolc_taped>>::
764 values(
const typename Types<ADNumberType>::tape_index active_tape_index,
765 const unsigned int n_dependent_variables,
766 const std::vector<scalar_type> &independent_variables,
769 Assert(values.size() == n_dependent_variables,
771 Assert(is_registered_tape(active_tape_index),
772 ExcMessage(
"This tape has not yet been recorded."));
777 status[active_tape_index] =
778 ::function(active_tape_index,
779 n_dependent_variables,
780 independent_variables.size(),
781 const_cast<scalar_type *
>(independent_variables.data()),
786 template <
typename ADNumberType>
788 TapedDrivers<ADNumberType,
790 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
791 NumberTypes::adolc_taped>>::
792 jacobian(
const typename Types<ADNumberType>::tape_index active_tape_index,
793 const unsigned int n_dependent_variables,
794 const std::vector<scalar_type> &independent_variables,
797 Assert(AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels >=
799 ExcSupportedDerivativeLevels(
800 AD::ADNumberTraits<ADNumberType>::n_supported_derivative_levels,
802 Assert(jacobian.
m() == n_dependent_variables,
804 Assert(jacobian.
n() == independent_variables.size(),
806 Assert(is_registered_tape(active_tape_index),
807 ExcMessage(
"This tape has not yet been recorded."));
809 std::vector<scalar_type *> J(n_dependent_variables);
810 for (
unsigned int i = 0; i < n_dependent_variables; ++i)
811 J[i] = &jacobian[i][0];
813 status[active_tape_index] = ::jacobian(active_tape_index,
814 n_dependent_variables,
815 independent_variables.size(),
816 independent_variables.data(),
824 template <
typename ADNumberType>
826 TapedDrivers<ADNumberType,
828 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
829 NumberTypes::adolc_taped>>::is_recording()
837 template <
typename ADNumberType>
838 typename Types<ADNumberType>::tape_index
842 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
843 NumberTypes::adolc_taped>>::active_tape_index()
const
846 return Numbers<ADNumberType>::invalid_tape_index;
850 template <
typename ADNumberType>
852 TapedDrivers<ADNumberType,
854 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
855 NumberTypes::adolc_taped>>::
856 keep_independent_values()
const
863 template <
typename ADNumberType>
865 TapedDrivers<ADNumberType,
867 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
868 NumberTypes::adolc_taped>>::
869 is_registered_tape(
const typename Types<ADNumberType>::tape_index)
const
876 template <
typename ADNumberType>
878 TapedDrivers<ADNumberType,
880 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
881 NumberTypes::adolc_taped>>::
882 set_tape_buffer_sizes(
883 const typename Types<ADNumberType>::tape_buffer_sizes,
884 const typename Types<ADNumberType>::tape_buffer_sizes,
885 const typename Types<ADNumberType>::tape_buffer_sizes,
886 const typename Types<ADNumberType>::tape_buffer_sizes)
892 template <
typename ADNumberType>
894 TapedDrivers<ADNumberType,
896 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
897 NumberTypes::adolc_taped>>::
898 start_taping(
const typename Types<ADNumberType>::tape_index,
const bool)
904 template <
typename ADNumberType>
906 TapedDrivers<ADNumberType,
908 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
909 NumberTypes::adolc_taped>>::
910 stop_taping(
const typename Types<ADNumberType>::tape_index,
const bool)
916 template <
typename ADNumberType>
917 std::vector<typename Types<ADNumberType>::tape_index>
918 TapedDrivers<ADNumberType,
920 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
921 NumberTypes::adolc_taped>>::
922 get_registered_tape_indices()
const
925 return std::vector<typename Types<ADNumberType>::tape_index>();
929 template <
typename ADNumberType>
931 TapedDrivers<ADNumberType,
933 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
934 NumberTypes::adolc_taped>>::
935 activate_tape(
const typename Types<ADNumberType>::tape_index)
941 template <
typename ADNumberType>
943 TapedDrivers<ADNumberType,
945 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
946 NumberTypes::adolc_taped>>::
947 requires_retaping(
const typename Types<ADNumberType>::tape_index)
const
954 template <
typename ADNumberType>
956 TapedDrivers<ADNumberType,
958 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
959 NumberTypes::adolc_taped>>::
960 last_action_requires_retaping()
const
967 template <
typename ADNumberType>
969 TapedDrivers<ADNumberType,
971 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
972 NumberTypes::adolc_taped>>::
973 remove_tape(
const typename Types<ADNumberType>::tape_index)
979 template <
typename ADNumberType>
981 TapedDrivers<ADNumberType,
983 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
984 NumberTypes::adolc_taped>>::reset(
const bool)
990 template <
typename ADNumberType>
992 TapedDrivers<ADNumberType,
994 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
995 NumberTypes::adolc_taped>>::print(std::ostream
1002 template <
typename ADNumberType>
1004 TapedDrivers<ADNumberType,
1006 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1007 NumberTypes::adolc_taped>>::
1008 print_tape_stats(
const typename Types<ADNumberType>::tape_index,
1009 std::ostream &)
const
1015 template <
typename ADNumberType>
1016 typename TapedDrivers<
1019 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1020 NumberTypes::adolc_taped>>::scalar_type
1021 TapedDrivers<ADNumberType,
1023 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1024 NumberTypes::adolc_taped>>::
1025 value(
const typename Types<ADNumberType>::tape_index,
1026 const std::vector<scalar_type> &)
const
1033 template <
typename ADNumberType>
1035 TapedDrivers<ADNumberType,
1037 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1038 NumberTypes::adolc_taped>>::
1039 gradient(
const typename Types<ADNumberType>::tape_index,
1040 const std::vector<scalar_type> &,
1047 template <
typename ADNumberType>
1049 TapedDrivers<ADNumberType,
1051 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1052 NumberTypes::adolc_taped>>::
1053 hessian(
const typename Types<ADNumberType>::tape_index,
1054 const std::vector<scalar_type> &,
1061 template <
typename ADNumberType>
1063 TapedDrivers<ADNumberType,
1065 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1066 NumberTypes::adolc_taped>>::
1067 values(
const typename Types<ADNumberType>::tape_index,
1069 const std::vector<scalar_type> &,
1076 template <
typename ADNumberType>
1078 TapedDrivers<ADNumberType,
1080 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1081 NumberTypes::adolc_taped>>::
1082 jacobian(
const typename Types<ADNumberType>::tape_index,
1084 const std::vector<scalar_type> &,
1096 template <
typename ADNumberType>
1098 TapedDrivers<ADNumberType,
1100 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1101 NumberTypes::adolc_taped>>::is_recording()
1106 return taped_driver.is_recording();
1110 template <
typename ADNumberType>
1111 typename Types<ADNumberType>::tape_index
1115 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1116 NumberTypes::adolc_taped>>::active_tape_index()
const
1120 return taped_driver.active_tape_index();
1124 template <
typename ADNumberType>
1126 TapedDrivers<ADNumberType,
1128 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1129 NumberTypes::adolc_taped>>::
1130 keep_independent_values()
const
1132 return taped_driver.keep_independent_values();
1136 template <
typename ADNumberType>
1138 TapedDrivers<ADNumberType,
1140 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1141 NumberTypes::adolc_taped>>::
1143 const typename Types<ADNumberType>::tape_index tape_index)
const
1147 return taped_driver.is_registered_tape(tape_index);
1151 template <
typename ADNumberType>
1153 TapedDrivers<ADNumberType,
1155 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1156 NumberTypes::adolc_taped>>::
1157 set_tape_buffer_sizes(
1158 const typename Types<ADNumberType>::tape_buffer_sizes obufsize,
1159 const typename Types<ADNumberType>::tape_buffer_sizes lbufsize,
1160 const typename Types<ADNumberType>::tape_buffer_sizes vbufsize,
1161 const typename Types<ADNumberType>::tape_buffer_sizes tbufsize)
1165 taped_driver.set_tape_buffer_sizes(obufsize,
1172 template <
typename ADNumberType>
1174 TapedDrivers<ADNumberType,
1176 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1177 NumberTypes::adolc_taped>>::
1178 start_taping(
const typename Types<ADNumberType>::tape_index tape_index,
1179 const bool keep_independent_values)
1183 taped_driver.start_taping(tape_index, keep_independent_values);
1187 template <
typename ADNumberType>
1189 TapedDrivers<ADNumberType,
1191 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1192 NumberTypes::adolc_taped>>::
1194 const typename Types<ADNumberType>::tape_index active_tape_index,
1195 const bool write_tapes_to_file)
1199 taped_driver.stop_taping(active_tape_index, write_tapes_to_file);
1203 template <
typename ADNumberType>
1204 std::vector<typename Types<ADNumberType>::tape_index>
1205 TapedDrivers<ADNumberType,
1207 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1208 NumberTypes::adolc_taped>>::
1209 get_registered_tape_indices()
const
1211 return taped_driver.get_registered_tape_indices();
1215 template <
typename ADNumberType>
1217 TapedDrivers<ADNumberType,
1219 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1220 NumberTypes::adolc_taped>>::
1221 activate_tape(
const typename Types<ADNumberType>::tape_index tape_index)
1223 taped_driver.activate_tape(tape_index);
1227 template <
typename ADNumberType>
1229 TapedDrivers<ADNumberType,
1231 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1232 NumberTypes::adolc_taped>>::
1234 const typename Types<ADNumberType>::tape_index tape_index)
const
1236 return taped_driver.requires_retaping(tape_index);
1240 template <
typename ADNumberType>
1242 TapedDrivers<ADNumberType,
1244 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1245 NumberTypes::adolc_taped>>::
1246 last_action_requires_retaping()
const
1248 return taped_driver.last_action_requires_retaping();
1252 template <
typename ADNumberType>
1254 TapedDrivers<ADNumberType,
1256 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1257 NumberTypes::adolc_taped>>::
1258 remove_tape(
const typename Types<ADNumberType>::tape_index tape_index)
1260 taped_driver.remove_tape(tape_index);
1264 template <
typename ADNumberType>
1266 TapedDrivers<ADNumberType,
1268 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1269 NumberTypes::adolc_taped>>::
1270 reset(
const bool clear_registered_tapes)
1272 taped_driver.reset(clear_registered_tapes);
1276 template <
typename ADNumberType>
1278 TapedDrivers<ADNumberType,
1280 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1281 NumberTypes::adolc_taped>>::print(std::ostream
1285 taped_driver.print(stream);
1289 template <
typename ADNumberType>
1291 TapedDrivers<ADNumberType,
1293 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1294 NumberTypes::adolc_taped>>::
1296 const typename Types<ADNumberType>::tape_index tape_index,
1297 std::ostream &stream)
const
1301 taped_driver.print_tape_stats(tape_index, stream);
1305 template <
typename ADNumberType>
1306 typename TapedDrivers<
1309 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1310 NumberTypes::adolc_taped>>::scalar_type
1311 TapedDrivers<ADNumberType,
1313 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1314 NumberTypes::adolc_taped>>::
1315 value(
const typename Types<ADNumberType>::tape_index active_tape_index,
1316 const std::vector<scalar_type> &independent_variables)
const
1320 return taped_driver.value(active_tape_index,
1321 vector_float_to_double(independent_variables));
1325 template <
typename ADNumberType>
1327 TapedDrivers<ADNumberType,
1329 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1330 NumberTypes::adolc_taped>>::
1331 gradient(
const typename Types<ADNumberType>::tape_index active_tape_index,
1332 const std::vector<scalar_type> &independent_variables,
1338 taped_driver.gradient(active_tape_index,
1339 vector_float_to_double(independent_variables),
1345 template <
typename ADNumberType>
1347 TapedDrivers<ADNumberType,
1349 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1350 NumberTypes::adolc_taped>>::
1351 hessian(
const typename Types<ADNumberType>::tape_index active_tape_index,
1352 const std::vector<scalar_type> &independent_variables,
1358 taped_driver.hessian(active_tape_index,
1359 vector_float_to_double(independent_variables),
1365 template <
typename ADNumberType>
1367 TapedDrivers<ADNumberType,
1369 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1370 NumberTypes::adolc_taped>>::
1371 values(
const typename Types<ADNumberType>::tape_index active_tape_index,
1372 const unsigned int n_dependent_variables,
1373 const std::vector<scalar_type> &independent_variables,
1379 taped_driver.values(active_tape_index,
1380 n_dependent_variables,
1381 vector_float_to_double(independent_variables),
1387 template <
typename ADNumberType>
1389 TapedDrivers<ADNumberType,
1391 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1392 NumberTypes::adolc_taped>>::
1393 jacobian(
const typename Types<ADNumberType>::tape_index active_tape_index,
1394 const unsigned int n_dependent_variables,
1395 const std::vector<scalar_type> &independent_variables,
1401 taped_driver.jacobian(active_tape_index,
1402 n_dependent_variables,
1403 vector_float_to_double(independent_variables),
1405 jacobian = jacobian_double;
1410 template <
typename ADNumberType>
1412 TapedDrivers<ADNumberType,
1414 std::enable_if_t<ADNumberTraits<ADNumberType>::type_code ==
1415 NumberTypes::adolc_taped>>::
1416 vector_float_to_double(
const std::vector<float> &in)
const
1418 std::vector<double> out(in.size());
1419 std::copy(in.begin(), in.end(), out.begin());
1428 template <
typename ADNumberType,
typename ScalarType,
typename T>
1433 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1436 template <
typename ADNumberType,
typename ScalarType,
typename T>
1441 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1444 template <
typename ADNumberType,
typename ScalarType,
typename T>
1449 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1452 template <
typename ADNumberType,
typename ScalarType,
typename T>
1457 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1462 template <
typename ADNumberType,
typename ScalarType,
typename T>
1465 const std::vector<ADNumberType> &)
const
1467 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1468 return ScalarType(0.0);
1472 template <
typename ADNumberType,
typename ScalarType,
typename T>
1475 const std::vector<ADNumberType> &,
1476 const std::vector<ADNumberType> &,
1479 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1483 template <
typename ADNumberType,
typename ScalarType,
typename T>
1486 const std::vector<ADNumberType> &,
1487 const std::vector<ADNumberType> &,
1490 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1494 template <
typename ADNumberType,
typename ScalarType,
typename T>
1497 const std::vector<ADNumberType> &,
1500 AssertThrow(
false, ExcRequiresADNumberSpecialization());
1504 template <
typename ADNumberType,
typename ScalarType,
typename T>
1507 const std::vector<ADNumberType> &,
1508 const std::vector<ADNumberType> &,
1511 AssertThrow(
false, ExcRequiresADNumberSpecialization());