commit
bb5d739e5d
9 changed files with 181 additions and 2 deletions
|
|
@ -27,6 +27,8 @@ namespace rotgen
|
||||||
|
|
||||||
static constexpr int storage_order = T::storage_order;
|
static constexpr int storage_order = T::storage_order;
|
||||||
|
|
||||||
|
using parent::evaluate;
|
||||||
|
using parent::noalias;
|
||||||
using parent::operator();
|
using parent::operator();
|
||||||
using parent::rows;
|
using parent::rows;
|
||||||
using parent::cols;
|
using parent::cols;
|
||||||
|
|
@ -99,6 +101,8 @@ namespace rotgen
|
||||||
|
|
||||||
static constexpr int storage_order = T::storage_order;
|
static constexpr int storage_order = T::storage_order;
|
||||||
|
|
||||||
|
using parent::evaluate;
|
||||||
|
using parent::noalias;
|
||||||
using parent::operator();
|
using parent::operator();
|
||||||
using parent::rows;
|
using parent::rows;
|
||||||
using parent::cols;
|
using parent::cols;
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,10 @@ namespace rotgen
|
||||||
return parent::operator()(i);
|
return parent::operator()(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto evaluate() const { return *this; }
|
||||||
|
decltype(auto) noalias() const { return *this; }
|
||||||
|
decltype(auto) noalias() { return *this; }
|
||||||
|
|
||||||
concrete_type transpose() const
|
concrete_type transpose() const
|
||||||
{
|
{
|
||||||
return concrete_type(static_cast<parent const &>(*this).transpose());
|
return concrete_type(static_cast<parent const &>(*this).transpose());
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,16 @@ namespace rotgen
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
map& operator=(concepts::entity auto const& other) requires(!is_immutable)
|
||||||
|
{
|
||||||
|
assert(parent::rows() == other.rows() && parent::cols() == other.cols());
|
||||||
|
for (rotgen::Index r = 0; r < parent::rows(); ++r)
|
||||||
|
for (rotgen::Index c = 0; c < parent::cols(); ++c)
|
||||||
|
(*this)(r, c) = other(r, c);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
value_type& operator()(Index i, Index j) requires(!is_immutable) { return parent::operator()(i,j); }
|
value_type& operator()(Index i, Index j) requires(!is_immutable) { return parent::operator()(i,j); }
|
||||||
value_type& operator()(Index i) requires(!is_immutable)
|
value_type& operator()(Index i) requires(!is_immutable)
|
||||||
{
|
{
|
||||||
|
|
@ -90,6 +100,10 @@ namespace rotgen
|
||||||
return parent::operator()(i);
|
return parent::operator()(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto evaluate() const { return *this; }
|
||||||
|
decltype(auto) noalias() const { return *this; }
|
||||||
|
decltype(auto) noalias() { return *this; }
|
||||||
|
|
||||||
concrete_type transpose() const
|
concrete_type transpose() const
|
||||||
{
|
{
|
||||||
return concrete_type(static_cast<parent const &>(*this).transpose());
|
return concrete_type(static_cast<parent const &>(*this).transpose());
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,23 @@ namespace rotgen
|
||||||
(*this)(r, c) = e(r, c);
|
(*this)(r, c) = e(r, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matrix& operator=(concepts::entity auto const& e)
|
||||||
|
{
|
||||||
|
if constexpr(Rows != -1) assert(e.rows() == Rows && "Mismatched between dynamic and static row size");
|
||||||
|
if constexpr(Cols != -1) assert(e.cols() == Cols && "Mismatched between dynamic and static col size");
|
||||||
|
resize(e.rows(), e.cols());
|
||||||
|
|
||||||
|
for (rotgen::Index r = 0; r < e.rows(); ++r)
|
||||||
|
for (rotgen::Index c = 0; c < e.cols(); ++c)
|
||||||
|
(*this)(r, c) = e(r, c);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto evaluate() const { return *this; }
|
||||||
|
decltype(auto) noalias() const { return *this; }
|
||||||
|
decltype(auto) noalias() { return *this; }
|
||||||
|
|
||||||
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1)
|
||||||
{
|
{
|
||||||
parent::resize(new_rows, new_cols);
|
parent::resize(new_rows, new_cols);
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,15 @@ namespace rotgen
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
block(const Eigen::EigenBase<OtherDerived>& other) : parent(other) {}
|
block(const Eigen::EigenBase<OtherDerived>& other) : parent(other) {}
|
||||||
|
|
||||||
|
block(concepts::entity auto const& other) : parent(other.base())
|
||||||
|
{}
|
||||||
|
|
||||||
|
block& operator=(concepts::entity auto const& other)
|
||||||
|
{
|
||||||
|
parent::operator=(other.base());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
block& operator=(const Eigen::MatrixBase<OtherDerived>& other)
|
block& operator=(const Eigen::MatrixBase<OtherDerived>& other)
|
||||||
{
|
{
|
||||||
|
|
@ -118,6 +127,23 @@ namespace rotgen
|
||||||
parent& base() { return static_cast<parent&>(*this); }
|
parent& base() { return static_cast<parent&>(*this); }
|
||||||
parent const& base() const { return static_cast<const parent&>(*this); }
|
parent const& base() const { return static_cast<const parent&>(*this); }
|
||||||
|
|
||||||
|
auto evaluate() const
|
||||||
|
{
|
||||||
|
auto res = static_cast<parent const &>(*this).eval();
|
||||||
|
return as_concrete_type<decltype(res)>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(auto) noalias() const
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().noalias();
|
||||||
|
else return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(auto) noalias()
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().noalias();
|
||||||
|
else return *this;
|
||||||
|
}
|
||||||
|
|
||||||
auto transpose() const
|
auto transpose() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,36 @@ namespace rotgen
|
||||||
: map( ptr, RowsAtCompileTime, ColsAtCompileTime )
|
: map( ptr, RowsAtCompileTime, ColsAtCompileTime )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
map(concepts::entity auto const& other) : parent(other.base())
|
||||||
|
{}
|
||||||
|
|
||||||
|
map& operator=(concepts::entity auto const& other)
|
||||||
|
{
|
||||||
|
parent::operator=(other.base());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
parent& base() { return static_cast<parent&>(*this); }
|
parent& base() { return static_cast<parent&>(*this); }
|
||||||
parent const& base() const { return static_cast<const parent&>(*this); }
|
parent const& base() const { return static_cast<const parent&>(*this); }
|
||||||
|
|
||||||
|
auto evaluate() const
|
||||||
|
{
|
||||||
|
auto res = static_cast<parent const &>(*this).eval();
|
||||||
|
return as_concrete_type<decltype(res)>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(auto) noalias() const
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().noalias();
|
||||||
|
else return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(auto) noalias()
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().noalias();
|
||||||
|
else return *this;
|
||||||
|
}
|
||||||
|
|
||||||
value_type& operator()(Index i, Index j) { return base()(i, j); }
|
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, Index j) const { return base()(i, j); }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,11 +118,33 @@ namespace rotgen
|
||||||
parent& base() { return static_cast<parent&>(*this); }
|
parent& base() { return static_cast<parent&>(*this); }
|
||||||
parent const& base() const { return static_cast<const parent&>(*this); }
|
parent const& base() const { return static_cast<const parent&>(*this); }
|
||||||
|
|
||||||
|
auto evaluate() const
|
||||||
|
{
|
||||||
|
auto res = static_cast<parent const &>(*this).eval();
|
||||||
|
return as_concrete_type<decltype(res)>(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(auto) noalias() const
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().noalias();
|
||||||
|
else return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
decltype(auto) noalias()
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().noalias();
|
||||||
|
else return *this;
|
||||||
|
}
|
||||||
|
|
||||||
auto transpose() const
|
auto transpose() const
|
||||||
|
{
|
||||||
|
if constexpr(use_expression_templates) return base().transpose();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
auto res = static_cast<parent const &>(*this).transpose();
|
auto res = static_cast<parent const &>(*this).transpose();
|
||||||
return as_concrete_type<decltype(res)>(res);
|
return as_concrete_type<decltype(res)>(res);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto conjugate() const
|
auto conjugate() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -69,4 +69,22 @@ namespace rotgen
|
||||||
static_assert(P == 1 || P == 2 || P == Infinity);
|
static_assert(P == 1 || P == 2 || P == Infinity);
|
||||||
return arg.template lpNorm<P>();
|
return arg.template lpNorm<P>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
decltype(auto) noalias(T&& t) requires( requires{std::forward<T>(t).noalias();} )
|
||||||
|
{
|
||||||
|
return std::forward<T>(t).noalias();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto evaluate(T&& t) requires( requires{std::forward<T>(t).evaluate();} )
|
||||||
|
{
|
||||||
|
return std::forward<T>(t).evaluate();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
auto evaluate(T&& t) requires( requires{std::forward<T>(t).eval();} )
|
||||||
|
{
|
||||||
|
return std::forward<T>(t).eval();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
47
test/integration/aliasing.cpp
Normal file
47
test/integration/aliasing.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
//==================================================================================================
|
||||||
|
/*
|
||||||
|
ROTGEN - Runtime Overlay for Eigen
|
||||||
|
Copyright : CODE RECKONS
|
||||||
|
SPDX-License-Identifier: BSL-1.0
|
||||||
|
*/
|
||||||
|
//==================================================================================================
|
||||||
|
#include "unit/tests.hpp"
|
||||||
|
#include <rotgen/rotgen.hpp>
|
||||||
|
|
||||||
|
TTS_CASE_TPL("noalias behavior - dynamicallly sized", rotgen::tests::types)
|
||||||
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||||
|
{
|
||||||
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a{{1,2},{3,4}};
|
||||||
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> ref{{7,10},{15,22}};
|
||||||
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> b(2,2),c(2,2),d(2,2);
|
||||||
|
|
||||||
|
rotgen::noalias(b) = a * a;
|
||||||
|
TTS_EQUAL(b, ref);
|
||||||
|
|
||||||
|
auto e = rotgen::extract(c,0,0,2,2);
|
||||||
|
rotgen::noalias(e) = a * a;
|
||||||
|
TTS_EQUAL(c, ref);
|
||||||
|
|
||||||
|
rotgen::map<rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> m(d.data(),2,2);
|
||||||
|
rotgen::noalias(m) = a * a;
|
||||||
|
TTS_EQUAL(m, ref);
|
||||||
|
};
|
||||||
|
|
||||||
|
TTS_CASE_TPL("noalias behavior - statically sized", rotgen::tests::types)
|
||||||
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||||
|
{
|
||||||
|
rotgen::matrix<T,2,2,O::value> a{{1,2},{3,4}};
|
||||||
|
rotgen::matrix<T,2,2,O::value> ref{{7,10},{15,22}};
|
||||||
|
rotgen::matrix<T,2,2,O::value> b,c,d;
|
||||||
|
|
||||||
|
rotgen::noalias(b) = a * a;
|
||||||
|
TTS_EQUAL(b, ref);
|
||||||
|
|
||||||
|
auto e = rotgen::extract(c,0,0,2,2);
|
||||||
|
rotgen::noalias(e) = a * a;
|
||||||
|
TTS_EQUAL(c, ref);
|
||||||
|
|
||||||
|
rotgen::map<rotgen::matrix<T,2,2,O::value>> m(d.data());
|
||||||
|
rotgen::noalias(m) = a * a;
|
||||||
|
TTS_EQUAL(m, ref);
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue