dynamic operations: call by index name (not the optimal solution...)
This commit is contained in:
parent
7cbd2a139d
commit
52e1efc974
3 changed files with 77 additions and 3 deletions
|
@ -37,6 +37,20 @@ namespace MultiArrayTools
|
|||
|
||||
|
||||
|
||||
template <class Range>
|
||||
void DynamicRangeFactory::appendx(std::shared_ptr<Range> r)
|
||||
{
|
||||
if(mProductCreated){
|
||||
|
||||
mProd = std::shared_ptr<oType>( new DynamicRange( *std::dynamic_pointer_cast<oType>(mProd) ) );
|
||||
mProductCreated = false;
|
||||
}
|
||||
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r);
|
||||
std::dynamic_pointer_cast<oType>(mProd)->mSize *= r->size();
|
||||
std::dynamic_pointer_cast<oType>(mProd)->mEmpty = false;
|
||||
//std::dynamic_pointer_cast<oType>(mProd)->mProtoI.push_back(mkIndexWrapper(r->begin()));
|
||||
}
|
||||
|
||||
template <class Range>
|
||||
void DynamicRangeFactory::append(std::shared_ptr<Range> r)
|
||||
{
|
||||
|
@ -48,6 +62,7 @@ namespace MultiArrayTools
|
|||
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r);
|
||||
std::dynamic_pointer_cast<oType>(mProd)->mSize *= r->size();
|
||||
std::dynamic_pointer_cast<oType>(mProd)->mEmpty = false;
|
||||
std::dynamic_pointer_cast<oType>(mProd)->mProtoI.push_back(mkIndexWrapper(r->begin()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,12 +153,51 @@ namespace MultiArrayTools
|
|||
* DynamicRange *
|
||||
***********************/
|
||||
|
||||
template <size_t N>
|
||||
struct InitProto
|
||||
{
|
||||
template <class... RangeTypes>
|
||||
static void mk(vector<std::shared_ptr<IndexW>>& proto,
|
||||
const std::tuple<std::shared_ptr<RangeTypes>...>& orig)
|
||||
{
|
||||
proto[N] = mkIndexWrapper(std::get<N>(orig)->begin());
|
||||
InitProto<N-1>::mk(proto, orig);
|
||||
}
|
||||
|
||||
template <class RangeType, class... RangeTypes>
|
||||
static void mk(vector<std::shared_ptr<IndexW>>& proto, size_t n,
|
||||
std::shared_ptr<RangeType> o, std::shared_ptr<RangeTypes>... origs)
|
||||
{
|
||||
proto[n-1-N] = mkIndexWrapper(o->begin());
|
||||
InitProto<N-1>::mk(proto, n, origs...);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InitProto<0>
|
||||
{
|
||||
template <class... RangeTypes>
|
||||
static void mk(vector<std::shared_ptr<IndexW>>& proto,
|
||||
const std::tuple<std::shared_ptr<RangeTypes>...>& orig)
|
||||
{
|
||||
proto[0] = mkIndexWrapper(std::get<0>(orig)->begin());
|
||||
}
|
||||
|
||||
template <class RangeType, class... RangeTypes>
|
||||
static void mk(vector<std::shared_ptr<IndexW>>& proto, size_t n,
|
||||
std::shared_ptr<RangeType> o, std::shared_ptr<RangeTypes>... origs)
|
||||
{
|
||||
proto[n-1] = mkIndexWrapper(o->begin());
|
||||
}
|
||||
};
|
||||
|
||||
template <class... RangeTypes>
|
||||
DynamicRange::DynamicRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
||||
RangeInterface<DynamicIndex>()
|
||||
{
|
||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
|
||||
mProtoI.resize(sizeof...(RangeTypes));
|
||||
InitProto<sizeof...(RangeTypes)-1>::mk(mProtoI, origs);
|
||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
|
||||
if(sizeof...(RangeTypes)){
|
||||
mEmpty = false;
|
||||
|
@ -157,6 +211,8 @@ namespace MultiArrayTools
|
|||
{
|
||||
auto rst = std::make_tuple(origs...);
|
||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
||||
mProtoI.resize(sizeof...(RangeTypes));
|
||||
InitProto<sizeof...(RangeTypes)-1>::mk(mProtoI, sizeof...(RangeTypes), origs...);
|
||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
||||
if(sizeof...(RangeTypes)){
|
||||
mEmpty = false;
|
||||
|
|
|
@ -166,6 +166,12 @@ namespace MultiArrayTools
|
|||
|
||||
};
|
||||
|
||||
template <class Index>
|
||||
std::shared_ptr<IndexWrapperBase> mkIndexWrapper(const Index& i)
|
||||
{
|
||||
return std::make_shared<IndexWrapper<Index>>(std::make_shared<Index>(i));
|
||||
}
|
||||
|
||||
//typedef SingleRange<size_t,SpaceType::DYN> DynamicRange;
|
||||
|
||||
class DynamicIndex : public IndexInterface<DynamicIndex,vector<char>>
|
||||
|
@ -268,6 +274,9 @@ namespace MultiArrayTools
|
|||
template <class Range>
|
||||
void append(std::shared_ptr<Range> r);
|
||||
|
||||
template <class Range>
|
||||
void appendx(std::shared_ptr<Range> r);
|
||||
|
||||
std::shared_ptr<RangeBase> create();
|
||||
|
||||
private:
|
||||
|
@ -287,6 +296,7 @@ namespace MultiArrayTools
|
|||
static constexpr size_t SIZE = -1;
|
||||
static constexpr bool HASMETACONT = false;
|
||||
|
||||
typedef vector<std::shared_ptr<IndexW>> IVecT;
|
||||
typedef RangeBase RB;
|
||||
typedef DynamicIndex IndexType;
|
||||
typedef DynamicRange RangeType;
|
||||
|
@ -309,6 +319,7 @@ namespace MultiArrayTools
|
|||
bool mEmpty = true;
|
||||
|
||||
vector<std::shared_ptr<RangeBase> > mOrig;
|
||||
IVecT mProtoI;
|
||||
|
||||
public:
|
||||
virtual size_t size() const final;
|
||||
|
@ -330,6 +341,7 @@ namespace MultiArrayTools
|
|||
virtual vector<char> data() const final;
|
||||
|
||||
std::shared_ptr<RangeBase> sub(size_t num) const;
|
||||
std::shared_ptr<IndexW> subI(size_t num) const;
|
||||
|
||||
template <class Range>
|
||||
std::shared_ptr<Range> fullsub(size_t num) const;
|
||||
|
@ -364,7 +376,7 @@ namespace MultiArrayHelper
|
|||
DynamicRangeFactory arf;
|
||||
for(size_t op = origpos; op != origpos + size; ++op){
|
||||
//VCHECK(op);
|
||||
arf.append(orig[op]);
|
||||
arf.appendx(orig[op]);
|
||||
}
|
||||
rp = std::dynamic_pointer_cast<DynamicRange>( arf.create() );
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace MultiArrayTools
|
|||
assert(this->range()->sub(i) == sIMap.at(iname)->range());
|
||||
}
|
||||
else {
|
||||
sIMap[iname] = this->range()->sub(i)->aindex();
|
||||
sIMap[iname] = this->range()->subI(i);
|
||||
}
|
||||
mIVec[i].first = sIMap.at(iname);
|
||||
}
|
||||
|
@ -444,6 +444,12 @@ namespace MultiArrayTools
|
|||
return mOrig.at(num);
|
||||
}
|
||||
|
||||
std::shared_ptr<IndexW> DynamicRange::subI(size_t num) const
|
||||
{
|
||||
assert(mProtoI.at(num) != nullptr);
|
||||
return mProtoI.at(num)->duplicate();
|
||||
}
|
||||
|
||||
|
||||
void DynamicRange::sreplace(const std::shared_ptr<RangeBase> in, size_t num)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue