10#if !defined(MiniTensor_Norms_h)
11#define MiniTensor_Norms_h
25template<
typename T, Index N>
34template<
typename T, Index N>
43template<
typename T, Index N>
55template<
typename T, Index N>
64template<
typename T, Index N>
73template<
typename T, Index N>
82template<
typename T, Index N>
91template<
typename T, Index N>
100template<
typename T, Index N>
110template<
typename T, Index N>
120template <
typename T, Index N>
128template <
typename T, Index N>
135template<
typename T, Index N>
153 s+= A(0,0)*A(0,0) + A(0,1)*A(0,1) + A(0,2)*A(0,2);
154 s+= A(1,0)*A(1,0) + A(1,1)*A(1,1) + A(1,2)*A(1,2);
155 s+= A(2,0)*A(2,0) + A(2,1)*A(2,1) + A(2,2)*A(2,2);
159 s+= A(0,0)*A(0,0) + A(0,1)*A(0,1);
160 s+= A(1,0)*A(1,0) + A(1,1)*A(1,1);
169 if (s > 0.0)
return std::sqrt(s);
178template<
typename T, Index N>
196 for (
Index i = 0; i < dimension; ++i) {
198 for (
Index j = 0; j < dimension; ++j) {
204 for (
Index i = 0; i < dimension; ++i) {
214 s =
max(
max(v(0), v(1)), v(2));
236template<
typename T, Index N>
252 for (
Index i = 0; i < dimension; ++i) {
254 for (
Index j = 0; j < dimension; ++j) {
260 for (
Index i = 0; i < dimension; ++i) {
270 s =
max(
max(v(0), v(1)), v(2));
297template<
typename T, Index N>
314 if (dimension == 1) {
320 if (dimension == 2) {
321 s = A(0,0) * A(1,1) - A(1,0) * A(0,1);
327 if (dimension == 3) {
328 s = -A(0,2)*A(1,1)*A(2,0) + A(0,1)*A(1,2)*A(2,0) +
329 A(0,2)*A(1,0)*A(2,1) - A(0,0)*A(1,2)*A(2,1) -
330 A(0,1)*A(1,0)*A(2,2) + A(0,0)*A(1,1)*A(2,2);
339 for (
Index i = 0; i < dimension; ++i) {
341 s += sign * d * A(i, 0);
354template<
typename T, Index N>
367 for (
Index i = 0; i < dimension; ++i) {
373 s = A(0,0) + A(1,1) + A(2,2);
394template<
typename T, Index N>
407template<
typename T, Index N>
424#ifdef KOKKOS_ENABLE_CUDA
425 Kokkos::abort(
"I2 for N > 3 not implemented.");
428 std::cerr <<
"I2 for N > 3 not implemented." << std::endl;
434 s = 0.5 * (trA*trA - A(0,0)*A(0,0) - A(1,1)*A(1,1) - A(2,2)*A(2,2)) -
435 A(0,1)*A(1,0) - A(0,2)*A(2,0) - A(1,2)*A(2,1);
456template<
typename T, Index N>
470#ifdef KOKKOS_ENABLE_CUDA
471 Kokkos::abort(
"I3 for N > 3 not implemented.");
474 std::cerr <<
"I3 for N > 3 not implemented." << std::endl;
503template<
typename T, Index N>
511 assert(i < dimension);
512 assert(j < dimension);
518 for (
Index m = 0; m < dimension; ++m) {
519 if (m == i)
continue;
521 for (
Index n = 0; n < dimension; ++n) {
522 if (n == j)
continue;
538template<
typename T, Index N>
552 for (
Index i = 0; i < dimension; ++i) {
553 for (
Index j = 0; j < dimension; ++j) {
554 if (i != j) s += A(i,j)*A(i,j);
560 s = A(0,1)*A(0,1) + A(0,2)*A(0,2) + A(1,2)*A(1,2) +
561 A(1,0)*A(1,0) + A(2,0)*A(2,0) + A(2,1)*A(2,1);
565 s = A(0,1)*A(0,1) + A(1,0)*A(1,0);
582template <
typename T, Index N>
589 s = std::abs(A(p,q));
594 for (
Index i = 0; i < dimension; ++i) {
595 for (
Index j = 0; j < dimension; ++j) {
596 if (std::abs(A(i,j)) > s) {
599 s = std::abs(A(i,j));
604 return std::make_pair(p,q);
613template <
typename T, Index N>
618 T s = std::abs(A(p,q));
623 for (
Index i = 0; i < dimension; ++i) {
624 for (
Index j = 0; j < dimension; ++j) {
625 if (i != j && std::abs(A(i,j)) > s) {
628 s = std::abs(A(i,j));
633 return std::make_pair(p,q);
#define KOKKOS_INLINE_FUNCTION
KOKKOS_INLINE_FUNCTION Index get_dimension() const
KOKKOS_INLINE_FUNCTION T norm_f_square(TensorBase< T, ST > const &X)
KOKKOS_INLINE_FUNCTION T I1(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION Tensor< T, N > subtensor(Tensor< T, N > const &A, Index const i, Index const j)
KOKKOS_INLINE_FUNCTION T norm(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T det(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T norm_off_diagonal(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T norm_1(Tensor< T, N > const &A)
std::pair< Index, Index > arg_max_abs(Tensor< T, N > const &A)
std::pair< Index, Index > arg_max_off_diagonal(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T I3(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T norm_infinity(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T I2(Tensor< T, N > const &A)
KOKKOS_INLINE_FUNCTION T trace(Tensor< T, N > const &A)
constexpr bool dimension_reachable
KOKKOS_INLINE_FUNCTION T abs(T const &a)
KOKKOS_INLINE_FUNCTION T max(T const &a, T const &b)
uint32_t Index
Indexing type.