add pre-execution function to operation classes

This commit is contained in:
Christian Zimmermann 2018-12-02 17:40:50 +01:00
parent f17d807d1a
commit 6671c784f3
4 changed files with 40 additions and 2 deletions

View file

@ -76,6 +76,27 @@ namespace MultiArrayTools
(THIS(), inds...); (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 T, class OperationClass>
template <typename R, class... Args> template <typename R, class... Args>
auto OperationBase<T,OperationClass>::a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll, auto OperationBase<T,OperationClass>::a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll,

View file

@ -61,6 +61,14 @@ namespace MultiArrayTools
auto slc(const std::shared_ptr<Indices>&... inds) const auto slc(const std::shared_ptr<Indices>&... inds) const
-> SliceContraction<T,OperationClass,Indices...>; -> 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 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 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...>; -> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>;

View file

@ -46,7 +46,7 @@ namespace MultiArrayTools
virtual int mm(std::intptr_t idxPtrNum) = 0; virtual int mm(std::intptr_t idxPtrNum) = 0;
virtual std::string stringMeta() const = 0; virtual std::string stringMeta() const = 0;
virtual size_t pos() const = 0; virtual size_t pos() const = 0;
virtual size_t max() const = 0; virtual size_t max() const = 0;
virtual size_t dim() const = 0; virtual size_t dim() const = 0;
@ -67,6 +67,15 @@ namespace MultiArrayTools
//virtual size_t posAt(const U& metaPos) const = 0; //virtual size_t posAt(const U& metaPos) const = 0;
//virtual bool isMeta(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> template <class ExpressionCollection>

View file

@ -565,7 +565,7 @@ namespace {
auto i1 = MAT::getIndex( mr1ptr ); auto i1 = MAT::getIndex( mr1ptr );
auto i2 = MAT::getIndex( sr4ptr ); 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'),'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) ); EXPECT_EQ( xround( res.at(mkt(mkt('1','a'),'B')) ), xround(0.353 + 4.790 - 2.210) );