continue Slice implementations

This commit is contained in:
Christian Zimmermann 2017-02-27 17:00:51 +01:00
parent 685023b09c
commit f489d165ab
5 changed files with 92 additions and 34 deletions

View file

@ -90,7 +90,7 @@ namespace MultiArrayTools
class MultiArrayOperation; class MultiArrayOperation;
// slice.h // slice.h
template <typename T, class Range, class MARange, class Index> template <typename T, class Range, class MARange>
class Slice; class Slice;
} }

View file

@ -25,6 +25,28 @@ namespace MultiArrayTools
* MultiArrayOperationBase * * MultiArrayOperationBase *
*********************************/ *********************************/
template <typename T, class Range>
void MultiArrayOperationRoot<T,Range>::performAssignment(const MultiArrayOperationBase<T>& in)
{
in.linkIndicesTo(MAOB::mIibPtr);
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr);
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
// build in vectorization later
get() = in.get();
}
MAOB::mIibPtr->freeLinked();
}
template <typename T, class Range>
template <class RangeX>
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::makeSlice(MultiArrayOperationRoot<T,RangeX>& in)
{
Slice<T,Range,RangeX>& sl = dynamic_cast<Slice<T,Range,RangeX>&>( mArrayRef );
sl.set(in.mArrayRef, name(), &in.index(), in.name());
return *this;
}
template <typename T, class Range> template <typename T, class Range>
MultiArrayOperationRoot<T,Range>:: MultiArrayOperationRoot<T,Range>::
MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma, MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma,
@ -43,21 +65,31 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in) MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in)
{ {
if(mArrayRef.isSlice()){ performAssignment(in);
Slice<T,Range>& sl = dynamic_cast<Slice<T,Range>&>( mArrayRef );
sl.set()
return *this; return *this;
} }
in.linkIndicesTo(MAOB::mIibPtr); template <typename T, class Range>
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr); MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range>& in)
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){ {
// build in vectorization later maketurnSlice(in);
get() = in.get(); if(mArrayRef.isSlice()){
return makeSlice(in);
} }
MAOB::mIibPtr->freeLinked(); performAssignment(in);
return *this;
}
template <typename T, class Range>
template <class Range2>
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range2>& in)
{
if(mArrayRef.isSlice()){
return makeSlice(in);
}
performAssignment(in);
return *this; return *this;
} }
@ -66,16 +98,12 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>& MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in) MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in)
{ {
if(mArrayRef.isSlice()){
// NO SLICE CREATION !!! (total array not initialized!!) // NO SLICE CREATION !!! (total array not initialized!!)
// throw !
in.linkIndicesTo(MAOB::mIibPtr); assert(0);
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr);
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
// build in vectorization later
get() = in.get();
} }
MAOB::mIibPtr->freeLinked(); performAssignment(in);
return *this; return *this;
} }
@ -153,6 +181,12 @@ namespace MultiArrayTools
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]; return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
} }
template <typename T, class Range>
const Name& MultiArrayOperationRoot<T,Range>::name() const
{
return mNm;
}
/***************************** /*****************************
* MultiArrayOperation * * MultiArrayOperation *
*****************************/ *****************************/

View file

@ -42,6 +42,11 @@ namespace MultiArrayTools
MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma, const Name& nm); MultiArrayOperationRoot(MultiArrayBase<T,Range>& ma, const Name& nm);
MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in); MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in);
MultiArrayOperationRoot& operator=(MultiArrayOperationRoot& in);
template <class Range2>
MultiArrayOperationRoot& operator=(MultiArrayOperationRoot<T,Range2>& in);
template <class Operation, class... MAOps> template <class Operation, class... MAOps>
MultiArrayOperationRoot& operator=(const MultiArrayOperation<T,Operation,MAOps...>& in); MultiArrayOperationRoot& operator=(const MultiArrayOperation<T,Operation,MAOps...>& in);
@ -67,15 +72,25 @@ namespace MultiArrayTools
virtual size_t argNum() const override; virtual size_t argNum() const override;
//IndexType& index() ; IndexType& index();
// set index
MultiArrayOperationRoot<T,Range>& operator[](const IndexType& ind);
virtual void linkIndicesTo(IndefinitIndexBase* target) const override; virtual void linkIndicesTo(IndefinitIndexBase* target) const override;
virtual T& get() override; virtual T& get() override;
virtual const T& get() const override; virtual const T& get() const override;
const Name& name() const;
protected: protected:
void performAssignment(const MultiArrayOperationBase<T>& in);
template <class RangeX>
MultiArrayOperationRoot& makeSlice(MultiArrayOperationRoot<T,RangeX>& in);
MultiArrayBase<T,Range>& mArrayRef; MultiArrayBase<T,Range>& mArrayRef;
mutable IndexType mIndex; mutable IndexType mIndex;
Name mNm; Name mNm;

View file

@ -7,8 +7,8 @@ namespace MultiArrayTools
template <typename T, class Range, class MARange> template <typename T, class Range, class MARange>
Slice<T,Range,MARange,Index>:: Slice<T,Range,MARange,Index>::
Slice() : Slice(const Range& range) :
MultiArrayBase<T,Range>(ma.range()), MultiArrayBase<T,Range>(range),
mMultiArrayRef(*this) {} mMultiArrayRef(*this) {}
template <typename T, class Range, class MARange> template <typename T, class Range, class MARange>
@ -18,10 +18,16 @@ namespace MultiArrayTools
} }
template <typename T, class Range, class MARange> template <typename T, class Range, class MARange>
void Slice<T,Range,MARange,Index>::set(MultiArrayBase<T,MARange>& multiArrayRef, IndefinitIndexBase* MAPtr) void Slice<T,Range,MARange,Index>::set(MultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm, // for correct linkage
IndefinitIndexBase* MAPtr, // for desired slice position
const Name& MANm) // for correct linkage)
{ {
mMultiArrayRef = multiArrayRef; mMultiArrayRef = multiArrayRef;
mMAPtr.reset(new typename MARange::IndexType(*MAPtr));
mMAPtr.reset(new typename MARange::IndexType(MAPtr)); mOwnPtr.reset(new typename Range::IndexType());
mMAPtr->name(MANm);
mOwnPtr->name(ownNm);
mMAPtr->linkTo(mOwnPtr);
} }
} }

View file

@ -21,7 +21,7 @@ namespace MultiArrayTools
typedef MultiArrayBase<T,Range> MAB; typedef MultiArrayBase<T,Range> MAB;
Slice(); Slice(const Range& range);
T& operator[](const typename Range::IndexType& i) override; T& operator[](const typename Range::IndexType& i) override;
const T& operator[](const typename Range::IndexType& i) const override; const T& operator[](const typename Range::IndexType& i) const override;
@ -34,13 +34,16 @@ namespace MultiArrayTools
virtual bool isSlice() const override; virtual bool isSlice() const override;
void set(MultiArrayBase<T,MARange>& multiArrayRef, IndefinitIndexBase* MAPtr); void set(MultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm,
IndefinitIndexBase* MAPtr,
const Name& MANm);
private: private:
MultiArrayBase<T,MARange>& mMultiArrayRef; MultiArrayBase<T,MARange>& mMultiArrayRef;
std::shared_ptr<IndefinitIndexBase> mMAPtr; // idx ptr for original MA Range std::shared_ptr<IndefinitIndexBase> mMAPtr; // idx ptr for original MA Range
IndefinitIndexBase* mOwnPtr; // idx ptr for own Range std::shared_ptr<IndefinitIndexBase> mOwnPtr; // idx ptr for own Range
//Index mSlicePos; //Index mSlicePos;
}; };