From 9543342db49a9b633bdddad9ff7344d67c03c56d Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Thu, 15 Sep 2022 16:45:45 +0200 Subject: [PATCH] further compile fixes --- src/include/array/darray.cc.h | 11 +- src/include/array/darray.h | 8 +- src/include/array/darray_base.cc.h | 18 +- src/include/array/darray_base.h | 19 +- src/include/array/dcontainer_index.cc.h | 23 +-- src/include/array/dcontainer_index.h | 37 ++-- src/include/base/base.cc.h | 1 + src/include/base/base.h | 2 + src/include/base/to_string.cc.h | 18 +- src/include/base/to_string.h | 6 + src/include/memory/memcount.h | 6 +- src/include/ranges/crange.h | 2 +- src/include/ranges/index_base.cc.h | 14 +- src/include/ranges/index_base.h | 10 +- src/include/ranges/range_base.cc.h | 16 +- src/include/ranges/range_base.h | 17 +- src/include/ranges/ranges.cc.h | 3 + src/include/ranges/urange.cc.h | 29 +-- src/include/ranges/urange.h | 6 +- src/include/ranges/xindex.cc.h | 8 +- src/include/ranges/xindex.h | 9 +- src/include/ranges/yindex.h | 2 + src/lib/CMakeLists.txt | 2 + src/lib/base/to_string.cc | 15 ++ src/lib/memory/memcount.cc | 23 +++ src/lib/ranges/range_base.cc | 20 +- src/lib/ranges/yindex.cc | 8 +- src/tests/CMakeLists.txt | 11 +- src/tests/darray_unit_test.cc | 248 ++---------------------- src/tests/range_unit_test.cc | 35 ++++ src/tests/test_numbers.cc | 2 +- src/tests/test_numbers.h | 9 +- 32 files changed, 267 insertions(+), 371 deletions(-) create mode 100644 src/lib/base/to_string.cc create mode 100644 src/lib/memory/memcount.cc create mode 100644 src/tests/range_unit_test.cc diff --git a/src/include/array/darray.cc.h b/src/include/array/darray.cc.h index fa8d911..a77fae9 100644 --- a/src/include/array/darray.cc.h +++ b/src/include/array/darray.cc.h @@ -1,5 +1,8 @@ -#include "cxz_darray.h" +#ifndef __cxz_darray_cc_h__ +#define __cxz_darray_cc_h__ + +#include "darray.h" namespace CNORXZ { @@ -11,11 +14,11 @@ namespace CNORXZ DArray::DArray(const RangePtr& range) : MDArrayBase(range), mCont(range->size()) {} template - DArray::DArray(const RangePtr& range, const vector& vec) : + DArray::DArray(const RangePtr& range, const Vector& vec) : MDArrayBase(range), mCont(vec) {} template - DArray::DArray(const RangePtr& range, vector&& vec) : + DArray::DArray(const RangePtr& range, Vector&& vec) : MDArrayBase(range), mCont(vec) {} template @@ -51,3 +54,5 @@ namespace CNORXZ } } + +#endif diff --git a/src/include/array/darray.h b/src/include/array/darray.h index d85c5cc..e6e71f1 100644 --- a/src/include/array/darray.h +++ b/src/include/array/darray.h @@ -2,7 +2,7 @@ #ifndef __cxz_darray_h__ #define __cxz_darray_h__ -#include "cxz_darray_base.h" +#include "darray_base.h" namespace CNORXZ { @@ -19,14 +19,14 @@ namespace CNORXZ using MDArrayBase::operator[]; private: - vector mCont; + Vector mCont; public: DEFAULT_MEMBERS(DArray); DArray(const RangePtr& range); - DArray(const RangePtr& range, const vector& vec); - DArray(const RangePtr& range, vector&& vec); + DArray(const RangePtr& range, const Vector& vec); + DArray(const RangePtr& range, Vector&& vec); virtual const T* data() const override; virtual T* data() override; diff --git a/src/include/array/darray_base.cc.h b/src/include/array/darray_base.cc.h index a1c9204..7e09dd1 100644 --- a/src/include/array/darray_base.cc.h +++ b/src/include/array/darray_base.cc.h @@ -1,5 +1,8 @@ -#include "cxz_darray_base.h" +#ifndef __cxz_darray_base_cc_h__ +#define __cxz_darray_base_cc_h__ + +#include "darray_base.h" namespace CNORXZ { @@ -53,14 +56,14 @@ namespace CNORXZ { return mInit; } - + /* template template ConstOperationRoot DArrayBase::operator()(const IndexPtr& i) const { - return ConstOperationRoot(/**/); + return ConstOperationRoot(); } - + */ /***************** * MDArrayBase * @@ -95,11 +98,14 @@ namespace CNORXZ return iterator(this->data(), this->cend()); } + /* template template OperationRoot MDArrayBase::operator()(const IndexPtr& i) { - return OperationRoot(/**/); + return OperationRoot(); } - + */ } + +#endif diff --git a/src/include/array/darray_base.h b/src/include/array/darray_base.h index 0a3f3fd..1a65be4 100644 --- a/src/include/array/darray_base.h +++ b/src/include/array/darray_base.h @@ -7,10 +7,9 @@ #include #include -#include "base_def.h" -#include "mbase_def.h" - -#include "ranges/rheader.h" +#include "base/base.h" +#include "dcontainer_index.h" +//#include "operation/" namespace CNORXZ { @@ -52,8 +51,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 @@ -71,7 +70,7 @@ namespace CNORXZ using DAB::end; using DAB::cbegin; using DAB::cend; - using DAB::operator(); + //using DAB::operator(); MDArrayBase(const RangePtr& range); DEFAULT_MEMBERS(MDArrayBase); @@ -89,9 +88,9 @@ namespace CNORXZ virtual iterator begin(); virtual iterator end(); - - template - OperationRoot operator()(const IndexPtr& i); + + //template + //OperationRoot operator()(const IndexPtr& i); }; } diff --git a/src/include/array/dcontainer_index.cc.h b/src/include/array/dcontainer_index.cc.h index 24805fa..f9a5d62 100644 --- a/src/include/array/dcontainer_index.cc.h +++ b/src/include/array/dcontainer_index.cc.h @@ -3,19 +3,20 @@ #define __cxz_dcontainer_index_cc_h__ #include "dcontainer_index.h" +#include "statics/static_for.h" namespace CNORXZ { template DConstContainerIndex::DConstContainerIndex(const T* data, const RangePtr& range): - mI(range->beginX()), mCData(data) + mI(range->begin()), mCData(data) { assert(0); } template - DConstContainerIndex& DConstContainerIndex::operator=(size_t pos) + DConstContainerIndex& DConstContainerIndex::operator=(SizeT pos) { (*mI) = pos; IB::mPos = mI->pos(); @@ -39,31 +40,31 @@ namespace CNORXZ } template - int DConstContainerIndex::pp(std::intptr_t idxPtrNum) + int DConstContainerIndex::pp(PtrId idxPtrNum) { return mI->pp(idxPtrNum); } template - int DConstContainerIndex::mm(std::intptr_t idxPtrNum) + int DConstContainerIndex::mm(PtrId idxPtrNum) { return mI->mm(idxPtrNum); } template - size_t DConstContainerIndex::dim() const + SizeT DConstContainerIndex::dim() const { return mI->dim(); } template - size_t DConstContainerIndex::getStepSize(size_t n) const + SizeT DConstContainerIndex::getStepSize(SizeT n) const { return mI->getStepSize(n); // dim() elements only!!! } template - std::string DConstContainerIndex::stringMeta() const + String DConstContainerIndex::stringMeta() const { return mI->stringMeta(); } @@ -81,19 +82,19 @@ namespace CNORXZ IB::mPos = mI->pos(); return *this; } - + /* template - DynamicExpression DConstContainerIndex::ifor(size_t step, DynamicExpression ex) const + DExpr DConstContainerIndex::ifor(SizeT step, DExpr ex) const { return mI->ifor(step, ex); } template - DynamicExpression DConstContainerIndex::iforh(size_t step, DynamicExpression ex) const + DExpr DConstContainerIndex::iforh(SizeT step, DExpr ex) const { return mI->iforh(step, ex); } - + */ template const T& DConstContainerIndex::operator*() const { diff --git a/src/include/array/dcontainer_index.h b/src/include/array/dcontainer_index.h index 2f7e05b..72a36cb 100644 --- a/src/include/array/dcontainer_index.h +++ b/src/include/array/dcontainer_index.h @@ -2,17 +2,16 @@ #ifndef __cxz_dcontainer_index_h__ #define __cxz_dcontainer_index_h__ -#include "range_base.h" -#include "index_base.h" -#include "statics/static_for.h" -#include "xfor/xfor.h" +#include "ranges/range_base.h" +#include "ranges/index_base.h" +#include "ranges/xfor/xfor.h" #include "ranges/xindex.h" #include "ranges/yindex.h" namespace CNORXZ { - + // rename: AIndex (A = Array) template class DConstContainerIndex : public IndexInterface,DType> { @@ -27,32 +26,20 @@ namespace CNORXZ DEFAULT_MEMBERS(DConstContainerIndex); DConstContainerIndex(const T* data, const RangePtr& range); - DConstContainerIndex& operator=(size_t pos); + DConstContainerIndex& operator=(SizeT 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; + int pp(PtrId idxPtrNum); + int mm(PtrId idxPtrNum); + SizeT dim() const; + SizeT getStepSize(SizeT n) const; + 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; + //DExpr ifor(SizeT step, DExpr ex) const; + //DExpr iforh(SizeT step, DExpr ex) const; const T& operator*() const; const T* operator->() const; diff --git a/src/include/base/base.cc.h b/src/include/base/base.cc.h index 8f547df..cd0374a 100644 --- a/src/include/base/base.cc.h +++ b/src/include/base/base.cc.h @@ -1,3 +1,4 @@ #include "dtype.cc.h" #include "obj_handle.cc.h" +#include "to_string.cc.h" diff --git a/src/include/base/base.h b/src/include/base/base.h index 673041f..523dbeb 100644 --- a/src/include/base/base.h +++ b/src/include/base/base.h @@ -24,4 +24,6 @@ #include "base.cc.h" +#include "memory/memory.h" + #endif diff --git a/src/include/base/to_string.cc.h b/src/include/base/to_string.cc.h index 4185857..2ac4878 100644 --- a/src/include/base/to_string.cc.h +++ b/src/include/base/to_string.cc.h @@ -16,15 +16,15 @@ namespace CNORXZ } template - String ToString>::func(const vector& a) + String ToString>::func(const Vector& a) { std::stringstream ss; ss << "["; auto it = a.begin(); for(; it != a.end()-1; ++it){ - ss << *it << ","; + ss << toString(*it) << ","; } - ss << *it << "]"; + ss << toString(*it) << "]"; return ss.str(); } @@ -35,22 +35,16 @@ namespace CNORXZ ss << "("; auto it = a.begin(); for(; it != a.end()-1; ++it){ - ss << *it << ","; + ss << toString(*it) << ","; } - ss << *it << ")"; + ss << toString(*it) << ")"; return ss.str(); } - template <> - String ToString::func(const DType& a) - { - return a.str(); - } - template String toString(const T& a) { - return ToString::func(a); + return ToString::func(a); } } diff --git a/src/include/base/to_string.h b/src/include/base/to_string.h index ef883fd..148ef1f 100644 --- a/src/include/base/to_string.h +++ b/src/include/base/to_string.h @@ -12,6 +12,12 @@ namespace CNORXZ static String func(const T& a); }; + template <> + struct ToString + { + static String func(const String& a); + }; + template struct ToString> { diff --git a/src/include/memory/memcount.h b/src/include/memory/memcount.h index b767e31..8a71768 100644 --- a/src/include/memory/memcount.h +++ b/src/include/memory/memcount.h @@ -10,12 +10,12 @@ namespace CNORXZ { private: static SizeT sMemUsage; - static void add(SizeT x) { sMemUsage += x; } - static void sub(SizeT x) { sMemUsage -= x; } + static void add(SizeT x);// { sMemUsage += x; } + static void sub(SizeT x);// { sMemUsage -= x; } public: MemCount() = delete; // static only - static SizeT usage() { return sMemUsage; } + static SizeT usage();// { return sMemUsage; } template friend class Allocator; diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index c98b8c7..6eb2b19 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -75,7 +75,7 @@ namespace CNORXZ RangePtr mRef; }; - class CRange : public RangeInterface + class CRange : public RangeInterface { public: typedef RangeBase RB; diff --git a/src/include/ranges/index_base.cc.h b/src/include/ranges/index_base.cc.h index 2a25edf..fade417 100644 --- a/src/include/ranges/index_base.cc.h +++ b/src/include/ranges/index_base.cc.h @@ -13,27 +13,26 @@ namespace CNORXZ template IndexInterface::IndexInterface() { - mPtrNum = reinterpret_cast(this); + mPtrId = reinterpret_cast(this); } template IndexInterface::IndexInterface(const IndexInterface& in) : mPos(in.mPos) { - mPtrNum = reinterpret_cast(this); + mPtrId = reinterpret_cast(this); } template IndexInterface::IndexInterface(IndexInterface&& in) : mPos(in.mPos) { - mPtrNum = reinterpret_cast(this); + mPtrId = reinterpret_cast(this); } template IndexInterface& IndexInterface::operator=(const IndexInterface& in) { - mRangePtr = in.mRangePtr; mPos = in.mPos; return *this; } @@ -41,7 +40,6 @@ namespace CNORXZ template IndexInterface& IndexInterface::operator=(IndexInterface&& in) { - mRangePtr = in.mRangePtr; mPos = in.mPos; return *this; } @@ -95,12 +93,6 @@ namespace CNORXZ return mPos; } - template - SizeT IndexInterface::max() const - { - return mMax; - } - template PtrId IndexInterface::ptrId() const { diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index 58cb141..508bc4b 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -9,7 +9,6 @@ namespace CNORXZ { - template class IndexInterface { @@ -20,8 +19,8 @@ namespace CNORXZ const I& THIS() const { return static_cast(*this); } I& operator=(SizeT pos) { return THIS() = pos; } - I& operator++() { return THIS()++; } - I& operator--() { return THIS()--;} + I& operator++() { return ++THIS(); } + I& operator--() { return --THIS();} I operator+(Int n) const { return THIS() + n; } I operator-(Int n) const { return THIS() - n; } I& operator+=(Int n) { return THIS() += n; } @@ -51,7 +50,7 @@ namespace CNORXZ String stringMeta() const { return THIS().stringMeta(); } auto meta() const { return THIS().meta(); } I& at(const MetaType& meta) { return THIS().at(meta); } - + /* template auto ifor(SizeT step, const Expr ex) const { return THIS().template ifor(step,ex); } @@ -59,7 +58,7 @@ namespace CNORXZ template auto iforh(SizeT step, const Expr ex) const { return THIS().template iforh(step,ex); } - + */ private: friend I; // why not protected???!!! @@ -70,7 +69,6 @@ namespace CNORXZ IndexInterface(IndexInterface&& in); IndexInterface& operator=(IndexInterface&& in); IndexInterface(SizeT pos); - IndexInterface(SizeT pos, const IndexPtr& rel); SizeT mPos = 0; PtrId mPtrId = 0; diff --git a/src/include/ranges/range_base.cc.h b/src/include/ranges/range_base.cc.h index ef45d0a..1949265 100644 --- a/src/include/ranges/range_base.cc.h +++ b/src/include/ranges/range_base.cc.h @@ -6,22 +6,28 @@ namespace CNORXZ { - template - Index RangeInterface::begin() const + template + Index RangeInterface::begin() const { return Index(RangePtr(RB::mThis), 0); } - template - Index RangeInterface::end() const + template + Index RangeInterface::end() const { return Index(RangePtr(RB::mThis), this->size()); } + template + XIndexPtr RangeInterface::index(SizeT pos) const + { + return std::make_shared>( this->begin()+pos ); + } + template Sptr RangeCast::func(const RangePtr& r) { - CXZ_ERROR("cast form '" << r->type().name() << "' to '" + CXZ_ERROR("cast from '" << r->type().name() << "' to '" << typeid(Range).name() << "' not available"); return nullptr; } diff --git a/src/include/ranges/range_base.h b/src/include/ranges/range_base.h index c0b625d..10b5f37 100644 --- a/src/include/ranges/range_base.h +++ b/src/include/ranges/range_base.h @@ -47,27 +47,31 @@ namespace CNORXZ virtual SizeT size() const = 0; virtual SizeT dim() const = 0; + virtual const TypeInfo& type() const = 0; + virtual const TypeInfo& metaType() const = 0; + virtual String stringMeta(SizeT pos) const = 0; + virtual XIndexPtr index(SizeT pos = 0) const = 0; bool operator==(const RangeBase& in) const; bool operator!=(const RangeBase& in) const; - virtual const TypeInfo& type() const = 0; - virtual const TypeInfo& metaType() const = 0; - virtual String stringMeta(SizeT pos) const = 0; - PtrId id() const; XIndexPtr begin() const; XIndexPtr end() const; + RangePtr orig() const; friend RangeFactoryBase; protected: RangeBase() = default; - std::weak_ptr mThis; + RangeBase(const RangePtr& rel); + // delete copy/move??? + Wptr mThis; + RangePtr mRel; // used, if created from another range, to point on it }; - template + template class RangeInterface : public RangeBase { public: @@ -77,6 +81,7 @@ namespace CNORXZ Index begin() const; Index end() const; + virtual XIndexPtr index(SizeT pos) const override final; protected: RangeInterface() = default; diff --git a/src/include/ranges/ranges.cc.h b/src/include/ranges/ranges.cc.h index 89228d1..a66fe57 100644 --- a/src/include/ranges/ranges.cc.h +++ b/src/include/ranges/ranges.cc.h @@ -1,3 +1,6 @@ +#include "index_base.cc.h" +#include "range_base.cc.h" #include "xindex.cc.h" +#include "urange.cc.h" #include "crange.cc.h" diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index 701b1cb..f605d46 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -16,8 +16,8 @@ namespace CNORXZ template UIndex::UIndex(const RangePtr& range) : IndexInterface,MetaType>(0), - mRange(rangeCast(range)), - mMetaPtr(&get(0)) + mRangePtr(rangeCast(range)), + mMetaPtr(&mRangePtr->get(0)) {} template @@ -62,9 +62,9 @@ namespace CNORXZ } template - MetaType& UIndex::meta() const + const MetaType& UIndex::meta() const { - return mSpace[IB::mPos]; + return mMetaPtr[IB::mPos]; } template @@ -81,17 +81,17 @@ namespace CNORXZ } template - Sptr> UIndex::range() + Sptr> UIndex::range() const { return mRangePtr; } template - size_t UIndex::getStepSize(SizeT n) + SizeT UIndex::getStepSize(SizeT n) const { return 1; } - + /* template template auto UIndex::ifor(size_t step, Expr ex) const @@ -115,7 +115,7 @@ namespace CNORXZ { return PFor,Expr>(this, step, ex); } - + */ /********************** * URangeFactory * @@ -140,14 +140,15 @@ namespace CNORXZ template void URangeFactory::make() { + auto info = typeid(URange); if(mRef != nullptr) { - mProd = this->fromCreated[typeid(oType)][mRef->id()]; + mProd = this->fromCreated[info.hash_code()][mRef->id()]; } if(mProd == nullptr){ - RangePtr key = mProd = std::shared_ptr + RangePtr key = mProd = std::shared_ptr> ( new URange( std::move(mSpace) ) ); - if(mRef != nullptr) { key = mRef->id(); } - this->addToCreated(typeid(oType), { key }, mProd); + if(mRef != nullptr) { key = mRef; } + this->addToCreated(info, { key->id() }, mProd); } } @@ -157,7 +158,7 @@ namespace CNORXZ template URange::URange(const Vector& space) : - RangeInterface>(), + RangeInterface,MetaType>(), mSpace(space) { std::sort(mSpace.begin(), mSpace.end(), std::less()); @@ -167,7 +168,7 @@ namespace CNORXZ template URange::URange(Vector&& space) : - RangeInterface>(), + RangeInterface,MetaType>(), mSpace(space) { std::sort(mSpace.begin(), mSpace.end(), std::less()); diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 073f519..bee4f12 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -42,7 +42,7 @@ namespace CNORXZ String stringMeta() const; const MetaType& meta() const; UIndex& at(const MetaType& metaPos); - + /* template auto ifor(SizeT step, Expr ex) const -> For,Expr>; @@ -54,7 +54,7 @@ namespace CNORXZ template auto pifor(SizeT step, Expr ex) const -> PFor,Expr>; - + */ private: Sptr mRangePtr; const MetaType* mMetaPtr; @@ -79,7 +79,7 @@ namespace CNORXZ }; template - class URange : public RangeInterface> + class URange : public RangeInterface,MetaType> { public: typedef RangeBase RB; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 226e192..1a6f6ad 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -13,6 +13,10 @@ namespace CNORXZ template XIndex::XIndex(const IndexPtr& i) : mI(i) {} + template + XIndex::XIndex(const IndexInterface& i) : + mI(std::make_shared(i.THIS())) {} + template XIndex& XIndex::operator=(SizeT pos) { @@ -77,7 +81,7 @@ namespace CNORXZ mI->at(std::any_cast(meta.get())); return *this; } - + /* template DExpr XIndex::ifor(SizeT step, DExpr ex) const { @@ -89,7 +93,7 @@ namespace CNORXZ { return mI->iforh(step, ex); } - + */ } #endif diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 76d8b88..fd9389d 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -24,8 +24,8 @@ namespace CNORXZ virtual String stringMeta() const = 0; virtual DType meta() const = 0; virtual XIndexBase& at(const DType& meta) = 0; - virtual DExpr ifor(SizeT step, DExpr ex) const = 0; - virtual DExpr iforh(SizeT step, DExpr ex) const = 0; + //virtual DExpr ifor(SizeT step, DExpr ex) const = 0; + //virtual DExpr iforh(SizeT step, DExpr ex) const = 0; // ...!!! }; @@ -39,6 +39,7 @@ namespace CNORXZ public: DEFAULT_MEMBERS(XIndex); XIndex(const IndexPtr& i); + XIndex(const IndexInterface& i); virtual XIndex& operator=(SizeT pos) override; virtual XIndex& operator++() override; @@ -50,8 +51,8 @@ namespace CNORXZ virtual String stringMeta() const override; virtual DType meta() const override; virtual XIndexBase& at(const DType& meta) override; - virtual DExpr ifor(SizeT step, DExpr ex) const override; - virtual DExpr iforh(SizeT step, DExpr ex) const override; + //virtual DExpr ifor(SizeT step, DExpr ex) const override; + //virtual DExpr iforh(SizeT step, DExpr ex) const override; // ....!!!! }; diff --git a/src/include/ranges/yindex.h b/src/include/ranges/yindex.h index ba8f6e8..11b362d 100644 --- a/src/include/ranges/yindex.h +++ b/src/include/ranges/yindex.h @@ -10,6 +10,8 @@ namespace CNORXZ { + // YRange!!!! + // Future DynamicIndex //class YIndex : public XIndexBase class YIndex : public IndexInterface diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 59dcfe0..d3b78a8 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,5 +1,7 @@ set(libcnorxz_a_SOURCES + ${CMAKE_SOURCE_DIR}/src/lib/base/to_string.cc + ${CMAKE_SOURCE_DIR}/src/lib/memory/memcount.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/yindex.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/crange.cc diff --git a/src/lib/base/to_string.cc b/src/lib/base/to_string.cc new file mode 100644 index 0000000..8289ffc --- /dev/null +++ b/src/lib/base/to_string.cc @@ -0,0 +1,15 @@ + +#include "base/base.h" + +namespace CNORXZ +{ + String ToString::func(const String& a) + { + return a; + } + + String ToString::func(const DType& a) + { + return a.str(); + } +} diff --git a/src/lib/memory/memcount.cc b/src/lib/memory/memcount.cc new file mode 100644 index 0000000..76a4ba2 --- /dev/null +++ b/src/lib/memory/memcount.cc @@ -0,0 +1,23 @@ + +#include "memory/memcount.h" + +namespace CNORXZ +{ + SizeT MemCount::sMemUsage = 0; + + void MemCount::add(SizeT x) + { + sMemUsage += x; + } + + void MemCount::sub(SizeT x) + { + sMemUsage -= x; + } + + SizeT MemCount::usage() + { + return sMemUsage; + } + +} diff --git a/src/lib/ranges/range_base.cc b/src/lib/ranges/range_base.cc index 21a4436..4e32e0a 100644 --- a/src/lib/ranges/range_base.cc +++ b/src/lib/ranges/range_base.cc @@ -49,9 +49,27 @@ namespace CNORXZ return this != ∈ } - std::intptr_t RangeBase::id() const + PtrId RangeBase::id() const { return reinterpret_cast(this); } + XIndexPtr RangeBase::begin() const + { + return this->index(0); + } + + XIndexPtr RangeBase::end() const + { + return this->index(this->size()); + } + + RangePtr RangeBase::orig() const + { + if(mRel) return mRel; + else return RangePtr(mThis); + } + + RangeBase::RangeBase(const RangePtr& rel) : mRel(rel) {} + } // end namespace CNORXZ diff --git a/src/lib/ranges/yindex.cc b/src/lib/ranges/yindex.cc index 4b808f4..f620def 100644 --- a/src/lib/ranges/yindex.cc +++ b/src/lib/ranges/yindex.cc @@ -1,5 +1,5 @@ -#include "ranges/yindex.h" +#include "ranges/ranges.h" namespace CNORXZ { @@ -20,6 +20,12 @@ namespace CNORXZ // init ...!!! } + YIndex& YIndex::sync() + { + assert(0); + return *this; + } + YIndex& YIndex::operator=(SizeT pos) { IB::mPos = pos; diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index cdb019f..24f48be 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -1,15 +1,22 @@ -add_definitions("-DTEST_NUMBER_FILE=${CMAKE_SOURCE_DIR}/src/tests/numbers.txt") +add_definitions(-DTEST_NUMBER_FILE="${CMAKE_SOURCE_DIR}/src/tests/numbers.txt") set(test_SOURCES ${CMAKE_SOURCE_DIR}/src/tests/test_numbers.cc ) +add_library(test_lib STATIC ${test_SOURCES}) + #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(rutest range_unit_test.cc ${test_SOURCES}) +add_dependencies(rutest cnorxz) +target_link_libraries(rutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) +add_test(NAME rutest COMMAND dautest) + #add_executable(autest ranges/anonymous_unit_test.cc) #add_dependencies(autest cnorxz) #target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) @@ -22,7 +29,7 @@ set(test_SOURCES add_executable(dautest darray_unit_test.cc ${test_SOURCES}) add_dependencies(dautest cnorxz) -target_link_libraries(dautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) +target_link_libraries(dautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz test_lib) add_test(NAME dautest COMMAND dautest) #add_executable(oputest op_unit_test.cc) diff --git a/src/tests/darray_unit_test.cc b/src/tests/darray_unit_test.cc index 27e73b6..f030153 100644 --- a/src/tests/darray_unit_test.cc +++ b/src/tests/darray_unit_test.cc @@ -1,150 +1,42 @@ // -*- C++ -*- #include -#include "gtest/gtest.h" #include +#include "gtest/gtest.h" + #include "cnorxz.h" -namespace MAT = CNORXZ; - namespace { - using namespace MAT; + using namespace CNORXZ; - 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 + class DA_1D_Test : public ::testing::Test { protected: - typedef SingleRangeFactory SRF; - typedef SRF::oType SRange; - - MATest_1Dim() + DA_1D_Test() { - swapFactory(rfbptr, {'x', 'y', 'l', 'f', 'g'} ); - srptr = std::dynamic_pointer_cast( rfbptr->create() ); - + mSize = 7; + mCR1 = CRangeFactory(mSize).create(); } - std::shared_ptr rfbptr; - std::shared_ptr srptr; - vector vv = { 3.141, 2.718, 1.618, 0.693, 0.577 }; + SizeT mSize; + RangePtr mCR1; }; - /* - class MATest_MDim : public ::testing::Test + TEST_F(DA_1D_Test, Basics) { - 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); - */ + DArray a(mCR1); + EXPECT_EQ(a.size(), mSize); } /* - 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) + TEST_F(DA_1D_Test, ReFormat) { swapFactory( rfbptr, { 'a', 'c', 'e', 'g', 'i' } ); std::shared_ptr sr2 = std::dynamic_pointer_cast( rfbptr->create() ); - Array ma(srptr, vv); + Array ma(srptr, vv); auto i = ma.cbegin(); EXPECT_EQ( ma[ i.at('x') ], 3.141); @@ -157,118 +49,6 @@ namespace { 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 diff --git a/src/tests/range_unit_test.cc b/src/tests/range_unit_test.cc new file mode 100644 index 0000000..b7b58df --- /dev/null +++ b/src/tests/range_unit_test.cc @@ -0,0 +1,35 @@ + + +#include +#include + +#include "gtest/gtest.h" + +//#include "cnorxz.h" +#include "ranges/ranges.h" + +namespace { + + using namespace CNORXZ; + + class CR_Test : public ::testing::Test + { + protected: + + CR_Test() + { + mSize = 7; + } + + SizeT mSize; + }; + + TEST_F(CR_Test, Basics) + { + auto cr = CRangeFactory(mSize).create(); + EXPECT_EQ(cr->size(), mSize); + } + + // UR_Test + // RCast_Test +} diff --git a/src/tests/test_numbers.cc b/src/tests/test_numbers.cc index cc535b0..81b1240 100644 --- a/src/tests/test_numbers.cc +++ b/src/tests/test_numbers.cc @@ -5,6 +5,6 @@ namespace CNORXZ { namespace Test { - static Vector Number::sCont; + Vector Numbers::sCont; } } diff --git a/src/tests/test_numbers.h b/src/tests/test_numbers.h index 7bd0b8d..9d7d5ec 100644 --- a/src/tests/test_numbers.h +++ b/src/tests/test_numbers.h @@ -1,11 +1,8 @@ #include -#include "base/types.h" -#include "base/assert.h" - -#ifndef TEST_NUMBER_FILE -#define TEST_NUMBER_FILE "" // CMake Variable -#endif +//#include "base/types.h" +//#include "base/assert.h" +#include "base/base.h" namespace CNORXZ {