change slice creation procedure -> works so far

This commit is contained in:
Christian Zimmermann 2017-03-20 13:26:52 +01:00
parent 7a02d0f6b8
commit cd7c5c6c7b
3 changed files with 53 additions and 19 deletions

View file

@ -8,8 +8,8 @@ namespace MultiArrayTools
template <typename T, class Range, class MARange>
Slice<T,Range,MARange>::
Slice(const Range& range,
MutableMultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm, // for correct linkage
MutableMultiArrayBase<T,MARange>& multiArrayRef,
const typename MARange::IndexType& MAIdx, // for desired slice position
const Name& MANm) :
MutableMultiArrayBase<T,Range>(range),
@ -23,6 +23,23 @@ namespace MultiArrayTools
mMAIdx.linkTo(&mOwnIdx);
}
template <typename T, class Range, class MARange>
Slice<T,Range,MARange>::
Slice(const Range& range,
const Name& ownNm,
MultiArrayOperationRoot<T,MARange>& mor,
const typename MARange::IndexType& MAIdx) :
MutableMultiArrayBase<T,Range>(range),
mOwnName(ownNm), mMAName(mor.name()), mMultiArrayPtr(&(*mor)),
mMAIdx(MAIdx)
{
MAB::mInit = true;
mOwnIdx = MAB::mRange->begin();
mMAIdx.name(mMAName);
mOwnIdx.name(ownNm);
mMAIdx.linkTo(&mOwnIdx);
}
template <typename T, class Range, class MARange>
bool Slice<T,Range,MARange>::isSlice() const
{
@ -110,11 +127,11 @@ namespace MultiArrayTools
template <typename T, class Range, class MARange>
ConstSlice<T,Range,MARange>::
ConstSlice(const Range& range,
const MultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm, // for correct linkage
const MultiArrayBase<T,MARange>& multiArrayRef,
const typename MARange::IndexType& MAIdx, // for desired slice position
const Name& MANm) :
MutableMultiArrayBase<T,Range>(range),
MultiArrayBase<T,Range>(range),
mMultiArrayPtr(&multiArrayRef),
mMAIdx(MAIdx)
{
@ -125,6 +142,22 @@ namespace MultiArrayTools
mMAIdx.linkTo(&mOwnIdx);
}
template <typename T, class Range, class MARange>
ConstSlice<T,Range,MARange>::
ConstSlice(const Range& range,
const Name& ownNm,
const ConstMultiArrayOperationRoot<T,MARange>& mor,
const typename MARange::IndexType& MAIdx) :
MultiArrayBase<T,Range>(range),
mMultiArrayPtr(&(*mor)),
mMAIdx(MAIdx)
{
MAB::mInit = true;
mOwnIdx = MAB::mRange->begin();
mMAIdx.name(mor.name());
mOwnIdx.name(ownNm);
mMAIdx.linkTo(&mOwnIdx);
}
template <typename T, class Range, class MARange>
ConstSlice<T,Range,MARange>::
@ -192,14 +225,4 @@ namespace MultiArrayTools
//mOwnIdx = i.pos();
return (*mMultiArrayPtr)[ mMAIdx ];
}
template <typename T, class Range, class MARange>
T& ConstSlice<T,Range,MARange>::operator[](const typename Range::IndexType& i)
{
assert(0);
mOwnIdx.copyPos(i);
//mOwnIdx = i.pos();
return x;
}
}

View file

@ -22,10 +22,16 @@ namespace MultiArrayTools
typedef MultiArrayBase<T,Range> MAB;
Slice(const Range& range,
MutableMultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm,
MutableMultiArrayBase<T,MARange>& multiArrayRef,
const typename MARange::IndexType& MAIdx,
const Name& MANm);
Slice(const Range& range,
const Name& ownNm,
MultiArrayOperationRoot<T,MARange>& mor,
const typename MARange::IndexType& MAIdx);
virtual T& operator[](const typename Range::IndexType& i) override;
virtual const T& operator[](const typename Range::IndexType& i) const override;
@ -71,13 +77,18 @@ namespace MultiArrayTools
//ConstSlice(const Range& range);
ConstSlice(const Range& range,
const MultiArrayBase<T,MARange>& multiArrayRef,
const Name& ownNm,
const MultiArrayBase<T,MARange>& multiArrayRef,
const typename MARange::IndexType& MAIdx,
const Name& MANm);
ConstSlice(const Range& range,
const Name& ownNm,
const ConstMultiArrayOperationRoot<T,MARange>& mor,
const typename MARange::IndexType& MAIdx);
ConstSlice(const Slice<T,Range,MARange>& slice);
virtual T& operator[](const typename Range::IndexType& i) override;
virtual const T& operator[](const typename Range::IndexType& i) const override;
//Slice& setSlicePos(const Index& slicePos);

View file

@ -413,7 +413,7 @@ namespace {
auto i2 = i.template getIndex<1>();
auto i3 = i.template getIndex<2>();
Slice2d3dAny sl(ra, ma, MAT::Name("master", "alpha", "gamma"),
Slice2d3dAny sl(ra, MAT::Name("master", "alpha", "gamma"), ma,
i(i1 = 0, i2 = 2, i3 = 0),
MAT::Name("master", "alpha","beta","gamma"));
@ -421,7 +421,7 @@ namespace {
//sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)];
EXPECT_EQ(sl.size(), 6);
Slice2d3dAny sl2(rb, ma, MAT::Name("master", "alpha", "beta"),
Slice2d3dAny sl2(rb, MAT::Name("master", "alpha", "beta"), ma,
i(i1 = 0, i2 = 0, i3 = 1),
MAT::Name("master", "alpha","beta","gamma"));
@ -436,7 +436,7 @@ namespace {
auto i1 = i.template getIndex<0>();
auto i2 = i.template getIndex<1>();
auto i3 = i.template getIndex<2>();
Slice2d3dAny sl(ra, ma, MAT::Name("master", "alpha", "gamma"),
Slice2d3dAny sl(ra, MAT::Name("master", "alpha", "gamma"), ma,
i(i1 = 0, i2 = 2, i3 = 0),
MAT::Name("master", "alpha","beta","gamma"));
//sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)];