im com (single expression)
This commit is contained in:
parent
f5cf35ae69
commit
89eb03ab7f
3 changed files with 100 additions and 3 deletions
|
@ -208,6 +208,7 @@ namespace MultiArrayTools
|
|||
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
template <class... MappedRanges>
|
||||
ConstOperationRoot<T,SRanges...>
|
||||
MultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
||||
|
@ -278,9 +279,10 @@ namespace MultiArrayTools
|
|||
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
template <class... MappedRanges>
|
||||
ConstOperationRoot<T,SRanges...>
|
||||
MultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds)
|
||||
MutableMultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename MappedRanges::IndexType>&... inds)
|
||||
{
|
||||
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
||||
"number of mapped ranges must be equal to number of original ranges");
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
|
||||
#include "xfor/xfor.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
namespace
|
||||
|
@ -115,7 +117,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <class Exprs>
|
||||
auto ifor(Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFors(mIPack, mOutIndex, exs));
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(mIPack, SinleExpression( mOutIndex, exs ) ));
|
||||
|
||||
/*
|
||||
template <class Exprs>
|
||||
|
@ -236,7 +238,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
// -> define in range_base.cc
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
||||
//std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
||||
|
||||
/******************
|
||||
* MapIndex *
|
||||
|
|
|
@ -53,6 +53,44 @@ namespace MultiArrayHelper
|
|||
}
|
||||
};
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
class SingleExpression
|
||||
{
|
||||
private:
|
||||
SingleExpression() = default;
|
||||
|
||||
const IndexClass* mIndPtr;
|
||||
size_t mSPos;
|
||||
size_t mMax;
|
||||
Expr mExpr;
|
||||
|
||||
typedef decltype(mExpr.rootSteps()) ExtType;
|
||||
ExtType mExt;
|
||||
|
||||
public:
|
||||
|
||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||
static constexpr size_t SIZE = Expr::SIZE;
|
||||
|
||||
SingleExpression(const SingleExpression& in) = default;
|
||||
SingleExpression& operator=(const SingleExpression& in) = default;
|
||||
SingleExpression(SingleExpression&& in) = default;
|
||||
SingleExpression& operator=(SingleExpression&& in) = default;
|
||||
|
||||
SingleExpression(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr expr);
|
||||
|
||||
SingleExpression(const IndexClass* indPtr,
|
||||
Expr expr);
|
||||
|
||||
|
||||
inline void operator()(size_t mlast, ExtType last) const;
|
||||
inline void operator()(size_t mlast = 0) const;
|
||||
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
|
||||
};
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT = ForType::DEFAULT>
|
||||
class For
|
||||
{
|
||||
|
@ -167,6 +205,61 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
SingleExpression<IndexClass,Expr>::SingleExpression(const std::shared_ptr<IndexClass>& indPtr,
|
||||
Expr expr) :
|
||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr),
|
||||
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr.get() )))
|
||||
{
|
||||
assert(mIndPtr != nullptr);
|
||||
//VCHECK(mIndPtr->id());
|
||||
//VCHECK(mIndPtr->max());
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
SingleExpression<IndexClass,Expr>::SingleExpression(const IndexClass* indPtr,
|
||||
Expr expr) :
|
||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
|
||||
mExpr(std::forward<Expr>( expr )),
|
||||
mExt(expr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr ) ))
|
||||
{
|
||||
assert(mIndPtr != nullptr);
|
||||
//VCHECK(mIndPtr->id());
|
||||
//VCHECK(mIndPtr->max());
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast,
|
||||
ExtType last) const
|
||||
{
|
||||
//typedef typename IndexClass::RangeType RangeType;
|
||||
const size_t pos = mIndPtr->pos();
|
||||
const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos);
|
||||
const ExtType npos = last + mExt*pos;
|
||||
mExpr(mnpos, npos);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast) const
|
||||
{
|
||||
//typedef typename IndexClass::RangeType RangeType;
|
||||
const ExtType last;
|
||||
const size_t pos = mIndPtr->pos();
|
||||
const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos);
|
||||
const ExtType npos = last + mExt*pos;
|
||||
mExpr(mlast, last);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
auto SingleExpression<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
|
||||
-> ExtType
|
||||
{
|
||||
return mExpr.rootSteps(iPtrNum);
|
||||
}
|
||||
|
||||
|
||||
} // namespace MultiArrayHelper
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue