commit
71109fa551
13 changed files with 70 additions and 54 deletions
|
|
@ -30,6 +30,7 @@ namespace rotgen
|
|||
static constexpr int RowsAtCompileTime = T::RowsAtCompileTime;
|
||||
static constexpr int ColsAtCompileTime = T::ColsAtCompileTime;
|
||||
static constexpr bool IsVectorAtCompileTime = T::IsVectorAtCompileTime;
|
||||
static constexpr bool is_immutable = T::is_immutable;
|
||||
|
||||
using parent::evaluate;
|
||||
using parent::noalias;
|
||||
|
|
@ -123,11 +124,13 @@ namespace rotgen
|
|||
using parent = map<const T, Options,Stride>;
|
||||
using value_type = typename T::value_type;
|
||||
using rotgen_tag = void;
|
||||
using rotgen_ref_tag = void;
|
||||
|
||||
static constexpr int storage_order = T::storage_order;
|
||||
static constexpr int RowsAtCompileTime = T::RowsAtCompileTime;
|
||||
static constexpr int ColsAtCompileTime = T::ColsAtCompileTime;
|
||||
static constexpr bool IsVectorAtCompileTime = T::IsVectorAtCompileTime;
|
||||
static constexpr bool is_immutable = T::is_immutable;
|
||||
|
||||
using parent::evaluate;
|
||||
using parent::noalias;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ namespace rotgen::detail
|
|||
return false;
|
||||
}();
|
||||
|
||||
template<typename T>
|
||||
using propagate_const = std::conditional_t<T::is_immutable || std::is_const_v<T>, std::add_const_t<T>, T>;
|
||||
|
||||
template<auto M, auto N>
|
||||
inline constexpr auto select_static = (M==rotgen::Dynamic || N==rotgen::Dynamic) ? rotgen::Dynamic : M;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ namespace rotgen
|
|||
static constexpr bool IsRowMajor = (Opts & RowMajor) == RowMajor;
|
||||
static constexpr bool is_defined_static = false;
|
||||
static constexpr bool has_static_storage = false;
|
||||
static constexpr bool is_immutable = false;
|
||||
|
||||
using transposed_type = matrix<value_type,Cols,Rows, storage_order ^ RowMajor>;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#pragma once
|
||||
#include <rotgen/detail/helpers.hpp>
|
||||
|
||||
namespace rotgen
|
||||
{
|
||||
|
|
@ -28,13 +29,10 @@ namespace rotgen
|
|||
auto extract(Entity& e, Index i0, Index j0, Index ni, Index nj)
|
||||
{
|
||||
detail::validate_extract(e,i0,j0,ni,nj);
|
||||
return block<Entity>(e, i0, j0, ni, nj);
|
||||
}
|
||||
template<concepts::entity Entity>
|
||||
auto extract(Entity const& e, Index i0, Index j0, Index ni, Index nj)
|
||||
{
|
||||
detail::validate_extract(e,i0,j0,ni,nj);
|
||||
return block<Entity const>(e, i0, j0, ni, nj);
|
||||
if constexpr(concepts::reference<Entity>)
|
||||
return extract(e.base(), i0, j0, ni, nj);
|
||||
else
|
||||
return block<detail::propagate_const<Entity>>(e, i0, j0, ni, nj);
|
||||
}
|
||||
|
||||
template<Index NI, Index NJ, concepts::entity Entity>
|
||||
|
|
@ -42,7 +40,10 @@ namespace rotgen
|
|||
auto extract(Entity& e, Index i0, Index j0)
|
||||
{
|
||||
detail::validate_extract(e,i0,j0,NI,NJ);
|
||||
return block<Entity,NI,NJ>(e, i0, j0);
|
||||
if constexpr(concepts::reference<Entity>)
|
||||
return extract<NI,NJ>(e.base(), i0, j0);
|
||||
else
|
||||
return block<detail::propagate_const<Entity> ,NI,NJ>(e, i0, j0);
|
||||
}
|
||||
|
||||
template<Index NI, Index NJ, concepts::entity Entity>
|
||||
|
|
@ -50,7 +51,10 @@ namespace rotgen
|
|||
auto extract(Entity& e, Index i0, Index j0, Index ni, Index nj)
|
||||
{
|
||||
detail::validate_extract(e,i0,j0,ni,nj);
|
||||
return block<Entity,NI,NJ>(e, i0, j0, ni, nj);
|
||||
if constexpr(concepts::reference<Entity>)
|
||||
return extract<NI,NJ>(e.base(), i0, j0, ni, nj);
|
||||
else
|
||||
return block<detail::propagate_const<Entity>,NI,NJ>(e, i0, j0, ni, nj);
|
||||
}
|
||||
|
||||
//======================== TOP LEFT CORNER ========================
|
||||
|
|
|
|||
|
|
@ -74,54 +74,31 @@ namespace rotgen
|
|||
static constexpr bool has_static_storage = storage_status<Rows,Cols,Rows,Cols>;
|
||||
|
||||
public:
|
||||
|
||||
block(const block& other) = default;
|
||||
block(block&& other) = default;
|
||||
block& operator=(const block&) = default;
|
||||
block& operator=(block&&) = default;
|
||||
|
||||
// Constructs from regular Ref
|
||||
block(Ref const& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj)
|
||||
requires(is_immutable && !concepts::reference<Ref>)
|
||||
requires(is_immutable)
|
||||
: parent(r.base(),i0,j0,ni,nj)
|
||||
{}
|
||||
|
||||
block(Ref const& r, std::size_t i0, std::size_t j0)
|
||||
requires(Rows != -1 && Cols != -1 && is_immutable && !concepts::reference<Ref>)
|
||||
requires(Rows != -1 && Cols != -1 && is_immutable)
|
||||
: parent(r.base(),i0,j0,Rows,Cols)
|
||||
{}
|
||||
|
||||
block(Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj)
|
||||
requires(!is_immutable && !concepts::reference<Ref>)
|
||||
requires(!is_immutable)
|
||||
: parent(r.base(),i0,j0,ni,nj)
|
||||
{}
|
||||
|
||||
block(Ref& r, std::size_t i0, std::size_t j0)
|
||||
requires(Rows != -1 && Cols != -1 && !is_immutable && !concepts::reference<Ref>)
|
||||
requires(Rows != -1 && Cols != -1 && !is_immutable)
|
||||
: parent(r.base(),i0,j0,Rows,Cols)
|
||||
{}
|
||||
|
||||
// Constructs from rotgen::ref<T>
|
||||
block(Ref const& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj)
|
||||
requires(is_immutable && concepts::reference<Ref>)
|
||||
: parent(r.base().base(),i0,j0,ni,nj)
|
||||
{}
|
||||
|
||||
block(Ref const& r, std::size_t i0, std::size_t j0)
|
||||
requires(Rows != -1 && Cols != -1 && is_immutable && concepts::reference<Ref>)
|
||||
: parent(r.base().base(),i0,j0,Rows,Cols)
|
||||
{}
|
||||
|
||||
block(Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj)
|
||||
requires(!is_immutable && concepts::reference<Ref>)
|
||||
: parent(r.base().base(),i0,j0,ni,nj)
|
||||
{}
|
||||
|
||||
block(Ref& r, std::size_t i0, std::size_t j0)
|
||||
requires(Rows != -1 && Cols != -1 && !is_immutable && concepts::reference<Ref>)
|
||||
: parent(r.base().base(),i0,j0,Rows,Cols)
|
||||
{}
|
||||
|
||||
template<typename B, Index R, Index C, bool I, int FS>
|
||||
block(block<B,R,C,I,FS> const& other) : parent(other.base())
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ namespace rotgen
|
|||
template<typename ET>
|
||||
using as_concrete_type = as_concrete_t<ET, matrix>;
|
||||
|
||||
static constexpr bool is_immutable = false;
|
||||
static constexpr bool is_defined_static = Rows!=-1 && Cols!=-1;
|
||||
static constexpr bool has_static_storage = storage_status<Rows,Cols,MaxRows,MaxCols>;
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ namespace rotgen
|
|||
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(); }
|
||||
auto sum(concepts::entity auto const& arg) { return arg.sum(); }
|
||||
auto sum(auto const& arg) requires requires{ arg.sum(); } { return arg.sum(); }
|
||||
auto prod(concepts::entity auto const& arg) { return arg.prod(); }
|
||||
auto mean(concepts::entity auto const& arg) { return arg.mean(); }
|
||||
|
||||
|
|
|
|||
|
|
@ -25,15 +25,19 @@ namespace rotgen
|
|||
#define USE_CONST
|
||||
#define CONST const
|
||||
#define BASENAME block_const_impl
|
||||
#define BASEMAP map_const_impl
|
||||
#include <rotgen/impl/block_indirect.hpp>
|
||||
#undef BASENAME
|
||||
#undef BASEMAP
|
||||
#undef CONST
|
||||
#undef USE_CONST
|
||||
|
||||
#define CONST
|
||||
#define BASENAME block_impl
|
||||
#define BASEMAP map_impl
|
||||
#include <rotgen/impl/block_indirect.hpp>
|
||||
#undef BASENAME
|
||||
#undef BASEMAP
|
||||
#undef CONST
|
||||
|
||||
template<typename Scalar,int Options, bool isConst> struct find_block_impl;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row)
|
||||
#include <rotgen/impl/block_model.hpp>
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
|
|||
|
|
@ -16,14 +16,18 @@ namespace rotgen
|
|||
#define USE_CONST
|
||||
#define CONST const
|
||||
#define BASENAME block_const_impl
|
||||
#define BASEMAP map_const_impl
|
||||
#include "block_indirect.cpp"
|
||||
#undef BASENAME
|
||||
#undef BASEMAP
|
||||
#undef USE_CONST
|
||||
#undef CONST
|
||||
|
||||
#define CONST
|
||||
#define BASENAME block_impl
|
||||
#define BASEMAP map_impl
|
||||
#include "block_indirect.cpp"
|
||||
#undef BASENAME
|
||||
#undef BASEMAP
|
||||
#undef CONST
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col)
|
||||
#include "block_model.cpp"
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row)
|
||||
#include "block_model.cpp"
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col)
|
||||
#include "block_model.cpp"
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row)
|
||||
#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row)
|
||||
#define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(map_impl,SIZE,_row)
|
||||
#define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row)
|
||||
#include "block_model.cpp"
|
||||
#undef CLASSNAME
|
||||
#undef TRANSSOURCENAME
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct CLASSNAME::payload
|
|||
using matrix_type = Eigen::Matrix<TYPE,Eigen::Dynamic,Eigen::Dynamic,STORAGE_ORDER>;
|
||||
using matrix_block_type = Eigen::Block<matrix_type CONST>;
|
||||
using matrix_storage_t = std::pair<matrix_block_type, matrix_type CONST*>;
|
||||
using map_type = Eigen::Map<matrix_type,Eigen::Unaligned,stride_type>;
|
||||
using map_type = Eigen::Map<matrix_type CONST,Eigen::Unaligned,stride_type>;
|
||||
using map_block_type = Eigen::Block<map_type CONST>;
|
||||
using map_storage_t = std::pair<map_block_type, map_type CONST*>;
|
||||
using data_type = std::variant<matrix_storage_t, map_storage_t>;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ TTS_CASE_TPL("Chains of extraction", rotgen::tests::types)
|
|||
auto b = topLeftCorner(a,5,5);
|
||||
TTS_EQUAL(b.startRow(), 0);
|
||||
TTS_EQUAL(b.startCol(), 0);
|
||||
b.setConstant(-7);
|
||||
setConstant(b,-7);
|
||||
|
||||
for(rotgen::Index r=0;r<5;r++)
|
||||
for(rotgen::Index c=0;c<5;c++)
|
||||
|
|
@ -26,7 +26,7 @@ TTS_CASE_TPL("Chains of extraction", rotgen::tests::types)
|
|||
auto bb = bottomRightCorner(b,3,3);
|
||||
TTS_EQUAL(bb.startRow(), 2);
|
||||
TTS_EQUAL(bb.startCol(), 2);
|
||||
bb.setConstant(42);
|
||||
setConstant(bb,42);
|
||||
|
||||
for(rotgen::Index r=2;r<5;r++)
|
||||
for(rotgen::Index c=2;c<5;c++)
|
||||
|
|
@ -35,7 +35,7 @@ TTS_CASE_TPL("Chains of extraction", rotgen::tests::types)
|
|||
auto bbb = row(bb,1);
|
||||
TTS_EQUAL(bbb.startRow(), 1);
|
||||
TTS_EQUAL(bbb.startCol(), 0);
|
||||
bbb.setConstant(99.5);
|
||||
setConstant(bbb,99.5);
|
||||
|
||||
for(rotgen::Index c=3;c<5;c++)
|
||||
TTS_EQUAL(a(3,c), 99.5);
|
||||
|
|
@ -43,9 +43,28 @@ TTS_CASE_TPL("Chains of extraction", rotgen::tests::types)
|
|||
auto bbbb = col(bbb,1);
|
||||
TTS_EQUAL(bbbb.startRow(), 0);
|
||||
TTS_EQUAL(bbbb.startCol(), 1);
|
||||
bbbb.setConstant(0.125);
|
||||
setConstant(bbbb,0.125);
|
||||
|
||||
TTS_EQUAL(a(3,3), 0.125);
|
||||
|
||||
std::cout << "a: \n" << a << std::endl;
|
||||
};
|
||||
|
||||
auto ref_extract ( rotgen::ref<rotgen::matrix<float> > m) { return rotgen::extract(m,0,0,3,4); }
|
||||
auto ref_cextract( rotgen::ref<const rotgen::matrix<float> > m) { return rotgen::extract(m,3,4,4,3); }
|
||||
|
||||
TTS_CASE("Extraction of ref/ref const")
|
||||
{
|
||||
auto m = rotgen::setRandom<rotgen::matrix<float,7,7>>();
|
||||
|
||||
auto extracted = ref_extract(m);
|
||||
extracted = rotgen::setOnes<rotgen::matrix<float,3,4>>();
|
||||
|
||||
for(rotgen::Index r=0;r<3;r++)
|
||||
for(rotgen::Index c=0;c<4;c++)
|
||||
TTS_EQUAL(m(r,c), 1.f);
|
||||
|
||||
auto sliced = ref_cextract(m);
|
||||
rotgen::extract(m,3,4,4,3) = rotgen::setConstant<rotgen::matrix<float,4,3>>(5);
|
||||
for(rotgen::Index r=0;r<4;r++)
|
||||
for(rotgen::Index c=0;c<3;c++)
|
||||
TTS_EQUAL(sliced(r,c), 5.f);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue