various fixes
This commit is contained in:
parent
3c72dc98a0
commit
341a70ef06
5 changed files with 76 additions and 20 deletions
|
@ -10,9 +10,9 @@ namespace MultiArrayTools
|
|||
{
|
||||
template <class F, class Tuple, typename... As>
|
||||
static inline auto mk(const Tuple& tp, As... as)
|
||||
-> decltype(ArgPack<N-1>::mk(tp, std::get<N>(tp), as...))
|
||||
-> decltype(ArgPack<N-1>::template mk<F,Tuple,decltype(std::get<N>(tp)),As...>(tp, std::get<N>(tp), as...))
|
||||
{
|
||||
return ArgPack<N-1>::mk(tp, std::get<N>(tp), as...);
|
||||
return ArgPack<N-1>::template mk<F,Tuple,decltype(std::get<N>(tp)),As...>(tp, std::get<N>(tp), as...);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -8,9 +8,38 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <bool HASMETACONT>
|
||||
struct ToMAObject
|
||||
{
|
||||
template <class Index>
|
||||
static auto mk(const std::shared_ptr<Index>& i)
|
||||
-> MultiArray<typename Index::MetaType, typename Index::RangeType>
|
||||
{
|
||||
std::vector<typename Index::MetaType> vv(i->range()->size());
|
||||
for(Index j = (*i); j.pos() != j.max(); ++j){
|
||||
vv[j.pos()] = j.meta();
|
||||
}
|
||||
return MultiArray<typename Index::MetaType, typename Index::RangeType>( i->range(), std::move( vv ) );
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ToMAObject<true>
|
||||
{
|
||||
template <class Index>
|
||||
static auto mk(const std::shared_ptr<Index>& i)
|
||||
-> ConstSlice<typename Index::MetaType, typename Index::RangeType>
|
||||
{
|
||||
return ConstSlice<typename Index::MetaType, typename Index::RangeType>( i->range(), i->metaPtr() );
|
||||
}
|
||||
};
|
||||
|
||||
template <class Index>
|
||||
auto indexToSlice(const std::shared_ptr<Index>& i)
|
||||
-> ConstSlice<typename Index::MetaType,typename Index::RangeType>;
|
||||
auto mkMAObject(const std::shared_ptr<Index>& i)
|
||||
-> decltype(ToMAObject<Index::RangeType::HASMETACONT>::mk(i))
|
||||
{
|
||||
return ToMAObject<Index::RangeType::HASMETACONT>::mk(i);
|
||||
}
|
||||
|
||||
|
||||
template <typename T, class Function, class... SRanges>
|
||||
|
@ -49,7 +78,7 @@ namespace MultiArrayTools
|
|||
// EVALUTAION CLASS ??!!!!
|
||||
|
||||
auto exec(std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||
-> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( indexToSlice( inds ), inds) ... ) );
|
||||
-> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds) ... ) );
|
||||
|
||||
virtual ConstOperationRoot<T,SRanges...>
|
||||
operator()(std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
||||
|
@ -66,13 +95,6 @@ namespace MultiArrayTools
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class Index>
|
||||
auto indexToSlice(const std::shared_ptr<Index>& i)
|
||||
-> ConstSlice<typename Index::MetaType, typename Index::RangeType>
|
||||
{
|
||||
return ConstSlice<typename Index::MetaType, typename Index::RangeType>( i->range(), i->metaPtr() );
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
* FunctionalMultiArray *
|
||||
|
@ -166,9 +188,9 @@ namespace MultiArrayTools
|
|||
template <typename T, class Function, class... SRanges>
|
||||
auto FunctionalMultiArray<T,Function,SRanges...>::
|
||||
exec(std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||
-> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( indexToSlice( inds ), inds) ... ) )
|
||||
-> decltype( mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds) ... ) )
|
||||
{
|
||||
return mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( indexToSlice( inds ), inds ) ... );
|
||||
return mkOperation( mFunc, ConstOperationRoot<typename SRanges::IndexType::MetaType,SRanges>( mkMAObject( inds ), inds ) ... );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace MultiArrayTools
|
|||
|
||||
DEFAULT_MEMBERS(MultiArray);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, const T& val);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, const std::vector<T>& vec);
|
||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec);
|
||||
MultiArray(const typename CRange::SpaceType& space);
|
||||
|
@ -170,6 +171,14 @@ namespace MultiArrayTools
|
|||
MAB::mInit = true;
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const T& val) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
mCont(MAB::mRange->size(), val)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const std::vector<T>& vec) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
|
@ -352,7 +361,8 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
MultiArray<T,SRanges...>::operator T() const
|
||||
{
|
||||
static_assert( sizeof...(SRanges) == 0, "try to cast non-scalar type into scalar" );
|
||||
static_assert( sizeof...(SRanges) == 1, "try to cast non-scalar type into scalar" );
|
||||
// TODO: check that SIZE is statically = 1 !!!
|
||||
return mCont[0];
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ namespace MultiArrayTools
|
|||
{
|
||||
typedef SingleIndex<size_t,SpaceType::NUL> NullIndex;
|
||||
|
||||
std::shared_ptr<SingleRange<size_t,SpaceType::NUL> > nullr();
|
||||
std::shared_ptr<NullIndex> nulli();
|
||||
|
||||
template <>
|
||||
class SingleRangeFactory<size_t,SpaceType::NUL> : public RangeFactoryBase
|
||||
{
|
||||
|
@ -24,6 +27,10 @@ namespace MultiArrayTools
|
|||
SingleRangeFactory();
|
||||
std::shared_ptr<RangeBase> create();
|
||||
|
||||
friend std::shared_ptr<oType> nullr();
|
||||
|
||||
private:
|
||||
static std::shared_ptr<oType> mRInstance;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
|
|
@ -7,12 +7,29 @@ namespace MultiArrayTools
|
|||
* SingleRange *
|
||||
********************/
|
||||
|
||||
std::shared_ptr<NullRange> nullr()
|
||||
{
|
||||
return SingleRangeFactory<size_t,SpaceType::NUL>::mRInstance;
|
||||
}
|
||||
|
||||
std::shared_ptr<NullIndex> nulli()
|
||||
{
|
||||
return std::make_shared<NullIndex>(nullr());
|
||||
}
|
||||
|
||||
std::shared_ptr<SingleRange<size_t,SpaceType::NUL>>
|
||||
SingleRangeFactory<size_t,SpaceType::NUL>::mRInstance = nullptr;
|
||||
|
||||
SingleRangeFactory<size_t,SpaceType::NUL>::SingleRangeFactory()
|
||||
{
|
||||
// Quasi Singleton
|
||||
if(not mProd){
|
||||
mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::NUL>() );
|
||||
setSelf();
|
||||
// Singleton
|
||||
if( not mRInstance){
|
||||
if(not mProd){
|
||||
mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::NUL>() );
|
||||
setSelf();
|
||||
}
|
||||
} else {
|
||||
mProd = mRInstance;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue