* Compound operators were not usable properly. * std::size_t was used in the API in places where Index should have been used.
368 lines
8.3 KiB
C++
368 lines
8.3 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
|
|
//==================================================================================================
|
|
/*
|
|
This file is a X-File to generate various matrix_impl_* definitions variant
|
|
*/
|
|
//==================================================================================================
|
|
|
|
//==================================================================================================
|
|
// Constructors & Special Members
|
|
//==================================================================================================
|
|
CLASSNAME::CLASSNAME() : storage_(std::make_unique<payload>(0, 0)) {}
|
|
|
|
CLASSNAME::CLASSNAME(Index r, Index c)
|
|
: storage_(std::make_unique<payload>(r, c))
|
|
{
|
|
}
|
|
|
|
CLASSNAME::CLASSNAME(std::initializer_list<std::initializer_list<TYPE>> init)
|
|
: storage_(std::make_unique<payload>(init))
|
|
{
|
|
}
|
|
|
|
CLASSNAME::CLASSNAME(Index r, Index c, std::initializer_list<TYPE> init)
|
|
: CLASSNAME(r, c)
|
|
{
|
|
auto first = init.begin();
|
|
for (std::size_t i = 0; i < init.size(); i++) (*this)(i) = first[i];
|
|
}
|
|
|
|
CLASSNAME::CLASSNAME(CLASSNAME const& o) : CLASSNAME(o.rows(), o.cols())
|
|
{
|
|
storage_->data = o.storage_->data;
|
|
}
|
|
|
|
CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default;
|
|
|
|
CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o)
|
|
{
|
|
if (this != &o) storage_->data = o.storage_->data;
|
|
return *this;
|
|
}
|
|
|
|
CLASSNAME& CLASSNAME::operator=(CLASSNAME&&) noexcept = default;
|
|
|
|
CLASSNAME::~CLASSNAME() = default;
|
|
|
|
//==================================================================================================
|
|
// Matrix API
|
|
//==================================================================================================
|
|
rotgen::Index CLASSNAME::rows() const
|
|
{
|
|
return storage_->data.rows();
|
|
}
|
|
|
|
rotgen::Index CLASSNAME::cols() const
|
|
{
|
|
return storage_->data.cols();
|
|
}
|
|
|
|
rotgen::Index CLASSNAME::size() const
|
|
{
|
|
return storage_->data.size();
|
|
}
|
|
|
|
void CLASSNAME::resize(Index new_rows, Index new_cols)
|
|
{
|
|
storage_->data.resize(new_rows, new_cols);
|
|
}
|
|
|
|
void CLASSNAME::conservativeResize(Index new_rows, Index new_cols)
|
|
{
|
|
storage_->data.conservativeResize(new_rows, new_cols);
|
|
}
|
|
|
|
TYPE& CLASSNAME::operator()(Index i, Index j)
|
|
{
|
|
return storage_->data(i, j);
|
|
}
|
|
|
|
TYPE const& CLASSNAME::operator()(Index i, Index j) const
|
|
{
|
|
return storage_->data(i, j);
|
|
}
|
|
|
|
TYPE& CLASSNAME::operator()(Index index)
|
|
{
|
|
return storage_->data(index);
|
|
}
|
|
|
|
TYPE const& CLASSNAME::operator()(Index index) const
|
|
{
|
|
return storage_->data(index);
|
|
}
|
|
|
|
const TYPE* CLASSNAME::data() const
|
|
{
|
|
return storage_->data.data();
|
|
}
|
|
|
|
TYPE* CLASSNAME::data()
|
|
{
|
|
return storage_->data.data();
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::normalized() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data.normalize();
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::transpose() const
|
|
{
|
|
CLASSNAME result;
|
|
result.storage()->data = storage_->data.transpose();
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::conjugate() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data = storage_->data.conjugate();
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::adjoint() const
|
|
{
|
|
CLASSNAME result;
|
|
result.storage()->data = storage_->data.adjoint();
|
|
return result;
|
|
}
|
|
|
|
void CLASSNAME::normalize()
|
|
{
|
|
storage_->data.normalize();
|
|
}
|
|
|
|
void CLASSNAME::transposeInPlace()
|
|
{
|
|
storage_->data.transposeInPlace();
|
|
}
|
|
|
|
void CLASSNAME::adjointInPlace()
|
|
{
|
|
storage_->data.adjointInPlace();
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::cwiseAbs() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data = storage_->data.cwiseAbs();
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::cwiseAbs2() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data = storage_->data.cwiseAbs2();
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::cwiseInverse() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data = storage_->data.cwiseInverse();
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::cwiseSqrt() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data = storage_->data.cwiseSqrt();
|
|
return result;
|
|
}
|
|
|
|
TYPE CLASSNAME::sum() const
|
|
{
|
|
return storage_->data.sum();
|
|
}
|
|
|
|
TYPE CLASSNAME::prod() const
|
|
{
|
|
return storage_->data.prod();
|
|
}
|
|
|
|
TYPE CLASSNAME::mean() const
|
|
{
|
|
return storage_->data.mean();
|
|
}
|
|
|
|
TYPE CLASSNAME::trace() const
|
|
{
|
|
return storage_->data.trace();
|
|
}
|
|
|
|
TYPE CLASSNAME::minCoeff() const
|
|
{
|
|
return storage_->data.minCoeff();
|
|
}
|
|
|
|
TYPE CLASSNAME::maxCoeff() const
|
|
{
|
|
return storage_->data.maxCoeff();
|
|
}
|
|
|
|
TYPE CLASSNAME::minCoeff(Index* row, Index* col) const
|
|
{
|
|
return storage_->data.minCoeff(row, col);
|
|
}
|
|
|
|
TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const
|
|
{
|
|
return storage_->data.maxCoeff(row, col);
|
|
}
|
|
|
|
TYPE CLASSNAME::squaredNorm() const
|
|
{
|
|
return storage_->data.squaredNorm();
|
|
}
|
|
|
|
TYPE CLASSNAME::norm() const
|
|
{
|
|
return storage_->data.norm();
|
|
}
|
|
|
|
TYPE CLASSNAME::lp_norm(int p) const
|
|
{
|
|
if (p == 1) return storage_->data.lpNorm<1>();
|
|
else if (p == 2) return storage_->data.lpNorm<2>();
|
|
else return storage_->data.lpNorm<Eigen::Infinity>();
|
|
}
|
|
|
|
//==================================================================================================
|
|
// Operators
|
|
//==================================================================================================
|
|
ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m)
|
|
{
|
|
return os << m.storage_->data;
|
|
}
|
|
|
|
ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,
|
|
format<CLASSNAME> const& m)
|
|
{
|
|
return os << m.matrix_.storage_->data.format(m.format_.storage()->instance);
|
|
}
|
|
|
|
ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs)
|
|
{
|
|
return lhs.storage_->data == rhs.storage_->data;
|
|
}
|
|
|
|
ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs)
|
|
{
|
|
return lhs.storage_->data != rhs.storage_->data;
|
|
}
|
|
|
|
CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs)
|
|
{
|
|
storage_->data += rhs.storage_->data;
|
|
return *this;
|
|
}
|
|
|
|
CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs)
|
|
{
|
|
storage_->data -= rhs.storage_->data;
|
|
return *this;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::operator-() const
|
|
{
|
|
CLASSNAME result(*this);
|
|
result.storage_->data = -result.storage_->data;
|
|
return result;
|
|
}
|
|
|
|
CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs)
|
|
{
|
|
storage_->data *= rhs.storage_->data;
|
|
return *this;
|
|
}
|
|
|
|
CLASSNAME& CLASSNAME::operator*=(TYPE s)
|
|
{
|
|
storage_->data *= s;
|
|
return *this;
|
|
}
|
|
|
|
CLASSNAME& CLASSNAME::operator/=(TYPE s)
|
|
{
|
|
storage_->data /= s;
|
|
return *this;
|
|
}
|
|
|
|
//==============================================================================
|
|
// Generators functions
|
|
//==============================================================================
|
|
void CLASSNAME::setOnes(Index rows, Index cols)
|
|
{
|
|
storage_->assign(payload::data_type::Ones(rows, cols).eval());
|
|
}
|
|
|
|
void CLASSNAME::setZero(Index rows, Index cols)
|
|
{
|
|
storage_->assign(payload::data_type::Zero(rows, cols).eval());
|
|
}
|
|
|
|
void CLASSNAME::setConstant(Index rows, Index cols, TYPE value)
|
|
{
|
|
storage_->assign(payload::data_type::Constant(rows, cols, value).eval());
|
|
}
|
|
|
|
void CLASSNAME::setRandom(Index rows, Index cols)
|
|
{
|
|
storage_->assign(payload::data_type::Random(rows, cols).eval());
|
|
}
|
|
|
|
void CLASSNAME::setIdentity(Index rows, Index cols)
|
|
{
|
|
storage_->assign(payload::data_type::Identity(rows, cols).eval());
|
|
}
|
|
|
|
//==============================================================================
|
|
// Static functions
|
|
//==============================================================================
|
|
CLASSNAME CLASSNAME::Ones(Index rows, Index cols)
|
|
{
|
|
CLASSNAME m;
|
|
m.storage_ = std::make_unique<payload>(payload::data_type::Ones(rows, cols));
|
|
return m;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::Zero(Index rows, Index cols)
|
|
{
|
|
CLASSNAME m;
|
|
m.storage_ = std::make_unique<payload>(payload::data_type::Zero(rows, cols));
|
|
return m;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::Constant(Index rows, Index cols, TYPE value)
|
|
{
|
|
CLASSNAME m;
|
|
m.storage_ =
|
|
std::make_unique<payload>(payload::data_type::Constant(rows, cols, value));
|
|
return m;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::Random(Index rows, Index cols)
|
|
{
|
|
CLASSNAME m;
|
|
m.storage_ =
|
|
std::make_unique<payload>(payload::data_type::Random(rows, cols));
|
|
return m;
|
|
}
|
|
|
|
CLASSNAME CLASSNAME::Identity(Index rows, Index cols)
|
|
{
|
|
CLASSNAME m;
|
|
m.storage_ =
|
|
std::make_unique<payload>(payload::data_type::Identity(rows, cols));
|
|
return m;
|
|
}
|