10#if !defined(MiniTensor_TestFunctions_h)
11#define MiniTensor_TestFunctions_h
32template<
typename S, Index M = 1>
61 template<
typename T, Index N>
72 template<
typename T, Index N>
84 r(0) = x(0) * x(0) -
c_;
93 template<
typename T, Index N>
116template<
typename S, Index M = 2>
146 template<
typename T, Index N>
157 template<
typename T, Index N>
169 r(0) = 2.0 *
c_ * (x(0) -
a_);
170 r(1) = 2.0 *
c_ * (x(1) -
b_);
179 template<
typename T, Index N>
215template<
typename S, Index M = 2>
245 template<
typename T, Index N>
256 template<
typename T, Index N>
269 xa = (x(0) -
a_) *
c_;
272 xb = (x(1) -
b_) *
c_;
275 e = std::exp(- xa * xa - xb * xb);
277 r(0) = 2.0 * xa * e *
c_ *
c_;
278 r(1) = 2.0 * xb * e *
c_ *
c_;
287 template<
typename T, Index N>
323template<
typename S, Index M = 2>
351 template<
typename T, Index N>
362 template<
typename T, Index N>
374 r(0) = 2.0 * (x(0) - 1.0) + 400.0 * x(0) * (x(0) * x(0) - x(1));
375 r(1) = 200.0 * (x(1) - x(0) * x(0));
384 template<
typename T, Index N>
402template<
typename S, Index M = 2>
428 template<
typename T, Index N>
439 template<
typename T, Index N>
451 r(0) = (13.0 * x(0) - 12.0 * x(1)) / 25.0;
452 r(1) = (13.0 * x(1) - 12.0 * x(0)) / 25.0;
461 template<
typename T, Index N>
479template<
typename S, Index M = 2>
505 template<
typename T, Index N>
516 template<
typename T, Index N>
528 r(0) = std::cos(x(0) + x(1)) + 2.0 * x(0) - 2.0 * x(1) - 1.5;
529 r(1) = std::cos(x(0) + x(1)) - 2.0 * x(0) + 2.0 * x(1) + 2.5;
538 template<
typename T, Index N>
558template<
typename S, Index M = 2>
584 template<
typename T, Index N>
595 template<
typename T, Index N>
607 r(0) = 2.0 * x(0) * x(0) * x(0) - 16.0 * x(0) + 2.5;
608 r(1) = 2.0 * x(1) * x(1) * x(1) - 16.0 * x(1) + 2.5;
617 template<
typename T, Index N>
638template<
typename S, Index M = 2>
668 template<
typename T, Index N>
690 template<
typename T, Index N>
701 template<
typename T, Index N>
731template<
typename S, Index M = 2>
751 NAME{
"Rosenbrock's Function 2D"};
762 template<
typename T, Index N>
770 b = (x(1) - x(0) * x(0));
772 return a * a +
b_ * b * b;
779 template<
typename T, Index N>
790 template<
typename T, Index N>
819template<
typename S, Index M = 2>
845 template<
typename T, Index N>
861 b = 2.25 - x + x * y * y;
864 c = 2.625 - x + x * y * y * y;
867 f = a * a + b * b + c * c;
876 template<
typename T, Index N>
887 template<
typename T, Index N>
904template<
typename S, Index M = 2>
930 template<
typename T, Index N>
958 template<
typename T, Index N>
969 template<
typename T, Index N>
988template<
typename S, Index M = 2>
1014 template<
typename T, Index N>
1030 b = 19 - 14 * x + 3 * x * x - 14 * y + 6 * x * y + 3 * y * y;
1036 d = 18 - 32 * x + 12 * x * x + 48 * y - 36 * x * y + 27 * y * y;
1054 template<
typename T, Index N>
1065 template<
typename T, Index N>
1082template<
typename S, Index M = 1>
1109 template<
typename T, Index N>
1114 this->
set_failed(
"Testing failure mechanism");
1126 template<
typename T, Index N>
1137 template<
typename T, Index N>
1155template<
typename S, Index M = 1>
1181 template<
typename T, Index N>
1191 if (-1.0 <= x && x <= 1.0) {
1202 template<
typename T, Index N>
1213 template<
typename T, Index N>
1231template<
typename S, Index M = 1>
1257 template<
typename T, Index N>
1289 template<
typename T, Index N>
1300 template<
typename T, Index N>
1320template<
typename S, Index NC, Index NV>
1346 template<
typename T, Index N>
1358 template<
typename T, Index N>
1375template<
typename S, Index NC = 3, Index NV = 5>
1401 template<
typename T, Index N = 5>
1410 c(0) =
dot(x, x) - 10.0;
1412 c(1) = x(1) * x(2) - 5.0 * x(3) * x(4);
1414 c(2) = x(0) * x(0) * x(0) + x(1) * x(1) * x(1) + 1.0;
1423 template<
typename T, Index N = 5>
1440template<
typename S, Index NC = 1, Index NV = 2>
1473 template<
typename T, Index N = 2>
1491 template<
typename T, Index N = 2>
1521template<
typename S, Index NC = 1, Index NV = 2>
1532 Circle(S
const r, S
const xc = S(0.0), S
const yc = S(0.0)) :
r_(r)
1554 template<
typename T, Index N = 2>
1572 template<
typename T, Index N = 2>
Tensor< T, N > hessian(Vector< T, N > const &x)
static constexpr char const *const NAME
T value(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x) const
T value(Vector< T, N > const &X)
Vector< T, N > gradient(Vector< T, N > const &x)
Tensor< T, N > hessian(Vector< T, N > const &x)
static constexpr char const *const NAME
Vector< T, N > gradient(Vector< T, N > const &x)
static constexpr char const *const NAME
T value(Vector< T, N > const &X)
Tensor< T, N > hessian(Vector< T, N > const &x)
Matrix< T, NC, NV > gradient(Vector< T, N > const &x)
Circle(S const r, S const xc=S(0.0), S const yc=S(0.0))
static constexpr char const *const NAME
Vector< T, NC > value(Vector< T, N > const &x)
Matrix< T, NC, NV > gradient(Vector< T, N > const &x)
Circumference(S const r, S const xc=S(0.0), S const yc=S(0.0))
Vector< T, NC > value(Vector< T, N > const &x)
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x)
T value(Vector< T, N > const &X)
static constexpr char const *const NAME
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
Gaussian(S const a, S const b, S const c)
T value(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x) const
T value(Vector< T, N > const &X)
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x)
static constexpr char const *const NAME
static constexpr char const *const NAME
Vector< T, NC > value(Vector< T, N > const &x)
Matrix< T, NC, NV > gradient(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x) const
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
T value(Vector< T, N > const &x)
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
T value(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x) const
T value(Vector< T, N > const &X)
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x)
Vector< T, NC > value(Vector< T, N > const &x)
Matrix< T, NC, NV > gradient(Vector< T, N > const &x)
static constexpr char const *const NAME
T value(Vector< T, N > const &x)
Paraboloid(S xc=0.0, S yc=0.0)
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x)
Quadratic(S const a, S const b, S const c)
T value(Vector< T, N > const &x)
static constexpr char const *const NAME
Vector< T, N > gradient(Vector< T, N > const &x) const
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x)
T value(Vector< T, N > const &x)
Tensor< T, N > hessian(Vector< T, N > const &x)
Rosenbrock(S a=1.0, S b=100.0)
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x)
T value(Vector< T, N > const &X)
static constexpr char const *const NAME
static constexpr char const *const NAME
Tensor< T, N > hessian(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x) const
T value(Vector< T, N > const &x)
T value(Vector< T, N > const &x)
Vector< T, N > gradient(Vector< T, N > const &x) const
Tensor< T, N > hessian(Vector< T, N > const &x)
static constexpr char const *const NAME
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION Vector< typename Promote< S, T >::type, M > dot(Matrix< T, M, N > const &A, Vector< S, N > const &u)
KOKKOS_INLINE_FUNCTION T norm_square(Vector< T, N > const &u)
Vector< T, N > gradient(FunctionDerived &f, Vector< T, N > const &x)
Tensor< T, N > hessian(FunctionDerived &f, Vector< T, N > const &x)
T value(FunctionDerived &f, Vector< T, N > const &x)
void set_failed(char const *const msg=nullptr)
Matrix< T, NC, NV > gradient(Identity< S, NC, NV > &c, Vector< T, N > const &x)
static constexpr Index DIMENSION
uint32_t Index
Indexing type.