Implement unary cwiseXXX() member functions + associated free functions

See merge request oss/rotgen!17
This commit is contained in:
Joel Falcou 2025-09-03 11:50:00 +02:00
parent a2e7718a48
commit 0a3abbb58b
15 changed files with 207 additions and 6 deletions

View file

@ -36,6 +36,10 @@ namespace rotgen
using parent::prod;
using parent::mean;
using parent::trace;
using parent::cwiseAbs;
using parent::cwiseAbs2;
using parent::cwiseInverse;
using parent::cwiseSqrt;
using parent::maxCoeff;
using parent::minCoeff;
using parent::norm;
@ -104,6 +108,10 @@ namespace rotgen
using parent::prod;
using parent::mean;
using parent::trace;
using parent::cwiseAbs;
using parent::cwiseAbs2;
using parent::cwiseInverse;
using parent::cwiseSqrt;
using parent::maxCoeff;
using parent::minCoeff;
using parent::norm;

View file

@ -129,11 +129,15 @@ namespace rotgen
concrete_type adjoint() const
{
return concrete_type(static_cast<parent const &>(*this).adjoint());
return concrete_type(static_cast<parent const&>(*this).adjoint());
}
void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); }
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(); }
friend bool operator==(block const& lhs, block const& rhs)

View file

@ -105,6 +105,11 @@ namespace rotgen
return concrete_type(static_cast<parent const &>(*this).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(); }

View file

@ -98,6 +98,11 @@ namespace rotgen
void transposeInPlace() { parent::transposeInPlace(); }
void adjointInPlace() { parent::adjointInPlace(); }
matrix cwiseAbs() const { return matrix(base().cwiseAbs()); }
matrix cwiseAbs2() const { return matrix(base().cwiseAbs2()); }
matrix cwiseInverse() const { return matrix(base().cwiseInverse()); }
matrix cwiseSqrt() const { return matrix(base().cwiseSqrt()); }
friend bool operator==(matrix const& lhs, matrix const& rhs)
{
return static_cast<parent const&>(lhs) == static_cast<parent const&>(rhs);

View file

@ -140,6 +140,30 @@ namespace rotgen
void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); }
void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); }
auto cwiseAbs() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs()};
else return base().cwiseAbs();
}
auto cwiseAbs2() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs2()};
else return base().cwiseAbs2();
}
auto cwiseInverse() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseInverse()};
else return base().cwiseInverse();
}
auto cwiseSqrt() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseSqrt()};
else return base().cwiseSqrt();
}
static concrete_type Constant(value_type value) requires (Rows != -1 && Cols != -1)
{
return parent::Constant(Rows, Cols, static_cast<value_type>(value));

View file

@ -121,6 +121,30 @@ namespace rotgen
return *this;
}
auto cwiseAbs() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs()};
else return base().cwiseAbs();
}
auto cwiseAbs2() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs2()};
else return base().cwiseAbs2();
}
auto cwiseInverse() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseInverse()};
else return base().cwiseInverse();
}
auto cwiseSqrt() const
{
if constexpr(!use_expression_templates) return concrete_type{parent::cwiseSqrt()};
else return base().cwiseSqrt();
}
auto transpose() const
{
if constexpr(use_expression_templates) return base().transpose();

View file

@ -139,6 +139,30 @@ namespace rotgen
void transposeInPlace() { parent::transposeInPlace(); }
void adjointInPlace() { parent::adjointInPlace(); }
auto cwiseAbs() const
{
if constexpr(!use_expression_templates) return matrix{parent::cwiseAbs()};
else return base().cwiseAbs();
}
auto cwiseAbs2() const
{
if constexpr(!use_expression_templates) return matrix{parent::cwiseAbs2()};
else return base().cwiseAbs2();
}
auto cwiseInverse() const
{
if constexpr(!use_expression_templates) return matrix{parent::cwiseInverse()};
else return base().cwiseInverse();
}
auto cwiseSqrt() const
{
if constexpr(!use_expression_templates) return matrix{parent::cwiseSqrt()};
else return base().cwiseSqrt();
}
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
{
parent::resize(new_rows, new_cols);

View file

@ -34,6 +34,18 @@ namespace rotgen
void transposeInPlace(concepts::entity auto& arg) { arg.transposeInPlace(); }
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(); }
auto rec(concepts::entity auto const& arg) { return arg.cwiseInverse(); }
auto sqrt(concepts::entity auto const& arg) { return arg.cwiseSqrt(); }
#if defined(ROTGEN_ENABLE_EXPRESSION_TEMPLATES)
decltype(auto) abs(concepts::eigen_compatible auto const& arg) { return arg.cwiseAbs(); }
decltype(auto) abs2(concepts::eigen_compatible auto const& arg) { return arg.cwiseAbs2(); }
decltype(auto) rec(concepts::eigen_compatible auto const& arg) { return arg.cwiseInverse(); }
decltype(auto) sqrt(concepts::eigen_compatible auto const& arg) { return arg.cwiseSqrt(); }
#endif
auto trace(concepts::entity auto const& arg) { return arg.trace(); }
auto squaredNorm(concepts::entity auto const& arg) { return arg.squaredNorm(); }
auto norm(concepts::entity auto const& arg) { return arg.norm(); }

View file

@ -50,6 +50,11 @@ class ROTGEN_EXPORT CLASSNAME
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME cwiseAbs() const;
SOURCENAME cwiseAbs2() const;
SOURCENAME cwiseInverse() const;
SOURCENAME cwiseSqrt() const;
#if !defined(USE_CONST)
void transposeInPlace();
void adjointInPlace();

View file

@ -40,6 +40,11 @@ class ROTGEN_EXPORT CLASSNAME
SOURCENAME conjugate() const;
SOURCENAME adjoint() const;
SOURCENAME cwiseAbs() const;
SOURCENAME cwiseAbs2() const;
SOURCENAME cwiseInverse() const;
SOURCENAME cwiseSqrt() const;
#if !defined(USE_CONST)
void transposeInPlace();
void adjointInPlace();

View file

@ -38,6 +38,11 @@ class ROTGEN_EXPORT CLASSNAME
CLASSNAME conjugate() const;
CLASSNAME adjoint() const;
CLASSNAME cwiseAbs() const;
CLASSNAME cwiseAbs2() const;
CLASSNAME cwiseInverse() const;
CLASSNAME cwiseSqrt() const;
void transposeInPlace();
void adjointInPlace();