im com (while extending anonymous range)
This commit is contained in:
parent
370a5c52ad
commit
0d951f892a
3 changed files with 90 additions and 7 deletions
|
@ -4,6 +4,7 @@
|
||||||
#define __anonymous_range_h__
|
#define __anonymous_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <map>
|
||||||
//#include "base_def.h"
|
//#include "base_def.h"
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "ranges/rpheader.h"
|
#include "ranges/rpheader.h"
|
||||||
|
@ -13,6 +14,10 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
typedef SingleIndex<size_t,SpaceType::NONE> AnonymousIndex;
|
typedef SingleIndex<size_t,SpaceType::NONE> AnonymousIndex;
|
||||||
|
|
||||||
|
template <class R>
|
||||||
|
using SIZET = size_t;
|
||||||
|
|
||||||
|
// NOT THREAD SAVE!!
|
||||||
class AnonymousRangeFactory : public RangeFactoryBase
|
class AnonymousRangeFactory : public RangeFactoryBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -32,6 +37,10 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> create();
|
std::shared_ptr<RangeBase> create();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec);
|
||||||
|
|
||||||
|
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AnonymousRange : public RangeInterface<AnonymousIndex>
|
class AnonymousRange : public RangeInterface<AnonymousIndex>
|
||||||
|
@ -61,7 +70,7 @@ namespace MultiArrayTools
|
||||||
std::shared_ptr<Range> fullsub(size_t num) const;
|
std::shared_ptr<Range> fullsub(size_t num) const;
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
MultiRange<Ranges...> scast() const; // save cast
|
MultiRange<Ranges...> scast(SIZET<Ranges>... sizes) const; // save cast
|
||||||
|
|
||||||
friend AnonymousRangeFactory;
|
friend AnonymousRangeFactory;
|
||||||
|
|
||||||
|
@ -131,8 +140,8 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
auto rst = std::make_tuple(origs...);
|
auto rst = std::make_tuple(origs...);
|
||||||
mOrig.resize(sizeof...(RangeTypes));
|
mOrig.resize(sizeof...(RangeTypes));
|
||||||
//RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
||||||
//RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Range>
|
template <class Range>
|
||||||
|
@ -142,9 +151,12 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
MultiRange<Ranges...> AnonymousRange::scast() const
|
MultiRange<Ranges...> AnonymousRange::scast(SIZET<Ranges>... sizes) const
|
||||||
{
|
{
|
||||||
// !!!!!!
|
std::tuple<Ranges...> rtp;
|
||||||
|
RPackNum<sizeof...(Ranges)-1>::resolveRangeType(mOrig, rtp, mOrig.size()-1, sizes...);
|
||||||
|
MultiRangeFactory<Ranges> mrf(rtp);
|
||||||
|
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf->create() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
|
|
|
@ -39,6 +39,26 @@ namespace MultiArrayHelper
|
||||||
template <class Index>
|
template <class Index>
|
||||||
inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
void resolveSetRange(std::shared_ptr<Range> rp, std::vector<std::shared_ptr<RangeBase> > orig,
|
||||||
|
size_t origpos, size_t size)
|
||||||
|
{
|
||||||
|
assert(size == 1);
|
||||||
|
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange> rp,
|
||||||
|
std::vector<std::shared_ptr<RangeBase> > orig,
|
||||||
|
size_t origpos, size_t size)
|
||||||
|
{
|
||||||
|
AnonymousRangeFactory arf;
|
||||||
|
for(size_t op = origpos - size + 1; op != origpos + 1; ++op){
|
||||||
|
arf.append(orig[op]);
|
||||||
|
}
|
||||||
|
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
||||||
|
}
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct RPackNum
|
struct RPackNum
|
||||||
{
|
{
|
||||||
|
@ -254,6 +274,16 @@ namespace MultiArrayHelper
|
||||||
sx *= max;
|
sx *= max;
|
||||||
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
|
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class RangeTuple, typename... SIZET>
|
||||||
|
static void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> > orig,
|
||||||
|
const RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
|
||||||
|
{
|
||||||
|
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||||
|
typedef decltype(std::get<tps-N-1>(rtp)) RangeType;
|
||||||
|
resolveSetRange(std::get<tps-N-1>(rtp), orig, off, size);
|
||||||
|
RPackNum<N-1>::resolveRangeType(orig, rtp, off-size, sizes...);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -433,6 +463,15 @@ namespace MultiArrayHelper
|
||||||
sx *= max;
|
sx *= max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class RangeTuple, typename... SIZET>
|
||||||
|
static void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> > orig,
|
||||||
|
const RangeTuple& rtp, size_t off, size_t size)
|
||||||
|
{
|
||||||
|
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||||
|
typedef decltype(std::get<tps-1>(rtp)) RangeType;
|
||||||
|
resolveSetRange(std::get<tps-1>(rtp), orig, off, size);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <IndexType IT>
|
template <IndexType IT>
|
||||||
|
|
|
@ -7,9 +7,41 @@ namespace MultiArrayTools
|
||||||
* AnonymousRangeFactory *
|
* AnonymousRangeFactory *
|
||||||
******************************/
|
******************************/
|
||||||
|
|
||||||
|
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec)
|
||||||
|
{
|
||||||
|
std::shared_ptr<RangeBase> out;
|
||||||
|
bool check = false;
|
||||||
|
for(auto& x: mAleadyCreated){
|
||||||
|
if(x.second.size() == pvec.size()){
|
||||||
|
check = true;
|
||||||
|
for(size_t i = 0; i != x.size(); ++i){
|
||||||
|
if(x.second[i] != static_cast<std::intptr_t>( pvec[i].get() ) ){
|
||||||
|
check = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(check == true){
|
||||||
|
out = x.first;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(not check){
|
||||||
|
std::vector<std::intptr_t> app(pvec.size());
|
||||||
|
for(size_t i = 0; i != app.size(); ++i){
|
||||||
|
app[i] = static_cast<std::intptr_t>( pvec[i].get() );
|
||||||
|
}
|
||||||
|
mAleadyCreated[mProd] = app;
|
||||||
|
out = mProd;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
|
std::shared_ptr<RangeBase> AnonymousRangeFactory::create()
|
||||||
{
|
{
|
||||||
//setSelf();
|
mProd = checkIfCreated();
|
||||||
|
setSelf();
|
||||||
return mProd;
|
return mProd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue