3 #include <funcy/concepts.h> 4 #include <funcy/util/chainer.h> 5 #include <funcy/util/derivative_wrappers.h> 6 #include <funcy/util/evaluate_if_present.h> 7 #include <funcy/util/mathop_traits.h> 8 #include <funcy/util/type_traits.h> 10 #include <type_traits> 19 template <
class Scalar, Function F >
20 struct Scale : Chainer< Scale< Scalar, F > >
27 constexpr
Scale( Scalar a_, F&& f_ )
28 : a( a_ ), f( std::move( f_ ) ), value( multiply_via_traits( a, f() ) )
37 constexpr
Scale( Scalar a_,
const F& f_ )
38 : a( a_ ), f( f_ ), value( multiply_via_traits( a, f() ) )
47 template <
class... InitF >
50 InitF&&... f_ ) requires std::is_constructible_v< F, std::decay_t< InitF >... >
51 : a( a_ ), f( std::forward< InitF >( f_ )... ), value( multiply_via_traits( a, f() ) )
56 template <
class Arg >
59 update_if_present( f, x );
60 value = multiply_via_traits( a, f() );
64 template <
int index,
class Arg >
67 update_if_present< index >( f, x );
68 value = multiply_via_traits( a, f() );
71 template <
class... IndexedArgs >
72 void bulk_update( IndexedArgs&&... args )
74 bulk_update_if_present( f, std::forward< IndexedArgs >( args )... );
75 value = multiply_via_traits( a, f() );
79 constexpr decltype(
auto ) d0()
const noexcept
85 template <
int idx,
class Arg,
class IndexedArg = IndexedType< Arg,
idx > >
86 auto d1(
const Arg& dx )
const requires( D1< F, IndexedArg >::present )
88 return multiply_via_traits( a, D1_< F, IndexedArg >::apply( f, dx ) );
92 template <
int idx,
int idy,
class ArgX,
class ArgY,
95 auto d2(
const ArgX& dx,
const ArgY& dy )
const 96 requires( D2< F, IndexedArgX, IndexedArgY >::present )
98 return multiply_via_traits( a, D2_< F, IndexedArgX, IndexedArgY >::apply( f, dx, dy ) );
102 template <
int idx,
int idy,
int idz,
class ArgX,
class ArgY,
class ArgZ,
106 auto d3(
const ArgX& dx,
const ArgY& dy,
const ArgZ& dz )
const 107 requires( D3< F, IndexedArgX, IndexedArgY, IndexedArgZ >::present )
109 return multiply_via_traits(
110 a, D3_< F, IndexedArgX, IndexedArgY, IndexedArgZ >::apply( f, dx, dy, dz ) );
116 std::decay_t< decltype( std::declval< F >()() ) > value;
constexpr Scale(Scalar a_, InitF &&... f_) requires std
Constructor passing arguments to function constructor.
Definition: scale.h:48
auto d3(const ArgX &dx, const ArgY &dy, const ArgZ &dz) const requires(D3< F
Third directional derivative.
void update(const Arg &x)
Update variable corresponding to index.
Definition: scale.h:65
auto d1(const Arg &dx) const requires(D1< F
First directional derivative.
Mathematical operations and corresponding differentation rules.
void update(const Arg &x)
Update point of evaluation.
Definition: scale.h:57
Definition: type_traits.h:54
constexpr Scale(Scalar a_, const F &f_)
Constructor passing arguments to function constructor.
Definition: scale.h:37
auto d2(const ArgX &dx, const ArgY &dy) const requires(D2< F
Second directional derivative.
Scaling of some function with a double .
Definition: scale.h:20
constexpr Scale(Scalar a_, F &&f_)
Constructor passing arguments to function constructor.
Definition: scale.h:27