VCCC  2024.05
VisualCamp Common C++ library
gradient.hpp
Go to the documentation of this file.
1 # /*
2 # * Created by YongGyu Lee on 2020/12/08.
3 # */
4 #
5 # ifndef VCCC_MATH_GRADIENT_HPP
6 # define VCCC_MATH_GRADIENT_HPP
7 #
9 # include "vccc/type_traits.hpp"
10 
11 namespace vccc {
12 
22 namespace internal {
23 namespace math {
24 template<typename T, typename DifferentialCategory, typename Func, typename VarTuple, std::size_t ...I, typename ...Args>
25 inline auto gradientImpl(Func f, VarTuple vars, std::index_sequence<I...>, Args&&... args) {
26  return std::make_tuple(
27  partialDiff<T, I>(DifferentialCategory{}, f, vars, std::forward<Args>(args)...)...);
28 }
29 } // namespace math
30 } // namespace internal
31 
32 
42 template<typename T, typename DifferentialCategory = differential_symmetric_t,
43  typename Func, typename ...Vars, typename ...Args>
44 inline auto gradient(Func f, std::tuple<Vars...> vars, Args&&... args) {
45  static_assert(negation<disjunction<std::is_reference<Vars>...>>::value,
46  "tuple element of vars must not be a reference vccc::gradient<>");
47  static_assert(conjunction<std::is_same<T, Vars>...>::value,
48  "tuple element of vars type must be same with T vccc::gradient<>");
49  return internal::math::gradientImpl<T, DifferentialCategory>(
50  f,
51  vars,
52  std::index_sequence_for<Vars...>{},
53  std::forward<Args>(args)...);
54 }
55 
58 
59 } // namespace vccc
60 
61 # endif // VCCC_MATH_GRADIENT_HPP
auto gradient(Func f, std::tuple< Vars... > vars, Args &&... args)
Definition: gradient.hpp:44
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: conjunction.hpp:22
Definition: disjunction.hpp:22
Definition: negation.hpp:23