Implement normalize and normalized

See merge request oss/rotgen!24
This commit is contained in:
Joel Falcou 2025-09-18 16:25:51 +02:00
parent e7cf89a903
commit 3e2e6f253c
14 changed files with 169 additions and 65 deletions

View file

@ -132,28 +132,25 @@ namespace rotgen
decltype(auto) noalias() const { return *this; }
decltype(auto) noalias() { return *this; }
concrete_type transpose() const
concrete_type normalized() const requires(IsVectorAtCompileTime)
{
return concrete_type(static_cast<parent const &>(*this).transpose());
}
concrete_type conjugate() const
{
return concrete_type(static_cast<parent const &>(*this).conjugate());
}
concrete_type adjoint() const
{
return concrete_type(static_cast<parent const&>(*this).adjoint());
return concrete_type(base().normalized());
}
concrete_type transpose() const { return concrete_type(base().transpose());}
concrete_type conjugate() const { return concrete_type(base().conjugate());}
concrete_type adjoint() const { return concrete_type(base().adjoint());}
concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); }
concrete_type cwiseAbs2() const { return concrete_type(base().cwiseAbs2()); }
concrete_type cwiseInverse() const { return concrete_type(base().cwiseInverse()); }
concrete_type cwiseSqrt() const { return concrete_type(base().cwiseSqrt()); }
void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); }
void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); }
void normalize() requires(!is_immutable && IsVectorAtCompileTime)
{
parent::normalize();
}
void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); }
void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); }
friend bool operator==(block const& lhs, block const& rhs)
{

View file

@ -123,26 +123,24 @@ namespace rotgen
decltype(auto) noalias() const { return *this; }
decltype(auto) noalias() { return *this; }
concrete_type transpose() const
concrete_type normalized() const requires(IsVectorAtCompileTime)
{
return concrete_type(static_cast<parent const &>(*this).transpose());
return concrete_type(base().normalized());
}
concrete_type conjugate() const
{
return concrete_type(static_cast<parent const &>(*this).conjugate());
}
concrete_type adjoint() const
{
return concrete_type(static_cast<parent const &>(*this).adjoint());
}
concrete_type transpose() const { return concrete_type(base().transpose()); }
concrete_type conjugate() const { return concrete_type(base().conjugate()); }
concrete_type adjoint() const { return concrete_type(base().adjoint()); }
concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); }
concrete_type cwiseAbs2() const { return concrete_type(base().cwiseAbs2()); }
concrete_type cwiseInverse() const { return concrete_type(base().cwiseInverse()); }
concrete_type cwiseSqrt() const { return concrete_type(base().cwiseSqrt()); }
void normalize() requires(!is_immutable && IsVectorAtCompileTime)
{
parent::normalize();
}
void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); }
void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); }

View file

@ -112,6 +112,11 @@ namespace rotgen
parent::conservativeResize(new_rows, new_cols);
}
matrix normalized() const requires(IsVectorAtCompileTime)
{
return matrix(base().normalized());
}
matrix transpose() const
{
return matrix(base().transpose());
@ -127,6 +132,11 @@ namespace rotgen
return matrix(base().adjoint());
}
void normalize() requires(IsVectorAtCompileTime)
{
parent::normalize();
}
void transposeInPlace() { parent::transposeInPlace(); }
void adjointInPlace() { parent::adjointInPlace(); }

View file

@ -126,11 +126,11 @@ namespace rotgen
}
parent& base() { return static_cast<parent&>(*this); }
parent const& base() const { return static_cast<const parent&>(*this); }
parent const& base() const { return static_cast<parent const&>(*this); }
auto evaluate() const
{
auto res = static_cast<parent const &>(*this).eval();
auto res = base().eval();
return as_concrete_type<decltype(res)>(res);
}
@ -146,22 +146,33 @@ namespace rotgen
else return *this;
}
auto transpose() const
auto normalized() const requires(IsVectorAtCompileTime)
{
auto res = static_cast<parent const &>(*this).transpose();
return as_concrete_type<decltype(res)>(res);
if constexpr(use_expression_templates) return base().normalized();
else return as_concrete_type<decltype(base().normalized())>(base().normalized());
}
auto conjugate() const
auto transpose() const
{
auto res = static_cast<parent const &>(*this).conjugate();
return as_concrete_type<decltype(res)>(res);
if constexpr(use_expression_templates) return base().transpose();
else return as_concrete_type<decltype(base().transpose())>(base().transpose());
}
auto adjoint() const
{
auto res = static_cast<parent const &>(*this).adjoint();
return as_concrete_type<decltype(res)>(res);
if constexpr(use_expression_templates) return base().adjoint();
else return as_concrete_type<decltype(base().adjoint())>(base().adjoint());
}
auto conjugate() const
{
if constexpr(use_expression_templates) return base().conjugate();
else return as_concrete_type<decltype(base().conjugate())>(base().conjugate());
}
void normalize() requires(!is_immutable && IsVectorAtCompileTime)
{
parent::normalize();
}
void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); }

View file

@ -185,6 +185,12 @@ namespace rotgen
else return base().cwiseSqrt();
}
auto normalized() const requires(IsVectorAtCompileTime)
{
if constexpr(use_expression_templates) return base().normalized();
else return as_concrete_type<decltype(base().normalized())>(base().normalized());
}
auto transpose() const
{
if constexpr(use_expression_templates) return base().transpose();
@ -203,6 +209,11 @@ namespace rotgen
else return as_concrete_type<decltype(base().conjugate())>(base().conjugate());
}
void normalize() requires(IsVectorAtCompileTime)
{
base().normalize();
}
void transposeInPlace() { base().transposeInPlace(); }
void adjointInPlace() { base().adjointInPlace(); }

