#include "functional_array.h" namespace CNORXZ { /**************************** * FunctionalMultiArray * ****************************/ template FunctionalMultiArray::FunctionalMultiArray(const std::shared_ptr&... ranges, const std::shared_ptr& func) : MultiArrayBase(ranges...), mFunc(func) {} template FunctionalMultiArray::FunctionalMultiArray(const std::shared_ptr&... ranges) : MultiArrayBase(ranges...) {} template FunctionalMultiArray::FunctionalMultiArray(const typename CRange::Space& space) : MultiArrayBase(space) {} template FunctionalMultiArray::FunctionalMultiArray(const typename CRange::Space& space, const std::shared_ptr& func) : MultiArrayBase(space), mFunc(func) {} template const T& FunctionalMultiArray::operator[](const IndexType& i) const { if constexpr(Function::FISSTATIC){ mVal = Function::apply(i.meta()); } else { mVal = (*mFunc)(i.meta()); } return mVal; } template const T& FunctionalMultiArray::at(const typename CRange::IndexType::MetaType& meta) const { if constexpr(Function::FISSTATIC){ mVal = Function::apply(meta); } else { mVal = (*mFunc)(meta); } return mVal; } template const T* FunctionalMultiArray::data() const { return &mVal; } template bool FunctionalMultiArray::isConst() const { return true; } template bool FunctionalMultiArray::isSlice() const { return false; } template std::shared_ptr > FunctionalMultiArray::anonymous(bool slice) const { assert(0); // think about it carefully return nullptr; } template ConstOperationRoot FunctionalMultiArray:: operator()(const std::shared_ptr&... inds) const { if(not mMaPtr){ mMaPtr = std::make_shared( MAB::mRange->space() ); (*mMaPtr)(inds...) = exec(inds...); } return ConstOperationRoot( *mMaPtr, inds... ); } template auto FunctionalMultiArray:: exec(const std::shared_ptr&... inds) const -> Operation...> { return mkOperation( mFunc, MetaOperationRoot( inds ) ... ); } } // namespace CNORXZ