fixes + anonymous slice option

This commit is contained in:
Christian Zimmermann 2018-08-06 15:20:06 +02:00
parent 86dc006b6f
commit 5ae28f9504
5 changed files with 26 additions and 16 deletions

View file

@ -124,7 +124,7 @@ namespace MultiArrayTools
virtual bool isConst() const override; virtual bool isConst() const override;
virtual bool isSlice() const override; virtual bool isSlice() const override;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous() const override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
// EVALUTAION CLASS ??!!!! // EVALUTAION CLASS ??!!!!
@ -219,7 +219,7 @@ namespace MultiArrayTools
} }
template <typename T, class Function, class... SRanges> template <typename T, class Function, class... SRanges>
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > FunctionalMultiArray<T,Function,SRanges...>::anonymous() const std::shared_ptr<MultiArrayBase<T,AnonymousRange> > FunctionalMultiArray<T,Function,SRanges...>::anonymous(bool slice) const
{ {
assert(0); // think about it carefully assert(0); // think about it carefully
return nullptr; return nullptr;

View file

@ -60,6 +60,9 @@ namespace MultiArrayTools
template <typename T, class... SRanges> template <typename T, class... SRanges>
class Slice; class Slice;
template <typename T, class... SRanges>
class ConstSlice;
// slice.h // slice.h
template <typename T, class... SRanges> template <typename T, class... SRanges>
class SliceDef; class SliceDef;

View file

@ -42,7 +42,7 @@ namespace MultiArrayTools
MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec); MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec);
MultiArray(const typename CRange::Space& space); MultiArray(const typename CRange::Space& space);
MultiArray(const typename CRange::Space& space, std::vector<T>&& vec); MultiArray(const typename CRange::Space& space, std::vector<T>&& vec);
MultiArray(MultiArray<T,AnonymousRange>& ama, SIZET<SRanges>... sizes); MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes);
// Only if ALL ranges have default extensions: // Only if ALL ranges have default extensions:
//MultiArray(const std::vector<T>& vec); //MultiArray(const std::vector<T>& vec);
@ -73,7 +73,7 @@ namespace MultiArrayTools
virtual std::vector<T>& vdata() { return mCont; } virtual std::vector<T>& vdata() { return mCont; }
virtual const std::vector<T>& vdata() const { return mCont; } virtual const std::vector<T>& vdata() const { return mCont; }
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous() const override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
auto cat() const auto cat() const
@ -202,7 +202,7 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
MultiArray<T,SRanges...>::MultiArray(MultiArray<T,AnonymousRange>& ama, SIZET<SRanges>... sizes) : MultiArray<T,SRanges...>::MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes) :
MutableMultiArrayBase<T,SRanges...> MutableMultiArrayBase<T,SRanges...>
( ama.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ), ( ama.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
mCont( std::move( ama.mCont ) ) mCont( std::move( ama.mCont ) )
@ -296,12 +296,19 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > MultiArray<T,SRanges...>::anonymous() const std::shared_ptr<MultiArrayBase<T,AnonymousRange> > MultiArray<T,SRanges...>::anonymous(bool slice) const
{ {
AnonymousRangeFactory arf(MAB::mRange->space()); AnonymousRangeFactory arf(MAB::mRange->space());
return std::make_shared<MultiArray<T,AnonymousRange> > if(slice){
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ), return std::make_shared<ConstSlice<T,AnonymousRange> >
mCont ); ( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
data() );
}
else {
return std::make_shared<MultiArray<T,AnonymousRange> >
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
mCont );
}
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>

View file

@ -57,7 +57,7 @@ namespace MultiArrayTools
virtual bool isConst() const; virtual bool isConst() const;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous() const = 0; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const = 0;
virtual ConstOperationRoot<T,SRanges...> virtual ConstOperationRoot<T,SRanges...>
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const; operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const;

View file

@ -19,7 +19,7 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(ConstSlice); DEFAULT_MEMBERS(ConstSlice);
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr); ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
ConstSlice(const MultiArray<T,AnonymousRange>& ma, SIZET<SRanges>... sizes); ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes);
virtual const T& operator[](const IType& i) const override; virtual const T& operator[](const IType& i) const override;
virtual const T& at(const typename IType::MetaType& meta) const override; virtual const T& at(const typename IType::MetaType& meta) const override;
@ -31,7 +31,7 @@ namespace MultiArrayTools
virtual auto begin() const -> IType override; virtual auto begin() const -> IType override;
virtual auto end() const -> IType override; virtual auto end() const -> IType override;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous() const override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds) auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
-> SliceDef<T,SRanges...>; -> SliceDef<T,SRanges...>;
@ -71,7 +71,7 @@ namespace MultiArrayTools
virtual auto begin() const -> IType override; virtual auto begin() const -> IType override;
virtual auto end() const -> IType override; virtual auto end() const -> IType override;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous() const override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds) auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
@ -137,7 +137,7 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
ConstSlice<T,SRanges...>::ConstSlice(const MultiArray<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) : ConstSlice<T,SRanges...>::ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) :
MultiArrayBase<T,SRanges...> MultiArrayBase<T,SRanges...>
( ma.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ), ( ma.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
mData( ma.data() ) mData( ma.data() )
@ -192,7 +192,7 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > ConstSlice<T,SRanges...>::anonymous() const std::shared_ptr<MultiArrayBase<T,AnonymousRange> > ConstSlice<T,SRanges...>::anonymous(bool slice) const
{ {
assert(0); // think about carefully!!!! assert(0); // think about carefully!!!!
return nullptr; return nullptr;
@ -290,7 +290,7 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymous() const std::shared_ptr<MultiArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymous(bool slice) const
{ {
assert(0); // think about carefully!!!! assert(0); // think about carefully!!!!
return nullptr; return nullptr;