first index mapping application works

This commit is contained in:
Christian Zimmermann 2017-03-28 17:55:12 +02:00
parent 83a712a772
commit 871a9be383
7 changed files with 79 additions and 41 deletions

View file

@ -5,12 +5,6 @@
#include <cassert>
#define DEFAULT_MEMBERS(__class_name__) __class_name__() = default; \
__class_name__(const __class_name__& in) = default; \
__class_name__& operator=(const __class_name__& in) = default; \
__class_name__(__class_name__&& in) = default; \
__class_name__& operator=(__class_name__&& in) = default
#define DEBUG_MODE_X
#ifdef DEBUG_MODE_X
@ -26,6 +20,13 @@
#endif
#define DEFAULT_MEMBERS(__class_name__) __class_name__() = default; \
__class_name__(const __class_name__& in) = default; \
__class_name__& operator=(const __class_name__& in) = default; \
__class_name__(__class_name__&& in) = default; \
__class_name__& operator=(__class_name__&& in) = default
namespace MultiArrayTools
{
template <class MultiArray>

View file

@ -13,6 +13,7 @@ namespace MultiArrayTools
mOutRange(new OutRange( outRange )),
mOIndex(mOutRange->begin())
{
//CHECK;
mOIndex.name(outName);
}
@ -35,10 +36,10 @@ namespace MultiArrayTools
}
/*
vec3d2Function::vec3d2Function(std::shared_ptr<OutRange>& outRange) : mOutRange(outRange),
out(mOutRange->begin()) {}
*/
vec3d2Function::vec3d2Function(const OutRange& outRange) : mOutRange(new OutRange( outRange )),
out(mOutRange->begin()) {}
vec3d2Function::OutIndex vec3d2Function::operator()(const InIndex& i) const
{
OutSubIndex& osi = out.template getIndex<0>();

View file

@ -21,10 +21,14 @@ namespace MultiArrayTools
typedef OutRange OR;
typedef typename OutRange::IndexType OutIndex;
//IndexMapFunction() = default;
IndexMapFunction(const MultiArrayBase<typename OutRange::IndexType,InRange>& ma,
const OutRange& outRange,
const Name& inName, const Name& outName);
IndexMapFunction(const IndexMapFunction& in) = default;
void linkIndicesTo(IndefinitIndexBase* target);
void eval() const;
@ -45,16 +49,17 @@ namespace MultiArrayTools
typedef MultiIndex<CoordIndex,CoordIndex,CoordIndex> InIndex;
typedef SingleIndex<size_t,RangeType::DISTANCE> OutSubIndex;
typedef MultiIndex<OutSubIndex> OutIndex;
typedef MultiRange<SingleRange<size_t,RangeType::DISTANCE> > OutRange;
vec3d2Function() = default;
//vec3d2Function(std::shared_ptr<OutRange>& outRange);
vec3d2Function(const vec3d2Function& in) = default;
vec3d2Function& operator=(const vec3d2Function& in) = default;
DEFAULT_MEMBERS(vec3d2Function);
vec3d2Function(const OutRange& outRange);
//vec3d2Function& operator=(const vec3d2Function& in) = default;
OutIndex operator()(const InIndex& i) const;
private:
//std::shared_ptr<OutRange> mOutRange;
std::shared_ptr<OutRange> mOutRange;
mutable OutIndex out;
};

View file

@ -183,6 +183,7 @@ namespace MultiArrayTools
template <typename T, class Range>
auto MultiArrayBase<T,Range>::beginIndex() const -> decltype(Range().begin())
{
//CHECK;
return mRange->begin();
}
@ -561,14 +562,15 @@ namespace MultiArrayTools
* FunctionalMultiArray *
****************************/
/*
template <typename T, class Range, class Function>
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range) :
MultiArrayBase<T,Range>(range), mFunc() {}
*/
template <typename T, class Range, class Function>
FunctionalMultiArray<T,Range,Function>::FunctionalMultiArray(const Range& range,
const Function& func) :
MultiArrayBase<T,Range>(range), mFunc(func) {}
MultiArrayBase<T,Range>(range), mFunc(func) { /*CHECK;*/ }
template <typename T, class Range, class Function>
const T& FunctionalMultiArray<T,Range,Function>::operator[](const typename Range::IndexType& i) const

View file

@ -243,7 +243,7 @@ namespace MultiArrayTools
typedef typename MultiArrayBase<T,Range>::const_iterator const_iterator;
DEFAULT_MEMBERS(FunctionalMultiArray);
FunctionalMultiArray(const Range& range);
//FunctionalMultiArray(const Range& range);
FunctionalMultiArray(const Range& range, const Function& func);
virtual const T& operator[](const typename Range::IndexType& i) const override;

View file

