im com (start xfor)

This commit is contained in:
Christian Zimmermann 2018-01-05 13:56:16 +01:00
parent 0bbbdf7168
commit 728f36f538
7 changed files with 133 additions and 30 deletions

View file

@ -27,20 +27,6 @@ namespace MultiArrayTools
using namespace MultiArrayHelper;
}
/*
* OperationBase
* MutableOperationBase
*
* OperationMaster : MutableOperationBase
*
* OperationTemplate<...>
* ConstOperationRoot : OperationBase, OperationTemplate<...>
* OperationRoot : MutableOperationBase,
* OperationTemplate<...>
*
*/
template <typename T>
Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize);
@ -91,7 +77,7 @@ namespace MultiArrayTools
};
template <typename T, class OpClass, class... Ranges>
class OperationMaster/* : public MutableOperationBase<T>*/
class OperationMaster
{
public:
@ -160,8 +146,7 @@ namespace MultiArrayTools
};
template <typename T, class... Ranges>
class OperationRoot : /*public MutableOperationBase<T>,*/
public OperationTemplate<T,OperationRoot<T,Ranges...> >
class OperationRoot : public OperationTemplate<T,OperationRoot<T,Ranges...> >
{
public:
@ -199,8 +184,7 @@ namespace MultiArrayTools
};
template <typename T, class OpFunction, class... Ops>
class Operation : /*public OperationBase<T>,*/
public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
{
public:
@ -242,7 +226,6 @@ namespace MultiArrayTools
const Op& mOp;
std::shared_ptr<IndexType> mInd;
//mutable BlockArray<Op::bType> mInBlock;
mutable bType mRes;
};
@ -399,31 +382,24 @@ namespace MultiArrayTools
template <typename T, class OpClass, class... Ranges>
void OperationMaster<T,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum)
{
//size_t cnt = 0;
//std::clock_t cs = clock();
static auto loop = mkLoop(mIndex, *this, mSecond);
loop();
for(*mIndex = 0; mIndex->pos() != mIndex->max(); mIndex->pp(blockIndexNum) ){
//std::clock_t c1 = clock();
block();
get() = mSecond.get();
//std::clock_t c2 = clock();
//cnt += c2 - c1;
}
//std::clock_t ce = clock();
//std::cout << "total time = " << ce - cs << std::endl;
//std::cout << "calc time = " << cnt << std::endl;
}
template <typename T, class OpClass, class... Ranges>
MBlock<T>& OperationMaster<T,OpClass,Ranges...>::get()
{
//block();
return mBlock;
}
template <typename T, class OpClass, class... Ranges>
const Block<T>& OperationMaster<T,OpClass,Ranges...>::get() const
{
//block();
return mBlock;
}

View file

@ -28,6 +28,9 @@ namespace MultiArrayTools
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
typedef ContainerRange<typename Indices::RangeType...> RangeType;
static IndexType sType() { return IndexType::CONT; }
static size_t sDim() { return sizeof...(Indices); }
private:
bool mExternControl = false;
@ -47,6 +50,8 @@ namespace MultiArrayTools
template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
const IndexPack& pack() const { return mIPack; }
ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
ContainerIndex& operator()(); // -> sync; just to shorten the code

View file

@ -13,6 +13,8 @@
#include "vindex_wrapper.h"
#include "index_info.h"
#include "xfor/xfor.h"
namespace MultiArrayTools
{
@ -71,6 +73,11 @@ namespace MultiArrayTools
void print(size_t offset = 0) const { THIS().print(offset); }
// CHECK / IMPLEMENT !!!!!!
template <class Expr, typename... Args>
auto ifor(const Args&... args) const -> decltype(THIS().template ifor<Expr>(args...))
{ return THIS().template ifor<Expr>(args...) }
private:
friend I;

View file

@ -32,6 +32,9 @@ namespace MultiArrayTools
typedef std::tuple<typename Indices::MetaType...> MetaType;
typedef MultiRange<typename Indices::RangeType...> RangeType;
static IndexType sType() { return IndexType::MULTI; }
static size_t sDim() { return sizeof...(Indices); }
private:
IndexPack mIPack;
@ -39,6 +42,8 @@ namespace MultiArrayTools
public:
const IndexPack& pack() const { return mIPack; }
MultiIndex() = delete;
// NO DEFAULT HERE !!!

View file

@ -27,6 +27,8 @@ namespace MultiArrayTools
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
static IndexType sType() { return IndexType::SINGLE; }
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
IndexType type() const;

View file

@ -0,0 +1,51 @@
#ifndef __index_for_utils_h__
#define __index_for_utils_h__
#include "ranges/rheader.h"
#include "xfor.h"
namespace MultiArrayHelper
{
template <size_t N>
struct XFPackNum
{
template <class Expr, class IndexClass, typename... Args>
static auto mkFor(const std::shared_ptr<IndexClass>& iPtr, const Args&... args)
-> For<IndexClass,decltype(XFPackNum<N-1>::mkFor<Expr>(args...))>
{
return For<IndexClass,decltype(XFPackNum<N-1>::mkFor<Expr>(args...))>(iPtr, args...);
}
template <class Expr, class IndexTuple, typename... Args>
static auto mkForTp(const IndexTuple& iTuple, const Args&... args)
-> decltype(XFPackNum<N-1>::mkForTp(std::get<N>(iTuple), args...))
{
return XFPackNum<N-1>::mkForTp(iTuple, std::get<N>(iTuple), args...)
}
};
template <>
struct XFPackNum<0>
{
template <class Expr, class IndexClass, typename... Args>
static auto mkFor(const std::shared_ptr<IndexClass>& iPtr, const Args&... args)
-> For<IndexClass,Expr>
{
return For<IndexClass,Expr>(iPtr, args...);
}
template <class Expr, class IndexTuple, typename... Args>
static auto mkForTp(const IndexTuple& iTuple, const Args&... args)
-> decltype(XFPackNum<std::tuple_size<IndexTuple>::value-1>::mkFor( std::get<0>(iTuple), args... ))
{
return XFPackNum<std::tuple_size<IndexTuple>::value-1>::mkFor( std::get<0>(iTuple), args... );
}
};
} // end namespace MultiArrayHelper
#endif

57
src/xfor/xfor.h Normal file
View file

@ -0,0 +1,57 @@
#ifndef __xfor_h__
#define __xfor_h__
#include <cstdlib>
#include <memory>
namespace MultiArrayHelper
{
template <class IndexClass, class Expr>
class For
{
public:
For(For&& in) = default;
For& operator=(For&& in) = default;
template <typename... Args>
For(const std::shared_ptr<IndexClass>& indPtr, const Args&... args);
inline void operator()(size_t start = 0);
private:
For() = default;
std::shared_ptr<IndexClass> mIndPtr;
Expr mExpr;
}
} // namespace MultiArrayHelper
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace MultiArrayHelper
{
template <class IndexClass, class Expr>
template <typename... Args>
For<IndexClass,Expr>::For(const std::shared_ptr<IndexClass>& indPtr,
const Args&... args) : mIndPtr(indPtr), mExpr(args...) {}
template <class IndexClass, class Expr>
inline void For<IndexClass,Expr>::operator()(size_t start)
{
auto& ind = *mIndPtr;
const size_t max = ind.max();
for(ind = 0; ind.pos() != max; ++ind){
mExpr(start * max + ind.pos()); // CHECK!!
}
}
} // namespace MultiArrayHelper
#endif