View file

@ -126,11 +126,11 @@ namespace rotgen
}
parent& base() { return static_cast<parent&>(*this); }
parent const& base() const { return static_cast<const parent&>(*this); }
parent const& base() const { return static_cast<parent const&>(*this); }
auto evaluate() const
{
auto res = static_cast<parent const &>(*this).eval();
auto res = base().eval();
return as_concrete_type<decltype(res)>(res);
}
@ -146,28 +146,43 @@ namespace rotgen
else return *this;
}
auto normalized() const requires(IsVectorAtCompileTime)
{
if constexpr(use_expression_templates) return base().normalized();
else
{
auto res = base().normalized();
return as_concrete_type<decltype(res)>(res);
}
}
auto transpose() const
{
if constexpr(use_expression_templates) return base().transpose();
else
{
auto res = static_cast<parent const &>(*this).transpose();
auto res = base().transpose();
return as_concrete_type<decltype(res)>(res);
}
}
auto conjugate() const
{
auto res = static_cast<parent const &>(*this).conjugate();
auto res = base().conjugate();
return as_concrete_type<decltype(res)>(res);
}
auto adjoint() const
{
auto res = static_cast<parent const &>(*this).adjoint();
auto res = base().adjoint();
return as_concrete_type<decltype(res)>(res);
}
void normalize() requires(IsVectorAtCompileTime)
{
parent::normalize();
}
void transposeInPlace() { parent::transposeInPlace(); }
void adjointInPlace() { parent::adjointInPlace(); }
@ -380,24 +395,24 @@ namespace rotgen
matrix& operator+=(matrix const& rhs)
{
static_cast<parent&>(*this) += static_cast<parent const&>(rhs);
static_cast<parent&>(*this) += rhs.base();
return *this;
}
matrix& operator-=(matrix const& rhs)
{
static_cast<parent&>(*this) -= static_cast<parent const&>(rhs);
static_cast<parent&>(*this) -= rhs.base();
return *this;
}
matrix operator-() const
{
return matrix(static_cast<parent const&>(*this).operator-());
return matrix(base()(*this).operator-());
}
matrix& operator*=(matrix const& rhs)
{
static_cast<parent&>(*this) *= static_cast<parent const&>(rhs);
static_cast<parent&>(*this) *= rhs.base();
return *this;
}

View file

@ -27,12 +27,14 @@ namespace rotgen
arg.conservativeResize(new_rows, new_cols);
}
decltype(auto) transpose(concepts::entity auto const& arg) { return arg.transpose(); }
decltype(auto) conjugate(concepts::entity auto const& arg) { return arg.conjugate(); }
decltype(auto) adjoint (concepts::entity auto const& arg) { return arg.adjoint(); }
decltype(auto) normalized(concepts::entity auto const& arg) { return arg.normalized(); }
decltype(auto) transpose (concepts::entity auto const& arg) { return arg.transpose(); }
decltype(auto) conjugate (concepts::entity auto const& arg) { return arg.conjugate(); }
decltype(auto) adjoint (concepts::entity auto const& arg) { return arg.adjoint(); }
void normalize(concepts::entity auto& arg) { arg.normalize(); }
void transposeInPlace(concepts::entity auto& arg) { arg.transposeInPlace(); }
void adjointInPlace(concepts::entity auto& arg) { arg.adjointInPlace(); }
void adjointInPlace(concepts::entity auto& arg) { arg.adjointInPlace(); }
auto abs(concepts::entity auto const& arg) { return arg.cwiseAbs(); }
auto abs2(concepts::entity auto const& arg) { return arg.cwiseAbs2(); }

View file

@ -46,9 +46,10 @@ class ROTGEN_EXPORT CLASSNAME
Index startRow() const;
Index startCol() const;
SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME normalized() const;
SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME cwiseAbs() const;
SOURCENAME cwiseAbs2() const;
@ -56,6 +57,7 @@ class ROTGEN_EXPORT CLASSNAME
SOURCENAME cwiseSqrt() const;
#if !defined(USE_CONST)
void normalize();
void transposeInPlace();
void adjointInPlace();
#endif

View file

@ -36,9 +36,10 @@ class ROTGEN_EXPORT CLASSNAME
Index innerStride() const;
Index outerStride() const;
SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME normalized() const;
SOURCENAME transpose() const;
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME cwiseAbs() const;
SOURCENAME cwiseAbs2() const;
@ -46,6 +47,7 @@ class ROTGEN_EXPORT CLASSNAME
SOURCENAME cwiseSqrt() const;
#if !defined(USE_CONST)
void normalize();
void transposeInPlace();
void adjointInPlace();
#endif

View file

@ -35,15 +35,17 @@ class ROTGEN_EXPORT CLASSNAME
void resize(std::size_t new_rows, std::size_t new_cols);
void conservativeResize(std::size_t new_rows, std::size_t new_cols);
CLASSNAME transpose() const;
CLASSNAME conjugate() const;
CLASSNAME adjoint() const;
CLASSNAME normalized() const;
CLASSNAME transpose() const;
CLASSNAME conjugate() const;
CLASSNAME adjoint() const;
CLASSNAME cwiseAbs() const;
CLASSNAME cwiseAbs2() const;
CLASSNAME cwiseInverse() const;
CLASSNAME cwiseSqrt() const;
void normalize();
void transposeInPlace();
void adjointInPlace();