3 #include <funcy/cmath/pow.h> 4 #include <funcy/concepts.h> 5 #include <funcy/linalg/at.h> 6 #include <funcy/linalg/concepts.h> 7 #include <funcy/linalg/rows_and_cols.h> 8 #include <funcy/util/chainer.h> 10 #include <type_traits> 20 template < ConstantSize Mat >
21 [[nodiscard]]
inline auto compute_scalar_product(
const Mat& A,
const Mat& B )
23 using Index = decltype( rows< Mat >() );
24 auto result = decltype(
at( A, 0, 0 ) ){ 0. };
25 for ( Index i = 0; i < rows< Mat >(); ++i )
26 for ( Index j = 0; j < cols< Mat >(); ++j )
27 result +=
at( A, i, j ) *
at( B, i, j );
31 template <
class Mat >
32 [[nodiscard]]
inline auto compute_scalar_product(
const Mat& A,
const Mat& B )
34 using Index = decltype(
rows( A ) );
35 auto result = decltype(
at( A, 0, 0 ) ){ 0. };
36 for ( Index i = 0; i <
rows( A ); ++i )
37 for ( Index j = 0; j <
cols( A ); ++j )
38 result +=
at( A, i, j ) *
at( B, i, j );
46 template <
class Mat >
53 value = detail::compute_scalar_product( A_, A_ );
58 value = detail::compute_scalar_product( A_, A_ );
65 value = detail::compute_scalar_product( A_, A_ );
69 [[nodiscard]]
auto d0() const noexcept
75 [[nodiscard]]
auto d1(
const Mat& dA )
const 77 return 2 * detail::compute_scalar_product( A_, dA );
81 [[nodiscard]]
auto d2(
const Mat& dA1,
const Mat& dA2 )
const 83 return 2 * detail::compute_scalar_product( dA1, dA2 );
88 std::decay_t< decltype( at( std::declval< Mat >(), 0, 0 ) ) > value;
93 template <
class Mat >
98 template <
class Mat >
106 template < Function F >
auto d0() const noexcept
Squared matrix norm.
Definition: frobenius_norm.h:69
void update(const Mat &A)
Reset matrix to compute squared norm from.
Definition: frobenius_norm.h:62
auto cols(const Mat &A) requires(!ConstantSize< Mat > &&static_check
Number of columns of a dynamic size matrix.
Definition: rows_and_cols.h:36
auto rows(const Mat &A) requires(!ConstantSize< Mat > &&static_check
Number of rows of a dynamic size matrix.
Definition: rows_and_cols.h:13
auto d1(const Mat &dA) const
First directional derivative.
Definition: frobenius_norm.h:75
auto d2(const Mat &dA1, const Mat &dA2) const
Second directional derivative.
Definition: frobenius_norm.h:81
Functionality from linear algebra such as (modified) principal and mixed matrix invariants.
auto frobenius_norm(const Mat &A)
Definition: frobenius_norm.h:99
decltype(auto) FUNCY_ALWAYS_INLINE at(M &&A, Index i, Index j) requires requires(std
Access matrix entry.
Definition: at.h:17
mathop::Chain< Sqrt, SquaredFrobeniusNorm< Mat > > FrobeniusNorm
Definition: frobenius_norm.h:94
Chain of functions and of type F resp. G.
Definition: chain.h:27
Definition: frobenius_norm.h:47