ad.h Source File

CPP API: ad.h Source File
ad.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Julian Litz
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 
21 #ifndef MIO_AD_H
22 #define MIO_AD_H
23 
24 #include "ad/ad.hpp"
25 #include "memilio/math/eigen.h"
26 
27 #include <cmath>
28 #include <limits>
29 
30 namespace ad
31 {
32 namespace internal
33 {
34 
40 template <class FP, class DataHandler>
41 const FP& format_as(const active_type<FP, DataHandler>& ad_type)
42 {
43  // Note: the format_as function needs to be in the same namespace as the value it takes
44  return value(ad_type);
45 }
46 
47 } // namespace internal
48 } // namespace ad
49 
50 // Allow std::numeric_limits to work with AD types.
51 template <class FP, class DataHandler>
52 struct std::numeric_limits<ad::internal::active_type<FP, DataHandler>> : public numeric_limits<FP> {
53 };
54 
55 // Ensures that Eigen recognizes our AD types as valid scalars.
56 namespace Eigen
57 {
58 template <class FP, class DataHandler>
59 struct NumTraits<ad::internal::active_type<FP, DataHandler>>
60  : GenericNumTraits<ad::internal::active_type<FP, DataHandler>> {
62  using Real = Scalar;
63  using NonInteger = Scalar;
64  using Nested = Scalar;
65  enum
66  {
67  IsComplex = 0,
68  IsInteger = 0,
69  IsSigned = 1,
70  RequireInitialization = 1,
71  ReadCost = 1,
72  AddCost = 3,
73  MulCost = 3
74  };
75 };
76 } // namespace Eigen
77 
78 #endif // MIO_AD_H
Definition: ad.h:57
const FP & format_as(const active_type< FP, DataHandler > &ad_type)
Format AD types (like ad::gt1s<double>::type) using their value for logging with spdlog.
Definition: ad.h:41
Definition: ad.h:31
trait_value< T >::RETURN_TYPE & value(T &x)
Definition: ad.hpp:3308
Definition: ad.hpp:692