@ -44,8 +44,10 @@ namespace MultiArrayTools
std::cout << "assignment: " << endPos << " elements" << std::endl;
// assignment loop
for(iref = mArrayRef.beginIndex().pos(); iref != mArrayRef.endIndex(); ++iref){
//std::cout << get() << " / " << in.get() << std::endl;
//std::cout << iref.pos() << '\r' << std::flush;
get() = in.get();
//assert(not std::isnan( get() ));
}
//CHECK;
@ -61,8 +63,10 @@ namespace MultiArrayTools
mIndex(mArrayRef.beginIndex()),
mNm(nm)
{
//CHECK;
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(nm);
//CHECK;
//mIndex.name(nm);
}
@ -74,8 +78,10 @@ namespace MultiArrayTools
mIndex(mArrayRef.beginIndex()),
mNm(in.mNm)
{
//CHECK;
MAOB::mIibPtr = &mIndex;
MAOB::mIibPtr->name(mNm);
//CHECK;
//mIndex.name(nm);
}
@ -180,7 +186,10 @@ namespace MultiArrayTools
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range>
MultiArrayOperationRoot<T,Range>::map(const IndexMapFunction<InRange,OutRange>& imf)
{
return MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range>(*this, imf);
//CHECK;
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,Range> mom(*this, imf);
//CHECK;
return mom;
}
template <typename T, class Range>
@ -292,7 +301,7 @@ namespace MultiArrayTools
{
//CHECK;
//return mArrayRef[mIndex];
assert(MAOB::mIibPtr == &mIndex);
//assert(MAOB::mIibPtr == &mIndex);
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
}
@ -302,7 +311,7 @@ namespace MultiArrayTools
{
//CHECK;
//return mArrayRef[mIndex];
assert(MAOB::mIibPtr == &mIndex);
//assert(MAOB::mIibPtr == &mIndex);
//VCHECK(mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)]);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
}
@ -494,7 +503,7 @@ namespace MultiArrayTools
const T& ConstMultiArrayOperationRoot<T,Range>::get() const
{
//CHECK;
assert(MAOB::mIibPtr == &mIndex);
//assert(MAOB::mIibPtr == &mIndex);
return mArrayRef[*dynamic_cast<IndexType*>(MAOB::mIibPtr)];
}
@ -534,7 +543,9 @@ namespace MultiArrayTools
//mIndex(mArrayRef.beginIndex()),
//mNm(nm)
{
//CHECK;
MAOB::mIibPtr = &mIndex;
//CHECK;
//MAOB::mIibPtr->name(nm);
//mIndex.name(nm);
}
@ -545,26 +556,33 @@ namespace MultiArrayTools
operator=(const MultiArrayOperationRoot<T,TotalInRange>& in)
{
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
MAOB::mIibPtr = &mIndex;
mNm = in.name();
mIndex.name(mNm); // to be sure...
mIndex.setPos( mIndex.max() );
typename TotalInRange::IndexType endIndex = mIndex;
// Implement Map Functions !!!!
typename TotalInRange::IndexType endIndex = mIndex;
endIndex.setPos( mIndex.max() );
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
mRoot.linkIndicesTo( &mIndex );
mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex );
in.linkIndicesTo( &mIndex );
MultiArray<size_t,TotalRange> cnt(mRoot->range());
auto cnto = cnt(mRoot.name(), true);
MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
cnto.linkIndicesTo( &mIndex );
cnto.linkIndicesTo( &mMF.index() );
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get();
++cnto.get();
cnto.get() += 1.;
}
mRoot.freeIndex();
// CHECK whether T / size_t mixture works!!
mRoot /= cnto;
mRoot /= cnt(mRoot.name(), true);
return *this;
}
@ -573,27 +591,34 @@ namespace MultiArrayTools
MultiArrayOperationMap<T,InRange,TotalInRange,OutRange,TotalRange>::
operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in)
{
mIndex = dynamic_cast<typename InRange::IndexType&>( in.index() );
mIndex = dynamic_cast<typename TotalInRange::IndexType const&>( in.index() );
MAOB::mIibPtr = &mIndex;
mNm = in.name();
mIndex.name(mNm); // to be sure...
mIndex.setPos( mIndex.max() );
typename OutRange::IndexType endIndex = mIndex;
// Implement Map Functions !!!!
typename TotalInRange::IndexType endIndex = mIndex;
endIndex.setPos( mIndex.max() );
std::cout << "map assignment: " << endIndex.pos() << " elements" << std::endl;
mRoot.linkIndicesTo( &mIndex );
mRoot.linkIndicesTo( &mMF.index() );
mMF.linkIndicesTo( &mIndex );
in.linkIndicesTo( &mIndex );
MultiArray<size_t,OutRange> cnt(mRoot->range());
auto cnto = cnt(mRoot.name(), true);
MultiArray<T,TotalRange> cnt(mRoot->range());
MultiArrayOperationRoot<T,TotalRange> cnto(cnt, mRoot.name());
cnto.linkIndicesTo( &mIndex );
cnto.linkIndicesTo( &mMF.index() );
for(mIndex.setPos(0), mMF.eval(); mIndex != endIndex; ++mIndex, mMF.eval()){
get() += in.get();
++cnto.get();
cnto.get() += 1.;
}
mRoot.freeIndex();
// CHECK whether T / size_t mixture works!!
mRoot /= cnto;
mRoot /= cnt(mRoot.name(), true);
return *this;
}

View file

@ -21,6 +21,7 @@ namespace MultiArrayTools
typedef T value_type;
MultiArrayOperationBase() /*{ CHECK; }*/ = default;
//MultiArrayOperationBase(const MultiArrayOperationBase& in) = default;
virtual ~MultiArrayOperationBase();
virtual size_t argNum() const = 0;
@ -45,6 +46,7 @@ namespace MultiArrayTools
public:
MutableMultiArrayOperationBase() /*{ CHECK; }*/ = default;
//MutableMultiArrayOperationBase(const MutableMultiArrayOperationBase& in) = default;
virtual T& get() = 0;
};
@ -250,6 +252,8 @@ namespace MultiArrayTools
MultiArrayOperationMap(MultiArrayOperationRoot<T,TotalRange>& root,
const IndexMapFunction<InRange,OutRange>& mf);
MultiArrayOperationMap(const MultiArrayOperationMap& in) = default;
MultiArrayOperationMap& operator=(const MultiArrayOperationRoot<T,TotalInRange>& in);
MultiArrayOperationMap& operator=(const ConstMultiArrayOperationRoot<T,TotalInRange>& in);