/usr/include/dune/functions/common/differentiablefunctionfromcallables.hh is in libdune-functions-dev 2.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
#define DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
#include <dune/common/typeutilities.hh>
#include <dune/common/hybridutilities.hh>
#include <dune/functions/common/signature.hh>
#include <dune/functions/common/differentiablefunction.hh>
#include <dune/functions/common/functionconcepts.hh>
namespace Dune {
namespace Functions {
template<class Signature, template<class> class DerivativeTraits, class... Callables>
class DifferentiableFunctionFromCallables;
/**
* \brief Wrap a list of callable objects as derivative sequence modelling \ref Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>
*
* \ingroup FunctionImplementations
*
* \tparam Range Range type of function
* \tparam Domain Domain type of function
*
* You can use this to implement a differentiable function including
* a variable number of derivatives using callable objects.
*
* This models the \ref Concept::DifferentiableFunction<Range(Domain), DerivativeTraits> concept.
*
* Note that using makeDifferentiableFunction will be less verbose than
* creating this wrapper manually.
*/
template<class Range, class Domain, template<class> class DerivativeTraits, class F>
class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F>
{
public:
//! Signature of function
using Signature = Range(Domain);
using RawSignature = typename SignatureTraits<Signature>::RawSignature;
//! Signature of derivative
using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
//! Type of derivative
using Derivative = DifferentiableFunction<DerivativeSignature, DerivativeTraits>;
//! Constructor copying the given function
template<class FF, disableCopyMove<DifferentiableFunctionFromCallables, FF> = 0>
DifferentiableFunctionFromCallables(FF&& f) :
f_(std::forward<FF>(f))
{}
//! Evaluate function
Range operator() (const Domain& x) const
{
return f_(x);
}
/**
* \brief Get derivative of DifferentiableFunctionFromCallables
*
* \ingroup FunctionImplementations
*/
friend Derivative derivative(const DifferentiableFunctionFromCallables& t)
{
DUNE_THROW(Dune::NotImplemented, "Derivative not implemented");
}
private:
F f_;
};
/**
* \brief Wrap a list of callable objects as derivative sequence modelling \ref Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>
*
* \ingroup FunctionImplementations
*
* \tparam Range Range type of function
* \tparam Domain Domain type of function
*
* You can use this to implement a differentiable function including
* a variable number of derivatives using callable objects.
*
* This models the \ref Concept::DifferentiableFunction<Range(Domain), DerivativeTraits> concept.
*
* Note that using makeDifferentiableFunction will be less verbose than
* creating this wrapper manually.
*/
template<class Range, class Domain, template<class> class DerivativeTraits, class F, class DF, class... Derivatives>
class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F, DF, Derivatives...>
{
public:
using Signature = Range(Domain);
using RawSignature = typename SignatureTraits<Signature>::RawSignature;
using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
using Derivative = DifferentiableFunctionFromCallables<DerivativeSignature, DerivativeTraits, DF, Derivatives...>;
/**
* \brief Constructor copying the given functions
*
* The arguments are used as implementation of the functions itself
* and its derivatives with increasing order
*/
template<class FF, class DFF, class... DDFF>
DifferentiableFunctionFromCallables(FF&& f, DFF&& df, DDFF&&... ddf) :
f_(std::forward<FF>(f)),
df_(std::forward<DFF>(df), std::forward<DDFF>(ddf)...)
{}
//! Evaluate function
Range operator() (const Domain& x) const
{
return f_(x);
}
/**
* \brief Get derivative of DifferentiableFunctionFromCallables
*
* \ingroup FunctionImplementations
*/
friend Derivative derivative(const DifferentiableFunctionFromCallables& t)
{
return t.df_;
}
private:
F f_;
Derivative df_;
};
/**
* \brief Create a DifferentiableFunction from callables
*
* \ingroup FunctionImplementations
*
* This will return a wrapper modelling the DifferentiableFunction interface
* where the evaluation of the function and its derivatives are implemented
* by the given callable objects.
*
* \param signatureTag A dummy parameter to pass the signature and derivative traits
* \param f Callable objects implementing the evaluation of the function and its derivatives
*
* \returns Object modelling DifferentiableFunction interface
*/
template<class Signature, template<class> class DerivativeTraits, class... F>
DifferentiableFunctionFromCallables<Signature, DerivativeTraits, F...>
makeDifferentiableFunctionFromCallables(const SignatureTag<Signature, DerivativeTraits>& signatureTag, F&&... f)
{
return DifferentiableFunctionFromCallables<Signature, DerivativeTraits, F...>(f...);
}
} // namespace Functions
} // namespace Dune
#endif //DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
|