//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #pragma once #include #include #include namespace rotgen { namespace detail { template struct compute_map_type { using base = Eigen::Matrix< typename Ref::value_type , Ref::RowsAtCompileTime, Ref::ColsAtCompileTime , Ref::storage_order >; using ref_t = std::conditional_t; using type = Eigen::Map>; }; template using map_type = typename compute_map_type::type; } template class map : private detail::map_type, Options, std::is_const_v> { public: using rotgen_tag = void; using parent = detail::map_type, Options, std::is_const_v>; using value_type = typename std::remove_const_t::value_type; using concrete_type = typename std::remove_const_t::concrete_type; static constexpr auto Flags = Ref::Flags; static constexpr Index RowsAtCompileTime = Ref::RowsAtCompileTime; static constexpr Index ColsAtCompileTime = Ref::ColsAtCompileTime; static constexpr bool has_static_storage = Ref::has_static_storage; static constexpr int storage_order = Ref::storage_order; static constexpr bool is_immutable = std::is_const_v; static constexpr bool is_defined_static = Ref::is_defined_static; template using as_concrete_type = as_concrete_t; using ptr_type = std::conditional_t; using stride_type = Stride; map(const map&) = default; map(map&&) = default; map& operator=(const map&) = default; map& operator=(map&&) = default; map(ptr_type ptr, Index r, Index c, stride_type s) : parent(ptr, r, c, strides(s)) {} map(ptr_type ptr, Index r, Index c) : parent(ptr, r, c, strides(r,c)) {} map(ptr_type ptr, stride_type s) requires(RowsAtCompileTime!=-1 && ColsAtCompileTime!=-1) : parent(ptr, strides(s)) {} map(ptr_type ptr, Index sz) requires(RowsAtCompileTime==1 || ColsAtCompileTime==1) : map(ptr, RowsAtCompileTime==1?1:sz, ColsAtCompileTime==1?1:sz) {} map(ptr_type ptr) requires(RowsAtCompileTime!=-1 && ColsAtCompileTime!=-1) : map( ptr, RowsAtCompileTime, ColsAtCompileTime ) {} parent& base() { return static_cast(*this); } parent const& base() const { return static_cast(*this); } value_type& operator()(Index i, Index j) { return base()(i, j); } value_type operator()(Index i, Index j) const { return base()(i, j); } value_type& operator()(Index i) requires(!is_immutable) { assert(is_contiguous_linear()); return base().data()[i]; } value_type operator()(Index i) const { assert(is_contiguous_linear()); return base().data()[i]; } map& operator+=(map const& rhs) { base() += rhs.base(); return *this; } map& operator-=(map const& rhs) { base() -= rhs.base(); return *this; } map& operator*=(map const& rhs) { base() *= rhs; return *this; } map& operator*=(value_type rhs) { base() *= rhs; return *this; } map& operator/=(value_type rhs) { base() /= rhs; return *this; } auto transpose() const { if constexpr(use_expression_templates) return base().transpose(); else return as_concrete_type(base().transpose()); } auto adjoint() const { if constexpr(use_expression_templates) return base().adjoint(); else return as_concrete_type(base().adjoint()); } auto conjugate() const { if constexpr(use_expression_templates) return base().conjugate(); else return as_concrete_type(base().conjugate()); } void transposeInPlace() { base().transposeInPlace(); } void adjointInPlace() { base().adjointInPlace(); } static auto Zero() requires( requires {Ref::Zero();} ) { return Ref::Zero(); } static auto Zero(int rows, int cols) { return Ref::Zero(rows,cols); } static auto Ones() requires( requires {Ref::Ones();} ) { return Ref::Ones(); } static auto Ones(int rows, int cols) { return Ref::Ones(rows,cols); } static auto Constant(value_type value) requires( requires {Ref::Constant(value);} ) { return Ref::Constant(value); } static auto Constant(int rows, int cols, value_type value) { return Ref::Constant(rows, cols, value); } static auto Random() requires( requires {Ref::Random();} ) { return Ref::Random(); } static auto Random(int rows, int cols) { return Ref::Random(rows, cols); } static auto Identity() requires( requires {Ref::Identity();} ) { return Ref::Identity(); } static auto Identity(int rows, int cols) { return Ref::Identity(rows, cols); } map& setOnes() { base() = parent::Ones(base().rows(), base().cols()); return *this; } map& setZero() { base() = parent::Zero(base().rows(), base().cols()); return *this; } map& setConstant(value_type value) { base() = parent::Constant(base().rows(), base().cols(), value); return *this; } map& setRandom() { base() = parent::Random(base().rows(), base().cols()); return *this; } map& setIdentity() { base() = parent::Identity(base().rows(), base().cols()); return *this; } bool is_contiguous_linear() const { if(base().innerStride() != 1) return false; if constexpr(storage_order == rotgen::RowMajor) return base().outerStride() == base().cols(); else return base().outerStride() == base().rows(); } using parent::innerStride; using parent::outerStride; using parent::rows; using parent::cols; using parent::size; using parent::data; using parent::sum; using parent::mean; using parent::prod; using parent::trace; using parent::maxCoeff; using parent::minCoeff; using parent::norm; using parent::squaredNorm; template value_type lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); return parent::template lpNorm

(); } }; template bool operator==(map const& lhs, map const& rhs) { return lhs.base() == rhs.base(); } template bool operator!=(map const& lhs, map const& rhs) { return lhs.base() != rhs.base(); } #if defined(ROTGEN_ENABLE_EXPRESSION_TEMPLATES) template auto operator+(map const& lhs, map const& rhs) { return lhs.base() + rhs.base(); } template auto operator-(map const& lhs, map const& rhs) { return lhs.base() - rhs.base(); } template auto operator*(map const& lhs, map const& rhs) { return lhs.base() * rhs.base(); } template auto operator*( map const& lhs, std::convertible_to auto s) { return lhs.base() * s; } template auto operator*(std::convertible_to auto s, map const& rhs) { return s * rhs.base(); } template auto operator/(map const& lhs, std::convertible_to auto s) { return lhs.base() / s; } #else template typename map::concrete_type operator+(map const& lhs, map const& rhs) { using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() + rhs.base()); } template typename map::concrete_type operator-(map const& lhs, map const& rhs) { using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() - rhs.base()); } template typename map::concrete_type operator*(map const& lhs, map const& rhs) { using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() * rhs.base()); } template typename map::concrete_type operator*( map const& lhs , std::convertible_to auto s ) { using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() * s); } template typename map::concrete_type operator*( std::convertible_to auto s , map const& rhs ) { using concrete_type = typename map::concrete_type; return concrete_type(rhs.base() * s); } template typename map::concrete_type operator/( map const& lhs , std::convertible_to auto s ) { using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() / s); } #endif }