From ebc0f5a807f2ba8992d0a4f53d6b66eebc0185ac Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Fri, 9 Sep 2022 19:41:43 +0200 Subject: [PATCH] wip: dynamic stuff; switched off most of the tests --- src/include/allocator.h | 22 ++- src/include/cnorxz.cc.h | 5 +- src/include/cnorxz.h | 3 + src/include/cxz_darray.cc.h | 53 +++++ src/include/cxz_darray.h | 41 ++++ src/include/cxz_darray_base.cc.h | 49 +++-- src/include/cxz_darray_base.h | 41 ++-- src/include/dcontainer_index.cc.h | 211 ++++++++++++++++++++ src/include/dcontainer_index.h | 140 +++++++++++++- src/include/ranges/dynamic_meta.cc.h | 94 +++++++++ src/include/ranges/dynamic_meta.h | 107 +++------- src/include/ranges/index_base.h | 16 +- src/include/ranges/range_base.h | 7 +- src/include/ranges/single_range.h | 63 ------ src/lib/CMakeLists.txt | 56 +++--- src/lib/dcontainer_index.cc | 100 ++++++++++ src/tests/CMakeLists.txt | 69 +++---- src/tests/darray_unit_test.cc | 279 +++++++++++++++++++++++++++ 18 files changed, 1075 insertions(+), 281 deletions(-) create mode 100644 src/include/cxz_darray.cc.h create mode 100644 src/include/cxz_darray.h create mode 100644 src/include/dcontainer_index.cc.h create mode 100644 src/include/ranges/dynamic_meta.cc.h create mode 100644 src/lib/dcontainer_index.cc create mode 100644 src/tests/darray_unit_test.cc diff --git a/src/include/allocator.h b/src/include/allocator.h index 56ca670..628fded 100644 --- a/src/include/allocator.h +++ b/src/include/allocator.h @@ -16,11 +16,17 @@ namespace CNORXZInternal { template - struct Allocator + class Allocator { + private: + static size_t sMemUsage; + + public: + static size_t memUsage() { return sMemUsage; } + typedef T value_type; static constexpr size_t type_size = sizeof(value_type); - static constexpr size_t N = 32; + static constexpr size_t N = 32; // get from environment!!! struct VX { @@ -35,6 +41,7 @@ namespace CNORXZInternal T* allocate(size_t n) { const size_t nn = n*type_size; + sMemUsage += nn; if(nn >= WARN_SIZE){ std::cout << __func__ << ": WARNING: allocating " << nn/(MIB_SIZE) << " MiB" << std::endl; } @@ -47,6 +54,8 @@ namespace CNORXZInternal void deallocate(T* p, size_t n) { + const size_t nn = n*type_size; + sMemUsage -= nn; VX* vx = reinterpret_cast(p); delete [] vx; } @@ -64,11 +73,20 @@ namespace CNORXZInternal return false; } + template + size_t Allocator::sMemUsage = 0; } // namespace CNORXZInternal namespace CNORXZ { + + template + inline size_t memUsage() + { + return CNORXZInternal::Allocator::memUsage(); + } + template using vector = std::vector>; diff --git a/src/include/cnorxz.cc.h b/src/include/cnorxz.cc.h index 488ebca..ea17e23 100644 --- a/src/include/cnorxz.cc.h +++ b/src/include/cnorxz.cc.h @@ -2,16 +2,17 @@ #include "ranges/ranges_header.cc.h" #include "container_index.cc.h" +#include "dcontainer_index.cc.h" #include "cxz_operation.cc.h" #include "functional_array.cc.h" #include "helper_tools.cc.h" #include "map_range.cc.h" #include "cxz_array_base.cc.h" #include "cxz_array.cc.h" +#include "cxz_darray_base.cc.h" +#include "cxz_darray.cc.h" #include "slice.cc.h" #include "dynamic_operation.cc.h" #include "access.cc.h" #include "op_expressions.cc.h" -//#include "high_level_operation.cc.h" -//#include "expressions.cc.h" diff --git a/src/include/cnorxz.h b/src/include/cnorxz.h index 6a655a5..80f98ed 100644 --- a/src/include/cnorxz.h +++ b/src/include/cnorxz.h @@ -5,9 +5,12 @@ #include #include "container_index.h" +#include "dcontainer_index.h" #include "cxz_operation.h" #include "cxz_array_base.h" #include "cxz_array.h" +#include "cxz_darray_base.h" +#include "cxz_darray.h" #include "functional_array.h" #include "helper_tools.h" #include "operation_def.h" diff --git a/src/include/cxz_darray.cc.h b/src/include/cxz_darray.cc.h new file mode 100644 index 0000000..fa8d911 --- /dev/null +++ b/src/include/cxz_darray.cc.h @@ -0,0 +1,53 @@ + +#include "cxz_darray.h" + +namespace CNORXZ +{ + /**************** + * DArray * + ***************/ + + template + DArray::DArray(const RangePtr& range) : MDArrayBase(range), mCont(range->size()) {} + + template + DArray::DArray(const RangePtr& range, const vector& vec) : + MDArrayBase(range), mCont(vec) {} + + template + DArray::DArray(const RangePtr& range, vector&& vec) : + MDArrayBase(range), mCont(vec) {} + + template + const T* DArray::data() const + { + return mCont.data(); + } + + template + T* DArray::data() + { + return mCont.data(); + } + + template + typename DArray::const_iterator DArray::cbegin() const + { + assert(0); + return const_iterator(); + } + + template + typename DArray::const_iterator DArray::cend() const + { + assert(0); + return const_iterator(); + } + + template + bool DArray::isView() const + { + return false; + } + +} diff --git a/src/include/cxz_darray.h b/src/include/cxz_darray.h new file mode 100644 index 0000000..d85c5cc --- /dev/null +++ b/src/include/cxz_darray.h @@ -0,0 +1,41 @@ + +#ifndef __cxz_darray_h__ +#define __cxz_darray_h__ + +#include "cxz_darray_base.h" + +namespace CNORXZ +{ + + template + class DArray : public MDArrayBase + { + public: + + typedef DArrayBase AB; + typedef typename AB::const_iterator const_iterator; + + using DArrayBase::operator[]; + using MDArrayBase::operator[]; + + private: + vector mCont; + + public: + + DEFAULT_MEMBERS(DArray); + DArray(const RangePtr& range); + DArray(const RangePtr& range, const vector& vec); + DArray(const RangePtr& range, vector&& vec); + + virtual const T* data() const override; + virtual T* data() override; + virtual const_iterator cbegin() const override; + virtual const_iterator cend() const override; + virtual bool isView() const override; + + }; + +} + +#endif diff --git a/src/include/cxz_darray_base.cc.h b/src/include/cxz_darray_base.cc.h index 228c3e1..a1c9204 100644 --- a/src/include/cxz_darray_base.cc.h +++ b/src/include/cxz_darray_base.cc.h @@ -8,23 +8,20 @@ namespace CNORXZ ***************/ template - DArrayBase::DArrayBase(const RangePtr& range) : mRange(range), mInit(true) - { - mIt = this->begin(); - } + DArrayBase::DArrayBase(const RangePtr& range) : mRange(range), mInit(true) {} template - template - const value_type& DArrayBase::operator[](const IndexInterface& i) const + template + const T& DArrayBase::operator[](const IndexInterface& i) const { - return *mIt(i); + return *(this->begin()+i); } template - template - const value_type& DArrayBase::at(const IndexInterface& i) const + template + const T& DArrayBase::at(const IndexInterface& i) const { - return *mIt.at(i); + return *this->begin().plus(i); } template @@ -40,26 +37,26 @@ namespace CNORXZ } template - DArrayBase::const_iterator DArrayBase::begin() const + typename DArrayBase::const_iterator DArrayBase::begin() const { return this->cbegin(); } template - DArrayBase::const_iterator DArrayBase::end() const + typename DArrayBase::const_iterator DArrayBase::end() const { return this->cend(); } template - virtual bool DArrayBase::isInit() const + bool DArrayBase::isInit() const { return mInit; } template - template - ConstOperationRoot DArrayBase::operator()(const IndexPtr& i) const + template + ConstOperationRoot DArrayBase::operator()(const IndexPtr& i) const { return ConstOperationRoot(/**/); } @@ -70,37 +67,37 @@ namespace CNORXZ ****************/ template - MDArrayBase::MDArrayBase(const RangePtr& range) : DArrayBase(range) {} + MDArrayBase::MDArrayBase(const RangePtr& range) : DArrayBase(range) {} template - template - value_type& MDArrayBase::operator[](const IndexInterface& i) + template + T& MDArrayBase::operator[](const IndexInterface& i) { - return *mIt(i); + return *(this->begin()+i); } template - template - value_type& MDArrayBase::at(const IndexInterface& i) + template + T& MDArrayBase::at(const IndexInterface& i) { - return *mIt.at(i); + return *this->begin().plus(i); } template - MDArrayBase::iterator MDArrayBase::begin() + typename MDArrayBase::iterator MDArrayBase::begin() { return iterator(this->data(), this->cbegin()); } template - MDArrayBase::iterator MDArrayBase::end() + typename MDArrayBase::iterator MDArrayBase::end() { return iterator(this->data(), this->cend()); } template - template - OperationRoot MDArrayBase::operator()(const IndexPtr& i) + template + OperationRoot MDArrayBase::operator()(const IndexPtr& i) { return OperationRoot(/**/); } diff --git a/src/include/cxz_darray_base.h b/src/include/cxz_darray_base.h index a6cc75f..0a3f3fd 100644 --- a/src/include/cxz_darray_base.h +++ b/src/include/cxz_darray_base.h @@ -18,12 +18,10 @@ namespace CNORXZ class DArrayBase { public: - typedef T value_type; - typedef DConstContainerIndex const_iterator; + typedef DConstContainerIndex const_iterator; protected: RangePtr mRange; - const_iterator mIt; bool mInit = false; public: @@ -33,14 +31,14 @@ namespace CNORXZ virtual ~DArrayBase() = default; - template - const value_type& operator[](const IndexInterface& i) const; + template + const T& operator[](const IndexInterface& i) const; - template - const value_type& at(const IndexInterface& i) const; + template + const T& at(const IndexInterface& i) const; - template - DArrayBase sl(const IndexInterface& i) const; + template + DArrayBase sl(const IndexInterface& i) const; virtual const T* data() const = 0; virtual size_t size() const; @@ -54,8 +52,8 @@ namespace CNORXZ virtual bool isView() const = 0; virtual bool isInit() const; - template - ConstOperationRoot operator()(const IndexPtr& i) const; + template + ConstOperationRoot operator()(const IndexPtr& i) const; }; template @@ -63,9 +61,8 @@ namespace CNORXZ { public: typedef DArrayBase DAB; - typedef DAB::value_type value_type; - typedef DAB::const_iterator const_iterator; - typedef DContainerIndex iterator; + typedef typename DAB::const_iterator const_iterator; + typedef DContainerIndex iterator; using DAB::operator[]; using DAB::at; @@ -79,22 +76,22 @@ namespace CNORXZ MDArrayBase(const RangePtr& range); DEFAULT_MEMBERS(MDArrayBase); - template - value_type& operator[](const IndexInterface& i); + template + T& operator[](const IndexInterface& i); - template - value_type& at(const IndexInterface& i); + template + T& at(const IndexInterface& i); - template - DArrayBase sl(const IndexInterface& i); + template + std::shared_ptr> sl(const IndexInterface& i); virtual T* data() = 0; virtual iterator begin(); virtual iterator end(); - template - OperationRoot operator()(const IndexPtr& i); + template + OperationRoot operator()(const IndexPtr& i); }; } diff --git a/src/include/dcontainer_index.cc.h b/src/include/dcontainer_index.cc.h new file mode 100644 index 0000000..5ec046b --- /dev/null +++ b/src/include/dcontainer_index.cc.h @@ -0,0 +1,211 @@ + +#include "dcontainer_index.h" + +namespace CNORXZ +{ + /************** + * XIndex * + **************/ + + template + XIndex::XIndex(const IndexPtr& i) : mI(i) {} + + template + XIndex& XIndex::operator=(size_t pos) + { + *mI = pos; + return *this; + } + + template + XIndex& XIndex::operator++() + { + ++(*mI); + return *this; + } + + template + XIndex& XIndex::operator--() + { + --(*mI); + return *this; + } + + template + int XIndex::pp(std::intptr_t idxPtrNum) + { + return mI->pp(idxPtrNum); + } + + template + int XIndex::mm(std::intptr_t idxPtrNum) + { + return mI->mm(idxPtrNum); + } + + template + size_t XIndex::dim() const + { + return mI->dim(); + } + + template + size_t XIndex::getStepSize(size_t n) const + { + return mI->getStepSize(n); + } + + template + std::string XIndex::stringMeta() const + { + return mI->stringMeta(); + } + + template + DType XIndex::meta() const + { + return DType(mI->meta()); + } + + template + XIndexBase& XIndex::at(const DType& meta) + { + // check!!! + mI->at(std::any_cast(meta.get())); + return *this; + } + + template + DynamicExpression XIndex::ifor(size_t step, DynamicExpression ex) const + { + return mI->ifor(step, ex); + } + + template + DynamicExpression XIndex::iforh(size_t step, DynamicExpression ex) const + { + return mI->iforh(step, ex); + } + + template + DConstContainerIndex::DConstContainerIndex(const T* data, const RangePtr& range): + mI(range->beginX()), mCData(data) + { + assert(0); + } + + template + DConstContainerIndex& DConstContainerIndex::operator=(size_t pos) + { + (*mI) = pos; + IB::mPos = mI->pos(); + return *this; + } + + template + DConstContainerIndex& DConstContainerIndex::operator++() + { + ++(*mI); + IB::mPos = mI->pos(); + return *this; + } + + template + DConstContainerIndex& DConstContainerIndex::operator--() + { + --(*mI); + IB::mPos = mI->pos(); + return *this; + } + + template + int DConstContainerIndex::pp(std::intptr_t idxPtrNum) + { + return mI->pp(idxPtrNum); + } + + template + int DConstContainerIndex::mm(std::intptr_t idxPtrNum) + { + return mI->mm(idxPtrNum); + } + + template + size_t DConstContainerIndex::dim() const + { + return mI->dim(); + } + + template + size_t DConstContainerIndex::getStepSize(size_t n) const + { + return mI->getStepSize(n); // dim() elements only!!! + } + + template + std::string DConstContainerIndex::stringMeta() const + { + return mI->stringMeta(); + } + + template + DType DConstContainerIndex::meta() const + { + return mI->meta(); + } + + template + DConstContainerIndex& DConstContainerIndex::at(const DType& meta) + { + mI->at(meta); + IB::mPos = mI->pos(); + return *this; + } + + template + DynamicExpression DConstContainerIndex::ifor(size_t step, DynamicExpression ex) const + { + return mI->ifor(step, ex); + } + + template + DynamicExpression DConstContainerIndex::iforh(size_t step, DynamicExpression ex) const + { + return mI->iforh(step, ex); + } + + template + const T& DConstContainerIndex::operator*() const + { + //this->sync(); + return mCData[mI->pos()]; + } + + template + const T* DConstContainerIndex::operator->() const + { + //this->sync(); + return mCData+mI->pos(); + } + + template + DContainerIndex::DContainerIndex(T* data, const RangePtr& range) : + DConstContainerIndex(range), mData(data) {} + + template + DContainerIndex::DContainerIndex(T* data, const DConstContainerIndex& cci) : + DConstContainerIndex(data, cci.range()), mData(data) {} + + template + T& DContainerIndex::operator*() + { + return mData[CCI::mI->pos()]; + } + + template + T* DContainerIndex::operator->() + { + return mData+CCI::mI->pos(); + } + +} diff --git a/src/include/dcontainer_index.h b/src/include/dcontainer_index.h index 1a5c95c..6865ba6 100644 --- a/src/include/dcontainer_index.h +++ b/src/include/dcontainer_index.h @@ -11,47 +11,171 @@ #include "mbase_def.h" #include "statics/static_for.h" #include "ranges/range_helper.h" +#include "ranges/dynamic_meta.h" +#include "xfor/xfor.h" namespace CNORXZ { - // Future DynamicIndex + namespace + { + using namespace CNORXZInternal; + } + + // Future IndexWrapper class XIndexBase : public IndexInterface { public: DEFAULT_MEMBERS(XIndexBase); + + constexpr IndexType type() const; + + virtual XIndexBase& operator=(size_t pos) = 0; + virtual XIndexBase& operator++() = 0; + virtual XIndexBase& operator--() = 0; + virtual int pp(std::intptr_t idxPtrNum) = 0; + virtual int mm(std::intptr_t idxPtrNum) = 0; + virtual size_t dim() const = 0; + virtual size_t getStepSize(size_t n) const = 0; + virtual std::string stringMeta() const = 0; + virtual DType meta() const = 0; + virtual XIndexBase& at(const DType& meta) = 0; + virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const = 0; + virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const = 0; // ...!!! }; typedef std::shared_ptr XIndexPtr; // MultiIndex Wrapper: - template - class XIndex + template + class XIndex : public XIndexBase { private: - std::shared_ptr> mI; + IndexPtr mI; public: DEFAULT_MEMBERS(XIndex); - XIndex(const std::shared_ptr>& i); + XIndex(const IndexPtr& i); + virtual XIndex& operator=(size_t pos) override; + virtual XIndex& operator++() override; + virtual XIndex& operator--() override; + virtual int pp(std::intptr_t idxPtrNum) override; + virtual int mm(std::intptr_t idxPtrNum) override; + virtual size_t dim() const override; + virtual size_t getStepSize(size_t n) const override; + virtual std::string stringMeta() const override; + virtual DType meta() const override; + virtual XIndexBase& at(const DType& meta) override; + virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const override; + virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override; // ....!!!! }; + + // Future DynamicIndex + //class YIndex : public IndexInterface + class YIndex : public XIndexBase + { + public: + typedef IndexInterface IB; + + private: + vector mIs; + RangePtr mRange; + std::vector mBlockSizes; // dim() elements only!!! + bool mExternalControl = false; + + public: + constexpr IndexType type() const; + + DEFAULT_MEMBERS(YIndex); + YIndex(const RangePtr& range); + YIndex(const RangePtr& range, const std::vector& is); + + YIndex& operator=(size_t pos); + YIndex& operator++(); + YIndex& operator--(); + int pp(std::intptr_t idxPtrNum); + int mm(std::intptr_t idxPtrNum); + size_t dim() const; + size_t getStepSize(size_t n) const; + std::string stringMeta() const; + DType meta() const; + YIndex& at(const DType& meta); + DynamicExpression ifor(size_t step, DynamicExpression ex) const; + DynamicExpression iforh(size_t step, DynamicExpression ex) const; + }; + + typedef std::shared_ptr YIndexPtr; template class DConstContainerIndex : public IndexInterface,DType> { + public: + typedef IndexInterface,DType> IB; + protected: - XIndexPtr mI; + YIndexPtr mI; const T* mCData = nullptr; - size_t mCPos = 0; + + public: + DEFAULT_MEMBERS(DConstContainerIndex); + DConstContainerIndex(const T* data, const RangePtr& range); + + DConstContainerIndex& operator=(size_t pos); + DConstContainerIndex& operator++(); + DConstContainerIndex& operator--(); + + template // fast but unsave + DConstContainerIndex operator+(const IndexInterface& i); + + template // fast but unsave + DConstContainerIndex operator-(const IndexInterface& i); + + template // save version of operator+ + DConstContainerIndex plus(const IndexInterface& i); + + template // save version of operator- + DConstContainerIndex minus(const IndexInterface& i); + + int pp(std::intptr_t idxPtrNum); + int mm(std::intptr_t idxPtrNum); + size_t dim() const; + size_t getStepSize(size_t n) const; + std::string stringMeta() const; + DType meta() const; + DType metaPtr() const; + DConstContainerIndex& at(const DType& meta); + DynamicExpression ifor(size_t step, DynamicExpression ex) const; + DynamicExpression iforh(size_t step, DynamicExpression ex) const; + + const T& operator*() const; + const T* operator->() const; + + DConstContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true + DConstContainerIndex& operator()(const std::vector& inds); // control via external indice + DConstContainerIndex& operator()(); // -> sync; just to shorten the code + }; template - class MDConstContainerIndex : public DConstContainerIndex + class DContainerIndex : public DConstContainerIndex { + public: + typedef DConstContainerIndex CCI; + typedef typename CCI::IB IB; + private: T* mData = nullptr; + + public: + + DEFAULT_MEMBERS(DContainerIndex); + DContainerIndex(T* data, const RangePtr& range); + DContainerIndex(T* data, const DConstContainerIndex& cci); + + T& operator*(); + T* operator->(); }; } diff --git a/src/include/ranges/dynamic_meta.cc.h b/src/include/ranges/dynamic_meta.cc.h new file mode 100644 index 0000000..fb8a8e0 --- /dev/null +++ b/src/include/ranges/dynamic_meta.cc.h @@ -0,0 +1,94 @@ + +#include +#include "dynamic_meta.h" + +namespace CNORXZ +{ + template + std::string toString(const T& a) + { + std::stringstream ss; + ss << a; + return ss.str(); + } + + template + std::string toString>(const vector& a) + { + std::stringstream ss; + ss << "["; + auto it = a.begin(); + for(; it != a.end()-1; ++it){ + ss << *it << ","; + } + ss << *it << "]"; + return ss.str(); + } + + template + std::string toString>(const std::array& a) + { + std::stringstream ss; + ss << "("; + auto it = a.begin(); + for(; it != a.end()-1; ++it){ + ss << *it << ","; + } + ss << *it << ")"; + return ss.str(); + } + + // for tuple use vector !!! + // (yes DType is slow, thats why one should only use it for debugging) + + template <> + std::string toString(const DType& a) + { + return a.str(); + } + + template + DType::DType(const T& d) : mD(d) + { + _mkToStr(); + } + + template + DType& DType::operator=(const T& d) + { + mD = d; + _mkToStr(); + return *this; + } + + template + void DType::_mkToStr() + { + mToStr = [&](){ + return toString(std::any_cast(mD)); + }; + } + + template + void DType::_mkComp() + { + mComp = [&](const std::any& a){ + if(mD.type() != a.type()){ + return 2; + } + else { + auto& at = std::any_cast(a); + auto& dt = std::any_cast(mD); + if(std::equal_to(dt,at)){ + return 0; + } + else if(std::less(dt,at)){ + return -1; + } + else { + return 1; + } + } + }; + } +} diff --git a/src/include/ranges/dynamic_meta.h b/src/include/ranges/dynamic_meta.h index 37473fb..64cda3f 100644 --- a/src/include/ranges/dynamic_meta.h +++ b/src/include/ranges/dynamic_meta.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "allocator.h" #include "rbase_def.h" @@ -69,93 +71,38 @@ namespace CNORXZ const DynamicMetaElem& operator[](size_t pos) const; }; - // NEW: - // Type Eraser: class DType { + private: + std::any mD; + std::function mToStr; + std::function mComp; + + template + void _mkToStr(); + + template + void _mkComp(); + public: DEFAULT_MEMBERS(DType); - virtual std::string str() const = 0; - virtual bool operator==(const DType& in) const = 0; - virtual bool operator!=(const DType& in) const = 0; - virtual size_t size() const = 0; - virtual std::shared_ptr operator[](size_t pos) const = 0; - }; - - // NEW: - template - class TypeWrapper : public DType - { - private: - T mD; - - public: - TypeWrapper(const T& d) : mD(d) {} - DEFAULT_MEMBERS(TypeWrapper); + template + DType(const T& d); - virtual std::string str() const { return std::to_string(mD); /*wrapper*/ } - virtual bool operator==(const DType& in) const { return this->str() == in.str(); } - virtual bool operator!=(const DType& in) const { return this->str() != in.str(); } - virtual size_t size() const { return 1; } - virtual std::shared_ptr operator[](size_t pos) const { return nullptr; } + template + DType& operator=(const T& d); + + std::string str() const { return mToStr(); } + const std::any& get() const { return mD; } + + bool operator==(const DType& a) const { return mComp(a.mD) == 0; } + bool operator!=(const DType& a) const { return mComp(a.mD) != 0; } + bool operator<(const DType& a) const { return mComp(a.mD) == -1; } + bool operator>(const DType& a) const { return mComp(a.mD) == 1; } + bool operator<=(const DType& a) const { auto c = mComp(a.mD); return c <= 0; } + bool operator>=(const DType& a) const { auto c = mComp(a.mD); return c == 1 or c == 0; } }; - - // NEW: - template - class TypeRefWrapper : public DType - { - private: - const T* mD; - - public: - TypeRefWrapper(const T* d) : mD(d) {} - DEFAULT_MEMBERS(TypeRefWrapper); - - virtual std::string str() const { return to_string(*mD); /*wrapper*/ } - virtual bool operator==(const DType& in) const { return this->str() == in.str(); } - virtual bool operator!=(const DType& in) const { return this->str() != in.str(); } - virtual size_t size() const { return 1; } - virtual std::shared_ptr operator[](size_t pos) const { return nullptr; } - }; - - // NEW: - template - class TypeWrapper> : public DType - { - private: - std::vector mD; - - public: - TypeWrapper(const std::vector& d) : mD(d) {} - DEFAULT_MEMBERS(TypeWrapper); - - virtual std::string str() const { return to_string(mD); /* overload before!!! */ } - virtual bool operator==(const DType& in) const { return this->str() == in.str(); } - virtual bool operator!=(const DType& in) const { return this->str() != in.str(); } - virtual size_t size() const { return mD.size(); } - virtual std::shared_ptr operator[](size_t pos) const { return std::make_shared(&mD[pos]); } - }; - - // NEW: - template - class TypeRefWrapper> : public DType - { - private: - const std::vector* mD; - - public: - TypeRefWrapper(const std::vector* d) : mD(d) {} - DEFAULT_MEMBERS(TypeRefWrapper); - - virtual std::string str() const { return to_string(*mD); /* overload before!!! */ } - virtual bool operator==(const DType& in) const { return this->str() == in.str(); } - virtual bool operator!=(const DType& in) const { return this->str() != in.str(); } - virtual size_t size() const { return mD->size(); } - virtual std::shared_ptr operator[](size_t pos) const { return std::make_shared(&(*mD)[pos]); } - }; - - // SPECIALIZE: for std::array and std::tuple } // namespace CNORXZ diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index c60e1c4..53123a2 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -27,8 +27,6 @@ namespace CNORXZ I& THIS() { return static_cast(*this); } I const& THIS() const { return static_cast(*this); } - static constexpr bool ISINDEX = true; - ~IndexInterface() = default; constexpr IndexType type() const { return THIS().type(); } @@ -46,20 +44,16 @@ namespace CNORXZ size_t dim() const { return THIS().dim(); } size_t pos() const; size_t max() const; - + bool last() const { return THIS().last(); } bool first() const { return THIS().first(); } - - std::shared_ptr vrange() const { return mRangePtr; } + std::shared_ptr range() const { return mRangePtr; } size_t getStepSize(size_t n) const { return THIS().getStepSize(n); } - operator size_t() const; - std::string stringMeta() const { return THIS().stringMeta(); } MetaType meta() const { return THIS().meta(); } - MetaType metaPtr() const { return THIS().metaPtr(); } I& at(const MetaType& meta) { return THIS().at(meta); } // CHECK / IMPLEMENT !!!!!! @@ -188,12 +182,6 @@ namespace CNORXZ return mMax; } - template - IndexInterface::operator size_t() const - { - return pos(); - } - template std::intptr_t IndexInterface::ptrNum() const { diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index b81508a..ff39e63 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -64,13 +64,11 @@ namespace CNORXZ std::shared_ptr createRangeFactory(const char** dp); std::shared_ptr createSingleRangeFactory(const vector*& d, int metaType, size_t size); - + class RangeBase { public: - static constexpr bool ISINDEX = false; - virtual ~RangeBase() = default; virtual size_t size() const = 0; @@ -81,6 +79,9 @@ namespace CNORXZ std::intptr_t id() const; + XIndexPtr beginX() const; + XIndexPtr endX() const; + virtual vector typeNum() const = 0; virtual size_t cmeta(char* target, size_t pos) const = 0; virtual size_t cmetaSize() const = 0; diff --git a/src/include/ranges/single_range.h b/src/include/ranges/single_range.h index c6e417f..992451f 100644 --- a/src/include/ranges/single_range.h +++ b/src/include/ranges/single_range.h @@ -34,8 +34,6 @@ namespace CNORXZ typedef GenSingleRange RangeType; typedef GenSingleIndex IType; - //DEFAULT_MEMBERS_X(GenSingleIndex); - GenSingleIndex(const std::shared_ptr >& range); static constexpr IndexType sType() { return IndexType::SINGLE; } @@ -117,7 +115,6 @@ namespace CNORXZ MetaMap& operator=(const MetaMap& in) = default; MetaMap& operator=(MetaMap&& in) = default; - //MetaMap(const std::map& in) : mMap(in) {} MetaMap(const vector& in) { for(size_t i = 0; i != in.size(); ++i){ @@ -137,58 +134,7 @@ namespace CNORXZ } size_t count(const U& in) const { return mMap.count(in); } }; - /* - template <> - class MetaMap > - { - private: - vector mMap; - int min1; - int min2; - int max1; - int max2; - size_t s1; - size_t s2; - public: - typedef std::array U; - - MetaMap() = default; - MetaMap(const MetaMap& in) = default; - MetaMap(MetaMap&& in) = default; - MetaMap& operator=(const MetaMap& in) = default; - MetaMap& operator=(MetaMap&& in) = default; - MetaMap(const vector& in) : min1(in[0][0]), - min2(in[0][1]), - max1(in[0][0]), - max2(in[0][1]) - { - for(auto& x: in){ - if(min1 > x[0]) min1 = x[0]; - if(min2 > x[1]) min2 = x[1]; - if(max1 < x[0]+1) max1 = x[0]+1; - if(max2 < x[1]+1) max2 = x[1]+1; - } - s1 = max1 - min1; - s2 = max2 - min2; - mMap.resize(s1*s2,-1); - for(size_t i = 0; i != in.size(); ++i){ - const size_t mpos = (in[i][0] - min1) * s2 + (in[i][1] - min2); - mMap[ mpos ] = i; - } - } - - size_t at(const U& in) const - { - //CHECK; - const size_t mpos = (in[0] - min1) * s2 + (in[1] - min2); - assert(mpos < mMap.size()); - assert(mMap[ mpos ] != static_cast( -1 ) ); - return mMap[ mpos ]; - } - - }; - */ template struct CheckStatic { @@ -263,7 +209,6 @@ namespace CNORXZ typedef GenSingleRange RangeType; typedef U MetaType; typedef GenSingleRangeFactory FType; - //typedef typename RangeInterface >::IndexType IndexType; virtual size_t size() const final; virtual size_t dim() const final; @@ -308,7 +253,6 @@ namespace CNORXZ GenSingleRange(vector&& space); vector mSpace; - //std::map mMSpace; MetaMap mMSpace; }; @@ -490,7 +434,6 @@ namespace CNORXZ auto GenSingleIndex::ifor(size_t step, Expr ex) const -> For,Expr> { - //static const size_t LAYER = typename Expr::LAYER; return For,Expr>(this, step, ex); } @@ -499,7 +442,6 @@ namespace CNORXZ auto GenSingleIndex::iforh(size_t step, Expr ex) const -> For,Expr,ForType::HIDDEN> { - //static const size_t LAYER = typename Expr::LAYER; return For,Expr,ForType::HIDDEN>(this, step, ex); } @@ -508,7 +450,6 @@ namespace CNORXZ auto GenSingleIndex::pifor(size_t step, Expr ex) const -> PFor,Expr> { - //static const size_t LAYER = typename Expr::LAYER; return PFor,Expr>(this, step, ex); } @@ -613,8 +554,6 @@ namespace CNORXZ template size_t GenSingleRange::cmeta(char* target, size_t pos) const { - //*reinterpret_cast(target) = mSpace[pos]; - //return sizeof(U); return ToCMeta::apply(target, mSpace[pos]); } @@ -639,8 +578,6 @@ namespace CNORXZ char* hcp = reinterpret_cast(&h); out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); stringCat(out, mSpace); - //const char* scp = reinterpret_cast(mSpace.data()); - //out.insert(out.end(), scp, scp + h.metaSize); return out; } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 681a337..ce7ba5a 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,6 +1,6 @@ -execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ ) +#execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ ) set(libcnorxz_a_SOURCES ${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc @@ -12,9 +12,9 @@ set(libcnorxz_a_SOURCES ${CMAKE_SOURCE_DIR}/src/lib/map_range_factory_product_map.cc ) -set(libhlcnorxz_a_SOURCES - ${CMAKE_SOURCE_DIR}/src/lib/high_level_operation.cc - ) +#set(libhlcnorxz_a_SOURCES +# ${CMAKE_SOURCE_DIR}/src/lib/high_level_operation.cc +# ) #message(WARNING ${libhlcnorxz_a_SOURCES}) file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc") @@ -23,20 +23,20 @@ foreach(ccfile ${cc_files}) ${ccfile}) endforeach(ccfile) -file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc") -foreach(ccfile ${cc_files}) - set(libhlcnorxz_a_SOURCES ${libhlcnorxz_a_SOURCES} - ${ccfile}) -endforeach(ccfile) +#file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc") +#foreach(ccfile ${cc_files}) +# set(libhlcnorxz_a_SOURCES ${libhlcnorxz_a_SOURCES} +# ${ccfile}) +#endforeach(ccfile) add_library(cnorxz_obj OBJECT ${libcnorxz_a_SOURCES} ) -add_library(hlcnorxz_obj OBJECT - ${libhlcnorxz_a_SOURCES} - ) +#add_library(hlcnorxz_obj OBJECT +# ${libhlcnorxz_a_SOURCES} +# ) set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) -set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) +#set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) add_library(cnorxz SHARED $ @@ -48,15 +48,15 @@ add_library(cnorxz_static ) set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) -add_library(hlcnorxz SHARED - $ - ) -set_target_properties(hlcnorxz PROPERTIES POSITION_INDEPENDENT_CODE TRUE) +#add_library(hlcnorxz SHARED +# $ +# ) +#set_target_properties(hlcnorxz PROPERTIES POSITION_INDEPENDENT_CODE TRUE) -add_library(hlcnorxz_static - $ - ) -set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) +#add_library(hlcnorxz_static +# $ +# ) +#set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) install(TARGETS cnorxz ARCHIVE DESTINATION ${INSTALL_PATH}/lib @@ -66,10 +66,10 @@ install(TARGETS cnorxz_static ARCHIVE DESTINATION ${INSTALL_PATH}/lib LIBRARY DESTINATION ${INSTALL_PATH}/lib) -install(TARGETS hlcnorxz - ARCHIVE DESTINATION ${INSTALL_PATH}/lib - LIBRARY DESTINATION ${INSTALL_PATH}/lib) +#install(TARGETS hlcnorxz +# ARCHIVE DESTINATION ${INSTALL_PATH}/lib +# LIBRARY DESTINATION ${INSTALL_PATH}/lib) -install(TARGETS hlcnorxz_static - ARCHIVE DESTINATION ${INSTALL_PATH}/lib - LIBRARY DESTINATION ${INSTALL_PATH}/lib) +#install(TARGETS hlcnorxz_static +# ARCHIVE DESTINATION ${INSTALL_PATH}/lib +# LIBRARY DESTINATION ${INSTALL_PATH}/lib) diff --git a/src/lib/dcontainer_index.cc b/src/lib/dcontainer_index.cc new file mode 100644 index 0000000..edd0495 --- /dev/null +++ b/src/lib/dcontainer_index.cc @@ -0,0 +1,100 @@ + +#include "dcontainer_index.h" + +namespace CNORXZ +{ + YIndex::YIndex(const RangePtr& range) : + IndexInterface(range, 0) + { + //...!!! + } + + YIndex::YIndex(const RangePtr& range, const std::vector& is) : + IndexInterface(range, 0) + { + //...!!! + } + + YIndex& YIndex::operator=(size_t pos) + { + IB::mPos = pos; + // sub inds...!!! + return *this; + } + + YIndex& YIndex::operator++() + { + if(mExternalControl) this->sync(); + // increment sub inds !!! + ++mPos; + return *this; + } + + YIndex& YIndex::operator--() + { + if(mExternalControl) this->sync(); + // decrement sub inds !!! + --mPos; + return *this; + } + + int YIndex::pp(std::intptr_t idxPtrNum) + { + + } + + int YIndex::mm(std::intptr_t idxPtrNum) + { + + } + + size_t YIndex::dim() const + { + return mIs.size(); + } + + size_t YIndex::getStepSize(size_t n) const + { + + } + + std::string YIndex::stringMeta() const + { + std::string out = "["; + auto it = mIs.begin(); + for(; it != mIs.end()-1; ++it){ + out += it->stringMeta() + "," + } + out += it->stringMeta() + "]" + return out; + } + + DType YIndex::meta() const + { + //this->sync(); + vector v(mIs.size()); + std::transform(mIs.begin(), mIs.end(), v.begin(), [](auto& x) { return x->meta() }); + return DType(v); + } + + YIndex& YIndex::at(const DType& meta) + { + auto& v = std::any_cast&>(meta.get()); + assert(v.size() == mIs.size()); + for(size_t i = 0; i != mIs.size()){ + mIs[i]->at(v[i]); + } + return *this; + } + + DynamicExpression YIndex::ifor(size_t step, DynamicExpression ex) const + { + + } + + DynamicExpression YIndex::iforh(size_t step, DynamicExpression ex) const + { + + } + +} // namespace CNORXZ diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 165a6bc..d284997 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,41 +1,44 @@ -#add_executable(iutest /ranges/index_unit_test.cc ${INDEX_CC_FILES}) -add_executable(iutest ranges/index_unit_test.cc) -add_dependencies(iutest cnorxz) -target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) -add_test(NAME iutest COMMAND iutest) +#add_executable(iutest ranges/index_unit_test.cc) +#add_dependencies(iutest cnorxz) +#target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +#add_test(NAME iutest COMMAND iutest) -add_executable(autest ranges/anonymous_unit_test.cc) -add_dependencies(autest cnorxz) -target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) -add_test(NAME autest COMMAND autest) +#add_executable(autest ranges/anonymous_unit_test.cc) +#add_dependencies(autest cnorxz) +#target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +#add_test(NAME autest COMMAND autest) -#add_executable(mautest src/tests/array_unit_test.cc ${MA_CC_FILES}) -add_executable(mautest array_unit_test.cc) -add_dependencies(mautest cnorxz) -target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) -add_test(NAME mautest COMMAND mautest) +#add_executable(mautest array_unit_test.cc) +#add_dependencies(mautest cnorxz) +#target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +#add_test(NAME mautest COMMAND mautest) -add_executable(oputest op_unit_test.cc) -add_dependencies(oputest cnorxz) -target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) -add_test(NAME oputest COMMAND oputest) +add_executable(dautest darray_unit_test.cc) +add_dependencies(dautest cnorxz) +target_link_libraries(dautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +add_test(NAME dautest COMMAND dautest) -add_executable(op2utest op2_unit_test.cc) -add_dependencies(op2utest cnorxz) -target_link_libraries(op2utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) -add_test(NAME op2utest COMMAND op2utest) +#add_executable(oputest op_unit_test.cc) +#add_dependencies(oputest cnorxz) +#target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +#add_test(NAME oputest COMMAND oputest) -add_executable(op3utest op3_unit_test.cc) -add_dependencies(op3utest cnorxz) -target_link_libraries(op3utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) -add_test(NAME op3utest COMMAND op3utest) +#add_executable(op2utest op2_unit_test.cc) +#add_dependencies(op2utest cnorxz) +#target_link_libraries(op2utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +#add_test(NAME op2utest COMMAND op2utest) -add_executable(op4utest op4_unit_test.cc) -add_dependencies(op4utest cnorxz hlcnorxz) -target_link_libraries(op4utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz hlcnorxz) -add_test(NAME op4utest COMMAND op4utest) +#add_executable(op3utest op3_unit_test.cc) +#add_dependencies(op3utest cnorxz) +#target_link_libraries(op3utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +#add_test(NAME op3utest COMMAND op3utest) -add_executable(opptest op_perf_test.cc) -add_dependencies(opptest cnorxz) -target_link_libraries(opptest cnorxz) +#add_executable(op4utest op4_unit_test.cc) +#add_dependencies(op4utest cnorxz hlcnorxz) +#target_link_libraries(op4utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz hlcnorxz) +#add_test(NAME op4utest COMMAND op4utest) + +#add_executable(opptest op_perf_test.cc) +#add_dependencies(opptest cnorxz) +#target_link_libraries(opptest cnorxz) diff --git a/src/tests/darray_unit_test.cc b/src/tests/darray_unit_test.cc new file mode 100644 index 0000000..27e73b6 --- /dev/null +++ b/src/tests/darray_unit_test.cc @@ -0,0 +1,279 @@ +// -*- C++ -*- + +#include +#include "gtest/gtest.h" +#include + +#include "cnorxz.h" + +namespace MAT = CNORXZ; + +namespace { + + using namespace MAT; + + template + void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) + { + vector tmp = ilist; + auto nptr = std::make_shared( tmp ); + fptr = nptr; + } + + template + void swapMFactory(std::shared_ptr& fptr, const Rs&... rs) + { + auto nptr = std::make_shared( rs... ); + fptr = nptr; + } + + template + auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...)) + { + return std::make_tuple(ts...); + } + + + class MATest_1Dim : public ::testing::Test + { + protected: + + typedef SingleRangeFactory SRF; + typedef SRF::oType SRange; + + MATest_1Dim() + { + swapFactory(rfbptr, {'x', 'y', 'l', 'f', 'g'} ); + srptr = std::dynamic_pointer_cast( rfbptr->create() ); + + } + + std::shared_ptr rfbptr; + std::shared_ptr srptr; + vector vv = { 3.141, 2.718, 1.618, 0.693, 0.577 }; + }; + + /* + class MATest_MDim : public ::testing::Test + { + protected: + + typedef SingleRangeFactory SRF; + typedef SRF::oType SRange; + + typedef MultiRangeFactory MRF; + typedef MRF::oType MRange; + + MATest_MDim() + { + swapFactory(rfbptr, {'x', 'y'} ); + sr1ptr = std::dynamic_pointer_cast( rfbptr->create() ); + + swapFactory(rfbptr, {'a', 'l', 'f', 'g'} ); + sr2ptr = std::dynamic_pointer_cast( rfbptr->create() ); + + swapFactory(rfbptr, {'1', '2', '3'} ); + sr3ptr = std::dynamic_pointer_cast( rfbptr->create() ); + + swapFactory(rfbptr, { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X' } ); + sr4ptr = std::dynamic_pointer_cast( rfbptr->create() ); + + swapMFactory(rfbptr, sr1ptr, sr2ptr); + mrptr = std::dynamic_pointer_cast( rfbptr->create() ); + + } + + std::shared_ptr rfbptr; + std::shared_ptr sr1ptr; + std::shared_ptr sr2ptr; + std::shared_ptr sr3ptr; + std::shared_ptr sr4ptr; + std::shared_ptr mrptr; + vector vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280, + 8.870, 4.790, 8.215, 5.063, 1.530, 3.084, 1.609, 4.847, + 8.175, 0.112, 6.712, 6.408, 1.959, 0.331, 4.209, 2.951 }; + }; + */ + TEST_F(MATest_1Dim, SimpleCall) + { + DArray a(srptr, vv); + Array ma(srptr, vv); + EXPECT_EQ( ma.size(), 5u); + /* + EXPECT_EQ( ma.isConst(), false); + EXPECT_EQ( ma.isSlice(), false); + + auto i = ma.cbegin(); + EXPECT_EQ( ma[ i.at('x') ], 3.141); + EXPECT_EQ( ma[ i.at('y') ], 2.718); + EXPECT_EQ( ma[ i.at('l') ], 1.618); + EXPECT_EQ( ma[ i.at('f') ], 0.693); + EXPECT_EQ( ma[ i.at('g') ], 0.577); + */ + } + /* + TEST_F(MATest_1Dim, ForLoop) + { + vector v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 }; + Array ma(srptr, std::move( v2 ) ); + size_t cnt = 0; + for(auto el: ma){ + + if(cnt == 0){ + EXPECT_EQ(el, 0.693); + } else if(cnt == 1u){ + EXPECT_EQ(el, 2.718); + } else if(cnt == 2u){ + EXPECT_EQ(el, 3.141); + } else if(cnt == 3u){ + EXPECT_EQ(el, 1.618); + } else if(cnt == 4u){ + EXPECT_EQ(el, 9.98); + } else { + EXPECT_EQ(cnt, 0u); + } + ++cnt; + } + EXPECT_EQ(cnt, ma.size()); + } + */ + TEST_F(MATest_1Dim, ReFormat) + { + swapFactory( rfbptr, { 'a', 'c', 'e', 'g', 'i' } ); + std::shared_ptr sr2 = std::dynamic_pointer_cast( rfbptr->create() ); + + Array ma(srptr, vv); + auto i = ma.cbegin(); + EXPECT_EQ( ma[ i.at('x') ], 3.141); + + auto ma2 = ma.format( sr2 ); + auto j = ma2.cbegin(); + + EXPECT_EQ( ma[ j.at('a') ], 3.141); + EXPECT_EQ( ma[ j.at('c') ], 2.718); + EXPECT_EQ( ma[ j.at('e') ], 1.618); + EXPECT_EQ( ma[ j.at('g') ], 0.693); + EXPECT_EQ( ma[ j.at('i') ], 0.577); + } + /* + TEST_F(MATest_MDim, SimpleCall) + { + Array ma(mrptr, sr3ptr, vv); + EXPECT_EQ( ma.size(), 24u ); + EXPECT_EQ( ma.range()->dim(), 2u ); + + auto i = ma.cbegin(); + EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '1' ) ) ], 2.917); + EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '2' ) ) ], 9.436); + + EXPECT_EQ( ma.at( mkt( mkt('x', 'a'), '1' ) ), 2.917); + EXPECT_EQ( ma.at( mkt( mkt('x', 'a'), '2' ) ), 9.436); + + ma.at( mkt( mkt('x', 'a'), '2' ) ) = 4.444; + EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '2' ) ) ], 4.444 ); + } + + TEST_F(MATest_MDim, ReFormat) + { + Array ma(mrptr, sr3ptr, vv); + + auto ma2 = ma.format( sr4ptr ); + auto i = ma2.cbegin(); + EXPECT_EQ( ma2.at('A') , 2.917 ); + EXPECT_EQ( ma2[ i.at('G') ], 4.892 ); + EXPECT_EQ( ma2.at('J') , 4.790 ); + EXPECT_EQ( ma2[ i.at('M') ], 1.530 ); + EXPECT_EQ( ma2.at('W') , 4.209 ); + } + + TEST_F(MATest_MDim, SliceTest1) + { + Array ma(mrptr, sr3ptr, vv); + Slice sl(sr3ptr); + + auto i = MAT::getIndex(sr3ptr); + auto mi = MAT::getIndex(mrptr); + mi->at( mkt('y', 'f') ); + sl.define(i) = ma(mi, i); + + EXPECT_EQ( sl.at('1'), 6.712 ); + EXPECT_EQ( sl.at('2'), 6.408 ); + EXPECT_EQ( sl.at('3'), 1.959 ); + + Slice sl2(sr2ptr); + auto j = MAT::getIndex(sr3ptr); + auto mj = MAT::getIndex(mrptr); + mj->at( mkt('y','a') ); + j->at('2'); + auto jj = mj->template getPtr<1>(); + sl2.define(jj) = ma(mj, j); + + EXPECT_EQ( sl2.at('a'), 3.084 ); + EXPECT_EQ( sl2.at('l'), 8.175 ); + EXPECT_EQ( sl2.at('f'), 6.408 ); + EXPECT_EQ( sl2.at('g'), 4.209 ); + + Slice sl3(sr3ptr, sr1ptr, sr2ptr); + mj->at( mkt('x','a') ); + auto j1 = MAT::getIndex(sr1ptr); + auto j2 = MAT::getIndex(sr2ptr); + (*mj)(j1,j2); + j->at('1'); + sl3.define(j, j1, j2) = ma(mj, j); + + auto ci = sl3.begin(); + + EXPECT_EQ( sl3.at( mkt('1', 'x','a') ), 2.917 ); + EXPECT_EQ( *ci, 2.917 ); + EXPECT_EQ( sl3.at( mkt('2', 'x','a') ), 9.436 ); + EXPECT_EQ( sl3.at( mkt('3', 'x','a') ), 0.373 ); + + EXPECT_EQ( sl3.at( mkt('1', 'x','l') ), 7.192 ); + EXPECT_EQ( *(++ci), 7.192 ); + EXPECT_EQ( sl3.at( mkt('2', 'x','l') ), 7.315 ); + EXPECT_EQ( sl3.at( mkt('3', 'x','l') ), 1.536 ); + + EXPECT_EQ( sl3.at( mkt('1', 'x','f') ), 4.892 ); + EXPECT_EQ( *(++ci), 4.892 ); + EXPECT_EQ( sl3.at( mkt('2', 'x','f') ), 0.280 ); + EXPECT_EQ( sl3.at( mkt('3', 'x','f') ), 8.870 ); + + EXPECT_EQ( sl3.at( mkt('1', 'x','g') ), 4.790 ); + EXPECT_EQ( *(++ci), 4.790 ); + EXPECT_EQ( sl3.at( mkt('2', 'x','g') ), 8.215 ); + EXPECT_EQ( sl3.at( mkt('3', 'x','g') ), 5.063 ); + + EXPECT_EQ( sl3.at( mkt('1', 'y','a') ), 1.530 ); + EXPECT_EQ( *(++ci), 1.530 ); + EXPECT_EQ( sl3.at( mkt('2', 'y','a') ), 3.084 ); + EXPECT_EQ( sl3.at( mkt('3', 'y','a') ), 1.609 ); + + EXPECT_EQ( sl3.at( mkt('1', 'y','l') ), 4.847 ); + EXPECT_EQ( *(++ci), 4.847 ); + EXPECT_EQ( sl3.at( mkt('2', 'y','l') ), 8.175 ); + EXPECT_EQ( sl3.at( mkt('3', 'y','l') ), 0.112 ); + + EXPECT_EQ( sl3.at( mkt('1', 'y','f') ), 6.712 ); + EXPECT_EQ( *(++ci), 6.712 ); + EXPECT_EQ( sl3.at( mkt('2', 'y','f') ), 6.408 ); + EXPECT_EQ( sl3.at( mkt('3', 'y','f') ), 1.959 ); + + EXPECT_EQ( sl3.at( mkt('1', 'y','g') ), 0.331 ); + EXPECT_EQ( *(++ci), 0.331 ); + EXPECT_EQ( sl3.at( mkt('2', 'y','g') ), 4.209 ); + EXPECT_EQ( sl3.at( mkt('3', 'y','g') ), 2.951 ); + + EXPECT_EQ( *(++ci), 9.436 ); + EXPECT_EQ( *(++ci), 7.315 ); + + } + */ +} // end namespace + +int main(int argc, char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}