add pre-execution function to operation classes
This commit is contained in:
parent
f17d807d1a
commit
6671c784f3
4 changed files with 40 additions and 2 deletions
|
@ -76,6 +76,27 @@ namespace MultiArrayTools
|
|||
(THIS(), inds...);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
template <class... Indices>
|
||||
auto OperationBase<T,OperationClass>::p(const std::shared_ptr<Indices>&... inds) const
|
||||
-> ConstOperationRoot<T,typename Indices::RangeType...>
|
||||
{
|
||||
auto ma = std::make_shared<MultiArray<T,typename Indices::RangeType...>>
|
||||
(inds->range()... , static_cast<T>(0));
|
||||
(*ma)(inds...) = THIS();
|
||||
return ConstOperationRoot<T,typename Indices::RangeType...>(ma, inds...);
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
template <class... Indices>
|
||||
auto OperationBase<T,OperationClass>::operator()(const std::shared_ptr<Indices>&... inds) const
|
||||
-> MultiArray<T,typename Indices::RangeType...>
|
||||
{
|
||||
MultiArray<T,typename Indices::RangeType...> out(inds->range()... , static_cast<T>(0));
|
||||
out(inds...) = THIS();
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
template <typename R, class... Args>
|
||||
auto OperationBase<T,OperationClass>::a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll,
|
||||
|
|
|
@ -61,6 +61,14 @@ namespace MultiArrayTools
|
|||
auto slc(const std::shared_ptr<Indices>&... inds) const
|
||||
-> SliceContraction<T,OperationClass,Indices...>;
|
||||
|
||||
template <class... Indices>
|
||||
auto p(const std::shared_ptr<Indices>&... inds) const
|
||||
-> ConstOperationRoot<T,typename Indices::RangeType...>;
|
||||
|
||||
template <class... Indices>
|
||||
auto operator()(const std::shared_ptr<Indices>&... inds) const
|
||||
-> MultiArray<T,typename Indices::RangeType...>;
|
||||
|
||||
template <typename R, class... Args> // Args = Operation Classes
|
||||
auto a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll, const Args&... args) const
|
||||
-> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>;
|
||||
|
|
|
@ -67,6 +67,15 @@ namespace MultiArrayTools
|
|||
//virtual size_t posAt(const U& metaPos) const = 0;
|
||||
|
||||
//virtual bool isMeta(const U& metaPos) const = 0;
|
||||
inline AbstractIW& at(const std::string smeta)
|
||||
{
|
||||
for((*this) = 0; this->pos() != this->max(); ++(*this)){
|
||||
if(this->stringMeta() == smeta){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <class ExpressionCollection>
|
||||
|
|
|
@ -565,7 +565,7 @@ namespace {
|
|||
auto i1 = MAT::getIndex( mr1ptr );
|
||||
auto i2 = MAT::getIndex( sr4ptr );
|
||||
|
||||
res(i1,i2) = ( ma1(i1) + ma2(i2) ) - ma3(i2);
|
||||
res(i1,i2) = ( ma1(i1) + ma2(i2) ).p(i1,i2) - ma3(i2);
|
||||
|
||||
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'A')) ), xround(0.353 + 8.870 - 1.470) );
|
||||
EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'B')) ), xround(0.353 + 4.790 - 2.210) );
|
||||
|
|
Loading…
Reference in a new issue