58 double norm(A
const &a,
double p = 2.0) {
59 static_assert(Scalar<get_value_t<A>>,
"Error in nda::norm: Only scalar value types are allowed");
61 if (p == 2.0) [[likely]] {
62 if constexpr (MemoryArray<A>)
63 return std::sqrt(std::real(nda::blas::dotc(a, a)));
65 return norm(make_regular(a));
66 }
else if (p == 1.0) {
68 }
else if (p == 0.0) {
70 for (
long i = 0; i < a.size(); ++i) {
71 if (a(i) != get_value_t<A>{0}) ++count;
74 }
else if (p == std::numeric_limits<
double>::infinity()) {
75 return max_element(abs(a));
76 }
else if (p == -std::numeric_limits<
double>::infinity()) {
77 return min_element(abs(a));
79 return std::pow(sum(pow(abs(a), p)), 1.0 / p);