wip: dynamic stuff; switched off most of the tests

This commit is contained in:
Christian Zimmermann 2022-09-09 19:41:43 +02:00
parent 5d473ddd8c
commit ebc0f5a807
18 changed files with 1075 additions and 281 deletions

View file

@ -16,11 +16,17 @@ namespace CNORXZInternal
{ {
template <typename T> template <typename T>
struct Allocator class Allocator
{ {
private:
static size_t sMemUsage;
public:
static size_t memUsage() { return sMemUsage; }
typedef T value_type; typedef T value_type;
static constexpr size_t type_size = sizeof(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 struct VX
{ {
@ -35,6 +41,7 @@ namespace CNORXZInternal
T* allocate(size_t n) T* allocate(size_t n)
{ {
const size_t nn = n*type_size; const size_t nn = n*type_size;
sMemUsage += nn;
if(nn >= WARN_SIZE){ if(nn >= WARN_SIZE){
std::cout << __func__ << ": WARNING: allocating " << nn/(MIB_SIZE) << " MiB" << std::endl; std::cout << __func__ << ": WARNING: allocating " << nn/(MIB_SIZE) << " MiB" << std::endl;
} }
@ -47,6 +54,8 @@ namespace CNORXZInternal
void deallocate(T* p, size_t n) void deallocate(T* p, size_t n)
{ {
const size_t nn = n*type_size;
sMemUsage -= nn;
VX* vx = reinterpret_cast<VX*>(p); VX* vx = reinterpret_cast<VX*>(p);
delete [] vx; delete [] vx;
} }
@ -64,11 +73,20 @@ namespace CNORXZInternal
return false; return false;
} }
template <typename T>
size_t Allocator<T>::sMemUsage = 0;
} // namespace CNORXZInternal } // namespace CNORXZInternal
namespace CNORXZ namespace CNORXZ
{ {
template <typename T>
inline size_t memUsage()
{
return CNORXZInternal::Allocator<T>::memUsage();
}
template <typename T> template <typename T>
using vector = std::vector<T,CNORXZInternal::Allocator<T>>; using vector = std::vector<T,CNORXZInternal::Allocator<T>>;

View file

@ -2,16 +2,17 @@
#include "ranges/ranges_header.cc.h" #include "ranges/ranges_header.cc.h"
#include "container_index.cc.h" #include "container_index.cc.h"
#include "dcontainer_index.cc.h"
#include "cxz_operation.cc.h" #include "cxz_operation.cc.h"
#include "functional_array.cc.h" #include "functional_array.cc.h"
#include "helper_tools.cc.h" #include "helper_tools.cc.h"
#include "map_range.cc.h" #include "map_range.cc.h"
#include "cxz_array_base.cc.h" #include "cxz_array_base.cc.h"
#include "cxz_array.cc.h" #include "cxz_array.cc.h"
#include "cxz_darray_base.cc.h"
#include "cxz_darray.cc.h"
#include "slice.cc.h" #include "slice.cc.h"
#include "dynamic_operation.cc.h" #include "dynamic_operation.cc.h"
#include "access.cc.h" #include "access.cc.h"
#include "op_expressions.cc.h" #include "op_expressions.cc.h"
//#include "high_level_operation.cc.h"
//#include "expressions.cc.h"

View file

@ -5,9 +5,12 @@
#include <cstdlib> #include <cstdlib>
#include "container_index.h" #include "container_index.h"
#include "dcontainer_index.h"
#include "cxz_operation.h" #include "cxz_operation.h"
#include "cxz_array_base.h" #include "cxz_array_base.h"
#include "cxz_array.h" #include "cxz_array.h"
#include "cxz_darray_base.h"
#include "cxz_darray.h"
#include "functional_array.h" #include "functional_array.h"
#include "helper_tools.h" #include "helper_tools.h"
#include "operation_def.h" #include "operation_def.h"

View file

@ -0,0 +1,53 @@
#include "cxz_darray.h"
namespace CNORXZ
{
/****************
* DArray *
***************/
template <typename T>
DArray<T>::DArray(const RangePtr& range) : MDArrayBase<T>(range), mCont(range->size()) {}
template <typename T>
DArray<T>::DArray(const RangePtr& range, const vector<T>& vec) :
MDArrayBase<T>(range), mCont(vec) {}
template <typename T>
DArray<T>::DArray(const RangePtr& range, vector<T>&& vec) :
MDArrayBase<T>(range), mCont(vec) {}
template <typename T>
const T* DArray<T>::data() const
{
return mCont.data();
}
template <typename T>
T* DArray<T>::data()
{
return mCont.data();
}
template <typename T>
typename DArray<T>::const_iterator DArray<T>::cbegin() const
{
assert(0);
return const_iterator();
}
template <typename T>
typename DArray<T>::const_iterator DArray<T>::cend() const
{
assert(0);
return const_iterator();
}
template <typename T>
bool DArray<T>::isView() const
{
return false;
}
}

41
src/include/cxz_darray.h Normal file
View file

@ -0,0 +1,41 @@
#ifndef __cxz_darray_h__
#define __cxz_darray_h__
#include "cxz_darray_base.h"
namespace CNORXZ
{
template <typename T>
class DArray : public MDArrayBase<T>
{
public:
typedef DArrayBase<T> AB;
typedef typename AB::const_iterator const_iterator;
using DArrayBase<T>::operator[];
using MDArrayBase<T>::operator[];
private:
vector<T> mCont;
public:
DEFAULT_MEMBERS(DArray);
DArray(const RangePtr& range);
DArray(const RangePtr& range, const vector<T>& vec);
DArray(const RangePtr& range, vector<T>&& 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

View file

@ -8,23 +8,20 @@ namespace CNORXZ
***************/ ***************/
template <typename T> template <typename T>
DArrayBase<T>::DArrayBase(const RangePtr& range) : mRange(range), mInit(true) DArrayBase<T>::DArrayBase(const RangePtr& range) : mRange(range), mInit(true) {}
template <typename T>
template <typename I, typename M>
const T& DArrayBase<T>::operator[](const IndexInterface<I,M>& i) const
{ {
mIt = this->begin(); return *(this->begin()+i);
} }
template <typename T> template <typename T>
template <typename I> template <typename I, typename M>
const value_type& DArrayBase<T>::operator[](const IndexInterface<I>& i) const const T& DArrayBase<T>::at(const IndexInterface<I,M>& i) const
{ {
return *mIt(i); return *this->begin().plus(i);
}
template <typename T>
template <typename I>
const value_type& DArrayBase<T>::at(const IndexInterface<I>& i) const
{
return *mIt.at(i);
} }
template <typename T> template <typename T>
@ -40,26 +37,26 @@ namespace CNORXZ
} }
template <typename T> template <typename T>
DArrayBase<T>::const_iterator DArrayBase<T>::begin() const typename DArrayBase<T>::const_iterator DArrayBase<T>::begin() const
{ {
return this->cbegin(); return this->cbegin();
} }
template <typename T> template <typename T>
DArrayBase<T>::const_iterator DArrayBase<T>::end() const typename DArrayBase<T>::const_iterator DArrayBase<T>::end() const
{ {
return this->cend(); return this->cend();
} }
template <typename T> template <typename T>
virtual bool DArrayBase<T>::isInit() const bool DArrayBase<T>::isInit() const
{ {
return mInit; return mInit;
} }
template <typename T> template <typename T>
template <typename I> template <typename I, typename M>
ConstOperationRoot<T,I> DArrayBase<T>::operator()(const IndexPtr<I>& i) const ConstOperationRoot<T,I> DArrayBase<T>::operator()(const IndexPtr<I,M>& i) const
{ {
return ConstOperationRoot<T,I>(/**/); return ConstOperationRoot<T,I>(/**/);
} }
@ -70,37 +67,37 @@ namespace CNORXZ
****************/ ****************/
template <typename T> template <typename T>
MDArrayBase<T>::MDArrayBase(const RangePtr& range) : DArrayBase(range) {} MDArrayBase<T>::MDArrayBase(const RangePtr& range) : DArrayBase<T>(range) {}
template <typename T> template <typename T>
template <typename I> template <typename I, typename M>
value_type& MDArrayBase<T>::operator[](const IndexInterface<I>& i) T& MDArrayBase<T>::operator[](const IndexInterface<I,M>& i)
{ {
return *mIt(i); return *(this->begin()+i);
} }
template <typename T> template <typename T>
template <typename I> template <typename I, typename M>
value_type& MDArrayBase<T>::at(const IndexInterface<I>& i) T& MDArrayBase<T>::at(const IndexInterface<I,M>& i)
{ {
return *mIt.at(i); return *this->begin().plus(i);
} }
template <typename T> template <typename T>
MDArrayBase<T>::iterator MDArrayBase<T>::begin() typename MDArrayBase<T>::iterator MDArrayBase<T>::begin()
{ {
return iterator(this->data(), this->cbegin()); return iterator(this->data(), this->cbegin());
} }
template <typename T> template <typename T>
MDArrayBase<T>::iterator MDArrayBase<T>::end() typename MDArrayBase<T>::iterator MDArrayBase<T>::end()
{ {
return iterator(this->data(), this->cend()); return iterator(this->data(), this->cend());
} }
template <typename T> template <typename T>
template <typename I> template <typename I, typename M>
OperationRoot<T,I> MDArrayBase<T>::operator()(const IndexPtr<I>& i) OperationRoot<T,I> MDArrayBase<T>::operator()(const IndexPtr<I,M>& i)
{ {
return OperationRoot<T,I>(/**/); return OperationRoot<T,I>(/**/);
} }

View file

@ -18,12 +18,10 @@ namespace CNORXZ
class DArrayBase class DArrayBase
{ {
public: public:
typedef T value_type; typedef DConstContainerIndex<T> const_iterator;
typedef DConstContainerIndex<value_type> const_iterator;
protected: protected:
RangePtr mRange; RangePtr mRange;
const_iterator mIt;
bool mInit = false; bool mInit = false;
public: public:
@ -33,14 +31,14 @@ namespace CNORXZ
virtual ~DArrayBase() = default; virtual ~DArrayBase() = default;
template <typename I> template <typename I, typename M>
const value_type& operator[](const IndexInterface<I>& i) const; const T& operator[](const IndexInterface<I,M>& i) const;
template <typename I> template <typename I, typename M>
const value_type& at(const IndexInterface<I>& i) const; const T& at(const IndexInterface<I,M>& i) const;
template <typename I> template <typename I, typename M>
DArrayBase sl(const IndexInterface<I>& i) const; DArrayBase sl(const IndexInterface<I,M>& i) const;
virtual const T* data() const = 0; virtual const T* data() const = 0;
virtual size_t size() const; virtual size_t size() const;
@ -54,8 +52,8 @@ namespace CNORXZ
virtual bool isView() const = 0; virtual bool isView() const = 0;
virtual bool isInit() const; virtual bool isInit() const;
template <typename I> template <typename I, typename M>
ConstOperationRoot<T,I> operator()(const IndexPtr<I>& i) const; ConstOperationRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
}; };
template <typename T> template <typename T>
@ -63,9 +61,8 @@ namespace CNORXZ
{ {
public: public:
typedef DArrayBase<T> DAB; typedef DArrayBase<T> DAB;
typedef DAB::value_type value_type; typedef typename DAB::const_iterator const_iterator;
typedef DAB::const_iterator const_iterator; typedef DContainerIndex<T> iterator;
typedef DContainerIndex<value_type> iterator;
using DAB::operator[]; using DAB::operator[];
using DAB::at; using DAB::at;
@ -79,22 +76,22 @@ namespace CNORXZ
MDArrayBase(const RangePtr& range); MDArrayBase(const RangePtr& range);
DEFAULT_MEMBERS(MDArrayBase); DEFAULT_MEMBERS(MDArrayBase);
template <typename I> template <typename I, typename M>
value_type& operator[](const IndexInterface<I>& i); T& operator[](const IndexInterface<I,M>& i);
template <typename I> template <typename I, typename M>
value_type& at(const IndexInterface<I>& i); T& at(const IndexInterface<I,M>& i);
template <typename I> template <typename I, typename M>
DArrayBase sl(const IndexInterface<I>& i); std::shared_ptr<DArrayBase<T>> sl(const IndexInterface<I,M>& i);
virtual T* data() = 0; virtual T* data() = 0;
virtual iterator begin(); virtual iterator begin();
virtual iterator end(); virtual iterator end();
template <typename I> template <typename I, typename M>
OperationRoot<T,I> operator()(const IndexPtr<I>& i); OperationRoot<T,I> operator()(const IndexPtr<I,M>& i);
}; };
} }

View file

@ -0,0 +1,211 @@
#include "dcontainer_index.h"
namespace CNORXZ
{
/**************
* XIndex *
**************/
template <class Index, typename Meta>
XIndex<Index,Meta>::XIndex(const IndexPtr<Index,Meta>& i) : mI(i) {}
template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator=(size_t pos)
{
*mI = pos;
return *this;
}
template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator++()
{
++(*mI);
return *this;
}
template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator--()
{
--(*mI);
return *this;
}
template <class Index, typename Meta>
int XIndex<Index,Meta>::pp(std::intptr_t idxPtrNum)
{
return mI->pp(idxPtrNum);
}
template <class Index, typename Meta>
int XIndex<Index,Meta>::mm(std::intptr_t idxPtrNum)
{
return mI->mm(idxPtrNum);
}
template <class Index, typename Meta>
size_t XIndex<Index,Meta>::dim() const
{
return mI->dim();
}
template <class Index, typename Meta>
size_t XIndex<Index,Meta>::getStepSize(size_t n) const
{
return mI->getStepSize(n);
}
template <class Index, typename Meta>
std::string XIndex<Index,Meta>::stringMeta() const
{
return mI->stringMeta();
}
template <class Index, typename Meta>
DType XIndex<Index,Meta>::meta() const
{
return DType(mI->meta());
}
template <class Index, typename Meta>
XIndexBase& XIndex<Index,Meta>::at(const DType& meta)
{
// check!!!
mI->at(std::any_cast<const Meta&>(meta.get()));
return *this;
}
template <class Index, typename Meta>
DynamicExpression XIndex<Index,Meta>::ifor(size_t step, DynamicExpression ex) const
{
return mI->ifor(step, ex);
}
template <class Index, typename Meta>
DynamicExpression XIndex<Index,Meta>::iforh(size_t step, DynamicExpression ex) const
{
return mI->iforh(step, ex);
}
template <typename T>
DConstContainerIndex<T>::DConstContainerIndex(const T* data, const RangePtr& range):
mI(range->beginX()), mCData(data)
{
assert(0);
}
template <typename T>
DConstContainerIndex<T>& DConstContainerIndex<T>::operator=(size_t pos)
{
(*mI) = pos;
IB::mPos = mI->pos();
return *this;
}
template <typename T>
DConstContainerIndex<T>& DConstContainerIndex<T>::operator++()
{
++(*mI);
IB::mPos = mI->pos();
return *this;
}
template <typename T>
DConstContainerIndex<T>& DConstContainerIndex<T>::operator--()
{
--(*mI);
IB::mPos = mI->pos();
return *this;
}
template <typename T>
int DConstContainerIndex<T>::pp(std::intptr_t idxPtrNum)
{
return mI->pp(idxPtrNum);
}
template <typename T>
int DConstContainerIndex<T>::mm(std::intptr_t idxPtrNum)
{
return mI->mm(idxPtrNum);
}
template <typename T>
size_t DConstContainerIndex<T>::dim() const
{
return mI->dim();
}
template <typename T>
size_t DConstContainerIndex<T>::getStepSize(size_t n) const
{
return mI->getStepSize(n); // dim() elements only!!!
}
template <typename T>
std::string DConstContainerIndex<T>::stringMeta() const
{
return mI->stringMeta();
}
template <typename T>
DType DConstContainerIndex<T>::meta() const
{
return mI->meta();
}
template <typename T>
DConstContainerIndex<T>& DConstContainerIndex<T>::at(const DType& meta)
{
mI->at(meta);
IB::mPos = mI->pos();
return *this;
}
template <typename T>
DynamicExpression DConstContainerIndex<T>::ifor(size_t step, DynamicExpression ex) const
{
return mI->ifor(step, ex);
}
template <typename T>
DynamicExpression DConstContainerIndex<T>::iforh(size_t step, DynamicExpression ex) const
{
return mI->iforh(step, ex);
}
template <typename T>
const T& DConstContainerIndex<T>::operator*() const
{
//this->sync();
return mCData[mI->pos()];
}
template <typename T>
const T* DConstContainerIndex<T>::operator->() const
{
//this->sync();
return mCData+mI->pos();
}
template <typename T>
DContainerIndex<T>::DContainerIndex(T* data, const RangePtr& range) :
DConstContainerIndex<T>(range), mData(data) {}
template <typename T>
DContainerIndex<T>::DContainerIndex(T* data, const DConstContainerIndex<T>& cci) :
DConstContainerIndex<T>(data, cci.range()), mData(data) {}
template <typename T>
T& DContainerIndex<T>::operator*()
{
return mData[CCI::mI->pos()];
}
template <typename T>
T* DContainerIndex<T>::operator->()
{
return mData+CCI::mI->pos();
}
}

View file

@ -11,47 +11,171 @@
#include "mbase_def.h" #include "mbase_def.h"
#include "statics/static_for.h" #include "statics/static_for.h"
#include "ranges/range_helper.h" #include "ranges/range_helper.h"
#include "ranges/dynamic_meta.h"
#include "xfor/xfor.h"
namespace CNORXZ namespace CNORXZ
{ {
// Future DynamicIndex namespace
{
using namespace CNORXZInternal;
}
// Future IndexWrapper
class XIndexBase : public IndexInterface<XIndexBase,DType> class XIndexBase : public IndexInterface<XIndexBase,DType>
{ {
public: public:
DEFAULT_MEMBERS(XIndexBase); 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<XIndexBase> XIndexPtr; typedef std::shared_ptr<XIndexBase> XIndexPtr;
// MultiIndex Wrapper: // MultiIndex Wrapper:
template <class... Indices> template <class Index, typename Meta>
class XIndex class XIndex : public XIndexBase
{ {
private: private:
std::shared_ptr<MultiIndex<Indices...>> mI; IndexPtr<Index,Meta> mI;
public: public:
DEFAULT_MEMBERS(XIndex); DEFAULT_MEMBERS(XIndex);
XIndex(const std::shared_ptr<MultiIndex<Indices...>>& i); XIndex(const IndexPtr<Index,Meta>& 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<YIndex,DType>
class YIndex : public XIndexBase
{
public:
typedef IndexInterface<YIndex,DType> IB;
private:
vector<XIndexPtr> mIs;
RangePtr mRange;
std::vector<size_t> 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<XIndexPtr>& 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<YIndex> YIndexPtr;
template <typename T> template <typename T>
class DConstContainerIndex : public IndexInterface<DConstContainerIndex<T>,DType> class DConstContainerIndex : public IndexInterface<DConstContainerIndex<T>,DType>
{ {
public:
typedef IndexInterface<DConstContainerIndex<T>,DType> IB;
protected: protected:
XIndexPtr mI; YIndexPtr mI;
const T* mCData = nullptr; 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 <class I, typename M> // fast but unsave
DConstContainerIndex operator+(const IndexInterface<I,M>& i);
template <class I, typename M> // fast but unsave
DConstContainerIndex operator-(const IndexInterface<I,M>& i);
template <class I, typename M> // save version of operator+
DConstContainerIndex plus(const IndexInterface<I,M>& i);
template <class I, typename M> // save version of operator-
DConstContainerIndex minus(const IndexInterface<I,M>& 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<XIndexPtr>& inds); // control via external indice
DConstContainerIndex& operator()(); // -> sync; just to shorten the code
}; };
template <typename T> template <typename T>
class MDConstContainerIndex : public DConstContainerIndex<T> class DContainerIndex : public DConstContainerIndex<T>
{ {
public:
typedef DConstContainerIndex<T> CCI;
typedef typename CCI::IB IB;
private: private:
T* mData = nullptr; T* mData = nullptr;
public:
DEFAULT_MEMBERS(DContainerIndex);
DContainerIndex(T* data, const RangePtr& range);
DContainerIndex(T* data, const DConstContainerIndex<T>& cci);
T& operator*();
T* operator->();
}; };
} }

View file

@ -0,0 +1,94 @@
#include <sstream>
#include "dynamic_meta.h"
namespace CNORXZ
{
template <typename T>
std::string toString(const T& a)
{
std::stringstream ss;
ss << a;
return ss.str();
}
template <typename T>
std::string toString<vector<T>>(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 <typename T, size_t N>
std::string toString<std::array<T,N>>(const std::array<T,N>& 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<DType> !!!
// (yes DType is slow, thats why one should only use it for debugging)
template <>
std::string toString<DType>(const DType& a)
{
return a.str();
}
template <typename T>
DType::DType(const T& d) : mD(d)
{
_mkToStr();
}
template <typename T>
DType& DType::operator=(const T& d)
{
mD = d;
_mkToStr();
return *this;
}
template <typename T>
void DType::_mkToStr()
{
mToStr = [&](){
return toString(std::any_cast<T>(mD));
};
}
template <typename T>
void DType::_mkComp()
{
mComp = [&](const std::any& a){
if(mD.type() != a.type()){
return 2;
}
else {
auto& at = std::any_cast<const T&>(a);
auto& dt = std::any_cast<const T&>(mD);
if(std::equal_to(dt,at)){
return 0;
}
else if(std::less(dt,at)){
return -1;
}
else {
return 1;
}
}
};
}
}

View file

@ -5,6 +5,8 @@
#include <cstdlib> #include <cstdlib>
#include <utility> #include <utility>
#include <memory> #include <memory>
#include <any>
#include <functional>
#include "allocator.h" #include "allocator.h"
#include "rbase_def.h" #include "rbase_def.h"
@ -69,94 +71,39 @@ namespace CNORXZ
const DynamicMetaElem& operator[](size_t pos) const; const DynamicMetaElem& operator[](size_t pos) const;
}; };
// NEW:
// Type Eraser:
class DType class DType
{ {
private:
std::any mD;
std::function<std::string()> mToStr;
std::function<int(std::any)> mComp;
template <typename T>
void _mkToStr();
template <typename T>
void _mkComp();
public: public:
DEFAULT_MEMBERS(DType); 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<DType> operator[](size_t pos) const = 0;
};
// NEW:
template <typename T> template <typename T>
class TypeWrapper : public DType DType(const T& d);
{
private:
T mD;
public:
TypeWrapper(const T& d) : mD(d) {}
DEFAULT_MEMBERS(TypeWrapper);
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<DType> operator[](size_t pos) const { return nullptr; }
};
// NEW:
template <typename T> template <typename T>
class TypeRefWrapper : public DType DType& operator=(const T& d);
{
private:
const T* mD;
public: std::string str() const { return mToStr(); }
TypeRefWrapper(const T* d) : mD(d) {} const std::any& get() const { return mD; }
DEFAULT_MEMBERS(TypeRefWrapper);
virtual std::string str() const { return to_string(*mD); /*wrapper*/ } bool operator==(const DType& a) const { return mComp(a.mD) == 0; }
virtual bool operator==(const DType& in) const { return this->str() == in.str(); } bool operator!=(const DType& a) const { return mComp(a.mD) != 0; }
virtual bool operator!=(const DType& in) const { return this->str() != in.str(); } bool operator<(const DType& a) const { return mComp(a.mD) == -1; }
virtual size_t size() const { return 1; } bool operator>(const DType& a) const { return mComp(a.mD) == 1; }
virtual std::shared_ptr<DType> operator[](size_t pos) const { return nullptr; } 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 <typename T>
class TypeWrapper<std::vector<T>> : public DType
{
private:
std::vector<T> mD;
public:
TypeWrapper(const std::vector<T>& 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<DType> operator[](size_t pos) const { return std::make_shared<TypeRefWrapper>(&mD[pos]); }
};
// NEW:
template <typename T>
class TypeRefWrapper<std::vector<T>> : public DType
{
private:
const std::vector<T>* mD;
public:
TypeRefWrapper(const std::vector<T>* 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<DType> operator[](size_t pos) const { return std::make_shared<TypeRefWrapper>(&(*mD)[pos]); }
};
// SPECIALIZE: for std::array<T,N> and std::tuple<T...>
} // namespace CNORXZ } // namespace CNORXZ
#endif #endif

View file

@ -27,8 +27,6 @@ namespace CNORXZ
I& THIS() { return static_cast<I&>(*this); } I& THIS() { return static_cast<I&>(*this); }
I const& THIS() const { return static_cast<I const&>(*this); } I const& THIS() const { return static_cast<I const&>(*this); }
static constexpr bool ISINDEX = true;
~IndexInterface() = default; ~IndexInterface() = default;
constexpr IndexType type() const { return THIS().type(); } constexpr IndexType type() const { return THIS().type(); }
@ -50,16 +48,12 @@ namespace CNORXZ
bool last() const { return THIS().last(); } bool last() const { return THIS().last(); }
bool first() const { return THIS().first(); } bool first() const { return THIS().first(); }
std::shared_ptr<RangeBase> range() const { return mRangePtr; }
std::shared_ptr<RangeBase> vrange() const { return mRangePtr; }
size_t getStepSize(size_t n) const { return THIS().getStepSize(n); } size_t getStepSize(size_t n) const { return THIS().getStepSize(n); }
operator size_t() const;
std::string stringMeta() const { return THIS().stringMeta(); } std::string stringMeta() const { return THIS().stringMeta(); }
MetaType meta() const { return THIS().meta(); } MetaType meta() const { return THIS().meta(); }
MetaType metaPtr() const { return THIS().metaPtr(); }
I& at(const MetaType& meta) { return THIS().at(meta); } I& at(const MetaType& meta) { return THIS().at(meta); }
// CHECK / IMPLEMENT !!!!!! // CHECK / IMPLEMENT !!!!!!
@ -188,12 +182,6 @@ namespace CNORXZ
return mMax; return mMax;
} }
template <class I, typename MetaType>
IndexInterface<I,MetaType>::operator size_t() const
{
return pos();
}
template <class I, typename MetaType> template <class I, typename MetaType>
std::intptr_t IndexInterface<I,MetaType>::ptrNum() const std::intptr_t IndexInterface<I,MetaType>::ptrNum() const
{ {

View file

@ -69,8 +69,6 @@ namespace CNORXZ
{ {
public: public:
static constexpr bool ISINDEX = false;
virtual ~RangeBase() = default; virtual ~RangeBase() = default;
virtual size_t size() const = 0; virtual size_t size() const = 0;
@ -81,6 +79,9 @@ namespace CNORXZ
std::intptr_t id() const; std::intptr_t id() const;
XIndexPtr beginX() const;
XIndexPtr endX() const;
virtual vector<size_t> typeNum() const = 0; virtual vector<size_t> typeNum() const = 0;
virtual size_t cmeta(char* target, size_t pos) const = 0; virtual size_t cmeta(char* target, size_t pos) const = 0;
virtual size_t cmetaSize() const = 0; virtual size_t cmetaSize() const = 0;

View file

@ -34,8 +34,6 @@ namespace CNORXZ
typedef GenSingleRange<U,TYPE,S> RangeType; typedef GenSingleRange<U,TYPE,S> RangeType;
typedef GenSingleIndex IType; typedef GenSingleIndex IType;
//DEFAULT_MEMBERS_X(GenSingleIndex);
GenSingleIndex(const std::shared_ptr<GenSingleRange<U,TYPE,S> >& range); GenSingleIndex(const std::shared_ptr<GenSingleRange<U,TYPE,S> >& range);
static constexpr IndexType sType() { return IndexType::SINGLE; } static constexpr IndexType sType() { return IndexType::SINGLE; }
@ -117,7 +115,6 @@ namespace CNORXZ
MetaMap& operator=(const MetaMap& in) = default; MetaMap& operator=(const MetaMap& in) = default;
MetaMap& operator=(MetaMap&& in) = default; MetaMap& operator=(MetaMap&& in) = default;
//MetaMap(const std::map<U,size_t>& in) : mMap(in) {}
MetaMap(const vector<U>& in) MetaMap(const vector<U>& in)
{ {
for(size_t i = 0; i != in.size(); ++i){ 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); } size_t count(const U& in) const { return mMap.count(in); }
}; };
/*
template <>
class MetaMap<std::array<int,2> >
{
private:
vector<size_t> mMap;
int min1;
int min2;
int max1;
int max2;
size_t s1;
size_t s2;
public:
typedef std::array<int,2> 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<U>& 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<size_t>( -1 ) );
return mMap[ mpos ];
}
};
*/
template <size_t S> template <size_t S>
struct CheckStatic struct CheckStatic
{ {
@ -263,7 +209,6 @@ namespace CNORXZ
typedef GenSingleRange RangeType; typedef GenSingleRange RangeType;
typedef U MetaType; typedef U MetaType;
typedef GenSingleRangeFactory<U,TYPE,S> FType; typedef GenSingleRangeFactory<U,TYPE,S> FType;
//typedef typename RangeInterface<GenSingleIndex<U,TYPE,S> >::IndexType IndexType;
virtual size_t size() const final; virtual size_t size() const final;
virtual size_t dim() const final; virtual size_t dim() const final;
@ -308,7 +253,6 @@ namespace CNORXZ
GenSingleRange(vector<U>&& space); GenSingleRange(vector<U>&& space);
vector<U> mSpace; vector<U> mSpace;
//std::map<U,size_t> mMSpace;
MetaMap<U> mMSpace; MetaMap<U> mMSpace;
}; };
@ -490,7 +434,6 @@ namespace CNORXZ
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
-> For<GenSingleIndex<U,TYPE,S>,Expr> -> For<GenSingleIndex<U,TYPE,S>,Expr>
{ {
//static const size_t LAYER = typename Expr::LAYER;
return For<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex); return For<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex);
} }
@ -499,7 +442,6 @@ namespace CNORXZ
auto GenSingleIndex<U,TYPE,S>::iforh(size_t step, Expr ex) const auto GenSingleIndex<U,TYPE,S>::iforh(size_t step, Expr ex) const
-> For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN> -> For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>
{ {
//static const size_t LAYER = typename Expr::LAYER;
return For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>(this, step, ex); return For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>(this, step, ex);
} }
@ -508,7 +450,6 @@ namespace CNORXZ
auto GenSingleIndex<U,TYPE,S>::pifor(size_t step, Expr ex) const auto GenSingleIndex<U,TYPE,S>::pifor(size_t step, Expr ex) const
-> PFor<GenSingleIndex<U,TYPE,S>,Expr> -> PFor<GenSingleIndex<U,TYPE,S>,Expr>
{ {
//static const size_t LAYER = typename Expr::LAYER;
return PFor<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex); return PFor<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex);
} }
@ -613,8 +554,6 @@ namespace CNORXZ
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::cmeta(char* target, size_t pos) const size_t GenSingleRange<U,TYPE,S>::cmeta(char* target, size_t pos) const
{ {
//*reinterpret_cast<U*>(target) = mSpace[pos];
//return sizeof(U);
return ToCMeta<U>::apply(target, mSpace[pos]); return ToCMeta<U>::apply(target, mSpace[pos]);
} }
@ -639,8 +578,6 @@ namespace CNORXZ
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
stringCat(out, mSpace); stringCat(out, mSpace);
//const char* scp = reinterpret_cast<const char*>(mSpace.data());
//out.insert(out.end(), scp, scp + h.metaSize);
return out; return out;
} }

View file

@ -1,6 +1,6 @@
execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh #execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ ) # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ )
set(libcnorxz_a_SOURCES set(libcnorxz_a_SOURCES
${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc ${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 ${CMAKE_SOURCE_DIR}/src/lib/map_range_factory_product_map.cc
) )
set(libhlcnorxz_a_SOURCES #set(libhlcnorxz_a_SOURCES
${CMAKE_SOURCE_DIR}/src/lib/high_level_operation.cc # ${CMAKE_SOURCE_DIR}/src/lib/high_level_operation.cc
) # )
#message(WARNING ${libhlcnorxz_a_SOURCES}) #message(WARNING ${libhlcnorxz_a_SOURCES})
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc") file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")
@ -23,20 +23,20 @@ foreach(ccfile ${cc_files})
${ccfile}) ${ccfile})
endforeach(ccfile) endforeach(ccfile)
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc") #file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc")
foreach(ccfile ${cc_files}) #foreach(ccfile ${cc_files})
set(libhlcnorxz_a_SOURCES ${libhlcnorxz_a_SOURCES} # set(libhlcnorxz_a_SOURCES ${libhlcnorxz_a_SOURCES}
${ccfile}) # ${ccfile})
endforeach(ccfile) #endforeach(ccfile)
add_library(cnorxz_obj OBJECT add_library(cnorxz_obj OBJECT
${libcnorxz_a_SOURCES} ${libcnorxz_a_SOURCES}
) )
add_library(hlcnorxz_obj OBJECT #add_library(hlcnorxz_obj OBJECT
${libhlcnorxz_a_SOURCES} # ${libhlcnorxz_a_SOURCES}
) # )
set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) 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 add_library(cnorxz SHARED
$<TARGET_OBJECTS:cnorxz_obj> $<TARGET_OBJECTS:cnorxz_obj>
@ -48,15 +48,15 @@ add_library(cnorxz_static
) )
set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_library(hlcnorxz SHARED #add_library(hlcnorxz SHARED
$<TARGET_OBJECTS:hlcnorxz_obj> # $<TARGET_OBJECTS:hlcnorxz_obj>
) # )
set_target_properties(hlcnorxz PROPERTIES POSITION_INDEPENDENT_CODE TRUE) #set_target_properties(hlcnorxz PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
add_library(hlcnorxz_static #add_library(hlcnorxz_static
$<TARGET_OBJECTS:hlcnorxz_obj> # $<TARGET_OBJECTS:hlcnorxz_obj>
) # )
set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE) #set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
install(TARGETS cnorxz install(TARGETS cnorxz
ARCHIVE DESTINATION ${INSTALL_PATH}/lib ARCHIVE DESTINATION ${INSTALL_PATH}/lib
@ -66,10 +66,10 @@ install(TARGETS cnorxz_static
ARCHIVE DESTINATION ${INSTALL_PATH}/lib ARCHIVE DESTINATION ${INSTALL_PATH}/lib
LIBRARY DESTINATION ${INSTALL_PATH}/lib) LIBRARY DESTINATION ${INSTALL_PATH}/lib)
install(TARGETS hlcnorxz #install(TARGETS hlcnorxz
ARCHIVE DESTINATION ${INSTALL_PATH}/lib # ARCHIVE DESTINATION ${INSTALL_PATH}/lib
LIBRARY DESTINATION ${INSTALL_PATH}/lib) # LIBRARY DESTINATION ${INSTALL_PATH}/lib)
install(TARGETS hlcnorxz_static #install(TARGETS hlcnorxz_static
ARCHIVE DESTINATION ${INSTALL_PATH}/lib # ARCHIVE DESTINATION ${INSTALL_PATH}/lib
LIBRARY DESTINATION ${INSTALL_PATH}/lib) # LIBRARY DESTINATION ${INSTALL_PATH}/lib)

100
src/lib/dcontainer_index.cc Normal file
View file

@ -0,0 +1,100 @@
#include "dcontainer_index.h"
namespace CNORXZ
{
YIndex::YIndex(const RangePtr& range) :
IndexInterface<YIndex,DType>(range, 0)
{
//...!!!
}
YIndex::YIndex(const RangePtr& range, const std::vector<XIndexPtr>& is) :
IndexInterface<YIndex,DType>(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<DType> 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<const vector<DType>&>(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

View file

@ -1,41 +1,44 @@
#add_executable(iutest /ranges/index_unit_test.cc ${INDEX_CC_FILES}) #add_executable(iutest ranges/index_unit_test.cc)
add_executable(iutest ranges/index_unit_test.cc) #add_dependencies(iutest cnorxz)
add_dependencies(iutest cnorxz) #target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) #add_test(NAME iutest COMMAND iutest)
add_test(NAME iutest COMMAND iutest)
add_executable(autest ranges/anonymous_unit_test.cc) #add_executable(autest ranges/anonymous_unit_test.cc)
add_dependencies(autest cnorxz) #add_dependencies(autest cnorxz)
target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) #target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
add_test(NAME autest COMMAND autest) #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_executable(mautest array_unit_test.cc) #add_dependencies(mautest cnorxz)
add_dependencies(mautest cnorxz) #target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) #add_test(NAME mautest COMMAND mautest)
add_test(NAME mautest COMMAND mautest)
add_executable(oputest op_unit_test.cc) add_executable(dautest darray_unit_test.cc)
add_dependencies(oputest cnorxz) add_dependencies(dautest cnorxz)
target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) target_link_libraries(dautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
add_test(NAME oputest COMMAND oputest) add_test(NAME dautest COMMAND dautest)
add_executable(op2utest op2_unit_test.cc) #add_executable(oputest op_unit_test.cc)
add_dependencies(op2utest cnorxz) #add_dependencies(oputest cnorxz)
target_link_libraries(op2utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) #target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
add_test(NAME op2utest COMMAND op2utest) #add_test(NAME oputest COMMAND oputest)
add_executable(op3utest op3_unit_test.cc) #add_executable(op2utest op2_unit_test.cc)
add_dependencies(op3utest cnorxz) #add_dependencies(op2utest cnorxz)
target_link_libraries(op3utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz) #target_link_libraries(op2utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
add_test(NAME op3utest COMMAND op3utest) #add_test(NAME op2utest COMMAND op2utest)
add_executable(op4utest op4_unit_test.cc) #add_executable(op3utest op3_unit_test.cc)
add_dependencies(op4utest cnorxz hlcnorxz) #add_dependencies(op3utest cnorxz)
target_link_libraries(op4utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz hlcnorxz) #target_link_libraries(op3utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
add_test(NAME op4utest COMMAND op4utest) #add_test(NAME op3utest COMMAND op3utest)
add_executable(opptest op_perf_test.cc) #add_executable(op4utest op4_unit_test.cc)
add_dependencies(opptest cnorxz) #add_dependencies(op4utest cnorxz hlcnorxz)
target_link_libraries(opptest cnorxz) #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)

View file

@ -0,0 +1,279 @@
// -*- C++ -*-
#include <cstdlib>
#include "gtest/gtest.h"
#include <iostream>
#include "cnorxz.h"
namespace MAT = CNORXZ;
namespace {
using namespace MAT;
template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{
vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr;
}
template <class Factory, class... Rs>
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
{
auto nptr = std::make_shared<Factory>( rs... );
fptr = nptr;
}
template <typename... Ts>
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
{
return std::make_tuple(ts...);
}
class MATest_1Dim : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
MATest_1Dim()
{
swapFactory<SRF>(rfbptr, {'x', 'y', 'l', 'f', 'g'} );
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> srptr;
vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
};
/*
class MATest_MDim : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
typedef MultiRangeFactory<SRange,SRange> MRF;
typedef MRF::oType MRange;
MATest_MDim()
{
swapFactory<SRF>(rfbptr, {'x', 'y'} );
sr1ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
sr2ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(rfbptr, {'1', '2', '3'} );
sr3ptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
swapFactory<SRF>(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<SRange>( rfbptr->create() );
swapMFactory<MRF>(rfbptr, sr1ptr, sr2ptr);
mrptr = std::dynamic_pointer_cast<MRange>( rfbptr->create() );
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<SRange> sr3ptr;
std::shared_ptr<SRange> sr4ptr;
std::shared_ptr<MRange> mrptr;
vector<double> 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<double> a(srptr, vv);
Array<double,MATest_1Dim::SRange> 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<double> v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 };
Array<double,MATest_1Dim::SRange> 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<SRF>( rfbptr, { 'a', 'c', 'e', 'g', 'i' } );
std::shared_ptr<SRange> sr2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
Array<double,MATest_1Dim::SRange> 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<double,MATest_MDim::MRange,MATest_MDim::SRange> 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<double,MATest_MDim::MRange,MATest_MDim::SRange> 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<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
Slice<double,MATest_MDim::SRange> 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<double,SRange> 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<double,SRange,SRange,SRange> 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();
}