10#if !defined(MiniTensor_Scalar_h)
11#define MiniTensor_Scalar_h
15#include "MiniTensor_config.h"
46max(T
const & a, T
const & b);
54min(T
const & a,T
const & b);
80typename Sacado::ScalarType<T>::type
91typename Sacado::ScalarType<T>::type
123typename Sacado::ScalarType<T>::type
129template <
typename T>
typename Sacado::ScalarType<T>::type
random();
134template <
typename T>
typename Sacado::ScalarType<T>::type
random_uniform();
139template <
typename T>
typename Sacado::ScalarType<T>::type
random_normal();
146using Sacado::ScalarType;
152 typename enable_if<is_same<T,
typename ScalarType<T>::type>::value, T>::type & x,
153 typename ScalarType<T>::type
const c);
159 typename enable_if<!is_same<T,
typename ScalarType<T>::type>::value, T>::type & x,
160 typename ScalarType<T>::type
const c);
246 return a < T(0) ? -a : a;
261 if (&a == &b)
return;
277max(T
const & a, T
const & b)
279 return a > b ? a : b;
291min(T
const & a, T
const & b)
293 return a < b ? a : b;
304 return (T(0) < s) - (s < T(0));
315 return b >= 0 ? T(std::abs(a)) : T(-std::abs(a));
326typename Sacado::ScalarType<T>::type
329 using S =
typename Sacado::ScalarType<T>::type;
330 return std::numeric_limits<S>::quiet_NaN();
341typename Sacado::ScalarType<T>::type
344 using S =
typename Sacado::ScalarType<T>::type;
345 return std::numeric_limits<S>::epsilon();
380typename Sacado::ScalarType<T>::type
383 using S =
typename Sacado::ScalarType<T>::type;
384 return static_cast<S
>(
385 6.283185307179586476925286766559005768394338798750211641949889185
392template <
typename T>
typename Sacado::ScalarType<T>::type
random() {
393 using S =
typename Sacado::ScalarType<T>::type;
394 S
const rnd =
static_cast<S
>(std::rand()) /
static_cast<S
>(RAND_MAX);
395 return S(-1.0) + S(2.0) * rnd;
402 using S =
typename Sacado::ScalarType<T>::type;
403 return static_cast<S
>(0.5 * random<S>() + 0.5);
410 using S =
typename Sacado::ScalarType<T>::type;
413 R = random_uniform<S>();
416 Theta = tau<S>() * random_uniform<S>();
417 return static_cast<S
>(std::sqrt(-2.0 * std::log(R)) * cos(Theta));
430 typename enable_if<is_same<T,
typename ScalarType<T>::type>::value, T>::type & x,
431 typename ScalarType<T>::type
const c)
444 typename enable_if<!is_same<T,
typename ScalarType<T>::type>::value, T>::type & x,
445 typename ScalarType<T>::type
const c)
451 if (order == 0)
return;
453 using S =
typename Sacado::ValueType<T>::type;
455 for (
auto i = 0; i < order; ++i) {
456 fill_AD<S>(x.fastAccessDx(i), c);
470 if (X == 0 || X == 1)
return X;
497 leftmost_bit = rightmost_bit << (number_digits - 1);
502 for (
Index j = 0; j < number_digits; ++j) {
504 if (((exponent << j) & leftmost_bit) != 0) {
506 t = number_digits - j - 1;
522 while ((m & rightmost_bit) == 0) {
531 for (
Index j = i + 1; j <= t; ++j) {
534 if (((exponent >> j) & rightmost_bit) != 0) {
553 if (root == 1 || x == 0 || x == 1)
return x;
561 while (hi - lo > 1) {
562 T mid = (lo + hi) / 2;
565 else if (x < t) hi = mid;
582 assert(0 <= i && i < 2);
583 assert(0 <= j && j < 2);
585 if (i == j)
return T(1);
598 assert(0 <= i && i < 3);
599 assert(0 <= j && j < 3);
600 assert(0 <= k && k < 3);
602 if (i == j && j == k)
return T(1);
615 assert(0 <= i && i < 4);
616 assert(0 <= j && j < 4);
617 assert(0 <= k && k < 4);
618 assert(0 <= l && l < 4);
620 if (i == j && j == k && k == l)
return T(1);
633 assert(0 <= i && i < 2);
634 assert(0 <= j && j < 2);
636 if (i == 0 && j == 1)
return T(1);
638 if (i == 1 && j == 0)
return T(-1);
651 assert(0 <= i && i < 3);
652 assert(0 <= j && j < 3);
653 assert(0 <= k && k < 3);
655 if (i == 0 && j == 1 && k == 2)
return T(1);
656 if (i == 1 && j == 2 && k == 0)
return T(1);
657 if (i == 2 && j == 0 && k == 1)
return T(1);
659 if (i == 2 && j == 1 && k == 0)
return T(-1);
660 if (i == 0 && j == 2 && k == 1)
return T(-1);
661 if (i == 1 && j == 0 && k == 2)
return T(-1);
674 assert(0 <= i && i < 4);
675 assert(0 <= j && j < 4);
676 assert(0 <= k && k < 4);
677 assert(0 <= l && l < 4);
679 if (i == 0 && j == 1 && k == 2 && l == 3)
return T(1);
680 if (i == 1 && j == 2 && k == 3 && l == 0)
return T(1);
681 if (i == 2 && j == 3 && k == 0 && l == 1)
return T(1);
682 if (i == 3 && j == 0 && k == 1 && l == 2)
return T(1);
684 if (i == 3 && j == 2 && k == 1 && l == 0)
return T(-1);
685 if (i == 0 && j == 3 && k == 2 && l == 1)
return T(-1);
686 if (i == 1 && j == 0 && k == 3 && l == 2)
return T(-1);
687 if (i == 2 && j == 1 && k == 0 && l == 3)
return T(-1);
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION Index num_digits< Index >()
uint32_t Index
Indexing type.
KOKKOS_INLINE_FUNCTION Sacado::ScalarType< T >::type machine_epsilon()
KOKKOS_INLINE_FUNCTION Index num_digits< LongIndex >()
KOKKOS_INLINE_FUNCTION Sacado::ScalarType< T >::type not_a_number()
KOKKOS_INLINE_FUNCTION T kronecker_delta(Index const i, Index const j)
constexpr Index INDEX_SIZE
constexpr Index LONG_INDEX_SIZE
Sacado::ScalarType< T >::type random()
KOKKOS_INLINE_FUNCTION Sacado::ScalarType< T >::type tau()
KOKKOS_INLINE_FUNCTION int sgn(T const &s)
KOKKOS_INLINE_FUNCTION T abs(T const &a)
KOKKOS_INLINE_FUNCTION void swap(T &a, T &b)
KOKKOS_INLINE_FUNCTION void fill_AD(typename enable_if< is_same< T, typename ScalarType< T >::type >::value, T >::type &x, typename ScalarType< T >::type const c)
Sacado::ScalarType< T >::type random_uniform()
KOKKOS_INLINE_FUNCTION Index num_digits()
Sacado::ScalarType< T >::type random_normal()
KOKKOS_INLINE_FUNCTION T min(T const &a, T const &b)
KOKKOS_INLINE_FUNCTION T integer_power(T const &X, Index const exponent)
KOKKOS_INLINE_FUNCTION T integer_root(T const &x, Index const root)
KOKKOS_INLINE_FUNCTION T max(T const &a, T const &b)
KOKKOS_INLINE_FUNCTION T copysign(T const &a, T const &b)
KOKKOS_INLINE_FUNCTION T levi_civita(Index const i, Index const j)