map utils
This commit is contained in:
parent
9c5c361fde
commit
9229ead298
2 changed files with 42 additions and 3 deletions
|
@ -26,6 +26,15 @@ namespace MultiArrayTools
|
||||||
auto mkMulti(std::shared_ptr<RangeTypes>... ranges)
|
auto mkMulti(std::shared_ptr<RangeTypes>... ranges)
|
||||||
-> std::shared_ptr<MultiRange<RangeTypes...> >;
|
-> std::shared_ptr<MultiRange<RangeTypes...> >;
|
||||||
|
|
||||||
|
template <class Func, class... RangeTypes>
|
||||||
|
auto mkMapR(const Func& f, std::shared_ptr<RangeTypes>... ranges)
|
||||||
|
-> std::shared_ptr<MapRange<FunctionalMultiArray<typename Func::value_type,Func,RangeTypes...>,
|
||||||
|
RangeTypes...> >;
|
||||||
|
|
||||||
|
template <class Func, class... IndexTypes>
|
||||||
|
auto mkMapI(const Func& f, std::shared_ptr<IndexTypes>... indices)
|
||||||
|
-> decltype( getIndex( mkMapR( f, indices->range()... ) ) );
|
||||||
|
|
||||||
template <class... IndexTypes>
|
template <class... IndexTypes>
|
||||||
auto mkMIndex(std::shared_ptr<IndexTypes>... indices)
|
auto mkMIndex(std::shared_ptr<IndexTypes>... indices)
|
||||||
-> decltype( getIndex( mkMulti( indices.range()... ) ) );
|
-> decltype( getIndex( mkMulti( indices.range()... ) ) );
|
||||||
|
@ -108,6 +117,33 @@ namespace MultiArrayTools
|
||||||
return mi;
|
return mi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Func, class... RangeTypes>
|
||||||
|
auto mkMapR(const std::shared_ptr<Func>& f, std::shared_ptr<RangeTypes>... ranges)
|
||||||
|
-> std::shared_ptr<MapRange<FunctionalMultiArray<typename Func::value_type,Func,RangeTypes...>,
|
||||||
|
RangeTypes...> >
|
||||||
|
{
|
||||||
|
typedef FunctionalMultiArray<typename Func::value_type,Func,RangeTypes...> FMA;
|
||||||
|
std::shared_ptr<MapRangeFactory<FMA,RangeTypes...>> mrfptr;
|
||||||
|
if(Func::FISSTATIC){
|
||||||
|
FMA fma(ranges...);
|
||||||
|
mrfptr = std::make_shared<MapRangeFactory<FMA,RangeTypes...> >( fma, ranges... );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FMA fma(ranges...,f);
|
||||||
|
mrfptr = std::make_shared<MapRangeFactory<FMA,RangeTypes...> >( fma, ranges... );
|
||||||
|
}
|
||||||
|
return std::dynamic_pointer_cast<MapRange<FMA,RangeTypes...> >( mrfptr->create() );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Func, class... IndexTypes>
|
||||||
|
auto mkMapI(const std::shared_ptr<Func>& f, std::shared_ptr<IndexTypes>... indices)
|
||||||
|
-> decltype( getIndex( mkMapR( f, indices->range()... ) ) )
|
||||||
|
{
|
||||||
|
auto mi = getIndex( mkMapR( f, indices->range()... ) );
|
||||||
|
(*mi)(indices...);
|
||||||
|
return mi;
|
||||||
|
}
|
||||||
|
|
||||||
template <class... RangeTypes>
|
template <class... RangeTypes>
|
||||||
auto mkMulti(std::tuple<std::shared_ptr<RangeTypes>...> rangesTuple)
|
auto mkMulti(std::tuple<std::shared_ptr<RangeTypes>...> rangesTuple)
|
||||||
-> MultiRange<RangeTypes...>
|
-> MultiRange<RangeTypes...>
|
||||||
|
|
|
@ -318,13 +318,16 @@ namespace {
|
||||||
TEST_F(MapTest, Exec1)
|
TEST_F(MapTest, Exec1)
|
||||||
{
|
{
|
||||||
MultiArray<double,SRange,SRange> ma1(sr1ptr,sr2ptr,v1);
|
MultiArray<double,SRange,SRange> ma1(sr1ptr,sr2ptr,v1);
|
||||||
MultiArray<double,MpRange> res(mpr1ptr);
|
|
||||||
|
|
||||||
auto ii1 = getIndex( rptr<0>( ma1 ) );
|
auto ii1 = getIndex( rptr<0>( ma1 ) );
|
||||||
auto ii2 = getIndex( rptr<1>( ma1 ) );
|
auto ii2 = getIndex( rptr<1>( ma1 ) );
|
||||||
|
|
||||||
auto jj = getIndex( mpr1ptr );
|
auto mr = mkMapR(std::make_shared<plus<size_t>>(),sr1ptr,sr2ptr);
|
||||||
|
MultiArray<double,MpRange> res(mr);
|
||||||
|
auto jj = getIndex( mr );
|
||||||
(*jj)(ii1,ii2);
|
(*jj)(ii1,ii2);
|
||||||
|
///auto jj = mkMapI( std::make_shared<plus<size_t> >(), ii1, ii1 );
|
||||||
|
|
||||||
res(jj) = ma1(ii1,ii2);
|
res(jj) = ma1(ii1,ii2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue