21 #ifndef RFFGEN_LINEAR_ALGEBRA_MATRIX_NORM_HH
22 #define RFFGEN_LINEAR_ALGEBRA_MATRIX_NORM_HH
24 #include <type_traits>
26 #include "../LinearAlgebra/extractRowsAndCols.hh"
27 #include "../MathematicalOperations/chain.hh"
28 #include "../CMath/pow.hh"
35 namespace Concepts {
template <
class>
struct MatrixConceptCheck; }
40 namespace LinearAlgebra
46 template <
class Matrix,
class = Concepts::MatrixConceptCheck<Matrix> >
62 resultOfD0 = computeSquareNorm(A_);
72 auto d0() const noexcept
79 auto d1(
const Matrix& dA)
const
81 return 2 * computeScalarProduct(A_,dA);
86 auto d2(
const Matrix& dA1,
const Matrix& dA2)
const
88 return 2 * computeScalarProduct(dA1,dA2);
93 auto computeSquareNorm(
const Matrix& A)
const
95 using Index = decltype(numberOfRows<Matrix>());
96 auto result = decltype(at(A,0,0)){0.};
97 for( Index i = 0; i < numberOfRows<Matrix>() ; ++i )
98 for( Index j = 0 ; j < numberOfColumns<Matrix>() ; ++j )
99 result += at(A,i,j) * at(A,i,j);
103 auto computeScalarProduct(
const Matrix& A,
const Matrix& B)
const
105 using Index = decltype(numberOfRows<Matrix>());
106 auto result = decltype(at(A,0,0)){0.};
107 for( Index i = 0; i < numberOfRows<Matrix>() ; ++i )
108 for( Index j = 0 ; j < numberOfColumns<Matrix>() ; ++j )
109 result += at(A,i,j) * at(B,i,j);
114 std::remove_const_t< std::remove_reference_t< at_t<Matrix> > > resultOfD0;
121 template <
class Matrix>
126 #endif // RFFGEN_LINEAR_ALGEBRA_MATRIX_NORM_HH
auto d0() const noexcept
Squared matrix norm.
Definition: matrixNorm.hh:72
SquaredMatrixNorm(const Matrix &A)
Constructor.
Definition: matrixNorm.hh:56
SquaredMatrixNorm()=default
Default constructor.
void update(const Matrix &A)
Reset matrix to compute squared norm from.
Definition: matrixNorm.hh:59
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Chain of functions and of type F resp. G (F and G must satisfy the requirements of Concepts::Funct...
Definition: chain.hh:61
auto operator()() const noexcept
Squared matrix norm. Convenient access to d0().
Definition: matrixNorm.hh:66
auto d1(const Matrix &dA) const
First directional derivative.
Definition: matrixNorm.hh:79
auto d2(const Matrix &dA1, const Matrix &dA2) const
Second directional derivative.
Definition: matrixNorm.hh:86
Compute squared matrix norm .
Definition: matrixNorm.hh:47