some fixes

This commit is contained in:
Christian Zimmermann 2018-08-06 19:20:57 +02:00
parent 5ae28f9504
commit 8ff366d40f
3 changed files with 19 additions and 5 deletions

View file

@ -88,6 +88,8 @@ namespace MultiArrayTools
template <class... Ranges> template <class... Ranges>
std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast
bool isEmpty() const;
friend AnonymousRangeFactory; friend AnonymousRangeFactory;
static AnonymousRangeFactory factory() static AnonymousRangeFactory factory()
@ -105,6 +107,7 @@ namespace MultiArrayTools
SingleRange(std::shared_ptr<RangeTypes>... origs); SingleRange(std::shared_ptr<RangeTypes>... origs);
size_t mSize = 1; size_t mSize = 1;
bool mEmpty = true;
std::vector<std::shared_ptr<RangeBase> > mOrig; std::vector<std::shared_ptr<RangeBase> > mOrig;
}; };
@ -143,6 +146,7 @@ namespace MultiArrayTools
} }
std::dynamic_pointer_cast<oType>(mProd)->mOrig.push_back(r); 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)->mSize *= r->size();
std::dynamic_pointer_cast<oType>(mProd)->mEmpty = false;
} }
/***************** /*****************
@ -162,7 +166,6 @@ namespace MultiArrayHelper
size_t origpos, size_t size) size_t origpos, size_t size)
{ {
AnonymousRangeFactory arf; AnonymousRangeFactory arf;
//VCHECK(size);
for(size_t op = origpos; op != origpos + size; ++op){ for(size_t op = origpos; op != origpos + size; ++op){
//VCHECK(op); //VCHECK(op);
arf.append(orig[op]); arf.append(orig[op]);
@ -174,8 +177,10 @@ namespace MultiArrayHelper
inline void setRangeToVec<AnonymousRange>(std::vector<std::shared_ptr<RangeBase> >& v, inline void setRangeToVec<AnonymousRange>(std::vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<AnonymousRange> r) std::shared_ptr<AnonymousRange> r)
{ {
for(size_t i = 0; i != r->dim(); ++i){ if(not r->isEmpty()){
v.insert(v.begin(), r->sub(i)); for(size_t i = r->anonymousDim(); i != 0; --i){
v.insert(v.begin(), r->sub(i-1));
}
} }
} }
@ -193,6 +198,9 @@ namespace MultiArrayTools
{ {
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig ); RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs ); mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
if(sizeof...(RangeTypes)){
mEmpty = false;
}
} }
template <class... RangeTypes> template <class... RangeTypes>
@ -202,6 +210,9 @@ namespace MultiArrayTools
auto rst = std::make_tuple(origs...); auto rst = std::make_tuple(origs...);
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig ); RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst ); mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
if(sizeof...(RangeTypes)){
mEmpty = false;
}
} }
template <class Range> template <class Range>

View file

@ -60,8 +60,6 @@ namespace MultiArrayHelper
v.insert(v.begin(), r); v.insert(v.begin(), r);
} }
template <size_t N> template <size_t N>
struct RPackNum struct RPackNum
{ {

View file

@ -82,6 +82,11 @@ namespace MultiArrayTools
return SpaceType::ANON; return SpaceType::ANON;
} }
bool AnonymousRange::isEmpty() const
{
return mEmpty;
}
std::string AnonymousRange::stringMeta(size_t pos) const std::string AnonymousRange::stringMeta(size_t pos) const
{ {
std::string out = "[ "; std::string out = "[ ";