diff --git a/src/block.cc b/src/block.cc index ea91bc2..ce5ea44 100644 --- a/src/block.cc +++ b/src/block.cc @@ -226,5 +226,43 @@ namespace MultiArrayHelper { return 1; } + + template + BlockResult& BlockResult::operator+=(const BlockBase& in) + { + return operateSelf >(in); + } + + template + BlockResult& BlockResult::operator-=(const BlockBase& in) + { + return operateSelf >(in); + } + + template + BlockResult& BlockResult::operator*=(const BlockBase& in) + { + return operateSelf >(in); + } + + template + BlockResult& BlockResult::operator/=(const BlockBase& in) + { + return operateSelf >(in); + } + + template + template + BlockResult& BlockResult::operateSelf(const BlockBase& in) + { + assert(mSize == in.size()); + OpFunction f; + //BlockResult res(mSize); + for(size_t i = 0; i != mSize; ++i){ + (*this)[i] = f((*this)[i], in[i]); + } + return *this; + } + } // end namespace MultiArrayHelper diff --git a/src/block.h b/src/block.h index 8efdfe0..09e9768 100644 --- a/src/block.h +++ b/src/block.h @@ -129,6 +129,14 @@ namespace MultiArrayHelper BlockResult& set(size_t npos); size_t stepSize() const; + BlockResult& operator+=(const BlockBase& in); + BlockResult& operator-=(const BlockBase& in); + BlockResult& operator*=(const BlockBase& in); + BlockResult& operator/=(const BlockBase& in); + + template + BlockResult& operateSelf(const BlockBase& in); + protected: std::vector mRes; }; diff --git a/src/multi_array_operation.cc b/src/multi_array_operation.cc index 9d4d275..3aaefaf 100644 --- a/src/multi_array_operation.cc +++ b/src/multi_array_operation.cc @@ -342,4 +342,36 @@ namespace MultiArrayTools return *this; } + /********************* + * Contraction * + *********************/ + + template + Contraction(const Op& op, std::shared_ptr ind) : + OperationTemplate >(this), + mOp(op) {} + + const BlockResult& get() const + { + // set mRes = 0 !!! + for(*mIndex = 0; mIndex->pos() != mIndex->max(); ++(*mIndex)){ + mRes += mOp.get(); + } + return mRes; + } + + template + std::vector Contraction::block(const std::shared_ptr blockIndex) const + { + std::vector btv; + PackNum::makeBlockTypeVec(btv, mOp, blockIndex); + return btv; + } + + template + const Contraction& block() const + { + return *this; + } + }