some minor changes

This commit is contained in:
Christian Zimmermann 2017-02-27 11:23:40 +01:00
parent d1363c3c3d
commit 685023b09c
6 changed files with 37 additions and 73 deletions

View file

@ -35,6 +35,13 @@ namespace MultiArrayTools
return *mRange;
}
template <typename T, class Range>
template <class... NameTypes>
MultiArrayOperationRoot<T,Range> MultiArrayBase<T,Range>::operator()(const NameTypes&... str)
{
return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
}
/*******************
* MultiArray *
*******************/
@ -76,13 +83,6 @@ namespace MultiArrayTools
return mCont[ i.pos() ];
}
template <typename T, class Range>
template <class... NameTypes>
MultiArrayOperationRoot<T,Range> MultiArray<T,Range>::operator()(const NameTypes&... str)
{
return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
}
template <typename T, class Range>
bool MultiArray<T,Range>::isSlice() const
{

View file

@ -33,6 +33,9 @@ namespace MultiArrayTools
virtual const Range& range() const;
template <class... NameTypes>
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);
protected:
std::shared_ptr<Range> mRange;
@ -50,9 +53,6 @@ namespace MultiArrayTools
MultiArray(const Range& range, const std::vector<T>& vec);
MultiArray(const Range& range, std::vector<T>&& vec);
template <class... NameTypes>
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);
T& operator[](const typename Range::IndexType& i) override;
const T& operator[](const typename Range::IndexType& i) const override;

View file

@ -43,12 +43,16 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationRoot<T,Range>& in)
{
if(mArrayRef.isSlice()){
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);
//if(mArrayRef.isSlice()){
// linkSlice(&in.index(), MAOB::mIibPtr);
// return *this;
//}
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
// build in vectorization later
get() = in.get();
@ -62,12 +66,11 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in)
{
// NO SLICE CREATION !!! (total array not initialized!!)
in.linkIndicesTo(MAOB::mIibPtr);
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr);
//if(mArrayRef.isSlice()){
// linkSlice(&in.index(), MAOB::mIibPtr);
// return *this;
//}
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
// build in vectorization later
get() = in.get();
@ -76,26 +79,6 @@ namespace MultiArrayTools
return *this;
}
/*
template <typename T, class Range>
template <class Range2>
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperationBase<T, Range2>& in)
{
in.linkIndicesTo(MAOB::mIibPtr);
IndexType& iref = dynamic_cast<IndexType&>(*MAOB::mIibPtr);
if(mArrayRef.isSlice()){
linkSlice(&in.index(), MAOB::mIibPtr);
return *this;
}
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
// build in vectorization later
get() = in.get();
}
MAOB::mIibPtr->freeLinked();
return *this;
}*/
template <typename T, class Range>
template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>

View file

@ -45,14 +45,6 @@ namespace MultiArrayTools
template <class Operation, class... MAOps>
MultiArrayOperationRoot& operator=(const MultiArrayOperation<T,Operation,MAOps...>& in);
//MultiArrayOperationRoot& operator=(const MultiArrayOperationRoot& in) = delete;
//MultiArrayOperationRoot(const MultiArrayOperationRoot& in) = default;
// execute AnyOperation
// exception if range types are inconsitent with names
//MultiArrayOperationRoot& operator=(const MultiArrayOperationBase<T>& in);
template <class Operation, class... MAOps>
MultiArrayOperation<T,Operation,MultiArrayOperationRoot<T,Range>, MAOps...>
operator()(Operation& op, const MAOps&... secs);

View file

@ -5,32 +5,23 @@
namespace MultiArrayTools
{
template <typename T, class Range, class MARange, class Index>
template <typename T, class Range, class MARange>
Slice<T,Range,MARange,Index>::
Slice(MultiArrayBase<T,MARange>& ma, const Index& slicePos) :
Slice() :
MultiArrayBase<T,Range>(ma.range()),
multiArrayRef(ma),
mSlicePos(slicePos) {}
mMultiArrayRef(*this) {}
template <typename T, class Range, class MARange, class Index>
Slice<T,Range,MARange,Index>& Slice<T,Range,MARange,Index>::setSlicePos(const Index& slicePos)
{
mSlicePos = slicePos;
mMAPtr->linkTo(&mSlicePos);
return *this;
}
template <typename T, class Range, class MARange, class Index>
template <typename T, class Range, class MARange>
bool Slice<T,Range,MARange,Index>::isSlice() const
{
return true;
}
template <typename T, class Range, class MARange, class Index>
void Slice<T,Range,MARange,Index>::setPtr(IndefinitIndexBase* MAPtr,
IndefinitIndexBase* ownPtr)
template <typename T, class Range, class MARange>
void Slice<T,Range,MARange,Index>::set(MultiArrayBase<T,MARange>& multiArrayRef, IndefinitIndexBase* MAPtr)
{
mMultiArrayRef = multiArrayRef;
mMAPtr.reset(new typename MARange::IndexType(MAPtr));
mOwnPtr.reset(new typename Range::IndexType(ownPtr));
}
}

View file

@ -14,20 +14,19 @@ namespace MultiArrayTools
// Range = range of slice
// MARange = original range of multi array of which this is the slice
// Index = index which determines the slice position (remnant of MARange w.o. Range)
template <typename T, class Range, class MARange, class Index>
template <typename T, class Range, class MARange/*, class Index*/>
class Slice : public MultiArrayBase<T,Range> // yes, 'Range' is correct !!!
{
//MA::mCont has to be empty; only make use of the provided functions
public:
typedef MultiArrayBase<T,MARange> MAB;
typedef MultiArrayBase<T,Range> MAB;
Slice(MultiArray<T,MARange>& ma, const Index& slicePos);
Slice();
T& operator[](const typename Range::IndexType& i) override;
const T& operator[](const typename Range::IndexType& i) const override;
Slice& setSlicePos(const Index& slicePos);
//Slice& setSlicePos(const Index& slicePos);
// link given Index to mMAPtr which is index of total array
auto begin() override -> decltype(Range().begin());
@ -35,15 +34,14 @@ namespace MultiArrayTools
virtual bool isSlice() const override;
void setPtr(IndefinitIndexBase* MAPtr,
IndefinitIndexBase* ownPtr);
void set(MultiArrayBase<T,MARange>& multiArrayRef, IndefinitIndexBase* MAPtr);
private:
MultiArrayBase<T,MARange>& multiArrayRef;
IndefinitIndexBase* mMAPtr; // idx ptr for original MA Range
MultiArrayBase<T,MARange>& mMultiArrayRef;
std::shared_ptr<IndefinitIndexBase> mMAPtr; // idx ptr for original MA Range
IndefinitIndexBase* mOwnPtr; // idx ptr for own Range
Index mSlicePos;
//Index mSlicePos;
};