diff --git a/src/include/multi_array_operation.cc.h b/src/include/multi_array_operation.cc.h index e3e012c..962157c 100644 --- a/src/include/multi_array_operation.cc.h +++ b/src/include/multi_array_operation.cc.h @@ -76,6 +76,27 @@ namespace MultiArrayTools (THIS(), inds...); } + template + template + auto OperationBase::p(const std::shared_ptr&... inds) const + -> ConstOperationRoot + { + auto ma = std::make_shared> + (inds->range()... , static_cast(0)); + (*ma)(inds...) = THIS(); + return ConstOperationRoot(ma, inds...); + } + + template + template + auto OperationBase::operator()(const std::shared_ptr&... inds) const + -> MultiArray + { + MultiArray out(inds->range()... , static_cast(0)); + out(inds...) = THIS(); + return out; + } + template template auto OperationBase::a(const std::shared_ptr>& ll, diff --git a/src/include/multi_array_operation.h b/src/include/multi_array_operation.h index 36dcbb9..c2f2fb4 100644 --- a/src/include/multi_array_operation.h +++ b/src/include/multi_array_operation.h @@ -61,6 +61,14 @@ namespace MultiArrayTools auto slc(const std::shared_ptr&... inds) const -> SliceContraction; + template + auto p(const std::shared_ptr&... inds) const + -> ConstOperationRoot; + + template + auto operator()(const std::shared_ptr&... inds) const + -> MultiArray; + template // Args = Operation Classes auto a(const std::shared_ptr>& ll, const Args&... args) const -> Operation,OperationClass, Args...>; diff --git a/src/include/ranges/dynamic_range.h b/src/include/ranges/dynamic_range.h index c7be122..057c091 100644 --- a/src/include/ranges/dynamic_range.h +++ b/src/include/ranges/dynamic_range.h @@ -46,7 +46,7 @@ namespace MultiArrayTools virtual int mm(std::intptr_t idxPtrNum) = 0; virtual std::string stringMeta() const = 0; - + virtual size_t pos() const = 0; virtual size_t max() const = 0; virtual size_t dim() const = 0; @@ -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 diff --git a/src/tests/op_unit_test.cc b/src/tests/op_unit_test.cc index 20d05ed..1321cd7 100644 --- a/src/tests/op_unit_test.cc +++ b/src/tests/op_unit_test.cc @@ -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) );