10#if !defined(MiniTensor_Norms_h)
11#define MiniTensor_Norms_h
25template<
typename T, Index N>
28norm(Tensor<T, N>
const & A);
34template<
typename T, Index N>
37norm_1(Tensor<T, N>
const & A);
43template<
typename T, Index N>
55template<
typename T, Index N>
64template<
typename T, Index N>
67det(Tensor<T, N>
const & A);
73template<
typename T, Index N>
76trace(Tensor<T, N>
const & A);
82template<
typename T, Index N>
85I1(Tensor<T, N>
const & A);
91template<
typename T, Index N>
94I2(Tensor<T, N>
const & A);
100template<
typename T, Index N>
103I3(Tensor<T, N>
const & A);
110template<
typename T, Index N>
120template <
typename T, Index N>
121std::pair<Index, Index>
arg_max_abs(Tensor<T, N>
const &A);
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) {
319 if constexpr (dimension_reachable<N, 2>) {
320 if (dimension == 2) {
321 s = A(0,0) * A(1,1) - A(1,0) * A(0,1);
326 if constexpr (dimension_reachable<N, 3>) {
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);
335 if constexpr (dimension_reachable<N, 4>) {
337 for (
Index i = 0; i < dimension; ++i) {
339 s += sign * d * A(i, 1);
352template<
typename T, Index N>
365 for (
Index i = 0; i < dimension; ++i) {
371 s = A(0,0) + A(1,1) + A(2,2);
392template<
typename T, Index N>
405template<
typename T, Index N>
422#ifdef KOKKOS_ENABLE_CUDA
423 Kokkos::abort(
"I2 for N > 3 not implemented.");
426 std::cerr <<
"I2 for N > 3 not implemented." << std::endl;
432 s = 0.5 * (trA*trA - A(0,0)*A(0,0) - A(1,1)*A(1,1) - A(2,2)*A(2,2)) -
433 A(0,1)*A(1,0) - A(0,2)*A(2,0) - A(1,2)*A(2,1);
454template<
typename T, Index N>
468#ifdef KOKKOS_ENABLE_CUDA
469 Kokkos::abort(
"I3 for N > 3 not implemented.");
472 std::cerr <<
"I3 for N > 3 not implemented." << std::endl;
501template<
typename T, Index N>
509 assert(i < dimension);
510 assert(j < dimension);
516 for (
Index m = 0; m < dimension; ++m) {
517 if (m == i)
continue;
519 for (
Index n = 0; n < dimension; ++n) {
520 if (n == j)
continue;
536template<
typename T, Index N>
550 for (
Index i = 0; i < dimension; ++i) {
551 for (
Index j = 0; j < dimension; ++j) {
552 if (i != j) s += A(i,j)*A(i,j);
558 s = A(0,1)*A(0,1) + A(0,2)*A(0,2) + A(1,2)*A(1,2) +
559 A(1,0)*A(1,0) + A(2,0)*A(2,0) + A(2,1)*A(2,1);
563 s = A(0,1)*A(0,1) + A(1,0)*A(1,0);
580template <
typename T, Index N>
587 s = std::abs(A(p,q));
592 for (
Index i = 0; i < dimension; ++i) {
593 for (
Index j = 0; j < dimension; ++j) {
594 if (std::abs(A(i,j)) > s) {
597 s = std::abs(A(i,j));
602 return std::make_pair(p,q);
611template <
typename T, Index N>
616 T s = std::abs(A(p,q));
621 for (
Index i = 0; i < dimension; ++i) {
622 for (
Index j = 0; j < dimension; ++j) {
623 if (i != j && std::abs(A(i,j)) > s) {
626 s = std::abs(A(i,j));
631 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)
uint32_t Index
Indexing type.
KOKKOS_INLINE_FUNCTION T abs(T const &a)
KOKKOS_INLINE_FUNCTION T max(T const &a, T const &b)