Tatooine
condition_number.h
Go to the documentation of this file.
1#ifndef TATOOINE_TENSOR_OPERATIONS_CONDITION_NUMBER_H
2#define TATOOINE_TENSOR_OPERATIONS_CONDITION_NUMBER_H
3//==============================================================================
4namespace tatooine {
5//==============================================================================
7template <typename T, size_t N, integral P = int>
8auto condition_number(tensor<T, N, N> const& A, P const p = 2) {
9 if (p == 1) {
10 return 1 / lapack::gecon(tensor{A});
11 } else if (p == 2) {
12 auto const s = singular_values(A);
13 return s(0) / s(N - 1);
14 } else {
15 throw std::runtime_error{"p = " + std::to_string(p) +
16 " is no valid base. p must be either 1 or 2."};
17 }
18}
19//------------------------------------------------------------------------------
20template <typename Tensor, typename T, size_t N, typename PReal>
22 return condition_number(tensor{A}, p);
23}
24//==============================================================================
25} // namespace tatooine
26//==============================================================================
27#endif
Definition: algorithm.h:6
constexpr auto singular_values(tensor< T, M, N > &&A)
Definition: singular_values.h:82
auto condition_number(tensor< T, N, N > const &A, P const p=2)
compute condition number
Definition: condition_number.h:8
Definition: base_tensor.h:23
Definition: tensor.h:17