further compile fixes

This commit is contained in:
Christian Zimmermann 2022-09-15 16:45:45 +02:00
parent 0dcf7d3b5a
commit 9543342db4
32 changed files with 267 additions and 371 deletions

View file

@ -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<T>::DArray(const RangePtr& range) : MDArrayBase<T>(range), mCont(range->size()) {}
template <typename T>
DArray<T>::DArray(const RangePtr& range, const vector<T>& vec) :
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) :
DArray<T>::DArray(const RangePtr& range, Vector<T>&& vec) :
MDArrayBase<T>(range), mCont(vec) {}
template <typename T>
@ -51,3 +54,5 @@ namespace CNORXZ
}
}
#endif

View file

@ -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<T>::operator[];
private:
vector<T> mCont;
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);
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;

View file

@ -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 <typename T>
template <typename I, typename M>
ConstOperationRoot<T,I> DArrayBase<T>::operator()(const IndexPtr<I,M>& i) const
{
return ConstOperationRoot<T,I>(/**/);
return ConstOperationRoot<T,I>();
}
*/
/*****************
* MDArrayBase *
@ -95,11 +98,14 @@ namespace CNORXZ
return iterator(this->data(), this->cend());
}
/*
template <typename T>
template <typename I, typename M>
OperationRoot<T,I> MDArrayBase<T>::operator()(const IndexPtr<I,M>& i)
{
return OperationRoot<T,I>(/**/);
return OperationRoot<T,I>();
}
*/
}
#endif

View file

@ -7,10 +7,9 @@
#include <memory>
#include <algorithm>
#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 <typename I, typename M>
ConstOperationRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
//template <typename I, typename M>
//ConstOperationRoot<T,I> operator()(const IndexPtr<I,M>& i) const;
};
template <typename T>
@ -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);
@ -90,8 +89,8 @@ namespace CNORXZ
virtual iterator begin();
virtual iterator end();
template <typename I, typename M>
OperationRoot<T,I> operator()(const IndexPtr<I,M>& i);
//template <typename I, typename M>
//OperationRoot<T,I> operator()(const IndexPtr<I,M>& i);
};
}

View file

@ -3,19 +3,20 @@
#define __cxz_dcontainer_index_cc_h__
#include "dcontainer_index.h"
#include "statics/static_for.h"
namespace CNORXZ
{
template <typename T>
DConstContainerIndex<T>::DConstContainerIndex(const T* data, const RangePtr& range):
mI(range->beginX()), mCData(data)
mI(range->begin()), mCData(data)
{
assert(0);
}
template <typename T>
DConstContainerIndex<T>& DConstContainerIndex<T>::operator=(size_t pos)
DConstContainerIndex<T>& DConstContainerIndex<T>::operator=(SizeT pos)
{
(*mI) = pos;
IB::mPos = mI->pos();
@ -39,31 +40,31 @@ namespace CNORXZ
}
template <typename T>
int DConstContainerIndex<T>::pp(std::intptr_t idxPtrNum)
int DConstContainerIndex<T>::pp(PtrId idxPtrNum)
{
return mI->pp(idxPtrNum);
}
template <typename T>
int DConstContainerIndex<T>::mm(std::intptr_t idxPtrNum)
int DConstContainerIndex<T>::mm(PtrId idxPtrNum)
{
return mI->mm(idxPtrNum);
}
template <typename T>
size_t DConstContainerIndex<T>::dim() const
SizeT DConstContainerIndex<T>::dim() const
{
return mI->dim();
}
template <typename T>
size_t DConstContainerIndex<T>::getStepSize(size_t n) const
SizeT DConstContainerIndex<T>::getStepSize(SizeT n) const
{
return mI->getStepSize(n); // dim() elements only!!!
}
template <typename T>
std::string DConstContainerIndex<T>::stringMeta() const
String DConstContainerIndex<T>::stringMeta() const
{
return mI->stringMeta();
}
@ -81,19 +82,19 @@ namespace CNORXZ
IB::mPos = mI->pos();
return *this;
}
/*
template <typename T>
DynamicExpression DConstContainerIndex<T>::ifor(size_t step, DynamicExpression ex) const
DExpr DConstContainerIndex<T>::ifor(SizeT step, DExpr ex) const
{
return mI->ifor(step, ex);
}
template <typename T>
DynamicExpression DConstContainerIndex<T>::iforh(size_t step, DynamicExpression ex) const
DExpr DConstContainerIndex<T>::iforh(SizeT step, DExpr ex) const
{
return mI->iforh(step, ex);
}
*/
template <typename T>
const T& DConstContainerIndex<T>::operator*() const
{

View file

@ -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 <typename T>
class DConstContainerIndex : public IndexInterface<DConstContainerIndex<T>,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 <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;
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;

View file

@ -1,3 +1,4 @@
#include "dtype.cc.h"
#include "obj_handle.cc.h"
#include "to_string.cc.h"

View file

@ -24,4 +24,6 @@
#include "base.cc.h"
#include "memory/memory.h"
#endif

View file

@ -16,15 +16,15 @@ namespace CNORXZ
}
template <typename T>
String ToString<vector<T>>::func(const vector& a)
String ToString<Vector<T>>::func(const Vector<T>& 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<DType>::func(const DType& a)
{
return a.str();
}
template <typename T>
String toString(const T& a)
{
return ToString::func(a);
return ToString<T>::func(a);
}
}

