start implementing class Slice
This commit is contained in:
parent
db4ad28f02
commit
6eb53111bb
7 changed files with 122 additions and 20 deletions
|
@ -80,6 +80,11 @@ namespace MultiArrayTools
|
|||
// multi_array_operation.h
|
||||
template <typename T, class Range, class Operation, class... Ranges>
|
||||
class MultiArrayOperation;
|
||||
|
||||
// slice.h
|
||||
template <typename T, class Range, class MARange, class Index>
|
||||
class Slice;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -69,5 +69,10 @@ namespace MultiArrayTools
|
|||
return mRange->end();
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
bool MultiArray<T,Range>::isSlice() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,12 +33,17 @@ namespace MultiArrayTools
|
|||
|
||||
size_t size() const;
|
||||
|
||||
virtual bool isSlice() const;
|
||||
|
||||
auto begin() -> decltype(Range().begin());
|
||||
auto end() -> decltype(Range().end());
|
||||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<Range> mRange;
|
||||
|
||||
private:
|
||||
bool mInit = false;
|
||||
std::shared_ptr<Range> mRange;
|
||||
std::vector<T> mCont;
|
||||
};
|
||||
|
||||
|
|
|
@ -11,10 +11,12 @@ namespace MultiArrayTools
|
|||
MultiArrayOperationBase<T,Range>::
|
||||
MultiArrayOperationBase(MultiArray<T,Range>& ma,
|
||||
const Name& nm) : mArrayRef(ma),
|
||||
//mIndex(mArrayRef.begin()),
|
||||
mIibPtr(new IndexType(mArrayRef.begin())),
|
||||
mNm(nm)
|
||||
{
|
||||
mIibPtr->name(nm);
|
||||
//mIndex.name(nm);
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
|
@ -43,7 +45,12 @@ namespace MultiArrayTools
|
|||
MultiArrayOperationBase<T,Range>::operator=(const MultiArrayOperationBase<T, Range2>& in)
|
||||
{
|
||||
in.linkIndicesTo(mIibPtr);
|
||||
for(*mIibPtr = mArrayRef.begin(); *mIibPtr != mArrayRef.end(); ++(*mIibPtr)){
|
||||
IndexType& iref = dynamic_cast<IndexType&>(*mIibPtr);
|
||||
if(mArrayRef.isSlice()){
|
||||
linkSlice(&in.index(), mIibPtr);
|
||||
return *this;
|
||||
}
|
||||
for(iref = mArrayRef.begin().pos(); iref != mArrayRef.end(); ++iref){
|
||||
// build in vectorization later
|
||||
get() = in.get();
|
||||
}
|
||||
|
@ -121,26 +128,16 @@ namespace MultiArrayTools
|
|||
template <typename T, class Range>
|
||||
T& MultiArrayOperationBase<T,Range>::get()
|
||||
{
|
||||
//return mArrayRef[mIndex];
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(mIibPtr)];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MultiArrayOperationBase<T,Range>::get() const
|
||||
{
|
||||
//return mArrayRef[mIndex];
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(mIibPtr)];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T& MultiArrayOperationBase<T,Range>::get(IndefinitIndexBase* iibPtr)
|
||||
{
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(iibPtr)];
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
const T& MultiArrayOperationBase<T,Range>::get(IndefinitIndexBase* iibPtr) const
|
||||
{
|
||||
return mArrayRef[*dynamic_cast<IndexType*>(iibPtr)];
|
||||
}
|
||||
|
||||
/*****************************
|
||||
* MultiArrayOperation *
|
||||
|
@ -197,7 +194,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class Operation, class Tuple, class... MBases>
|
||||
static auto callOperation(const Operation& op, const Tuple& tp, const T& first, const MBases&... secs)
|
||||
-> decltype(op(first.get(), std::get<0>(tp).get(), secs.get()...))
|
||||
-> decltype(op(first, std::get<0>(tp).get(), secs.get()...))
|
||||
{
|
||||
return op(first, std::get<0>(tp).get(), secs.get()...);
|
||||
}
|
||||
|
@ -239,6 +236,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
mVal = OperationCall<sizeof...(Ranges)-1>::
|
||||
template callOperation(mOp, mSecs,
|
||||
//OB::mArrayRef[OB::mIndex]);
|
||||
OB::mArrayRef[*dynamic_cast<typename OB::IndexType*>(OB::mIibPtr)]);
|
||||
return mVal;
|
||||
}
|
||||
|
@ -248,6 +246,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
mVal = OperationCall<sizeof...(Ranges)-1>::
|
||||
template callOperation(mOp, mSecs,
|
||||
//OB::mArrayRef[OB::mIndex]);
|
||||
OB::mArrayRef[*dynamic_cast<typename OB::IndexType*>(OB::mIibPtr)]);
|
||||
return mVal;
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ namespace MultiArrayTools
|
|||
|
||||
virtual size_t argNum() const;
|
||||
|
||||
//IndexType& index() ;
|
||||
IndefinitIndexBase* index();
|
||||
|
||||
virtual void linkIndicesTo(IndefinitIndexBase* target) const;
|
||||
|
@ -60,13 +61,11 @@ namespace MultiArrayTools
|
|||
virtual T& get();
|
||||
virtual const T& get() const;
|
||||
|
||||
virtual T& get(IndefinitIndexBase* iibPtr);
|
||||
virtual const T& get(IndefinitIndexBase* iibPtr) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
MultiArray<T,Range>& mArrayRef;
|
||||
IndefinitIndexBase mutable* mIibPtr = nullptr;
|
||||
//mutable IndexType mIndex;
|
||||
IndefinitIndexBase* mIibPtr = nullptr;
|
||||
Name mNm;
|
||||
};
|
||||
|
||||
|
|
35
src/slice.cc
Normal file
35
src/slice.cc
Normal file
|
@ -0,0 +1,35 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#include "slice.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <typename T, class Range, class MARange, class Index>
|
||||
Slice<T,Range,MARange,Index>::
|
||||
Slice(const Range& range, const Index& slicePos) :
|
||||
MA::mRange(new Range(range)),
|
||||
mSlicePos(slicePos) {}
|
||||
|
||||
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>
|
||||
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)
|
||||
{
|
||||
mMAPtr.reset(new typename MARange::IndexType(MAPtr));
|
||||
mOwnPtr.reset(new typename Range::IndexType(ownPtr));
|
||||
}
|
||||
}
|
54
src/slice.h
Normal file
54
src/slice.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __slice_h__
|
||||
#define __slice_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include "base_def.h"
|
||||
#include "multi_array.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
// T = data type
|
||||
// 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>
|
||||
class Slice : public MultiArray<T,Range> // yes, Range is correct !!!
|
||||
{
|
||||
//MA::mCont has to be empty; only make use of the provided functions
|
||||
public:
|
||||
|
||||
typedef MultiArray<T,MARange> MA;
|
||||
|
||||
Slice(const Range& range, const Index& slicePos);
|
||||
|
||||
T& operator[](const typename Range::IndexType& i) override;
|
||||
const T& operator[](const typename Range::IndexType& i) const override;
|
||||
|
||||
Slice& setSlicePos(const Index& slicePos);
|
||||
|
||||
// link given Index to mMAPtr which is index of total array
|
||||
auto begin() override -> decltype(Range().begin());
|
||||
auto end() override -> decltype(Range().end());
|
||||
|
||||
virtual bool isSlice() const override;
|
||||
|
||||
void setPtr(IndefinitIndexBase* MAPtr,
|
||||
IndefinitIndexBase* ownPtr);
|
||||
|
||||
private:
|
||||
|
||||
MultiArray<T,MARange>& multiArrayRef;
|
||||
IndefinitIndexBase* mMAPtr; // idx ptr for original MA Range
|
||||
IndefinitIndexBase* mOwnPtr; // idx ptr for own Range
|
||||
Index mSlicePos;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#include "slice.cc"
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue