various fixes and adds -> map range test works

This commit is contained in:
Christian Zimmermann 2018-08-20 17:50:04 +02:00
parent 3abdf61c33
commit 9e5c51428a
8 changed files with 211 additions and 68 deletions

View file

@ -63,6 +63,7 @@ namespace MultiArrayTools
struct plus : public StaticFunctionBase<T, plus<T>, T, T> struct plus : public StaticFunctionBase<T, plus<T>, T, T>
{ {
static constexpr bool FISSTATIC = true; static constexpr bool FISSTATIC = true;
using StaticFunctionBase<T, plus<T>, T, T>::apply;
static inline T apply(T a1, T a2) static inline T apply(T a1, T a2)
{ {
@ -74,6 +75,7 @@ namespace MultiArrayTools
struct minus : public StaticFunctionBase<T, minus<T>, T, T> struct minus : public StaticFunctionBase<T, minus<T>, T, T>
{ {
static constexpr bool FISSTATIC = true; static constexpr bool FISSTATIC = true;
using StaticFunctionBase<T, minus<T>, T, T>::apply;
static inline T apply(T a1, T a2) static inline T apply(T a1, T a2)
{ {
@ -85,6 +87,7 @@ namespace MultiArrayTools
struct multiplies : public StaticFunctionBase<T, multiplies<T>, T, T> struct multiplies : public StaticFunctionBase<T, multiplies<T>, T, T>
{ {
static constexpr bool FISSTATIC = true; static constexpr bool FISSTATIC = true;
using StaticFunctionBase<T, multiplies<T>, T, T>::apply;
static inline T apply(T a1, T a2) static inline T apply(T a1, T a2)
{ {
@ -96,6 +99,7 @@ namespace MultiArrayTools
struct divides : public StaticFunctionBase<T, divides<T>, T, T> struct divides : public StaticFunctionBase<T, divides<T>, T, T>
{ {
static constexpr bool FISSTATIC = true; static constexpr bool FISSTATIC = true;
using StaticFunctionBase<T, divides<T>, T, T>::apply;
static inline T apply(T a1, T a2) static inline T apply(T a1, T a2)
{ {

View file

@ -104,6 +104,7 @@ namespace MultiArrayTools
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType; typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
//typedef typename CRange::IndexType IndexType; //typedef typename CRange::IndexType IndexType;
typedef MultiArray<T,SRanges...> MAType; typedef MultiArray<T,SRanges...> MAType;
typedef T value_type;
private: private:
mutable T mVal; mutable T mVal;
@ -116,6 +117,8 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(FunctionalMultiArray); DEFAULT_MEMBERS(FunctionalMultiArray);
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const Function& func); FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const Function& func);
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges); FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges);
FunctionalMultiArray(const typename CRange::Space& space);
FunctionalMultiArray(const typename CRange::Space& space, const Function& func);
virtual const T& operator[](const IndexType& i) const override; virtual const T& operator[](const IndexType& i) const override;
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override; virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
@ -186,6 +189,16 @@ namespace MultiArrayTools
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges) : FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges) :
MultiArrayBase<T,SRanges...>(ranges...) {} MultiArrayBase<T,SRanges...>(ranges...) {}
template <typename T, class Function, class... SRanges>
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const typename CRange::Space& space) :
MultiArrayBase<T,SRanges...>(space) {}
template <typename T, class Function, class... SRanges>
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const typename CRange::Space& space,
const Function& func) :
MultiArrayBase<T,SRanges...>(space), mFunc(func) {}
template <typename T, class Function, class... SRanges> template <typename T, class Function, class... SRanges>
const T& FunctionalMultiArray<T,Function,SRanges...>::operator[](const IndexType& i) const const T& FunctionalMultiArray<T,Function,SRanges...>::operator[](const IndexType& i) const
{ {

View file

@ -29,17 +29,17 @@ namespace MultiArrayTools
template <class MA, class... Indices> template <class MA, class... Indices>
auto mkMapOp(const MA& ma, auto mkMapOp(const MA& ma,
const std::tuple<std::shared_ptr<Indices>...>& itp) const std::tuple<std::shared_ptr<Indices>...>& itp)
-> ConstOperationRoot<typename MA::value_type,typename Indices::RangeType...> -> decltype(PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp))
{ {
return PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp); return PackNum<sizeof...(Indices)-1>::mkMapOp(ma, itp);
} }
template <class MapF, class Expr> template <class MapF, class IndexPack, class Expr>
class OpExpr class OpExpr
{ {
public: public:
typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType; typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType;
typedef typename MapF::IndexPack IndexPack; //typedef typename MapF::IndexPack IndexPack;
static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t LAYER = Expr::LAYER + 1;
static constexpr size_t SIZE = Expr::SIZE; static constexpr size_t SIZE = Expr::SIZE;
@ -82,13 +82,13 @@ namespace MultiArrayTools
std::tuple<typename Indices::MetaType...> > IB; std::tuple<typename Indices::MetaType...> > IB;
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack; typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef std::tuple<typename Indices::MetaType...> MetaType; typedef std::tuple<typename Indices::MetaType...> MetaType;
typedef MapRange<typename Indices::RangeType...> RangeType; typedef MapRange<MapF,typename Indices::RangeType...> RangeType;
typedef MapIndex IType; typedef MapIndex IType;
typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType; typedef SingleIndex<typename MapF::value_type,SpaceType::ANY> OIType;
static constexpr IndexType sType() { return IndexType::MULTI; } static constexpr IndexType sType() { return IndexType::MULTI; }
static constexpr size_t sDim() { return sizeof...(Indices); } static constexpr size_t sDim() { return sizeof...(Indices); }
static constexpr size_t totalDim() { return mkTotalDim<MapF,Indices...>(); } static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
static constexpr SpaceType STYPE = SpaceType::ANY; static constexpr SpaceType STYPE = SpaceType::ANY;
@ -148,23 +148,23 @@ namespace MultiArrayTools
MetaType meta() const; MetaType meta() const;
MapIndex& at(const MetaType& metaPos); MapIndex& at(const MetaType& metaPos);
size_t dim(); size_t dim() const;
bool first(); bool first() const;
bool last(); bool last() const;
std::shared_ptr<RangeType> range(); std::shared_ptr<RangeType> range() const;
template <size_t N> template <size_t N>
auto getPtr() -> decltype( std::get<N>( mIPack ) )&; auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
size_t getStepSize(size_t n); size_t getStepSize(size_t n) const;
std::string id() const; std::string id() const;
void print(size_t offset); void print(size_t offset) const;
template <class Exprs> template <class Exprs>
auto ifor(Exprs exs) const auto ifor(Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor -> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(mIPack, OpExpr<MapF,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ) ); (mIPack, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ) );
/* /*
template <class Exprs> template <class Exprs>
@ -208,12 +208,12 @@ namespace MultiArrayTools
******************/ ******************/
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
class MapRange : public RangeInterface<MapIndex<typename Ranges::IndexType...> > class MapRange : public RangeInterface<MapIndex<MapF,typename Ranges::IndexType...> >
{ {
public: public:
typedef RangeBase RB; typedef RangeBase RB;
typedef std::tuple<std::shared_ptr<Ranges>...> Space; typedef std::tuple<std::shared_ptr<Ranges>...> Space;
typedef MapIndex<typename Ranges::IndexType...> IndexType; typedef MapIndex<MapF,typename Ranges::IndexType...> IndexType;
typedef MapRange RangeType; typedef MapRange RangeType;
typedef SingleRange<typename MapF::value_type,SpaceType::ANY> ORType; typedef SingleRange<typename MapF::value_type,SpaceType::ANY> ORType;
typedef SingleRangeFactory<typename MapF::value_type,SpaceType::ANY> ORFType; typedef SingleRangeFactory<typename MapF::value_type,SpaceType::ANY> ORFType;
@ -230,10 +230,14 @@ namespace MultiArrayTools
Space mSpace; Space mSpace;
const MapF& mMapf; const MapF& mMapf;
std::shared_ptr<ORType> mOutRange; std::shared_ptr<ORType> mOutRange;
MultiArray<size_t,ORType> mMapMult;
private:
void mkOutRange();
public: public:
static const size_t sdim = sizeof...(Ranges); static constexpr size_t sdim = sizeof...(Ranges);
template <size_t N> template <size_t N>
auto get() const -> decltype( *std::get<N>( mSpace ) )&; auto get() const -> decltype( *std::get<N>( mSpace ) )&;
@ -257,6 +261,8 @@ namespace MultiArrayTools
virtual IndexType begin() const final; virtual IndexType begin() const final;
virtual IndexType end() const final; virtual IndexType end() const final;
const MultiArray<size_t,ORType>& mapMultiplicity() const;
template <class... ERanges> template <class... ERanges>
auto cat(const std::shared_ptr<MapRange<ERanges...> >& erange) auto cat(const std::shared_ptr<MapRange<ERanges...> >& erange)
-> std::shared_ptr<MapRange<Ranges...,ERanges...> >; -> std::shared_ptr<MapRange<Ranges...,ERanges...> >;
@ -287,42 +293,44 @@ namespace MultiArrayTools
* OpExpr * * OpExpr *
**************/ **************/
template <class MapF, class Expr> template <class MapF, class IndexPack, class Expr>
OpExpr<MapF,Expr>::OpExpr(const MapF& mapf, const IndexPack& ipack, OpExpr<MapF,IndexPack,Expr>::OpExpr(const MapF& mapf, const IndexPack& ipack,
const std::shared_ptr<OIType> oind, Expr ex) : const std::shared_ptr<OIType> oind, Expr ex) :
mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(ex), mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(ex),
mExt(ex.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr.get() ))), mOp(mkMapOp(mapf, ipack)),
mOp(mapf, ipack) //mExt(ex.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
mExt( mOp.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr) ).extend
( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr) ) ) )
{ {
assert(mIndPtr != nullptr); assert(mIndPtr != nullptr);
//VCHECK(mIndPtr->id()); //VCHECK(mIndPtr->id());
//VCHECK(mIndPtr->max()); //VCHECK(mIndPtr->max());
} }
template <class MapF, class Expr> template <class MapF, class IndexPack, class Expr>
inline void OpExpr<MapF,Expr>::operator()(size_t mlast, inline void OpExpr<MapF,IndexPack,Expr>::operator()(size_t mlast,
ExtType last) const ExtType last) const
{ {
constexpr size_t NEXT = Op::SIZE; constexpr size_t NEXT = Op::SIZE;
const ExtType npos = last; const ExtType npos = last;
const size_t pos = mIndPtr->getMeta( mOp.get( npos ) ); const size_t pos = mIndPtr->posAt( mOp.get( npos ) );
const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos); const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos);
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) ); mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
} }
template <class MapF, class Expr> template <class MapF, class IndexPack, class Expr>
inline void OpExpr<MapF,Expr>::operator()(size_t mlast) const inline void OpExpr<MapF,IndexPack,Expr>::operator()(size_t mlast) const
{ {
const ExtType last; const ExtType last;
constexpr size_t NEXT = Op::SIZE; constexpr size_t NEXT = Op::SIZE;
const ExtType npos = last; const ExtType npos = last;
const size_t pos = mIndPtr->at( mOp.get( npos ) ).pos(); const size_t pos = mIndPtr->posAt( mOp.get( npos ) );
const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos); const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos);
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos )); mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
} }
template <class MapF, class Expr> template <class MapF, class IndexPack, class Expr>
auto OpExpr<MapF,Expr>::rootSteps(std::intptr_t iPtrNum) const auto OpExpr<MapF,IndexPack,Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType -> ExtType
{ {
return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) ); return mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) );
@ -364,7 +372,8 @@ namespace MultiArrayTools
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack); IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
std::get<sizeof...(Indices)>(mBlockSizes) = 1; std::get<sizeof...(Indices)>(mBlockSizes) = 1;
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element! RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element!
mOutIndex = std::dynamic_pointer_cast<OIType>( IB::mRangePtr )->outRange()->begin(); mOutIndex = std::make_shared<OIType>
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
@ -484,26 +493,26 @@ namespace MultiArrayTools
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
size_t MapIndex<MapF,Indices...>::dim() size_t MapIndex<MapF,Indices...>::dim() const
{ {
return sizeof...(Indices); return sizeof...(Indices);
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
bool MapIndex<MapF,Indices...>::first() bool MapIndex<MapF,Indices...>::first() const
{ {
return IB::mPos == 0; return IB::mPos == 0;
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
bool MapIndex<MapF,Indices...>::last() bool MapIndex<MapF,Indices...>::last() const
{ {
return IB::mPos == IB::mMax - 1; return IB::mPos == IB::mMax - 1;
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
std::shared_ptr<typename MapIndex<MapF,Indices...>::RangeType> std::shared_ptr<typename MapIndex<MapF,Indices...>::RangeType>
MapIndex<MapF,Indices...>::range() MapIndex<MapF,Indices...>::range() const
{ {
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr ); return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
} }
@ -516,7 +525,7 @@ namespace MultiArrayTools
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
size_t MapIndex<MapF,Indices...>::getStepSize(size_t n) size_t MapIndex<MapF,Indices...>::getStepSize(size_t n) const
{ {
if(n >= sizeof...(Indices)){ if(n >= sizeof...(Indices)){
assert(0); assert(0);
@ -532,7 +541,7 @@ namespace MultiArrayTools
} }
template <class MapF, class... Indices> template <class MapF, class... Indices>
void MapIndex<MapF,Indices...>::print(size_t offset) void MapIndex<MapF,Indices...>::print(size_t offset) const
{ {
if(offset == 0){ if(offset == 0){
std::cout << " === " << std::endl; std::cout << " === " << std::endl;
@ -546,11 +555,11 @@ namespace MultiArrayTools
template <class MapF, class... Indices> template <class MapF, class... Indices>
template <class Exprs> template <class Exprs>
auto MapIndex<MapF,Indices...>::ifor(Exprs exs) const auto MapIndex<MapF,Indices...>::ifor(Exprs exs) const
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor -> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
(mIPack, OpExpr<MapF,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ) ) (mIPack, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ) )
{ {
return RPackNum<sizeof...(Indices)-1>::mkFor return RPackNum<sizeof...(Indices)-1>::mkForh
(mIPack, OpExpr<MapF,Exprs>( range()->map(), mIPack, mOutIndex, exs ) ); (mIPack, OpExpr<MapF,IndexPack,Exprs>( range()->map(), mIPack, mOutIndex, exs ) );
} }
/* /*
template <class MapF, class... Indices> template <class MapF, class... Indices>
@ -603,7 +612,7 @@ namespace MultiArrayTools
std::vector<std::intptr_t> pv(sizeof...(Ranges)); std::vector<std::intptr_t> pv(sizeof...(Ranges));
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv); RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
pv.push_back( reinterpret_cast<std::intptr_t> pv.push_back( reinterpret_cast<std::intptr_t>
( &std::dynamic_pointer_cast<oType>( mProd ).mMapf ) ); ( &std::dynamic_pointer_cast<oType>( mProd )->mMapf ) );
MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv; MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
out = mProd; out = mProd;
} }
@ -614,15 +623,36 @@ namespace MultiArrayTools
* MapRange * * MapRange *
******************/ ******************/
template <class MapF, class... Ranges>
void MapRange<MapF,Ranges...>::mkOutRange()
{
//FunctionalMultiArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
std::map<typename MapF::value_type,size_t> mult;
for(auto ii = mMapf.begin(); ii.max() != ii.pos(); ++ii) {
mult[mMapf[ii]]++;
}
std::vector<typename MapF::value_type> outmeta(mult.size());
std::vector<size_t> outmult(mult.size());
size_t cnt = 0;
for(auto& x: mult){
outmeta[cnt] = x.first;
outmult[cnt] = x.second;
++cnt;
}
ORFType orf(outmeta);
mOutRange = std::dynamic_pointer_cast<ORType>( orf.create() );
mMapMult = MultiArray<size_t,ORType>( mOutRange, outmult );
}
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
MapRange<MapF,Ranges...>::MapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) : MapRange<MapF,Ranges...>::MapRange(const MapF& mapf, const std::shared_ptr<Ranges>&... rs) :
mSpace(std::make_tuple(rs...)), mSpace(std::make_tuple(rs...)),
mMapf(mapf) mMapf(mapf)
{ {
std::vector<typename MapF::value_type> outmeta; mkOutRange();
// set !!!!
ORFType orf(outmeta);
mOutRange = std::dynamic_pointer_cast<ORType>( orf.create() );
} }
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
@ -630,10 +660,7 @@ namespace MultiArrayTools
mSpace( space ), mSpace( space ),
mMapf(mapf) mMapf(mapf)
{ {
std::vector<typename MapF::value_type> outmeta; mkOutRange();
// set !!!!
ORFType orf(outmeta);
mOutRange = std::dynamic_pointer_cast<ORType>( orf.create() );
} }
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
@ -712,7 +739,7 @@ namespace MultiArrayTools
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::begin() const
{ {
MapIndex<typename Ranges::IndexType...> MapIndex<MapF,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> > i( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ); ( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0; i = 0;
@ -722,13 +749,20 @@ namespace MultiArrayTools
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::end() const typename MapRange<MapF,Ranges...>::IndexType MapRange<MapF,Ranges...>::end() const
{ {
MapIndex<typename Ranges::IndexType...> MapIndex<MapF,typename Ranges::IndexType...>
i( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> > i( std::dynamic_pointer_cast<MapRange<MapF,Ranges...> >
( std::shared_ptr<RangeBase>( RB::mThis )) ); ( std::shared_ptr<RangeBase>( RB::mThis )) );
i = size(); i = size();
return i; return i;
} }
template <class MapF, class... Ranges>
auto MapRange<MapF,Ranges...>::mapMultiplicity() const
-> const MultiArray<size_t,ORType>&
{
return mMapMult;
}
template <class MapF, class... Ranges> template <class MapF, class... Ranges>
template <class... ERanges> template <class... ERanges>
auto MapRange<MapF,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange) auto MapRange<MapF,Ranges...>::cat(const std::shared_ptr<MapRange<ERanges...> >& erange)

View file

@ -63,8 +63,8 @@ namespace MultiArrayTools
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const; operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const;
template <class... MappedRanges> template <class... MappedRanges>
ConstOperationRoot<T,SRanges...> ConstOperationRoot<T,MappedRanges...>
operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const; m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const;
virtual bool isInit() const; virtual bool isInit() const;
@ -111,8 +111,12 @@ namespace MultiArrayTools
virtual OperationRoot<T,SRanges...> operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds); virtual OperationRoot<T,SRanges...> operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds);
template <class... MappedRanges> template <class... MappedRanges>
ConstOperationRoot<T,SRanges...> OperationRoot<T,MappedRanges...>
operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds); m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds);
template <class... MappedRanges>
ConstOperationRoot<T,MappedRanges...>
m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const;
}; };
@ -210,12 +214,12 @@ namespace MultiArrayTools
template <typename T, class... SRanges> template <typename T, class... SRanges>
template <class... MappedRanges> template <class... MappedRanges>
ConstOperationRoot<T,SRanges...> ConstOperationRoot<T,MappedRanges...>
MultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const MultiArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
{ {
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges), static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
"number of mapped ranges must be equal to number of original ranges"); "number of mapped ranges must be equal to number of original ranges");
return (*this)(MapResult(inds)...); // NO !!!!! return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
@ -281,12 +285,22 @@ namespace MultiArrayTools
template <typename T, class... SRanges> template <typename T, class... SRanges>
template <class... MappedRanges> template <class... MappedRanges>
ConstOperationRoot<T,SRanges...> OperationRoot<T,MappedRanges...>
MutableMultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) MutableMultiArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds)
{ {
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges), static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
"number of mapped ranges must be equal to number of original ranges"); "number of mapped ranges must be equal to number of original ranges");
return (*this)(MapResult(inds)...); return OperationRoot<T,MappedRanges...>(*this, inds...);
}
template <typename T, class... SRanges>
template <class... MappedRanges>
ConstOperationRoot<T,MappedRanges...>
MutableMultiArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
{
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
"number of mapped ranges must be equal to number of original ranges");
return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
} }
} // end namespace MultiArrayTools } // end namespace MultiArrayTools

View file

@ -159,7 +159,7 @@ namespace MultiArrayTools
//MultiArrayBase<T,Ranges...> const& mArrayRef; //MultiArrayBase<T,Ranges...> const& mArrayRef;
const T* mDataPtr; const T* mDataPtr;
IndexType mIndex; IndexType mIndex;
std::shared_ptr<MultiArrayBase<T,Ranges...> > mMaPtr; //std::shared_ptr<MultiArrayBase<T,Ranges...> > mMaPtr;
}; };
template <typename T, class Op> template <typename T, class Op>
@ -545,8 +545,8 @@ namespace MultiArrayTools
ConstOperationRoot(std::shared_ptr<MultiArrayBase<T,Ranges...> > maptr, ConstOperationRoot(std::shared_ptr<MultiArrayBase<T,Ranges...> > maptr,
const std::shared_ptr<typename Ranges::IndexType>&... indices) : const std::shared_ptr<typename Ranges::IndexType>&... indices) :
mDataPtr(maptr->data()), mDataPtr(maptr->data()),
mIndex(maptr->begin()), mIndex(maptr->begin())
mMaPtr(maptr) //mMaPtr(maptr)
{ {
mIndex(indices...); mIndex(indices...);
} }

View file

@ -42,7 +42,8 @@ namespace MultiArrayTools
bool mExternControl = false; bool mExternControl = false;
IndexPack mIPack; IndexPack mIPack;
std::array<size_t,sizeof...(Indices)+1> mBlockSizes; std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
const T* mData; const T* mData = nullptr;
//const MultiArrayBase<T,typename Indices::RangeType...>* mMa = nullptr;
std::intptr_t mObjPtrNum; std::intptr_t mObjPtrNum;
public: public:
@ -465,12 +466,14 @@ namespace MultiArrayTools
template <typename T, class... Indices> template <typename T, class... Indices>
const T& ContainerIndex<T,Indices...>::operator*() const const T& ContainerIndex<T,Indices...>::operator*() const
{ {
//return mMa[*this];
return mData[IB::mPos]; return mData[IB::mPos];
} }
template <typename T, class... Indices> template <typename T, class... Indices>
const T* ContainerIndex<T,Indices...>::operator->() const const T* ContainerIndex<T,Indices...>::operator->() const
{ {
//return &mMa[*this];
return &mData[IB::mPos]; return &mData[IB::mPos];
} }

View file

@ -8,7 +8,7 @@
#include <memory> #include <memory>
#include <map> #include <map>
//#include "base_def.h" #include "base_def.h"
//#include "ranges/rpack_num.h" //#include "ranges/rpack_num.h"
#include "ranges/index_base.h" #include "ranges/index_base.h"
#include "ranges/range_base.h" #include "ranges/range_base.h"
@ -57,6 +57,7 @@ namespace MultiArrayTools
U meta() const; U meta() const;
const U* metaPtr() const; const U* metaPtr() const;
SingleIndex& at(const U& metaPos); SingleIndex& at(const U& metaPos);
size_t posAt(const U& metaPos) const;
size_t dim(); // = 1 size_t dim(); // = 1
bool last(); bool last();
@ -258,6 +259,12 @@ namespace MultiArrayTools
return *this; return *this;
} }
template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::posAt(const U& metaPos) const
{
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos );
}
template <typename U, SpaceType TYPE> template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::dim() // = 1 size_t SingleIndex<U,TYPE>::dim() // = 1
{ {
@ -354,7 +361,7 @@ namespace MultiArrayTools
mSpace(space) mSpace(space)
{ {
for(size_t i = 0; i != mSpace.size(); ++i){ for(size_t i = 0; i != mSpace.size(); ++i){
mMSpace[mSpace[i]] = i; mMSpace[mSpace[i]] = i;
} }
} }

View file

@ -155,6 +155,43 @@ namespace {
std::vector<double> v4 = { 1.470, 2.210 }; std::vector<double> v4 = { 1.470, 2.210 };
}; };
class MapTest : public ::testing::Test
{
protected:
typedef SingleRangeFactory<size_t,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef FunctionalMultiArray<size_t,plus<size_t>,SRange,SRange> MapF;
typedef MapRangeFactory<MapF,SRange,SRange> MpRF;
typedef MpRF::oType MpRange;
typedef MpRange::ORType TRange;
MapTest()
{
SRF srf1( { 1, 3, 7, 10 } );
SRF srf2( { 2, 6, 8 } );
sr1ptr = std::dynamic_pointer_cast<SRange>( srf1.create() );
sr2ptr = std::dynamic_pointer_cast<SRange>( srf2.create() );
MapF map(sr1ptr,sr2ptr);
MpRF mprf1( map, sr1ptr, sr2ptr );
mpr1ptr = std::dynamic_pointer_cast<MpRange>( mprf1.create() );
}
std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<MpRange> mpr1ptr;
std::vector<double> v1 = { -31.71, -77.16, -18.81,
-67.06, 72.31, -54.48,
-50.91, -11.62, -59.57,
-42.53, 80.41, 6.35 };
};
class OpTest_Performance : public ::testing::Test class OpTest_Performance : public ::testing::Test
{ {
protected: protected:
@ -277,6 +314,37 @@ namespace {
} }
}; };
TEST_F(MapTest, Exec1)
{
MultiArray<double,SRange,SRange> ma1(sr1ptr,sr2ptr,v1);
MultiArray<double,MpRange> res(mpr1ptr);
auto ii1 = getIndex( rptr<0>( ma1 ) );
auto ii2 = getIndex( rptr<1>( ma1 ) );
auto jj = getIndex( mpr1ptr );
(*jj)(ii1,ii2);
res(jj) = ma1(ii1,ii2);
MultiArray<double,TRange> form = res.format(mpr1ptr->outRange());
EXPECT_EQ( jj->range()->outRange()->size(), 10 );
EXPECT_EQ( jj->range()->mapMultiplicity().at(9), 3 );
EXPECT_EQ( jj->range()->mapMultiplicity().at(3), 1 );
EXPECT_EQ( form.at(3), -31.71 );
EXPECT_EQ( form.at(7), -77.16 );
EXPECT_EQ( form.at(9), -18.81 + 72.31 -50.91 );
EXPECT_EQ( form.at(5), -67.06 );
EXPECT_EQ( form.at(11), -54.48 );
EXPECT_EQ( form.at(13), -11.62 );
EXPECT_EQ( form.at(15), -59.57 );
EXPECT_EQ( form.at(12), -42.53 );
EXPECT_EQ( form.at(16), 80.41 );
EXPECT_EQ( form.at(18), 6.35 );
}
TEST_F(MetaOp_Test, SimpleCall) TEST_F(MetaOp_Test, SimpleCall)
{ {