View file

@ -12,6 +12,12 @@ namespace CNORXZ
static String func(const T& a);
};
template <>
struct ToString<String>
{
static String func(const String& a);
};
template <typename T>
struct ToString<Vector<T>>
{

View file

@ -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 <typename T>
friend class Allocator;

View file

@ -75,7 +75,7 @@ namespace CNORXZ
RangePtr mRef;
};
class CRange : public RangeInterface<CIndex>
class CRange : public RangeInterface<CIndex,SizeT>
{
public:
typedef RangeBase RB;

View file

@ -13,27 +13,26 @@ namespace CNORXZ
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface()
{
mPtrNum = reinterpret_cast<PtrId>(this);
mPtrId = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(const IndexInterface& in) :
mPos(in.mPos)
{
mPtrNum = reinterpret_cast<PtrId>(this);
mPtrId = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>::IndexInterface(IndexInterface&& in) :
mPos(in.mPos)
{
mPtrNum = reinterpret_cast<PtrId>(this);
mPtrId = reinterpret_cast<PtrId>(this);
}
template <class I, typename MetaType>
IndexInterface<I,MetaType>& IndexInterface<I,MetaType>::operator=(const IndexInterface& in)
{
mRangePtr = in.mRangePtr;
mPos = in.mPos;
return *this;
}
@ -41,7 +40,6 @@ namespace CNORXZ
template <class I, typename MetaType>
IndexInterface<I,MetaType>& IndexInterface<I,MetaType>::operator=(IndexInterface&& in)
{
mRangePtr = in.mRangePtr;
mPos = in.mPos;
return *this;
}
@ -95,12 +93,6 @@ namespace CNORXZ
return mPos;
}
template <class I, typename MetaType>
SizeT IndexInterface<I,MetaType>::max() const
{
return mMax;
}
template <class I, typename MetaType>
PtrId IndexInterface<I,MetaType>::ptrId() const
{

View file

@ -9,7 +9,6 @@
namespace CNORXZ
{
template <class I, typename MetaType>
class IndexInterface
{
@ -20,8 +19,8 @@ namespace CNORXZ
const I& THIS() const { return static_cast<const I&>(*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 <class Expr>
auto ifor(SizeT step, const Expr ex) const
{ return THIS().template ifor<Expr>(step,ex); }
@ -59,7 +58,7 @@ namespace CNORXZ
template <class Expr>
auto iforh(SizeT step, const Expr ex) const
{ return THIS().template iforh<Expr>(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<I,MetaType>& rel);
SizeT mPos = 0;
PtrId mPtrId = 0;

View file

@ -6,22 +6,28 @@
namespace CNORXZ
{
template <class Index>
Index RangeInterface<Index>::begin() const
template <class Index, typename Meta>
Index RangeInterface<Index,Meta>::begin() const
{
return Index(RangePtr(RB::mThis), 0);
}
template <class Index>
Index RangeInterface<Index>::end() const
template <class Index, typename Meta>
Index RangeInterface<Index,Meta>::end() const
{
return Index(RangePtr(RB::mThis), this->size());
}
template <class Index, typename Meta>
XIndexPtr RangeInterface<Index,Meta>::index(SizeT pos) const
{
return std::make_shared<XIndex<Index,Meta>>( this->begin()+pos );
}
template <class Range>
Sptr<Range> RangeCast<Range>::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;
}

View file

@ -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<RangeBase> mThis;
RangeBase(const RangePtr& rel);
// delete copy/move???
Wptr<RangeBase> mThis;
RangePtr mRel; // used, if created from another range, to point on it
};
template <class Index>
template <class Index, typename Meta>
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;

View file

@ -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"

View file

@ -16,8 +16,8 @@ namespace CNORXZ
template <typename MetaType>
UIndex<MetaType>::UIndex(const RangePtr& range) :
IndexInterface<UIndex<MetaType>,MetaType>(0),
mRange(rangeCast<MetaType>(range)),
mMetaPtr(&get(0))
mRangePtr(rangeCast<MetaType>(range)),
mMetaPtr(&mRangePtr->get(0))
{}
template <typename MetaType>
@ -62,9 +62,9 @@ namespace CNORXZ
}
template <typename MetaType>
MetaType& UIndex<MetaType>::meta() const
const MetaType& UIndex<MetaType>::meta() const
{
return mSpace[IB::mPos];
return mMetaPtr[IB::mPos];
}
template <typename MetaType>
@ -81,17 +81,17 @@ namespace CNORXZ
}
template <typename MetaType>
Sptr<URange<MetaType>> UIndex<MetaType>::range()
Sptr<URange<MetaType>> UIndex<MetaType>::range() const
{
return mRangePtr;
}
template <typename MetaType>
size_t UIndex<MetaType>::getStepSize(SizeT n)
SizeT UIndex<MetaType>::getStepSize(SizeT n) const
{
return 1;
}
/*
template <typename MetaType>
template <class Expr>
auto UIndex<MetaType>::ifor(size_t step, Expr ex) const
@ -115,7 +115,7 @@ namespace CNORXZ
{
return PFor<UIndex<MetaType>,Expr>(this, step, ex);
}
*/
/**********************
* URangeFactory *
@ -140,14 +140,15 @@ namespace CNORXZ
template <typename MetaType>
void URangeFactory<MetaType>::make()
{
auto info = typeid(URange<MetaType>);
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<oType>
RangePtr key = mProd = std::shared_ptr<URange<MetaType>>
( new URange<MetaType>( 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 <typename MetaType>
URange<MetaType>::URange(const Vector<MetaType>& space) :
RangeInterface<URange<MetaType>>(),
RangeInterface<URange<MetaType>,MetaType>(),
mSpace(space)
{
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
@ -167,7 +168,7 @@ namespace CNORXZ
template <typename MetaType>
URange<MetaType>::URange(Vector<MetaType>&& space) :
RangeInterface<URange<MetaType>>(),
RangeInterface<URange<MetaType>,MetaType>(),
mSpace(space)
{
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());

View file

@ -42,7 +42,7 @@ namespace CNORXZ
String stringMeta() const;
const MetaType& meta() const;
UIndex& at(const MetaType& metaPos);
/*
template <class Expr>
auto ifor(SizeT step, Expr ex) const
-> For<UIndex<MetaType>,Expr>;
@ -54,7 +54,7 @@ namespace CNORXZ
template <class Expr>
auto pifor(SizeT step, Expr ex) const
-> PFor<UIndex<MetaType>,Expr>;
*/
private:
Sptr<RangeType> mRangePtr;
const MetaType* mMetaPtr;
@ -79,7 +79,7 @@ namespace CNORXZ
};
template <typename MetaType>
class URange : public RangeInterface<UIndex<MetaType>>
class URange : public RangeInterface<UIndex<MetaType>,MetaType>
{
public:
typedef RangeBase RB;

View file

@ -13,6 +13,10 @@ namespace CNORXZ
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(const IndexInterface<Index,Meta>& i) :
mI(std::make_shared<Index>(i.THIS())) {}
template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator=(SizeT pos)
{
@ -77,7 +81,7 @@ namespace CNORXZ
mI->at(std::any_cast<const Meta&>(meta.get()));
return *this;
}
/*
template <class Index, typename Meta>
DExpr XIndex<Index,Meta>::ifor(SizeT step, DExpr ex) const
{
@ -89,7 +93,7 @@ namespace CNORXZ
{
return mI->iforh(step, ex);
}
*/
}
#endif

View file

@ -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<Index,Meta>& i);
XIndex(const IndexInterface<Index,Meta>& 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;
// ....!!!!
};

View file

@ -10,6 +10,8 @@
namespace CNORXZ
{
// YRange!!!!
// Future DynamicIndex
//class YIndex : public XIndexBase
class YIndex : public IndexInterface<YIndex,DType>

View file

@ -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

15
src/lib/base/to_string.cc Normal file
View file

@ -0,0 +1,15 @@
#include "base/base.h"
namespace CNORXZ
{
String ToString<String>::func(const String& a)
{
return a;
}
String ToString<DType>::func(const DType& a)
{
return a.str();
}
}

View file

@ -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;
}
}

View file

@ -49,9 +49,27 @@ namespace CNORXZ
return this != &in;
}
std::intptr_t RangeBase::id() const
PtrId RangeBase::id() const
{
return reinterpret_cast<std::intptr_t>(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

View file

@ -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;

View file

@ -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)

View file

@ -1,150 +1,42 @@
// -*- C++ -*-
#include <cstdlib>
#include "gtest/gtest.h"
#include <iostream>
#include "gtest/gtest.h"
#include "cnorxz.h"
namespace MAT = CNORXZ;
namespace {
using namespace MAT;
using namespace CNORXZ;
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
class DA_1D_Test : public ::testing::Test
{
protected:
typedef SingleRangeFactory<char,SpaceType::ANY> SRF;
typedef SRF::oType SRange;
MATest_1Dim()
DA_1D_Test()
{
swapFactory<SRF>(rfbptr, {'x', 'y', 'l', 'f', 'g'} );
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
mSize = 7;
mCR1 = CRangeFactory(mSize).create();
}
std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> srptr;
vector<double> 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<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);
*/
DArray<double> a(mCR1);
EXPECT_EQ(a.size(), mSize);
}
/*
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)
TEST_F(DA_1D_Test, 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);
Array<double,DA_1D_Test::SRange> 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<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

View file

@ -0,0 +1,35 @@
#include <cstdlib>
#include <iostream>
#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
}

View file

@ -5,6 +5,6 @@ namespace CNORXZ
{
namespace Test
{
static Vector<Double> Number::sCont;
Vector<Double> Numbers::sCont;
}
}

View file

@ -1,11 +1,8 @@
#include <fstream>
#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
{