diff --git a/src/index_base.h b/src/index_base.h index bc8d2ea..a45f904 100644 --- a/src/index_base.h +++ b/src/index_base.h @@ -9,7 +9,7 @@ #include "base_def.h" #include "range_base.h" -#include "name.h" + namespace MultiArrayTools { diff --git a/src/ma_functional.cc b/src/ma_functional.cc deleted file mode 100644 index d4c7f80..0000000 --- a/src/ma_functional.cc +++ /dev/null @@ -1,96 +0,0 @@ -// -*- C++ -*- - -#include "ma_functional.h" - -namespace MultiArrayTools -{ - - template - IndexMapFunction:: - IndexMapFunction(const MultiArrayBase& ma, - const OutRange& outRange, - const Name& inName, const Name& outName) : mMap(ma, inName), - mOutRange(new OutRange( outRange )), - mOIndex(mOutRange->begin()) - { - //CHECK; - mOIndex.name(outName); - } - - template - void IndexMapFunction::linkIndicesTo(IndefinitIndexBase* target) - { - mMap.linkIndicesTo(target); - } - - template - void IndexMapFunction::eval() const - { - mOIndex.copyPos( mMap.get() ); - } - - template - IndefinitIndexBase& IndexMapFunction::index() const - { - return mOIndex; - } - - - - vec3d2Function::vec3d2Function(const OutRange& outRange) : mOutRange(new OutRange( outRange )), - out(mOutRange->begin()) {} - - vec3d2Function::OutIndex vec3d2Function::operator()(const InIndex& i) const - { - OutSubIndex& osi = out.template getIndex<0>(); - - osi.atMeta( i.template getIndex<0>().getMetaPos() * i.template getIndex<0>().getMetaPos() + - i.template getIndex<1>().getMetaPos() * i.template getIndex<1>().getMetaPos() + - i.template getIndex<2>().getMetaPos() * i.template getIndex<2>().getMetaPos() ); - return out; - } - - pyProjFunction::pyProjFunction(const OutRange& outRange) : mOutRange(new OutRange( outRange )), - out(mOutRange->begin()) {} - - pyProjFunction::OutIndex pyProjFunction::operator()(const InIndex& i) const - { - DistIndex& di = out.template getIndex<0>(); - ScalProdIndex& si = out.template getIndex<1>(); - const int xx = i.template getIndex<1>().getMetaPos(); - const int yy = i.template getIndex<2>().getMetaPos(); - const int zz = i.template getIndex<3>().getMetaPos(); - if(xx == 0 or yy == 0 or zz == 0){ // anistotropy in C2 - di.atMeta(0); - si.atMeta(0); - } - - di.atMeta( xx * xx + yy * yy + zz * zz ); - si.atMeta( abs( xx * i.template getIndex<0>().getMetaPos()[0] + - yy * i.template getIndex<0>().getMetaPos()[1] + - zz * i.template getIndex<0>().getMetaPos()[2] ) ); - return out; - } - - pyProjNoSymFunction::pyProjNoSymFunction(const OutRange& outRange) : mOutRange(new OutRange( outRange )), - out(mOutRange->begin()) {} - - pyProjNoSymFunction::OutIndex pyProjNoSymFunction::operator()(const InIndex& i) const - { - DistIndex& di = out.template getIndex<0>(); - ScalProdIndex& si = out.template getIndex<1>(); - const int xx = i.template getIndex<1>().getMetaPos(); - const int yy = i.template getIndex<2>().getMetaPos(); - const int zz = i.template getIndex<3>().getMetaPos(); - if(xx == 0 or yy == 0 or zz == 0){ // anistotropy in C2 - di.atMeta(0); - si.atMeta(0); - } - - di.atMeta( xx * xx + yy * yy + zz * zz ); - si.atMeta( xx * i.template getIndex<0>().getMetaPos()[0] + - yy * i.template getIndex<0>().getMetaPos()[1] + - zz * i.template getIndex<0>().getMetaPos()[2] ); - return out; - } -} diff --git a/src/ma_functional.h b/src/ma_functional.h deleted file mode 100644 index 7d39f36..0000000 --- a/src/ma_functional.h +++ /dev/null @@ -1,114 +0,0 @@ -// -*- C++ -*- - -#ifndef __ma_functional_h__ -#define __ma_functional_h__ - -#include -#include -#include - -#include "base_def.h" - -namespace MultiArrayTools -{ - - // Map is a ConstMultiArrayOperationRoot where the corresponding MultiArray defines the map - template - class IndexMapFunction - { - public: - - typedef OutRange OR; - typedef typename OutRange::IndexType OutIndex; - - //IndexMapFunction() = default; - - IndexMapFunction(const MultiArrayBase& ma, - const OutRange& outRange, - const Name& inName, const Name& outName); - - IndexMapFunction(const IndexMapFunction& in) = default; - - void linkIndicesTo(IndefinitIndexBase* target); - void eval() const; - - IndefinitIndexBase& index() const; - - private: - - ConstMultiArrayOperationRoot mMap; - std::shared_ptr mOutRange; - mutable typename OutRange::IndexType mOIndex; - }; - - class vec3d2Function - { - public: - - typedef SingleIndex CoordIndex; - typedef MultiIndex InIndex; - typedef SingleIndex OutSubIndex; - typedef MultiIndex OutIndex; - typedef MultiRange > OutRange; - - DEFAULT_MEMBERS(vec3d2Function); - - vec3d2Function(const OutRange& outRange); - //vec3d2Function& operator=(const vec3d2Function& in) = default; - - OutIndex operator()(const InIndex& i) const; - - private: - std::shared_ptr mOutRange; - mutable OutIndex out; - }; - - class pyProjFunction - { - public: - typedef SingleIndex CoordIndex; - typedef SingleIndex,RangeType::MOMENTUM> MomIndex; - typedef MultiIndex InIndex; - typedef SingleIndex DistIndex; - typedef SingleIndex ScalProdIndex; - typedef MultiIndex OutIndex; - typedef MultiRange, - SingleRange > OutRange; - - DEFAULT_MEMBERS(pyProjFunction); - - pyProjFunction(const OutRange& outRange); - OutIndex operator()(const InIndex& i) const; - - private: - std::shared_ptr mOutRange; - mutable OutIndex out; - }; - - class pyProjNoSymFunction - { - public: - typedef SingleIndex CoordIndex; - typedef SingleIndex,RangeType::MOMENTUM> MomIndex; - typedef MultiIndex InIndex; - typedef SingleIndex DistIndex; - typedef SingleIndex ScalProdIndex; - typedef MultiIndex OutIndex; - typedef MultiRange, - SingleRange > OutRange; - - DEFAULT_MEMBERS(pyProjNoSymFunction); - - pyProjNoSymFunction(const OutRange& outRange); - OutIndex operator()(const InIndex& i) const; - - private: - std::shared_ptr mOutRange; - mutable OutIndex out; - }; - -} - -#include "ma_functional.cc" - -#endif diff --git a/src/multi_array.h b/src/multi_array.h index 07d6564..4e37e70 100644 --- a/src/multi_array.h +++ b/src/multi_array.h @@ -13,7 +13,7 @@ #include "multi_range.h" //#include "multi_array_operation.h" //#include "manipulator.h" -//#include "name.h" +// namespace MultiArrayTools { diff --git a/src/name.cc b/src/name.cc deleted file mode 100644 index 620f475..0000000 --- a/src/name.cc +++ /dev/null @@ -1,95 +0,0 @@ - -#include "name.h" - -namespace MultiArrayTools -{ - - namespace - { - struct Naming - { - static void giveNames(std::vector& nvec) - { - nvec.clear(); - } - - static void giveNames(std::vector& nvec, const Name& name) - { - nvec.push_back(name); - } - - template - static void giveNames(std::vector& nvec, const Name& name1, - const Name& name2, const NameTypes&... names) - { - nvec.push_back(name1); - giveNames(nvec, name2, names...); - } - }; - } - - template - Name::Name(const std::string& mainName, const NameTypes&... names) : mMain(mainName) - { - mSub.reserve(sizeof...(NameTypes)); - Naming::giveNames(mSub, names...); - } - - template - Name::Name(char const* mainName, const NameTypes&... names) : mMain(mainName) - { - mSub.reserve(sizeof...(NameTypes)); - Naming::giveNames(mSub, names...); - } - - const std::string& Name::own() const - { - return mMain; - } - - const Name& Name::get(size_t n) const - { - return mSub.at(n); - } - - void Name::autoName(size_t newSize) - { - size_t oldSize = mSub.size(); - mSub.resize(newSize); - if(oldSize < newSize){ - for(size_t i = oldSize; i != newSize; ++i){ - mSub[i] = Name( mMain + std::to_string( i ) ); - } - } - } - - void Name::remove(const std::string& s) - { - for(size_t i = 0; i != mSub.size(); ++i){ - if(mSub[i].own() == s){ - mSub.erase(mSub.begin()+i); - break; - } - } - } - - size_t Name::size() const - { - return mSub.size(); - } - -} - -std::ostream& operator<<(std::ostream& os, const MultiArrayTools::Name& name) -{ - if(name.size() != 0){ - for(size_t i = 0; i != name.size(); ++i){ - os << name.get(i) << '\t'; - } - } - else { - os << name.own(); - } - return os; -} - diff --git a/src/name.h b/src/name.h deleted file mode 100644 index b213690..0000000 --- a/src/name.h +++ /dev/null @@ -1,44 +0,0 @@ -// -*- C++ -*- - -#ifndef __name_h__ -#define __name_h__ - -#include -#include -#include - -#include "base_def.h" - -namespace MultiArrayTools -{ - class Name - { - public: - - DEFAULT_MEMBERS(Name); - - template - Name(const std::string& mainName, const NameTypes&... names); - - template - Name(char const* mainName, const NameTypes&... names); - - const std::string& own() const; - const Name& get(size_t n) const; - - void autoName(size_t newSize); - void remove(const std::string& s); - size_t size() const; - - private: - std::string mMain; - std::vector mSub; - }; - -} - -std::ostream& operator<<(std::ostream& os, const MultiArrayTools::Name& name); - -#include "name.cc" - -#endif diff --git a/src/range_transformer.cc b/src/range_transformer.cc deleted file mode 100644 index 94f8e4f..0000000 --- a/src/range_transformer.cc +++ /dev/null @@ -1,34 +0,0 @@ -// -*- C++ -*- - -#include "range_transformer.h" - -namespace MultiArrayTools -{ - - template - MultiRange makeRange(const std::tuple& rangeTuple) - { - return MultiRange( rangeTuple ); - } - - template - MultiRange combine(const Ranges&... ranges) - { - return MultiRange(ranges...); - } - - template - auto extend(const Range& r, const MultiRange& mr) - -> decltype( MultiRange(std::tuple_cat( std::make_tuple(r), mr.space() ) ) ) - { - return MultiRange(std::tuple_cat( std::make_tuple(r), mr.space() ) ); - } - - template - auto merge(const MultiRange1& mr1, const MultiRange2& mr2) - -> decltype( makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ) ) - { - return makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ); - } - -} diff --git a/src/range_transformer.h b/src/range_transformer.h deleted file mode 100644 index f6a415f..0000000 --- a/src/range_transformer.h +++ /dev/null @@ -1,29 +0,0 @@ -// -*- C++ -*- - -#ifndef __range_transformer_h__ -#define __range_transformer_h__ - -#include -#include "base_def.h" - -namespace MultiArrayTools -{ - - template - MultiRange makeRange(const std::tuple& rangeTuple); - - template - MultiRange combine(const Ranges&... ranges); - - template - auto extend(const Range& r, const MultiRange& mr) - -> decltype( MultiRange(std::tuple_cat( std::make_tuple(r), mr.space() ) ) ); - - template - auto merge(const MultiRange1& mr1, const MultiRange2& mr2) - -> decltype(makeRange( std::tuple_cat( mr1.space(), mr2.space() ) ) ); -} - -#include "range_transformer.cc" - -#endif diff --git a/src/slice.cc b/src/slice.cc deleted file mode 100644 index 33f70b7..0000000 --- a/src/slice.cc +++ /dev/null @@ -1,181 +0,0 @@ -// -*- C++ -*- - -#include "slice.h" - -namespace MultiArrayTools -{ - - template - Slice:: - Slice(const Range& range, - const Name& ownNm, // for correct linkage - MutableMultiArrayBase& multiArrayRef, - const typename MARange::IndexType& MAIdx, // for desired slice position - const Name& MANm) : - MutableMultiArrayBase(range), - mOwnName(ownNm), mMAName(MANm), mMultiArrayPtr(&multiArrayRef), - mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end()) - { - MAB::mInit = true; - mOwnIdx = MAB::mRange->begin(); - mMAIdx.name(MANm); - mOwnIdx.name(ownNm); - mMAIdx.linkTo(&mOwnIdx); - } - - template - Slice:: - Slice(const Range& range, - const Name& ownNm, - MultiArrayOperationRoot& mor, - const typename MARange::IndexType& MAIdx) : - MutableMultiArrayBase(range), - mOwnName(ownNm), mMAName(mor.name()), mMultiArrayPtr(&(*mor)), - mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end()) - { - MAB::mInit = true; - mOwnIdx = MAB::mRange->begin(); - mMAIdx.name(mMAName); - mOwnIdx.name(ownNm); - mMAIdx.linkTo(&mOwnIdx); - } - - template - bool Slice::isSlice() const - { - return true; - } - - template - auto Slice::beginIndex() const -> decltype(Range().begin()) - { - return mBeginIndex; - } - - template - auto Slice::endIndex() const -> decltype(Range().end()) - { - return mEndIndex; - } - - // slow!! - template - T& Slice::operator[](const typename Range::IndexType& i) - { - mOwnIdx.copyPos(i); - return (*mMultiArrayPtr)[ mMAIdx ]; - } - - // slow!! - template - const T& Slice::operator[](const typename Range::IndexType& i) const - { - mOwnIdx.copyPos(i); - return (*mMultiArrayPtr)[ mMAIdx ]; - } - - template - bool Slice::isConst() const - { - return false; - } - - template - void Slice::link(IndefinitIndexBase* iibPtr) const - { - mMAIdx.linkTo(iibPtr); - } - - template - ConstSlice:: - ConstSlice(const Range& range, - const Name& ownNm, // for correct linkage - const MultiArrayBase& multiArrayRef, - const typename MARange::IndexType& MAIdx, // for desired slice position - const Name& MANm) : - MultiArrayBase(range), - mMultiArrayPtr(&multiArrayRef), - mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end()) - { - MAB::mInit = true; - mOwnIdx = MAB::mRange->begin(); - mMAIdx.name(MANm); - mOwnIdx.name(ownNm); - mMAIdx.linkTo(&mOwnIdx); - } - - template - ConstSlice:: - ConstSlice(const Range& range, - const Name& ownNm, - const ConstMultiArrayOperationRoot& mor, - const typename MARange::IndexType& MAIdx) : - MultiArrayBase(range), - mMultiArrayPtr(&(*mor)), - mMAIdx(MAIdx), mBeginIndex(range.begin()), mEndIndex(range.end()) - { - MAB::mInit = true; - mOwnIdx = MAB::mRange->begin(); - mMAIdx.name(mor.name()); - mOwnIdx.name(ownNm); - mMAIdx.linkTo(&mOwnIdx); - } - - template - ConstSlice:: - ConstSlice(const Slice& slice) : - MultiArrayBase(slice.range()), - mOwnIdx(slice.mOwnIdx), - mMAIdx(slice.mMAIdx), mBeginIndex(slice.mBeginIndex), mEndIndex(slice.mEndIndex) - { - if(slice.mInit){ - MAB::mInit = true; - mMultiArrayPtr = slice.mConstMultiArrayPtr; - mMAIdx = slice.mMAIdx; - mOwnIdx = MAB::mRange->begin(); - mMAIdx.name(slice.mMAName); - mOwnIdx.name(slice.mOwnName); - mMAIdx.linkTo(&mOwnIdx); - } - } - - - template - bool ConstSlice::isSlice() const - { - return true; - } - - template - bool ConstSlice::isConst() const - { - return true; - } - - template - void ConstSlice::link(IndefinitIndexBase* iibPtr) const - { - mMAIdx.linkTo(iibPtr); - } - - template - auto ConstSlice::beginIndex() const -> decltype(Range().begin()) - { - return mBeginIndex; - } - - template - auto ConstSlice::endIndex() const -> decltype(Range().end()) - { - return mEndIndex; - } - - // slow!! - template - const T& ConstSlice::operator[](const typename Range::IndexType& i) const - { - mOwnIdx.copyPos(i); - //mOwnIdx = i.pos(); - return (*mMultiArrayPtr)[ mMAIdx ]; - } -} diff --git a/src/slice.h b/src/slice.h deleted file mode 100644 index 76feb9b..0000000 --- a/src/slice.h +++ /dev/null @@ -1,108 +0,0 @@ -// -*- C++ -*- - -#ifndef __slice_h__ -#define __slice_h__ - -#include -#include "base_def.h" -#include "multi_array.h" - -namespace MultiArrayTools -{ - - // T = data type - // Range = range of slice - // MARange = original range of multi array of which this is the slice - // Index = index which determines the slice position (remnant of MARange w.o. Range) - template - class Slice : public MutableMultiArrayBase // yes, 'Range' is correct !!! - { - public: - - typedef MultiArrayBase MAB; - - Slice(const Range& range, - const Name& ownNm, - MutableMultiArrayBase& multiArrayRef, - const typename MARange::IndexType& MAIdx, - const Name& MANm); - - Slice(const Range& range, - const Name& ownNm, - MultiArrayOperationRoot& mor, - const typename MARange::IndexType& MAIdx); - - - virtual T& operator[](const typename Range::IndexType& i) override; - virtual const T& operator[](const typename Range::IndexType& i) const override; - - // link given Index to mMAPtr which is index of total array - virtual auto beginIndex() const -> decltype(Range().begin()) override; - virtual auto endIndex() const -> decltype(Range().end()) override; - - virtual bool isSlice() const override; - virtual bool isConst() const override; - - virtual void link(IndefinitIndexBase* iibPtr) const override; - - template - friend class ConstSlice; - - private: - - Name mOwnName; - Name mMAName; - MutableMultiArrayBase* mMultiArrayPtr = nullptr; - mutable typename Range::IndexType mOwnIdx; - mutable typename MARange::IndexType mMAIdx; - typename Range::IndexType mBeginIndex; - typename Range::IndexType mEndIndex; - }; - - template - class ConstSlice : public MultiArrayBase // yes, 'Range' is correct !!! - { - public: - - typedef MultiArrayBase MAB; - - //ConstSlice(const Range& range); - ConstSlice(const Range& range, - const Name& ownNm, - const MultiArrayBase& multiArrayRef, - const typename MARange::IndexType& MAIdx, - const Name& MANm); - - ConstSlice(const Range& range, - const Name& ownNm, - const ConstMultiArrayOperationRoot& mor, - const typename MARange::IndexType& MAIdx); - - ConstSlice(const Slice& slice); - - virtual const T& operator[](const typename Range::IndexType& i) const override; - - // link given Index to mMAPtr which is index of total array - virtual auto beginIndex() const -> decltype(Range().begin()) override; - virtual auto endIndex() const -> decltype(Range().end()) override; - - virtual bool isSlice() const override; - virtual bool isConst() const override; - - virtual void link(IndefinitIndexBase* iibPtr) const override; - - private: - - MultiArrayBase const* mMultiArrayPtr = nullptr; - mutable typename Range::IndexType mOwnIdx; - mutable typename MARange::IndexType mMAIdx; - typename Range::IndexType mBeginIndex; - typename Range::IndexType mEndIndex; - }; - - -} - -#include "slice.cc" - -#endif diff --git a/src/tuple_helper.cc b/src/tuple_helper.cc deleted file mode 100644 index 0055226..0000000 --- a/src/tuple_helper.cc +++ /dev/null @@ -1,46 +0,0 @@ - -#include "tuple_helper.h" - -namespace MultiArrayTools -{ - - template - auto make_left_x(const Tuple& tp) -> decltype(std::tuple_cat(make_left(tp), - std::make_tuple(get(tp)))) - { - return std::tuple_cat(make_left(tp), std::make_tuple(get(tp))); - } - - template - auto make_left_x(const Tuple& tp) -> decltype(std::make_tuple(get(tp))) - { - return std::make_tuple(get(tp)); - } - - template - auto make_right_x(const Tuple& tp) -> decltype(std::tuple_cat(std::make_tuple(get(tp)), - make_left(tp))) - { - const size_t M = std::tuple_size(tp) - N; - return std::tuple_cat(std::make_tuple(get(tp)), make_left(tp)); - } - - template - auto make_right_x(const Tuple& tp) -> decltype(std::make_tuple(get(tp))) - { - const size_t M = std::tuple_size(tp); - return std::make_tuple(get(tp)); - } - - template - auto make_left(const Tuple& tp) -> decltype(make_left_x(tp)) - { - return make_left_x(tp); - } - - template - auto make_right(const Tuple& tp) -> decltype(make_right_x(tp)) - { - return make_right_x(tp); - } -} diff --git a/src/tuple_helper.h b/src/tuple_helper.h deleted file mode 100644 index dde29ce..0000000 --- a/src/tuple_helper.h +++ /dev/null @@ -1,39 +0,0 @@ -// -*- C++ -*- - -#ifndef __tuple_helper_h__ -#define __tuple_helper_h__ - -#include -#include - -#include "base_def.h" - - -namespace MultiArrayTools -{ - - template - auto make_left_x(const Tuple& tp) -> decltype(std::tuple_cat(make_left(tp), - std::make_tuple(get(tp)))); - - template - auto make_left_x(const Tuple& tp) -> decltype(std::make_tuple(get(tp))); - - template - auto make_right_x(const Tuple& tp) -> decltype(std::tuple_cat(std::make_tuple(get(tp)), - make_left(tp))); - - template - auto make_right_x(const Tuple& tp) -> decltype(std::make_tuple(get(tp))); - - template - auto make_left(const Tuple& tp) -> decltype(make_left_x(tp)); - - template - auto make_right(const Tuple& tp) -> decltype(make_right_x(tp)); - -} - -#include "tuple_helper.cc" - -#endif diff --git a/src/unit_test.cc b/src/unit_test.cc deleted file mode 100644 index 371b323..0000000 --- a/src/unit_test.cc +++ /dev/null @@ -1,560 +0,0 @@ -// -*- C++ -*- - -#include -#include "gtest/gtest.h" -#include - -#include "multi_array_header.h" - -namespace MAT = MultiArrayTools; - -namespace { - - template - struct sum - { - public: - sum() = default; - - T& operator()() const - { - return res; - } - - T& operator()(const T& a) const - { - return res += a; - } - - void endOp() const {} - - void reset() const - { - res = static_cast(0); - } - - private: - mutable T res = static_cast(0); - }; - - class OneDimTest : public ::testing::Test - { - protected: - - typedef MAT::SingleRange Range1dAny; - typedef MAT::MultiArray MultiArray1dAny; - - OneDimTest() : r({'a','b','c','d','e'}), ma(r, {-5,6,2,1,9}) {} - - //virtual void SetUp(); - - Range1dAny r; - MultiArray1dAny ma; - - }; - - class TwoDimTest : public ::testing::Test - { - protected: - - typedef MAT::SingleRange Range1dAny; - typedef MAT::MultiRange Range2dAny; - typedef MAT::MultiArray MultiArray2dAny; - - TwoDimTest() : r1({'a','b','c'}), - r2({'a','b','c','d'}), - r(r1,r2), - ma(r, {-5,6,2,1,9,54,27,-7,-13,32,90,-67}) {} - - //virtual void SetUp(); - - Range1dAny r1; - Range1dAny r2; - Range2dAny r; - MultiArray2dAny ma; - - }; - - class ReorderTest : public ::testing::Test - { - protected: - - typedef MAT::SingleRange Range1dAny; - typedef MAT::MultiRange Range2dAny; - typedef MAT::MultiRange Range3dAny; - typedef MAT::MultiArray MultiArray2dAny; - typedef MAT::MultiArray MultiArray3dAny; - - ReorderTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}), - ra(r1,r2), rb(r2,r1), - r3da(r1,r2,r3), r3db(r1,r3,r2), r3dc(r3,r1,r2), - ma(ra, {-5,6,2,1,9,54,27,-7,-13,32,90,-67}), - ma3d(r3da, {-5,6,2,1,9,54,27,-7,-13,32,90,-67, - -10,16,-2,101,39,-64,81,-22,14,34,95,-62}) {} - - Range1dAny r1; - Range1dAny r2; - Range1dAny r3; - Range2dAny ra; - Range2dAny rb; - Range3dAny r3da; - Range3dAny r3db; - Range3dAny r3dc; - MultiArray2dAny ma; - MultiArray3dAny ma3d; - }; - - class OperationTest : public ::testing::Test - { - protected: - - typedef MAT::SingleRange Range1dAny; - typedef MAT::MultiRange RangeAny; - typedef MAT::MultiRange Range2dAny; - typedef MAT::MultiRange Range3dAny; - typedef MAT::MultiArray MultiArray1dAny; - typedef MAT::MultiArray MultiArray2dAny; - typedef MAT::MultiArray MultiArray3dAny; - - OperationTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}), - r11(r1), - ra(r1,r2), - r3d(r1,r2,r3), - ma1d(r11, {-5,6,2}), - ma(ra, {-5,6,2,1,9,54,27,-7,-13,32,90,-67}), - ma3d(r3d, {-5,6,2,1,9,54,27,-7,-13,32,90,-67, - -10,16,-2,101,39,-64,81,-22,14,34,95,-62}) {} - - Range1dAny r1; - Range1dAny r2; - Range1dAny r3; - RangeAny r11; - Range2dAny ra; - Range3dAny r3d; - MultiArray1dAny ma1d; - MultiArray2dAny ma; - MultiArray3dAny ma3d; - }; - - class SliceTest : public ::testing::Test - { - protected: - - typedef MAT::SingleRange Range1dAny; - typedef MAT::MultiRange Range2dAny; - typedef MAT::MultiRange Range3dAny; - typedef MAT::MultiArray MultiArray3dAny; - typedef MAT::Slice Slice2d3dAny; - - SliceTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}), - ra(r1,r3), - rb(r1,r2), - r3d(r1,r2,r3), - ma(r3d, {-5,6,2,1,9,54,27,-7,-13,32,90,-67, - -10,16,-2,101,39,-64,81,-22,14,34,95,-62}) {} - - Range1dAny r1; - Range1dAny r2; - Range1dAny r3; - Range2dAny ra; - Range2dAny rb; - Range3dAny r3d; - MultiArray3dAny ma; - //Slice2d3dAny sl; - }; - - class ContractionTest : public ::testing::Test - { - protected: - typedef MAT::SingleRange Range1dAny; - typedef MAT::MultiRange Range2dAny; - typedef MAT::MultiRange Range3dAny; - typedef MAT::MultiArray MultiArray3dAny; - typedef MAT::Slice Slice2d3dAny; - typedef MAT::MultiArray MultiArray2dAny; - - ContractionTest() : r1({'a','b','c'}), r2({'a','b','c','d'}), r3({'a','b'}), - ra(r1,r3), - rb(r1,r2), - r3d(r1,r2,r3), - ma(r3d, {-5,6,2,1,9,54,27,-7,-13,32,90,-67, - -10,16,-2,101,39,-64,81,-22,14,34,95,-62}), - max(ra, {-5,6,2,1,9,54}){} - - Range1dAny r1; - Range1dAny r2; - Range1dAny r3; - Range2dAny ra; - Range2dAny rb; - Range3dAny r3d; - MultiArray3dAny ma; - MultiArray2dAny max; - }; - - TEST_F(OneDimTest, CorrectExtensions) - { - EXPECT_EQ(ma.size(), 5); - } - - TEST_F(OneDimTest, CorrectAssigned) - { - auto i = ma.beginIndex(); - EXPECT_EQ(ma[i = 0], -5); - EXPECT_EQ(ma[i = 1], 6); - EXPECT_EQ(ma[i = 2], 2); - EXPECT_EQ(ma[i = 3], 1); - EXPECT_EQ(ma[i = 4], 9); - } - - TEST_F(TwoDimTest, CorrectExtensions) - { - auto i = ma.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - EXPECT_EQ(ma.size(), 12); - EXPECT_EQ(i1.max(), 3); - EXPECT_EQ(i1.majorStep(), 4); - EXPECT_EQ(i2.max(), 4); - EXPECT_EQ(i2.majorStep(), 1); - } - - TEST_F(TwoDimTest, CorrectAssigned) - { - auto i = ma.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - - EXPECT_EQ(ma[i(i1 = 0, i2 = 0)], -5); - EXPECT_EQ(ma[i(i1 = 0, i2 = 1)], 6); - EXPECT_EQ(ma[i(i1 = 0, i2 = 2)], 2); - EXPECT_EQ(ma[i(i1 = 0, i2 = 3)], 1); - EXPECT_EQ(ma[i(i1 = 1, i2 = 0)], 9); - EXPECT_EQ(ma[i(i1 = 1, i2 = 1)], 54); - EXPECT_EQ(ma[i(i1 = 1, i2 = 2)], 27); - EXPECT_EQ(ma[i(i1 = 1, i2 = 3)], -7); - EXPECT_EQ(ma[i(i1 = 2, i2 = 0)], -13); - EXPECT_EQ(ma[i(i1 = 2, i2 = 1)], 32); - EXPECT_EQ(ma[i(i1 = 2, i2 = 2)], 90); - EXPECT_EQ(ma[i(i1 = 2, i2 = 3)], -67); - } - - TEST_F(ReorderTest, ReorderingWorks2d) - { - MultiArray2dAny ma2(rb); - auto i = ma2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - ma2("alpha","beta") = ma("beta","alpha"); - - EXPECT_EQ(ma2[i(i1 = 0,i2 = 0)],-5); - EXPECT_EQ(ma2[i(i1 = 1,i2 = 0)],6); - EXPECT_EQ(ma2[i(i1 = 2,i2 = 0)],2); - EXPECT_EQ(ma2[i(i1 = 3,i2 = 0)],1); - - EXPECT_EQ(ma2[i(i1 = 0,i2 = 1)],9); - EXPECT_EQ(ma2[i(i1 = 1,i2 = 1)],54); - EXPECT_EQ(ma2[i(i1 = 2,i2 = 1)],27); - EXPECT_EQ(ma2[i(i1 = 3,i2 = 1)],-7); - - EXPECT_EQ(ma2[i(i1 = 0,i2 = 2)],-13); - EXPECT_EQ(ma2[i(i1 = 1,i2 = 2)],32); - EXPECT_EQ(ma2[i(i1 = 2,i2 = 2)],90); - EXPECT_EQ(ma2[i(i1 = 3,i2 = 2)],-67); - } - - TEST_F(ReorderTest, ReorderingWorks3d_Test1) - { - MultiArray3dAny ma3d2(r3db); - auto i = ma3d2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - - EXPECT_EQ(i1.max(), 3); - EXPECT_EQ(i1.majorStep(), 8); - EXPECT_EQ(i2.max(), 2); - EXPECT_EQ(i2.majorStep(), 4); - EXPECT_EQ(i3.max(), 4); - EXPECT_EQ(i3.majorStep(), 1); - - ma3d2("alpha","beta","gamma") = ma3d("alpha","gamma","beta"); - - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 0)],-5); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 0)],6); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 1)],2); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 1)],1); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 2)],9); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 2)],54); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 3)],27); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 3)],-7); - - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 0)],-13); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 0)],32); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 1)],90); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 1)],-67); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 2)],-10); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 2)],16); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 3)],-2); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 3)],101); - - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 0)],39); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 0)],-64); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 1)],81); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 1)],-22); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 2)],14); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 2)],34); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 0,i3 = 3)],95); - EXPECT_EQ(ma3d2[i(i1 = 2,i2 = 1,i3 = 3)],-62); - } - - TEST_F(ReorderTest, ReorderingWorks3d_Test2) - { - MultiArray3dAny ma3d2(r3dc); - auto i = ma3d2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - - ma3d2("gamma","alpha","beta") = ma3d("alpha","beta","gamma"); - - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 0)],-5); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 0)],6); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 1)],2); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 1)],1); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 2)],9); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 2)],54); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 0,i3 = 3)],27); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 0,i3 = 3)],-7); - - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 0)],-13); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 0)],32); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 1)],90); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 1)],-67); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 2)],-10); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 2)],16); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 1,i3 = 3)],-2); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 1,i3 = 3)],101); - - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 0)],39); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 0)],-64); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 1)],81); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 1)],-22); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 2)],14); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 2)],34); - EXPECT_EQ(ma3d2[i(i1 = 0,i2 = 2,i3 = 3)],95); - EXPECT_EQ(ma3d2[i(i1 = 1,i2 = 2,i3 = 3)],-62); - } - - TEST_F(OperationTest, CorrectlyAdded) - { - MultiArray3dAny ma3d2(r3d); - auto i = ma3d2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - - ma3d2("alpha","beta","gamma") = ma3d("alpha","beta","gamma") + ma("alpha","beta"); - - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 0)], -10); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 1)], 1); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 0)], 8); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 1)], 7); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 0)], 11); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 1)], 56); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 0)], 28); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 1)], -6); - - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 0)], -4); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 1)], 41); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 0)], 144); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 1)], -13); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 0)], 17); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 1)], 43); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 0)], -9); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 1)], 94); - - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 0)], 26); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 1)], -77); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 0)], 113); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 1)], 10); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 0)], 104); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 1)], 124); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 0)], 28); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 1)], -129); - } - - TEST_F(OperationTest, CorrectlyAdded2) - { - //MultiArray3dAny ma3d2(r3d); - auto i = ma3d.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - - ma3d("alpha","beta","gamma") += ma("alpha","beta"); - - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 0, i3 = 0)], -10); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 0, i3 = 1)], 1); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 1, i3 = 0)], 8); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 1, i3 = 1)], 7); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 2, i3 = 0)], 11); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 2, i3 = 1)], 56); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 3, i3 = 0)], 28); - EXPECT_EQ(ma3d[i(i1 = 0, i2 = 3, i3 = 1)], -6); - - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 0, i3 = 0)], -4); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 0, i3 = 1)], 41); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 1, i3 = 0)], 144); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 1, i3 = 1)], -13); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 2, i3 = 0)], 17); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 2, i3 = 1)], 43); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 3, i3 = 0)], -9); - EXPECT_EQ(ma3d[i(i1 = 1, i2 = 3, i3 = 1)], 94); - - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 0, i3 = 0)], 26); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 0, i3 = 1)], -77); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 1, i3 = 0)], 113); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 1, i3 = 1)], 10); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 2, i3 = 0)], 104); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 2, i3 = 1)], 124); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 3, i3 = 0)], 28); - EXPECT_EQ(ma3d[i(i1 = 2, i2 = 3, i3 = 1)], -129); - } - - TEST_F(OperationTest, CorrectlyAdded_3args) - { - MultiArray3dAny ma3d2(r3d); - //MultiArray2dAny ma2(ra); - auto i = ma3d2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - - //ma2("alpha","beta") = ma("alpha","beta") + ma1d("alpha"); - ma3d2("alpha","beta","gamma") = ma3d("alpha","beta","gamma") + ma("alpha","beta") + ma1d("alpha"); - - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 0)], -15); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 0, i3 = 1)], -4); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 0)], 3); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 1, i3 = 1)], 2); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 0)], 6); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 2, i3 = 1)], 51); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 0)], 23); - EXPECT_EQ(ma3d2[i(i1 = 0, i2 = 3, i3 = 1)], -11); - - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 0)], 2); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 0, i3 = 1)], 47); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 0)], 150); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 1, i3 = 1)], -7); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 0)], 23); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 2, i3 = 1)], 49); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 0)], -3); - EXPECT_EQ(ma3d2[i(i1 = 1, i2 = 3, i3 = 1)], 100); - - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 0)], 28); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 0, i3 = 1)], -75); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 0)], 115); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 1, i3 = 1)], 12); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 0)], 106); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 2, i3 = 1)], 126); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 0)], 30); - EXPECT_EQ(ma3d2[i(i1 = 2, i2 = 3, i3 = 1)], -127); - } - - TEST_F(SliceTest, CorrectSize) - { - auto i = ma.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - - Slice2d3dAny sl(ra, MAT::Name("master", "alpha", "gamma"), ma, - i(i1 = 0, i2 = 2, i3 = 0), - MAT::Name("master", "alpha","beta","gamma")); - - //Slice2d3dAny sl(ra); - //sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)]; - EXPECT_EQ(sl.size(), 6); - - Slice2d3dAny sl2(rb, MAT::Name("master", "alpha", "beta"), ma, - i(i1 = 0, i2 = 0, i3 = 1), - MAT::Name("master", "alpha","beta","gamma")); - - //Slice2d3dAny sl2(rb); - //sl2("alpha","beta") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 0, i3 = 1)]; - EXPECT_EQ(sl2.size(), 12); - } - - TEST_F(SliceTest, CorrectContent) - { - auto i = ma.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - auto i3 = i.template getIndex<2>(); - Slice2d3dAny sl(ra, MAT::Name("master", "alpha", "gamma"), ma, - i(i1 = 0, i2 = 2, i3 = 0), - MAT::Name("master", "alpha","beta","gamma")); - //sl("alpha","gamma") = ma("alpha","beta","gamma")[i(i1 = 0, i2 = 2, i3 = 0)]; - - auto j = sl.beginIndex(); - auto j1 = j.template getIndex<0>(); - auto j2 = j.template getIndex<1>(); - - EXPECT_EQ(sl[j(j1 = 0, j2 = 0)], 9); - EXPECT_EQ(sl[j(j1 = 0, j2 = 1)], 54); - - EXPECT_EQ(sl[j(j1 = 1, j2 = 0)], -10); - EXPECT_EQ(sl[j(j1 = 1, j2 = 1)], 16); - - EXPECT_EQ(sl[j(j1 = 2, j2 = 0)], 14); - EXPECT_EQ(sl[j(j1 = 2, j2 = 1)], 34); - } - - TEST_F(ContractionTest, ContractionWorks) - { - MultiArray2dAny ma2(ra); - - ma2("alpha","gamma") = ma("alpha","beta","gamma").contract(sum(),"beta"); - - auto i = ma2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - - EXPECT_EQ(ma2[i(i1 = 0, i2 = 0)], 33); - EXPECT_EQ(ma2[i(i1 = 0, i2 = 1)], 54); - - EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 65); - EXPECT_EQ(ma2[i(i1 = 1, i2 = 1)], 82); - - EXPECT_EQ(ma2[i(i1 = 2, i2 = 0)], 229); - EXPECT_EQ(ma2[i(i1 = 2, i2 = 1)], -114); - } - - TEST_F(ContractionTest, ContractionWorks_2) - { - MultiArray2dAny ma2(ra); - - ma2("alpha","gamma") = ma("alpha","beta","gamma").contract(sum(),"beta") - * max("alpha","gamma"); - - auto i = ma2.beginIndex(); - auto i1 = i.template getIndex<0>(); - auto i2 = i.template getIndex<1>(); - - EXPECT_EQ(ma2[i(i1 = 0, i2 = 0)], -165); - EXPECT_EQ(ma2[i(i1 = 0, i2 = 1)], 324); - - EXPECT_EQ(ma2[i(i1 = 1, i2 = 0)], 130); - EXPECT_EQ(ma2[i(i1 = 1, i2 = 1)], 82); - - EXPECT_EQ(ma2[i(i1 = 2, i2 = 0)], 2061); - EXPECT_EQ(ma2[i(i1 = 2, i2 = 1)], -6156); - } - -} // end namespace - -int main(int argc, char** argv) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -}