add some range transformation routines
This commit is contained in:
parent
5f4931757d
commit
a6c860a352
14 changed files with 102 additions and 52 deletions
|
@ -93,6 +93,13 @@ namespace MultiArrayTools
|
|||
template <typename T, class Range, class MARange>
|
||||
class Slice;
|
||||
|
||||
// manipulator.h
|
||||
template <typename T>
|
||||
class ManipulatorBase;
|
||||
|
||||
// manipulator.h
|
||||
template <typename T>
|
||||
class BinReader;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -91,12 +91,6 @@ namespace MultiArrayTools
|
|||
}
|
||||
}
|
||||
|
||||
size_t IndefinitIndexBase::max() const
|
||||
{
|
||||
//assert(not virt());
|
||||
return static_cast<size_t>( -1 );
|
||||
}
|
||||
|
||||
size_t IndefinitIndexBase::outOfRange() const
|
||||
{
|
||||
//assert(not virt());
|
||||
|
|
|
@ -44,9 +44,11 @@ namespace MultiArrayTools
|
|||
virtual bool linked() const;
|
||||
virtual void linkTo(IndefinitIndexBase* target) = 0;
|
||||
|
||||
virtual IndefinitIndexBase* getLinked(const std::string& name) = 0;
|
||||
|
||||
virtual void setPos(size_t pos);
|
||||
|
||||
virtual size_t max() const;
|
||||
virtual size_t max() const = 0;
|
||||
virtual size_t outOfRange() const;
|
||||
|
||||
virtual bool toNull() const;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T>
|
||||
BinReader<T>::BinReader(const std::string& fname, size_t readBegin):
|
||||
fs(fname, std::fstream::in | std::fstream::binary),
|
||||
mFs(fname, std::fstream::in | std::fstream::binary),
|
||||
mReadBegin(readBegin) {}
|
||||
|
||||
template <typename T>
|
||||
|
@ -37,18 +37,18 @@ namespace MultiArrayTools
|
|||
const size_t blockSize = sizeof(T) * readSize;
|
||||
char* buffer = new char[blockSize];
|
||||
|
||||
mFs.seekg(mReadBegin + MB::mLastPos, fs.beg);
|
||||
mFs.seekg(mReadBegin + MB::mLastPos, mFs.beg);
|
||||
mFs.read(buffer, blockSize);
|
||||
MB::mLastPos += blockSize;
|
||||
|
||||
T* content = reinterpret_cast<T*>( buffer );
|
||||
|
||||
if(mTargetPtr->size() < MB::mEnd){
|
||||
if(MB::mTargetPtr->size() < MB::mEnd){
|
||||
assert(0);
|
||||
// throw
|
||||
}
|
||||
|
||||
std::copy(&content[0], &content[readSize], mTargetPtr->begin() + MB::mBegin);
|
||||
std::copy(&content[0], &content[readSize], MB::mTargetPtr->begin() + MB::mBegin);
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
class BinReader : public ManipulatorBase
|
||||
class BinReader : public ManipulatorBase<T>
|
||||
{
|
||||
public:
|
||||
typedef ManipulatorBase<T> MB;
|
||||
|
|
|
@ -71,6 +71,32 @@ namespace MultiArrayTools
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <class Range2, class Range3>
|
||||
MultiArray<T,Range>::MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in) :
|
||||
MultiArrayBase<T,Range>(merge(in.range(), in[ in.begin() ].range()))
|
||||
// assert that Range2 has always same extension
|
||||
{
|
||||
mCont.clear();
|
||||
for(auto i = in.begin(); i != in.end(); ++i){
|
||||
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());
|
||||
}
|
||||
assert(mCont.size() == MAB::mRange->size());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
template <class Range2, class Range3>
|
||||
MultiArray<T,Range>& MultiArray<T,Range>::operator=(const MultiArray<MultiArray<T,Range2>,Range3> in)
|
||||
{
|
||||
MAB::mRange.reset(new Range(merge(in.range(), in[ in.begin() ].range())));
|
||||
// assert that Range2 has always same extension
|
||||
mCont.clear();
|
||||
for(auto i = in.begin(); i != in.end(); ++i){
|
||||
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());
|
||||
}
|
||||
assert(mCont.size() == MAB::mRange->size());
|
||||
}
|
||||
|
||||
template <typename T, class Range>
|
||||
T& MultiArray<T,Range>::operator[](const typename Range::IndexType& i)
|
||||
{
|
||||
|
@ -89,12 +115,14 @@ namespace MultiArrayTools
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T, class Range>
|
||||
void MultiArray<T,Range>::manipulate(ManipulatorBase<T>& mb, size_t manBegin, size_t manEnd)
|
||||
void MultiArray<T,Range>::manipulate(ManipulatorBase<T>& mb,
|
||||
const typename Range::IndexType& manBegin,
|
||||
const typename Range::IndexType& manEnd)
|
||||
{
|
||||
//mb.reset();
|
||||
mb.setup(mCont, manBegin, manEnd);
|
||||
mb.setup(mCont, manBegin.pos(), manEnd.pos());
|
||||
mb.execute();
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ namespace MultiArrayTools
|
|||
{
|
||||
public:
|
||||
|
||||
// iterator ( containing idx of Range )
|
||||
|
||||
DEFAULT_MEMBERS(MultiArrayBase);
|
||||
MultiArrayBase(const Range& range);
|
||||
|
||||
|
@ -37,8 +39,6 @@ namespace MultiArrayTools
|
|||
template <class... NameTypes>
|
||||
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);
|
||||
|
||||
virtual void manipulate(ManipulatorBase<T>& mb, size_t manBegin, size_t manEnd) = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Range> mRange;
|
||||
|
||||
|
@ -56,12 +56,20 @@ namespace MultiArrayTools
|
|||
MultiArray(const Range& range, const std::vector<T>& vec);
|
||||
MultiArray(const Range& range, std::vector<T>&& vec);
|
||||
|
||||
template <class Range2, class Range3>
|
||||
MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
|
||||
template <class Range2, class Range3>
|
||||
MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
||||
|
||||
T& operator[](const typename Range::IndexType& i) override;
|
||||
const T& operator[](const typename Range::IndexType& i) const override;
|
||||
|
||||
virtual bool isSlice() const override;
|
||||
|
||||
virtual void manipulate(ManipulatorBase<T>& mb, size_t manBegin, size_t manEnd) override;
|
||||
// virtual void manipulate(ManipulatorBase<T>& mb,
|
||||
// const typename Range::IndexType& manBegin,
|
||||
// const typename Range::IndexType& manEnd);
|
||||
|
||||
template <typename U, class RangeX>
|
||||
friend class MultiArray;
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "multi_array_operation.h"
|
||||
#include "multi_array.h"
|
||||
#include "slice.h"
|
||||
#include "manipulator.h"
|
||||
#include "range_transformer.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
|
|
@ -598,6 +598,9 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
MultiRange<Ranges...>::MultiRange(const Ranges&... rs) : mSpace(std::make_tuple(rs...)) {}
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...>::MultiRange(const SpaceType& space) : mSpace(space) {}
|
||||
|
||||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
auto MultiRange<Ranges...>::getRange() -> decltype( std::get<N>(MultiRange<Ranges...>::SpaceType()) )
|
||||
|
|
|
@ -104,6 +104,7 @@ namespace MultiArrayTools
|
|||
DEFAULT_MEMBERS(MultiRange);
|
||||
|
||||
MultiRange(const Ranges&... rs);
|
||||
MultiRange(const SpaceType& space);
|
||||
|
||||
static const size_t dim = sizeof...(Ranges);
|
||||
|
||||
|
|
|
@ -5,5 +5,30 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> makeRange(const std::tuple<Ranges...>& rangeTuple)
|
||||
{
|
||||
return MultiRange<Ranges...>( rangeTuple );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> combine(const Ranges&... ranges)
|
||||
{
|
||||
return MultiRange<Ranges...>(ranges...);
|
||||
}
|
||||
|
||||
template <class Range, class... Ranges>
|
||||
auto extend(const Range& r, const MultiRange<Ranges...>& mr)
|
||||
-> decltype( MultiRange<Range,Ranges...>(std::tuple_cat( std::make_tuple(r), mr.space() ) ) )
|
||||
{
|
||||
return MultiRange<Range,Ranges...>(std::tuple_cat( std::make_tuple(r), mr.space() ) );
|
||||
}
|
||||
|
||||
template <class MultiRange1, class MultiRange2>
|
||||
auto merge(const MultiRange1& mr1, const MultiRange2& mr2)
|
||||
-> decltype( makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ) )
|
||||
{
|
||||
return makeRange( std::tuple_cat( mr1.space(), mr2.space() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,10 +9,19 @@
|
|||
namespace MultiArrayTools
|
||||
{
|
||||
|
||||
// init 'MultiRange' with 'new'
|
||||
template <class... Ranges>
|
||||
shared_ptr<MultiRange<Ranges...> > combine(const Ranges&... ranges);
|
||||
MultiRange<Ranges...> makeRange(const std::tuple<Ranges...>& rangeTuple);
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...> combine(const Ranges&... ranges);
|
||||
|
||||
template <class Range, class... Ranges>
|
||||
auto extend(const Range& r, const MultiRange<Ranges...>& mr)
|
||||
-> decltype( MultiRange<Range,Ranges...>(std::tuple_cat( std::make_tuple(r), mr.space() ) ) );
|
||||
|
||||
template <class MultiRange1, class MultiRange2>
|
||||
auto merge(const MultiRange1& mr1, const MultiRange2& mr2)
|
||||
-> decltype(makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ) );
|
||||
}
|
||||
|
||||
#include "range_transformer.cc"
|
||||
|
|
23
src/slice.cc
23
src/slice.cc
|
@ -57,27 +57,4 @@ namespace MultiArrayTools
|
|||
//mOwnIdx = i.pos();
|
||||
return (*mMultiArrayPtr)[ mMAIdx ];
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
void Slice<T,Range,MARange>::manipulate(ManipulatorBase<T>& mb, size_t manBegin, size_t manEnd)
|
||||
{
|
||||
mOwnIdx = manBegin;
|
||||
const size_t blockSize = getBlockSize();
|
||||
const size_t totalManSize = manEnd - manBegin;
|
||||
size_t curBegin = mMAIdx.pos();
|
||||
size_t curBlockNum = (mMAIdx.pos() - mMAIdx.pos() % blockSize) / blockSize;
|
||||
size_t tempEnd = blockSize - mMAIdx.pos() % blockSize + blockSize * curBlockNum;
|
||||
size_t manipulated = 0;
|
||||
for(; manipulated < totalManSize; ){
|
||||
mMultiArrayPtr->manipulate(mb, curBegin, tempEnd);
|
||||
// update variables... !!!!
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, class Range, class MARange>
|
||||
size_t Slice<T,Range,MARange>::getBlockSize() const
|
||||
{
|
||||
// implement !!!
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,6 @@ namespace MultiArrayTools
|
|||
const typename MARange::IndexType& MAIdx,
|
||||
const Name& MANm);
|
||||
|
||||
virtual void manipulate(ManipulatorBase<T>& mb, size_t manBegin, size_t manEnd) override;
|
||||
|
||||
// size of coherent data blocks (vectorizable) managed by the slice
|
||||
// = 1 if the smallest index of original array is NOT managed by the slice
|
||||
size_t getBlockSize() const;
|
||||
|
||||
private:
|
||||
|
||||
MultiArrayBase<T,MARange>* mMultiArrayPtr = nullptr;
|
||||
|
|
Loading…
Reference in a new issue