cnorxz/src/multi_array_operation.h

714 lines
20 KiB
C
Raw Normal View History

2017-02-16 11:20:40 +01:00
// -*- C++ -*-
#ifndef __multi_array_operation_h__
#define __multi_array_operation_h__
#include <cstdlib>
#include <tuple>
2017-03-22 21:51:54 +01:00
#include <cmath>
2017-08-30 17:56:38 +02:00
#include <map>
#include <utility>
2017-02-16 11:20:40 +01:00
#include "base_def.h"
2017-12-18 11:19:04 +01:00
#include "mbase_def.h"
#include "block/block.h"
#include "operation_utils.h"
2017-12-18 13:13:13 +01:00
#include "ranges/rheader.h"
#include "pack_num.h"
2017-02-16 11:20:40 +01:00
2017-12-25 13:44:55 +01:00
#include "ranges/index_info.h"
2017-02-16 11:20:40 +01:00
namespace MultiArrayTools
{
namespace
{
using namespace MultiArrayHelper;
}
2017-08-30 17:56:38 +02:00
template <typename T>
2017-12-16 20:38:57 +01:00
Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize);
2017-12-24 18:14:07 +01:00
2017-08-30 17:56:38 +02:00
template <typename T>
2017-12-16 20:38:57 +01:00
MBlock<T> makeBlock(T* vec, size_t stepSize, size_t blockSize);
2017-08-30 17:56:38 +02:00
// dont use this for now !!
template <class OpClass>
std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx,
const OpClass& second);
template <class OpClass>
const IndexInfo* seekBlockIndex(const IndexInfo* ownII,
const OpClass& second);
template <typename T, class OperationClass>
2017-08-11 11:30:27 +02:00
class OperationTemplate
{
public:
2017-08-27 17:52:50 +02:00
2017-12-25 13:44:55 +01:00
OperationClass& THIS() { return static_cast<OperationClass&>(*this); }
const OperationClass& THIS() const { return static_cast<OperationClass const&>(*this); }
2017-08-11 11:30:27 +02:00
template <class Second>
2017-08-26 17:18:42 +02:00
auto operator+(const Second& in) const
-> Operation<T,std::plus<T>,OperationClass,Second>;
2017-08-26 17:18:42 +02:00
template <class Second>
auto operator-(const Second& in) const
-> Operation<T,std::minus<T>,OperationClass,Second>;
2017-08-26 17:18:42 +02:00
template <class Second>
auto operator*(const Second& in) const
-> Operation<T,std::multiplies<T>,OperationClass,Second>;
2017-08-26 17:18:42 +02:00
template <class Second>
auto operator/(const Second& in) const
-> Operation<T,std::divides<T>,OperationClass,Second>;
2017-11-05 18:46:38 +01:00
2017-11-02 21:20:31 +01:00
template <class IndexType>
auto c(std::shared_ptr<IndexType>& ind) const
-> Contraction<T,OperationClass,IndexType>;
2017-11-05 18:46:38 +01:00
2017-08-11 15:26:10 +02:00
private:
2017-12-25 13:44:55 +01:00
friend OperationClass;
OperationTemplate() = default;
2017-08-11 11:30:27 +02:00
};
template <typename T, class OpClass, class... Ranges>
2018-01-05 13:56:16 +01:00
class OperationMaster
{
public:
2018-01-07 23:08:16 +01:00
class AssignmentExpr
{
public:
static size_t layer() { return 0; }
AssignmentExpr(OperationMaster* mPtr, const OpClass* secPtr);
2018-01-07 23:08:16 +01:00
AssignmentExpr(AssignmentExpr&& in) = default;
AssignmentExpr& operator=(AssignmentExpr&& in) = default;
inline void operator()(size_t start = 0);
private:
AssignmentExpr() = default;
OperationMaster* mMPtr;
const OpClass* mSecPtr;
2018-01-07 23:08:16 +01:00
};
2017-08-27 17:52:50 +02:00
typedef T value_type;
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
2017-08-11 15:26:10 +02:00
typedef ContainerRange<Ranges...> CRange;
2017-08-10 15:12:26 +02:00
typedef typename MultiRange<Ranges...>::IndexType IndexType;
typedef MBlock<T> bType;
static size_t rootNum() { return 1; }
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
2017-08-11 15:26:10 +02:00
std::shared_ptr<typename CRange::IndexType>& index);
2017-12-24 18:14:07 +01:00
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index,
const IndexInfo* blockIndex);
MBlock<T>& get();
const Block<T>& get() const;
2017-02-27 17:00:51 +01:00
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const OperationMaster& block() const;
private:
2017-12-25 13:44:55 +01:00
std::shared_ptr<IndexType> mkIndex(std::shared_ptr<typename CRange::IndexType>& index);
2017-12-24 18:14:07 +01:00
void performAssignment(std::intptr_t blockIndexNum);
OpClass const& mSecond;
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
2017-08-11 11:30:27 +02:00
std::shared_ptr<IndexType> mIndex;
2017-12-25 13:44:55 +01:00
IndexInfo mIInfo;
mutable bType mBlock;
2017-02-16 11:20:40 +01:00
};
2017-08-10 15:12:26 +02:00
2017-08-10 15:12:26 +02:00
template <typename T, class... Ranges>
class ConstOperationRoot : /*public OperationBase<T>,*/
public OperationTemplate<T,ConstOperationRoot<T,Ranges...> >
{
public:
2017-08-27 17:52:50 +02:00
typedef T value_type;
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef OperationTemplate<T,ConstOperationRoot<T,Ranges...> > OT;
2017-08-10 15:12:26 +02:00
typedef ContainerRange<Ranges...> CRange;
typedef typename CRange::IndexType IndexType;
typedef Block<T> bType;
static size_t rootNum() { return 1; }
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
2017-08-10 15:12:26 +02:00
const std::shared_ptr<typename Ranges::IndexType>&... indices);
const Block<T>& get() const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const ConstOperationRoot& block() const;
std::tuple<size_t> rootSteps(const IndexInfo* ii = nullptr) const; // nullptr for simple usage with decltype
private:
2017-12-25 13:44:55 +01:00
std::shared_ptr<IndexType>
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices);
MultiArrayBase<T,Ranges...> const& mArrayRef;
2017-08-10 15:12:26 +02:00
std::shared_ptr<IndexType> mIndex;
2017-12-25 13:44:55 +01:00
IndexInfo mIInfo;
mutable bType mBlock;
};
2017-09-11 12:54:24 +02:00
2017-08-10 15:12:26 +02:00
template <typename T, class... Ranges>
2018-01-05 13:56:16 +01:00
class OperationRoot : public OperationTemplate<T,OperationRoot<T,Ranges...> >
{
public:
2017-08-27 17:52:50 +02:00
typedef T value_type;
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef OperationTemplate<T,OperationRoot<T,Ranges...> > OT;
2017-08-10 15:12:26 +02:00
typedef ContainerRange<Ranges...> CRange;
typedef typename CRange::IndexType IndexType;
typedef MBlock<T> bType;
static size_t rootNum() { return 1; }
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
2017-08-10 15:12:26 +02:00
const std::shared_ptr<typename Ranges::IndexType>&... indices);
2017-08-11 11:30:27 +02:00
template <class OpClass>
OperationMaster<T,OpClass,Ranges...> operator=(const OpClass& in);
2017-08-11 11:30:27 +02:00
const MBlock<T>& get() const;
MBlock<T>& get();
OperationRoot& set(const IndexInfo* blockIndex);
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const OperationRoot& block() const;
std::tuple<size_t> rootSteps(const IndexInfo* ii = nullptr) const; // nullptr for simple usage with decltype
2017-05-24 19:01:02 +02:00
private:
2017-12-25 13:44:55 +01:00
std::shared_ptr<IndexType>
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices);
MutableMultiArrayBase<T,Ranges...>& mArrayRef;
2017-08-10 15:12:26 +02:00
std::shared_ptr<IndexType> mIndex;
2017-12-25 13:44:55 +01:00
IndexInfo mIInfo;
mutable bType mBlock;
const IndexInfo* mBlockII; // predefine to save time
2017-02-16 11:20:40 +01:00
};
template <class Op>
size_t sumRootNum()
{
return typename Op::rootNum();
}
template <class Op1, class Op2, class... Ops>
size_t sumRootNum()
{
return typename Op1::rootNum() + sumRootNum<Op2,Ops...>();
}
2017-09-11 12:54:24 +02:00
2017-08-10 15:12:26 +02:00
template <typename T, class OpFunction, class... Ops>
2018-01-05 13:56:16 +01:00
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
2017-03-22 11:44:33 +01:00
{
public:
2017-08-27 17:52:50 +02:00
typedef T value_type;
2017-08-10 15:12:26 +02:00
typedef OperationBase<T> OB;
typedef OperationTemplate<T,Operation<T,OpFunction,Ops...> > OT;
2017-08-10 15:12:26 +02:00
typedef OpFunction F;
typedef BlockResult<T> bType;
static size_t rootNum() { return sumRootNum<Ops...>(); }
private:
std::tuple<Ops const&...> mOps;
mutable bType mRes;
public:
2017-08-11 15:26:10 +02:00
Operation(const Ops&... ops);
2017-03-22 11:44:33 +01:00
const BlockResult<T>& get() const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const Operation& block() const;
auto rootSteps(const IndexInfo* ii = nullptr) const // nullptr for simple usage with decltype
-> decltype(PackNum<sizeof...(Ops)-1>::mkStepTuple(ii, mOps));
2017-03-22 11:44:33 +01:00
};
2017-11-04 22:49:55 +01:00
2017-11-02 21:20:31 +01:00
template <typename T, class Op, class IndexType>
2017-11-04 22:49:55 +01:00
class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> >
{
public:
typedef T value_type;
2017-11-02 21:20:31 +01:00
typedef OperationTemplate<T,Contraction<T,Op,IndexType> > OT;
typedef BlockResult<T> bType;
static size_t rootNum() { return typename Op::rootNum(); }
private:
const Op& mOp;
std::shared_ptr<IndexType> mInd;
mutable bType mRes;
public:
2017-11-02 21:20:31 +01:00
Contraction(const Op& op, std::shared_ptr<IndexType> ind);
const BlockResult<T>& get() const;
std::vector<BTSS> block(const IndexInfo* blockIndex, bool init = false) const;
const Contraction& block() const;
auto rootSteps(const IndexInfo* ii = nullptr) const // nullptr for simple usage with decltype
-> decltype(mOp.rootSteps(ii));
};
2017-08-11 15:26:10 +02:00
}
2017-02-16 11:20:40 +01:00
/* ========================= *
* --- TEMPLATE CODE --- *
* ========================= */
namespace MultiArrayTools
{
namespace
{
using namespace MultiArrayHelper;
}
template <typename T>
2017-12-16 20:38:57 +01:00
Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize)
{
2017-12-16 20:38:57 +01:00
return Block<T>(vec, 0, blockSize, stepSize);
}
template <typename T>
2017-12-16 20:38:57 +01:00
MBlock<T> makeBlock(T* vec, size_t stepSize, size_t blockSize)
{
2017-12-16 20:38:57 +01:00
return MBlock<T>(vec, 0, blockSize, stepSize);
}
// dont use this for now !!
template <class OpClass>
std::shared_ptr<VIWB> seekBlockIndex(std::shared_ptr<VIWB> ownIdx,
const OpClass& second)
{
assert(0); // dont use this for now !!
std::vector<std::shared_ptr<VIWB> > ivec;
seekIndexInst(ownIdx, ivec);
std::map<std::shared_ptr<VIWB>, std::vector<BTSS> > mp;
for(auto& xx: ivec){
mp[xx] = second.block(xx);
}
// seek minimal number of VALUEs => guarantees absence of conflicting blocks
minimizeAppearanceOfType(mp, BlockType::VALUE);
// seek mininmal number of SPLITs => maximal vectorization possible
minimizeAppearanceOfType(mp, BlockType::SPLIT);
return mp.begin()->first;
}
template <class OpClass>
const IndexInfo* seekBlockIndex(const IndexInfo* ownII,
const OpClass& second)
{
const IndexInfo* ii = ownII;
while(ii->type() == IndexType::CONT or
ii->type() == IndexType::MULTI){
ii = ii->getPtr(ii->dim()-1);
}
return ii;
}
/***************************
* OperationTemplate *
***************************/
template <typename T, class OperationClass>
template <class Second>
auto OperationTemplate<T,OperationClass>::operator+(const Second& in) const
-> Operation<T,std::plus<T>,OperationClass,Second>
{
2017-12-25 13:44:55 +01:00
return Operation<T,std::plus<T>,OperationClass,Second>(THIS(), in);
}
template <typename T, class OperationClass>
template <class Second>
auto OperationTemplate<T,OperationClass>::operator-(const Second& in) const
-> Operation<T,std::minus<T>,OperationClass,Second>
{
2017-12-25 13:44:55 +01:00
return Operation<T,std::minus<T>,OperationClass,Second>(THIS(), in);
}
template <typename T, class OperationClass>
template <class Second>
auto OperationTemplate<T,OperationClass>::operator*(const Second& in) const
-> Operation<T,std::multiplies<T>,OperationClass,Second>
{
2017-12-25 13:44:55 +01:00
return Operation<T,std::multiplies<T>,OperationClass,Second>(THIS(), in);
}
template <typename T, class OperationClass>
template <class Second>
auto OperationTemplate<T,OperationClass>::operator/(const Second& in) const
-> Operation<T,std::divides<T>,OperationClass,Second>
{
2017-12-25 13:44:55 +01:00
return Operation<T,std::divides<T>,OperationClass,Second>(THIS(), in);
}
template <typename T, class OperationClass>
template <class IndexType>
auto OperationTemplate<T,OperationClass>::c(std::shared_ptr<IndexType>& ind) const
-> Contraction<T,OperationClass,IndexType>
{
2017-12-25 13:44:55 +01:00
return Contraction<T,OperationClass,IndexType>(THIS(), ind);
}
/*************************
* OperationMaster *
*************************/
template <typename T, class OpClass, class... Ranges>
OperationMaster<T,OpClass,Ranges...>::
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index) :
2017-12-25 13:44:55 +01:00
mSecond(second), mArrayRef(ma), mIndex(mkIndex(index)), mIInfo(*mIndex)
{
auto blockIndex = seekBlockIndex( &mIInfo, second);
std::intptr_t blockIndexNum = blockIndex->getPtrNum();
block(blockIndex, true);
second.block(blockIndex, true);
2017-12-24 18:14:07 +01:00
performAssignment(blockIndexNum);
}
template <typename T, class OpClass, class... Ranges>
OperationMaster<T,OpClass,Ranges...>::
OperationMaster(MutableMultiArrayBase<T,Ranges...>& ma, const OpClass& second,
std::shared_ptr<typename CRange::IndexType>& index,
const IndexInfo* blockIndex) :
2017-12-25 13:44:55 +01:00
mSecond(second), mArrayRef(ma), mIndex(mkIndex(index)), mIInfo(*mIndex)
2017-12-24 18:14:07 +01:00
{
std::intptr_t blockIndexNum = blockIndex->getPtrNum();
second.block(blockIndex, true);
performAssignment(blockIndexNum);
}
2017-12-25 13:44:55 +01:00
template <typename T, class OpClass, class... Ranges>
std::shared_ptr<typename OperationMaster<T,OpClass,Ranges...>::IndexType>
OperationMaster<T,OpClass,Ranges...>::
mkIndex(std::shared_ptr<typename CRange::IndexType>& index)
{
MultiRangeFactory<Ranges...> mrf( index->range() );
std::shared_ptr<MultiRange<Ranges...> > mr =
std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
auto i = std::make_shared<IndexType>( mr->begin() );
(*i) = *index;
return i;
}
2017-12-24 18:14:07 +01:00
2017-12-25 13:44:55 +01:00
template <typename T, class OpClass, class... Ranges>
2017-12-24 18:14:07 +01:00
void OperationMaster<T,OpClass,Ranges...>::performAssignment(std::intptr_t blockIndexNum)
{
#ifdef XX_USE_NEW_LOOP_ROUTINE_XX
// === N E W ===
2018-01-09 22:38:46 +01:00
static const size_t TDIM = IndexType::totalDim()
typedef std::array<std::intptr_t,TDIM> IAT;
typedef decltype(mSecond.rootSteps()) RootStepType;
2018-01-09 22:38:46 +01:00
AssignmentExpr ae(this, &mSecond);
IAT siar = mIndex->getSIndexTuple();
std::array<RootStepType,TDIM> ee;
PackNum<TDIM-1>::mkExt(ee, siar, mSecond);
auto loop = mIndex->ifor(ee, ae);
loop();
#else
// === O L D ===
for(*mIndex = 0; mIndex->pos() != mIndex->max(); mIndex->pp(blockIndexNum) ){
block();
get() = mSecond.get();
}
#endif
}
template <typename T, class OpClass, class... Ranges>
MBlock<T>& OperationMaster<T,OpClass,Ranges...>::get()
{
2017-12-16 20:38:57 +01:00
return mBlock;
}
template <typename T, class OpClass, class... Ranges>
const Block<T>& OperationMaster<T,OpClass,Ranges...>::get() const
{
2017-12-16 20:38:57 +01:00
return mBlock;
}
template <typename T, class OpClass, class... Ranges>
std::vector<BTSS> OperationMaster<T,OpClass,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{
std::vector<BTSS> btv(1, getBlockType( &mIInfo, blockIndex, true) );
if(init){
mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
}
return btv;
}
template <typename T, class OpClass, class... Ranges>
const OperationMaster<T,OpClass,Ranges...>& OperationMaster<T,OpClass,Ranges...>::block() const
{
2017-12-16 20:38:57 +01:00
mBlock.set( mIndex->pos() );
return *this;
}
/****************************
* ConstOperationRoot *
****************************/
template <typename T, class... Ranges>
ConstOperationRoot<T,Ranges...>::
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
2017-12-25 13:44:55 +01:00
//OperationTemplate<T,ConstOperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mIndex( mkIndex(ma,indices...) ), mIInfo(*mIndex)
{}
template <typename T, class... Ranges>
std::shared_ptr<typename ConstOperationRoot<T,Ranges...>::IndexType>
ConstOperationRoot<T,Ranges...>::
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices)
{
2017-12-25 13:44:55 +01:00
auto i = std::make_shared<IndexType>( ma.range() );
(*mIndex)(indices...);
2017-12-25 13:44:55 +01:00
return i;
}
2017-12-25 13:44:55 +01:00
template <typename T, class... Ranges>
const Block<T>& ConstOperationRoot<T,Ranges...>::get() const
{
block();
2017-12-16 20:38:57 +01:00
return mBlock;
}
template <typename T, class... Ranges>
std::vector<BTSS> ConstOperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{
std::vector<BTSS> btv(1, getBlockType( &mIInfo, blockIndex, true) );
if(init){
mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
}
return btv;
}
template <typename T, class... Ranges>
const ConstOperationRoot<T,Ranges...>& ConstOperationRoot<T,Ranges...>::block() const
{
2017-12-16 20:38:57 +01:00
mBlock.set( (*mIndex)().pos() );
return *this;
}
template <typename T, class... Ranges>
std::tuple<size_t> ConstOperationRoot<T,Ranges...>::rootSteps(const IndexInfo* ii) const
{
return std::tuple<size_t>(0ul); // !!!!!!
}
/***********************
* OperationRoot *
***********************/
template <typename T, class... Ranges>
OperationRoot<T,Ranges...>::
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices) :
2017-12-25 13:44:55 +01:00
//OperationTemplate<T,OperationRoot<T,Ranges...> >(this),
mArrayRef(ma), mIndex( mkIndex( ma, indices... ) ), mIInfo(*mIndex),
mBlockII(nullptr)
2017-12-25 13:44:55 +01:00
{}
template <typename T, class... Ranges>
std::shared_ptr<typename OperationRoot<T,Ranges...>::IndexType>
OperationRoot<T,Ranges...>::
mkIndex(const MultiArrayBase<T,Ranges...>& ma,
const std::shared_ptr<typename Ranges::IndexType>&... indices)
{
2017-12-25 13:44:55 +01:00
auto i = std::make_shared<IndexType>( ma.range() );
(*mIndex)(indices...);
2017-12-25 13:44:55 +01:00
return i;
}
2017-12-25 13:44:55 +01:00
template <typename T, class... Ranges>
template <class OpClass>
OperationMaster<T,OpClass,Ranges...> OperationRoot<T,Ranges...>::operator=(const OpClass& in)
{
if(mBlockII != nullptr){
return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex, mBlockII);
2017-12-24 18:14:07 +01:00
}
else {
return OperationMaster<T,OpClass,Ranges...>(mArrayRef, in, mIndex);
}
}
template <typename T, class... Ranges>
const MBlock<T>& OperationRoot<T,Ranges...>::get() const
{
block();
2017-12-16 20:38:57 +01:00
return mBlock;
}
template <typename T, class... Ranges>
MBlock<T>& OperationRoot<T,Ranges...>::get()
{
block();
2017-12-16 20:38:57 +01:00
return mBlock;
}
template <typename T, class... Ranges>
OperationRoot<T,Ranges...>&
OperationRoot<T,Ranges...>::set(const IndexInfo* blockIndex)
{
mBlockII = blockIndex;
return *this;
}
template <typename T, class... Ranges>
std::vector<BTSS> OperationRoot<T,Ranges...>::block(const IndexInfo* blockIndex, bool init) const
{
std::vector<BTSS> btv(1, getBlockType( &mIInfo, blockIndex, true) );
if(init){
mBlock = makeBlock(mArrayRef.data(), btv[0].second, blockIndex->max());
}
return btv;
}
template <typename T, class... Ranges>
const OperationRoot<T,Ranges...>& OperationRoot<T,Ranges...>::block() const
{
2017-12-16 20:38:57 +01:00
mBlock.set( (*mIndex)().pos() );
return *this;
}
template <typename T, class... Ranges>
std::tuple<size_t> OperationRoot<T,Ranges...>::rootSteps(const IndexInfo* ii) const
{
return std::tuple<size_t>(0ul); // !!!!!!
}
/*******************
* Operation *
*******************/
template <typename T, class OpFunction, class... Ops>
Operation<T,OpFunction,Ops...>::Operation(const Ops&... ops) :
2017-12-25 13:44:55 +01:00
//OperationTemplate<T,Operation<T,OpFunction,Ops...> >(this),
mOps(ops...) {}
template <typename T, class OpFunction, class... Ops>
const BlockResult<T>& Operation<T,OpFunction,Ops...>::get() const
{
2017-12-22 14:15:09 +01:00
PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mRes, mOps);
return mRes;
}
template <typename T, class OpFunction, class... Ops>
std::vector<BTSS> Operation<T,OpFunction,Ops...>::block(const IndexInfo* blockIndex, bool init) const
{
std::vector<BTSS> btv;
PackNum<sizeof...(Ops)-1>::makeBlockTypeVec(btv, mOps, blockIndex, init);
if(init){
mRes.init(blockIndex->max());
}
return btv;
}
template <typename T, class OpFunction, class... Ops>
const Operation<T,OpFunction,Ops...>& Operation<T,OpFunction,Ops...>::block() const
{
2017-12-16 20:38:57 +01:00
//mBlock.set( mIndex->pos() );
return *this;
}
template <typename T, class OpFunction, class... Ops>
auto Operation<T,OpFunction,Ops...>::rootSteps(const IndexInfo* ii) const
-> decltype(PackNum<sizeof...(Ops)-1>::mkStepTuple(ii, mOps))
{
return PackNum<sizeof...(Ops)-1>::mkStepTuple(ii, mOps);
}
/*********************
* Contraction *
*********************/
template <typename T, class Op, class IndexType>
Contraction<T,Op,IndexType>::Contraction(const Op& op, std::shared_ptr<IndexType> ind) :
2017-12-25 13:44:55 +01:00
//OperationTemplate<T,Contraction<T,Op,IndexType> >(this),
mOp(op),
mInd(ind) {}
template <typename T, class Op, class IndexType>
const BlockResult<T>& Contraction<T,Op,IndexType>::get() const
{
BlockBinaryOpSelf<T,std::plus<T>,decltype(mOp.get())> f(mRes);
for(*mInd = 0; mInd->pos() != mInd->max(); ++(*mInd)){
f(mOp.get());
}
return mRes;
}
template <typename T, class Op, class IndexType>
std::vector<BTSS> Contraction<T,Op,IndexType>::block(const IndexInfo* blockIndex, bool init) const
{
if(init){
mRes.init(blockIndex->max());
}
return mOp.block(blockIndex, init);
}
template <typename T, class Op, class IndexType>
const Contraction<T,Op,IndexType>& Contraction<T,Op,IndexType>::block() const
{
return *this;
}
template <typename T, class Op, class IndexType>
auto Contraction<T,Op,IndexType>::rootSteps(const IndexInfo* ii) const
-> decltype(mOp.rootSteps(ii))
{
return mOp.rootSteps(ii);
}
}
2017-02-16 11:20:40 +01:00
#endif