Implements map and ref for both static & dynamic mode
See merge request oss/rotgen!12
This commit is contained in:
parent
aacae1cbb1
commit
6c2b260229
58 changed files with 4121 additions and 1205 deletions
|
|
@ -8,7 +8,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <rotgen/detail/static_info.hpp>
|
||||
#include <rotgen/fixed/common.hpp>
|
||||
#include <Eigen/Dense>
|
||||
#include <iostream>
|
||||
|
||||
|
|
@ -17,7 +16,7 @@ namespace rotgen
|
|||
namespace detail
|
||||
{
|
||||
template<typename Scalar, int Rows, int Cols, int Opts,int MaxRows, int MaxCols>
|
||||
using storage_type = std::conditional_t < storage_status<Rows,Cols>
|
||||
using storage_type = std::conditional_t < storage_status<Rows,Cols,MaxRows,MaxCols>
|
||||
, Eigen::Matrix<Scalar, Rows, Cols, Opts, MaxRows, MaxCols>
|
||||
, Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Opts>
|
||||
>;
|
||||
|
|
@ -25,27 +24,31 @@ namespace rotgen
|
|||
|
||||
template< typename Scalar
|
||||
, int Rows = Dynamic , int Cols = Dynamic
|
||||
, int Options = ColMajor
|
||||
, int Opts = ColMajor
|
||||
, int MaxRows = Rows , int MaxCols = Cols
|
||||
>
|
||||
class matrix : private detail::storage_type<Scalar, Rows, Cols, Options, MaxRows, MaxCols>
|
||||
class matrix : private detail::storage_type<Scalar, Rows, Cols, Opts, MaxRows, MaxCols>
|
||||
{
|
||||
public:
|
||||
using rotgen_tag = void;
|
||||
using parent = detail::storage_type<Scalar, Rows, Cols, Options, MaxRows, MaxCols>;
|
||||
using rotgen_tag = void;
|
||||
using parent = detail::storage_type<Scalar, Rows, Cols, Opts, MaxRows, MaxCols>;
|
||||
using value_type = Scalar;
|
||||
using scalar_type = Scalar;
|
||||
using Index = typename parent::Index;
|
||||
|
||||
static constexpr auto storage_order = Options & 1;
|
||||
static constexpr auto storage_order = Opts & 1;
|
||||
using concrete_type = matrix;
|
||||
using concrete_dynamic_type = matrix<scalar_type>;
|
||||
using concrete_dynamic_type = matrix<value_type>;
|
||||
|
||||
static constexpr auto Flags = parent::Flags;
|
||||
static constexpr int RowsAtCompileTime = Rows;
|
||||
static constexpr int ColsAtCompileTime = Cols;
|
||||
static constexpr int Options = parent::Options;
|
||||
|
||||
template<typename ET>
|
||||
using as_concrete_type = as_concrete_t<ET, matrix>;
|
||||
|
||||
private:
|
||||
static constexpr bool has_static_storage = storage_status<Rows,Cols>;
|
||||
static constexpr bool is_defined_static = Rows!=-1 && Cols!=-1;
|
||||
static constexpr bool has_static_storage = storage_status<Rows,Cols,MaxRows,MaxCols>;
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -58,7 +61,6 @@ namespace rotgen
|
|||
matrix& operator=(const matrix&) = default;
|
||||
matrix& operator=(matrix&&) = default;
|
||||
|
||||
|
||||
matrix(std::initializer_list<std::initializer_list<Scalar>> init) : parent(init)
|
||||
{}
|
||||
|
||||
|
|
@ -82,10 +84,17 @@ namespace rotgen
|
|||
}
|
||||
}
|
||||
|
||||
matrix(concepts::entity auto const& other) : parent(other.base())
|
||||
{}
|
||||
|
||||
template<typename OtherDerived>
|
||||
matrix(const Eigen::MatrixBase<OtherDerived>& other) : parent(other)
|
||||
{}
|
||||
|
||||
template<typename OtherDerived>
|
||||
matrix(const Eigen::EigenBase<OtherDerived>& other) : parent(other)
|
||||
{}
|
||||
|
||||
template<typename OtherDerived>
|
||||
matrix& operator=(const Eigen::MatrixBase<OtherDerived>& other)
|
||||
{
|
||||
|
|
@ -100,22 +109,31 @@ namespace rotgen
|
|||
return *this;
|
||||
}
|
||||
|
||||
matrix& operator=(concepts::entity auto const& other)
|
||||
{
|
||||
parent::operator=(other.base());
|
||||
return *this;
|
||||
}
|
||||
|
||||
parent& base() { return static_cast<parent&>(*this); }
|
||||
parent const& base() const { return static_cast<const parent&>(*this); }
|
||||
|
||||
concrete_type transpose() const
|
||||
auto transpose() const
|
||||
{
|
||||
return concrete_type(static_cast<parent const &>(*this).transpose());
|
||||
auto res = static_cast<parent const &>(*this).transpose();
|
||||
return as_concrete_type<decltype(res)>(res);
|
||||
}
|
||||
|
||||
concrete_type conjugate() const
|
||||
auto conjugate() const
|
||||
{
|
||||
return concrete_type(static_cast<parent const &>(*this).conjugate());
|
||||
auto res = static_cast<parent const &>(*this).conjugate();
|
||||
return as_concrete_type<decltype(res)>(res);
|
||||
}
|
||||
|
||||
concrete_type adjoint() const
|
||||
auto adjoint() const
|
||||
{
|
||||
return concrete_type(static_cast<parent const &>(*this).adjoint());
|
||||
auto res = static_cast<parent const &>(*this).adjoint();
|
||||
return as_concrete_type<decltype(res)>(res);
|
||||
}
|
||||
|
||||
void transposeInPlace() { parent::transposeInPlace(); }
|
||||
|
|
@ -155,6 +173,18 @@ namespace rotgen
|
|||
return parent::Identity(rows, cols);
|
||||
}
|
||||
|
||||
static matrix Ones() requires (Rows != -1 && Cols != -1)
|
||||
{
|
||||
return parent::Ones(Rows, Cols);
|
||||
}
|
||||
|
||||
static matrix Ones(int rows, int cols)
|
||||
{
|
||||
if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size");
|
||||
if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size");
|
||||
return parent::Ones(rows, cols);
|
||||
}
|
||||
|
||||
static matrix Zero() requires (Rows != -1 && Cols != -1)
|
||||
{
|
||||
return parent::Zero(Rows, Cols);
|
||||
|
|
@ -180,7 +210,7 @@ namespace rotgen
|
|||
}
|
||||
|
||||
template<int P>
|
||||
scalar_type lpNorm() const
|
||||
value_type lpNorm() const
|
||||
{
|
||||
static_assert(P == 1 || P == 2 || P == Infinity);
|
||||
return parent::template lpNorm<P>();
|
||||
|
|
@ -200,6 +230,66 @@ namespace rotgen
|
|||
using parent::sum;
|
||||
using parent::data;
|
||||
|
||||
matrix& setOnes()
|
||||
{
|
||||
*this = parent::Ones(rows(),cols());
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setOnes(int r, int c)
|
||||
{
|
||||
*this = parent::Ones(r, c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setZero()
|
||||
{
|
||||
*this = parent::Zero(rows(),cols());
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setZero(int r, int c)
|
||||
{
|
||||
*this = parent::Zero(r, c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setConstant(Scalar value)
|
||||
{
|
||||
*this = parent::Constant(rows(),cols(), static_cast<Scalar>(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setConstant(int r, int c, Scalar value)
|
||||
{
|
||||
*this = parent::Constant(r, c, static_cast<Scalar>(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setRandom()
|
||||
{
|
||||
*this = parent::Random(rows(),cols());
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setRandom(int r, int c)
|
||||
{
|
||||
*this = parent::Random(r, c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setIdentity()
|
||||
{
|
||||
*this = parent::Identity(rows(),cols());
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& setIdentity(int r, int c)
|
||||
{
|
||||
*this = parent::Identity(r, c);
|
||||
return *this;
|
||||
}
|
||||
|
||||
matrix& operator+=(matrix const& rhs)
|
||||
{
|
||||
static_cast<parent&>(*this) += static_cast<parent const&>(rhs);
|
||||
|
|
@ -234,13 +324,5 @@ namespace rotgen
|
|||
static_cast<parent&>(*this) /= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
static void print_storage_info()
|
||||
{
|
||||
std::cout << "Matrix " << Rows << "x" << Cols
|
||||
<< " - Storage: " << (has_static_storage ? "Static" : "Dynamic")
|
||||
<< " (Max. size=" << max_static_size << ")"
|
||||
<< std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue