continue Slice implementations
This commit is contained in:
parent
685023b09c
commit
f489d165ab
5 changed files with 92 additions and 34 deletions
|
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,39 +65,45 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, class Range>
|
||||||
|
MultiArrayOperationRoot<T,Range>&
|
||||||
|
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range>& in)
|
||||||
|
{
|
||||||
|
maketurnSlice(in);
|
||||||
|
if(mArrayRef.isSlice()){
|
||||||
|
return makeSlice(in);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, class Range>
|
template <typename T, class Range>
|
||||||
template <class Operation, class... MAOps>
|
template <class Operation, class... MAOps>
|
||||||
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)
|
||||||
{
|
{
|
||||||
// NO SLICE CREATION !!! (total array not initialized!!)
|
if(mArrayRef.isSlice()){
|
||||||
|
// NO SLICE CREATION !!! (total array not initialized!!)
|
||||||
in.linkIndicesTo(MAOB::mIibPtr);
|
// throw !
|
||||||
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr);
|
assert(0);
|
||||||
|
|
||||||
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 *
|
||||||
*****************************/
|
*****************************/
|
||||||
|
|
|
@ -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,14 +72,24 @@ 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;
|
||||||
|
|
16
src/slice.cc
16
src/slice.cc
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue