21 #ifndef RFFGEN_LINEAR_ALGEBRA_EUCLIDEAN_NORM_HH
22 #define RFFGEN_LINEAR_ALGEBRA_EUCLIDEAN_NORM_HH
24 #include <type_traits>
26 #include "../LinearAlgebra/extractRowsAndCols.hh"
27 #include "../MathematicalOperations/chain.hh"
28 #include "../CMath/pow.hh"
29 #include "../Util/staticChecks.hh"
36 namespace Concepts {
template <
class>
struct MatrixConceptCheck; }
41 namespace LinearAlgebra
48 template <
class Matrix , std::enable_if_t<Checks::isConstantSizeMatrix<Matrix>()> >
49 inline auto computeSquareEuclideanNorm(
const Matrix& A)
51 using Index = decltype(numberOfRows<Matrix>());
52 auto result = decltype(at(A,0,0)){0.};
53 for( Index i = 0; i < numberOfRows<Matrix>() ; ++i )
54 for( Index j = 0 ; j < numberOfColumns<Matrix>() ; ++j )
55 result += at(A,i,j) * at(A,i,j);
59 template <
class Vector , std::enable_if_t<Checks::isStaticVector<Vector>() && !Checks::isConstantSizeMatrix<Vector>()> >
60 inline auto computeSquareEuclideanNorm(
const Vector& A)
62 using Index = decltype(numberOfRows<Vector>());
63 auto result = decltype(at(A,0)){0.};
64 for( Index i = 0; i < numberOfRows<Vector>() ; ++i )
65 result += at(A,i) * at(A,i);
69 template <
class Matrix , std::enable_if_t<Checks::isConstantSizeMatrix<Matrix>()> >
70 inline auto computeEuclideanScalarProduct(
const Matrix& A,
const Matrix& B)
72 using Index = decltype(numberOfRows<Matrix>());
73 auto result = decltype(at(A,0,0)){0.};
74 for( Index i = 0; i < numberOfRows<Matrix>() ; ++i )
75 for( Index j = 0 ; j < numberOfColumns<Matrix>() ; ++j )
76 result += at(A,i,j) * at(B,i,j);
80 template <
class Vector , std::enable_if_t<Checks::isStaticVector<Vector>() && !Checks::isConstantSizeMatrix<Vector>()> >
81 inline auto computeEuclideanScalarProduct(
const Vector& v,
const Vector& w)
83 using Index = decltype(numberOfRows<Vector>());
84 auto result = at(v,0) * at(w,1);
85 for( Index i = 1; i < numberOfRows<Vector>() ; ++i )
86 result += at(v,i) * at(w,i);
99 template <
class Matrix,
class = Concepts::MatrixConceptCheck<Matrix> >
115 resultOfD0 = computeSquareNorm(A_);
125 auto d0() const noexcept
132 auto d1(
const Matrix& dA)
const
134 return 2 * computeScalarProduct(A_,dA);
139 auto d2(
const Matrix& dA1,
const Matrix& dA2)
const
141 return 2 * computeScalarProduct(dA1,dA2);
147 std::remove_const_t< std::remove_reference_t< at_t<Matrix> > > resultOfD0;
154 template <
class Matrix>
159 #endif // RFFGEN_LINEAR_ALGEBRA_EUCLIDEAN_NORM_HH
auto d0() const noexcept
Squared matrix norm.
Definition: euclideanNorm.hh:125
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 d2(const Matrix &dA1, const Matrix &dA2) const
Second directional derivative.
Definition: euclideanNorm.hh:139
void update(const Matrix &A)
Reset matrix to compute squared norm from.
Definition: euclideanNorm.hh:112
auto d1(const Matrix &dA) const
First directional derivative.
Definition: euclideanNorm.hh:132
SquaredEuclideanNorm(const Matrix &A)
Constructor.
Definition: euclideanNorm.hh:109
Compute squared matrix norm .
Definition: euclideanNorm.hh:100
auto operator()() const noexcept
Squared matrix norm. Convenient access to d0().
Definition: euclideanNorm.hh:119
SquaredEuclideanNorm()=default
Default constructor.