wip...
This commit is contained in:
parent
ebc0f5a807
commit
3463e6ceea
123 changed files with 11226 additions and 1011 deletions
|
@ -3,18 +3,7 @@
|
|||
#ifndef __cxz_ranges_base_def_h__
|
||||
#define __cxz_ranges_base_def_h__
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <iostream>
|
||||
#ifndef CHECK
|
||||
#define CHECK std::cout << __FILE__ << ": @" << __LINE__ << " in " << __func__ << std::endl;
|
||||
#endif
|
||||
#ifndef VCHECK
|
||||
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
|
||||
<< " in " << __func__ << ": " << #a << " = " << a << std::endl;
|
||||
#endif
|
||||
|
||||
#include "base_def.h"
|
||||
#include "base/base.h"
|
||||
|
||||
#include "allocator.h"
|
||||
#define MUI static_cast<size_t>(-1)
|
8
orig/lib/hl_ops/divides.cc
Normal file
8
orig/lib/hl_ops/divides.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template class HighLevelOp<OpCD,dividesx<double,double>,2>;
|
||||
template class HighLevelOp<OpD,dividesx<double,double>,2>;
|
||||
}
|
10
orig/lib/hl_ops/exp.cc
Normal file
10
orig/lib/hl_ops/exp.cc
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template class HighLevelOp<OpCD,x_exp<double>,1>;
|
||||
template class HighLevelOp<OpD,x_exp<double>,1>;
|
||||
template HighLevelOpHolder<OpCD> hl_exp (const HighLevelOpHolder<OpCD>& in);
|
||||
template HighLevelOpHolder<OpD> hl_exp (const HighLevelOpHolder<OpD>& in);
|
||||
}
|
8
orig/lib/hl_ops/minus.cc
Normal file
8
orig/lib/hl_ops/minus.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template class HighLevelOp<OpCD,minusx<double,double>,2>;
|
||||
template class HighLevelOp<OpD,minusx<double,double>,2>;
|
||||
}
|
8
orig/lib/hl_ops/multiplies.cc
Normal file
8
orig/lib/hl_ops/multiplies.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template class HighLevelOp<OpCD,multipliesx<double,double>,2>;
|
||||
template class HighLevelOp<OpD,multipliesx<double,double>,2>;
|
||||
}
|
8
orig/lib/hl_ops/negate.cc
Normal file
8
orig/lib/hl_ops/negate.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template class HighLevelOp<OpCD,negate<double>,1>;
|
||||
template class HighLevelOp<OpD,negate<double>,1>;
|
||||
}
|
8
orig/lib/hl_ops/plus.cc
Normal file
8
orig/lib/hl_ops/plus.cc
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template class HighLevelOp<OpCD,plusx<double,double>,2>;
|
||||
template class HighLevelOp<OpD,plusx<double,double>,2>;
|
||||
}
|
175
orig/lib/ranges/ranges_deserialize_legacy.cc
Normal file
175
orig/lib/ranges/ranges_deserialize_legacy.cc
Normal file
|
@ -0,0 +1,175 @@
|
|||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <class... Ranges>
|
||||
using STP = std::tuple<std::shared_ptr<Ranges>...>;
|
||||
|
||||
typedef vector<std::shared_ptr<RangeBase> > RVEC;
|
||||
|
||||
template <class... Ranges>
|
||||
inline bool compareSpaceTypes(const RVEC& rvec)
|
||||
{
|
||||
return RangeHelper::compareSpaceTypes<sizeof...(Ranges)-1,sizeof...(Ranges),Ranges...>(rvec);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
inline bool setFactory(const RVEC& rvec, std::shared_ptr<RangeFactoryBase>& fptr)
|
||||
{
|
||||
if(compareSpaceTypes<Ranges...>(rvec)) {
|
||||
STP<Ranges...> stp;
|
||||
RangeHelper::setSpace<sizeof...(Ranges)-1>(rvec, stp);
|
||||
fptr = std::make_shared<MultiRangeFactory<Ranges...> >(stp);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size_t indexId()
|
||||
{
|
||||
static size_t id = 0;
|
||||
++id;
|
||||
return id;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char const** dp, size_t metaSize)
|
||||
{
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
RVEC rvec(metaSize);
|
||||
for(size_t i = 0; i != metaSize; ++i){
|
||||
auto ff = createRangeFactory(dp);
|
||||
rvec[i] = ff->create();
|
||||
}
|
||||
|
||||
if(metaSize == 0){
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 1) {
|
||||
#define register_multi1(TT0) if(setFactory<TT0>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi1
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 2) {
|
||||
#define register_multi2(TT0,TT1) if(setFactory<TT0,TT1>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi2
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 3) {
|
||||
#define register_multi3(TT0,TT1,TT2) if(setFactory<TT0,TT1,TT2>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi3
|
||||
assert(0);
|
||||
}
|
||||
else if(metaSize == 4) {
|
||||
#define register_multi4(TT0,TT1,TT2,TT3) if(setFactory<TT0,TT1,TT2,TT3>(rvec, out)) {} else
|
||||
#include "ranges/multi_range_register.h"
|
||||
#undef register_multi4
|
||||
assert(0);
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char const** dp, size_t metaSize)
|
||||
{
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
auto arf = std::make_shared<AnonymousRangeFactory>();
|
||||
for(size_t i = 0; i != metaSize; ++i){
|
||||
auto ff = createRangeFactory(dp);
|
||||
arf->append( ff->create() );
|
||||
}
|
||||
out = arf;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> mkANY(int metaType, size_t metaSize, char const** dp)
|
||||
{
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
if(metaType == -1){
|
||||
assert(0);
|
||||
}
|
||||
#define register_type(x) else if(x == metaType) { \
|
||||
vector<TypeMap<x>::type> vd; \
|
||||
metaCat(vd, *dp, metaSize); \
|
||||
out = std::make_shared<SingleRangeFactory<TypeMap<x>::type, \
|
||||
SpaceType::ANY> >(vd); }
|
||||
#include "ranges/type_map.h"
|
||||
#undef register_type
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> createSingleRangeFactory(const vector<char>*& d, int metaType, size_t size)
|
||||
{
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
if(metaType == -1){
|
||||
assert(0);
|
||||
}
|
||||
#define register_type(x) else if(x == metaType) { \
|
||||
vector<TypeMap<x>::type> vd(size); \
|
||||
std::transform(d,d+size,vd.begin(), \
|
||||
[](const vector<char>& c) \
|
||||
{ assert(c.size() == sizeof(TypeMap<x>::type)); \
|
||||
return *reinterpret_cast<TypeMap<x>::type const*>(c.data()); }); \
|
||||
out = std::make_shared<SingleRangeFactory<TypeMap<x>::type, \
|
||||
SpaceType::ANY> >(vd); }
|
||||
#include "ranges/type_map.h"
|
||||
#undef register_type
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(char const** dp)
|
||||
{
|
||||
DataHeader h = *reinterpret_cast<const DataHeader*>(*dp);
|
||||
*dp += sizeof(DataHeader);
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
|
||||
if(h.multiple != 0){
|
||||
if(h.spaceType == static_cast<int>( SpaceType::ANY )) {
|
||||
// multi range
|
||||
out = mkMULTI(dp, h.metaSize);
|
||||
}
|
||||
else if(h.spaceType == static_cast<int>( SpaceType::ANON ) ) {
|
||||
// anonymous range
|
||||
out = mkANONYMOUS(dp, h.metaSize);
|
||||
}
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(h.spaceType == static_cast<int>( SpaceType::ANY ) ) {
|
||||
// generic single range
|
||||
out = mkANY(h.metaType, h.metaSize, dp);
|
||||
}
|
||||
else if(h.spaceType == static_cast<int>( SpaceType::NONE ) ) {
|
||||
// classic range
|
||||
size_t size = *reinterpret_cast<const size_t*>(*dp);
|
||||
out = std::make_shared<SingleRangeFactory<size_t,SpaceType::NONE> >(size);
|
||||
}
|
||||
#define include_range_type(x,n) else if(h.spaceType == static_cast<int>( SpaceType::x ) ) { \
|
||||
out = mk##x(*dp, h.metaSize); }
|
||||
#include "ranges/range_types/header.h"
|
||||
#undef inlcude_range_type
|
||||
else {
|
||||
assert(0);
|
||||
}
|
||||
*dp += h.metaSize;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
|
||||
#ifndef __cxz_allocator__
|
||||
#define __cxz_allocator__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#define MIB_SIZE 1024*1024 // 1MiB
|
||||
#define WARN_SIZE MIB_SIZE*100 // 100 MiB
|
||||
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
class Allocator
|
||||
{
|
||||
private:
|
||||
static size_t sMemUsage;
|
||||
|
||||
public:
|
||||
static size_t memUsage() { return sMemUsage; }
|
||||
|
||||
typedef T value_type;
|
||||
static constexpr size_t type_size = sizeof(value_type);
|
||||
static constexpr size_t N = 32; // get from environment!!!
|
||||
|
||||
struct VX
|
||||
{
|
||||
alignas(N) char x[N];
|
||||
};
|
||||
|
||||
Allocator() = default;
|
||||
|
||||
template <typename U>
|
||||
Allocator(const Allocator<U>& x) {}
|
||||
|
||||
T* allocate(size_t n)
|
||||
{
|
||||
const size_t nn = n*type_size;
|
||||
sMemUsage += nn;
|
||||
if(nn >= WARN_SIZE){
|
||||
std::cout << __func__ << ": WARNING: allocating " << nn/(MIB_SIZE) << " MiB" << std::endl;
|
||||
}
|
||||
const size_t off = nn%N;
|
||||
const size_t nnx = (off == 0) ? nn : nn + N - off;
|
||||
const size_t nnd = nnx/N;
|
||||
VX* vx = new VX[nnd];
|
||||
return reinterpret_cast<T*>(vx);
|
||||
}
|
||||
|
||||
void deallocate(T* p, size_t n)
|
||||
{
|
||||
const size_t nn = n*type_size;
|
||||
sMemUsage -= nn;
|
||||
VX* vx = reinterpret_cast<VX*>(p);
|
||||
delete [] vx;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
bool operator==(const Allocator<T>& a, const Allocator<U>& b)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
bool operator!=(const Allocator<T>& a, const Allocator<U>& b)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t Allocator<T>::sMemUsage = 0;
|
||||
|
||||
} // namespace CNORXZInternal
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
inline size_t memUsage()
|
||||
{
|
||||
return CNORXZInternal::Allocator<T>::memUsage();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using vector = std::vector<T,CNORXZInternal::Allocator<T>>;
|
||||
|
||||
template <typename T>
|
||||
inline std::vector<T> toStdVec(const vector<T>& v)
|
||||
{
|
||||
return std::vector<T>(v.begin(), v.end());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline vector<T> toMatVec(const std::vector<T>& v)
|
||||
{
|
||||
return vector<T>(v.begin(), v.end());
|
||||
}
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
6
src/include/array/array.cc.h
Normal file
6
src/include/array/array.cc.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
//#include "access.cc.h"
|
||||
#include "darray_base.cc.h"
|
||||
#include "darray.cc.h"
|
||||
#include "dcontainer_index.cc.h"
|
||||
//#include "functional_array.cc.h"
|
6
src/include/array/array.h
Normal file
6
src/include/array/array.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
//#include "access.h"
|
||||
#include "darray_base.h"
|
||||
#include "darray.h"
|
||||
#include "dcontainer_index.h"
|
||||
//#include "functional_array.h"
|
|
@ -1,91 +1,11 @@
|
|||
|
||||
#ifndef __cxz_dcontainer_index_cc_h__
|
||||
#define __cxz_dcontainer_index_cc_h__
|
||||
|
||||
#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):
|
||||
|
@ -209,3 +129,5 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
87
src/include/array/dcontainer_index.h
Normal file
87
src/include/array/dcontainer_index.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
|
||||
#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/xindex.h"
|
||||
#include "ranges/yindex.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
|
||||
template <typename T>
|
||||
class DConstContainerIndex : public IndexInterface<DConstContainerIndex<T>,DType>
|
||||
{
|
||||
public:
|
||||
typedef IndexInterface<DConstContainerIndex<T>,DType> IB;
|
||||
|
||||
protected:
|
||||
YIndexPtr mI;
|
||||
const T* mCData = nullptr;
|
||||
|
||||
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>
|
||||
class DContainerIndex : public DConstContainerIndex<T>
|
||||
{
|
||||
public:
|
||||
typedef DConstContainerIndex<T> CCI;
|
||||
typedef typename CCI::IB IB;
|
||||
|
||||
private:
|
||||
T* mData = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(DContainerIndex);
|
||||
DContainerIndex(T* data, const RangePtr& range);
|
||||
DContainerIndex(T* data, const DConstContainerIndex<T>& cci);
|
||||
|
||||
T& operator*();
|
||||
T* operator->();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
15
src/include/base/assert.h
Normal file
15
src/include/base/assert.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#define CXZ_ERRTAG __FILE__ << '@' << __LINE__ << '(' << __func__ << "): error"
|
||||
#define CXZ_WARNTAG __FILE__ << '@' << __LINE__ << ": warning"
|
||||
#define CXZ_ERROR(errmsg) {\
|
||||
std::stringstream ss;\
|
||||
ss << CXZ_ERRTAG << ": " << errmsg << std::flush;\
|
||||
throw std::runtime_error(ss.str()); }
|
||||
|
||||
#define CXZ_WARNING(errmsg) {\
|
||||
std::cerr << CXZ_WARNTAG << ": " << errmsg << std::endl; }
|
||||
|
||||
#define CXZ_ASSERT(statement, errmsg) if(not (statement)) { CXZ_ERROR(errmsg); }
|
2
src/include/base/base.cc.h
Normal file
2
src/include/base/base.cc.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
#include "dtype.cc.h"
|
12
src/include/base/base.h
Normal file
12
src/include/base/base.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
#ifndef __cxz_base_h__
|
||||
#define __cxz_base_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include "macros.h"
|
||||
#include "assert.h"
|
||||
#include "types.h"
|
||||
|
||||
#endif
|
|
@ -1,52 +1,16 @@
|
|||
|
||||
#ifndef __cxz_dtype_cc_h__
|
||||
#define __cxz_dtype_cc_h__
|
||||
|
||||
#include <sstream>
|
||||
#include "dynamic_meta.h"
|
||||
#include "dtype.h"
|
||||
#include "to_string.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)
|
||||
{
|
||||
|
@ -92,3 +56,5 @@ namespace CNORXZ
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
51
src/include/base/dtype.h
Normal file
51
src/include/base/dtype.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
#ifndef __cxz_dynamic_meta_h__
|
||||
#define __cxz_dynamic_meta_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <any>
|
||||
#include <functional>
|
||||
|
||||
#include "macros.h"
|
||||
#include "types.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
class DType
|
||||
{
|
||||
private:
|
||||
std::any mD;
|
||||
std::function<String()> mToStr;
|
||||
std::function<Int(std::any)> mComp;
|
||||
|
||||
template <typename T>
|
||||
void _mkToStr();
|
||||
|
||||
template <typename T>
|
||||
void _mkComp();
|
||||
|
||||
public:
|
||||
DEFAULT_MEMBERS(DType);
|
||||
|
||||
template <typename T>
|
||||
DType(const T& d);
|
||||
|
||||
template <typename T>
|
||||
DType& operator=(const T& d);
|
||||
|
||||
std::string str() const { return mToStr(); }
|
||||
const std::any& get() const { return mD; }
|
||||
|
||||
bool operator==(const DType& a) const { return mComp(a.mD) == 0; }
|
||||
bool operator!=(const DType& a) const { return mComp(a.mD) != 0; }
|
||||
bool operator<(const DType& a) const { return mComp(a.mD) == -1; }
|
||||
bool operator>(const DType& a) const { return mComp(a.mD) == 1; }
|
||||
bool operator<=(const DType& a) const { auto c = mComp(a.mD); return c <= 0; }
|
||||
bool operator>=(const DType& a) const { auto c = mComp(a.mD); return c == 1 or c == 0; }
|
||||
};
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
26
src/include/base/macros.h
Normal file
26
src/include/base/macros.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
#ifndef __cxz_macros_h__
|
||||
#define __cxz_macros_h__
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#ifndef CHECK
|
||||
#define CHECK std::cout << __FILE__ << ": @" << __LINE__ << " in " << __func__ << std::endl;
|
||||
#endif
|
||||
#ifndef VCHECK
|
||||
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
|
||||
<< " in " << __func__ << ": " << #a << " = " << a << std::endl;
|
||||
#endif
|
||||
|
||||
#define DEFAULT_C(__class_name__) __class_name__() = default
|
||||
#define DEFAULT_COPY_C(__class_name__) __class_name__(const __class_name__& a) = default
|
||||
#define DEFAULT_COPY_A(__class_name__) __class_name__& operator=(const __class_name__& a) = default
|
||||
#define DEFAULT_MOVE_C(__class_name__) __class_name__(__class_name__&& a) = default
|
||||
#define DEFAULT_MOVE_A(__class_name__) __class_name__& operator=(__class_name__&& a) = default
|
||||
#define DEFAULT_COPY(__class_name__) DEFAULT_COPY_C(__class_name__); DEFAULT_COPY_A(__class_name__)
|
||||
#define DEFAULT_MOVE(__class_name__) DEFAULT_MOVE_C(__class_name__); DEFAULT_MOVE_A(__class_name__)
|
||||
|
||||
#define DEFAULT_MEMBERS_X(__class_name__) DEFAULT_COPY(__class_name__); DEFAULT_MOVE(__class_name__)
|
||||
#define DEFAULT_MEMBERS(__class_name__) DEFAULT_C(__class_name__); DEFAULT_MEMBERS_X(__class_name__)
|
||||
|
||||
#endif
|
52
src/include/base/to_string.cc.h
Normal file
52
src/include/base/to_string.cc.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
#ifndef __cxz_to_string_cc_h__
|
||||
#define __cxz_to_string_cc_h__
|
||||
|
||||
#include "to_string.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T>
|
||||
String toString(const T& a)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << a;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
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>
|
||||
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();
|
||||
}
|
||||
|
||||
template <>
|
||||
String toString<DType>(const DType& a)
|
||||
{
|
||||
return a.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
23
src/include/base/to_string.h
Normal file
23
src/include/base/to_string.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
#ifndef __cxz_to_string_h__
|
||||
#define __cxz_to_string_h__
|
||||
|
||||
#include "types.h"
|
||||
#include <array>
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T>
|
||||
String toString(const T& a);
|
||||
|
||||
template <typename T>
|
||||
String toString<vector<T>>(const vector& a);
|
||||
|
||||
template <typename T, size_t N>
|
||||
String toString<std::array<T,N>>(const std::array<T,N>& a);
|
||||
|
||||
template <>
|
||||
String toString<DType>(const DType& a);
|
||||
}
|
||||
|
||||
#endif
|
68
src/include/base/types.h
Normal file
68
src/include/base/types.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
#ifndef __cxz_types_h__
|
||||
#define __cxz_types_h__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <complex>
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
/**********************
|
||||
* standard types *
|
||||
**********************/
|
||||
|
||||
typedef std::intptr_t PtrId;
|
||||
typedef int32_t Int;
|
||||
typedef uint64_t SizeT;
|
||||
typedef double Double;
|
||||
typedef Double Real;
|
||||
typedef std::complex<Real> Complex;
|
||||
typedef std::string String;
|
||||
|
||||
template <typename T, size_t N>
|
||||
using Arr = std::array<T,N>;
|
||||
|
||||
template <typename T>
|
||||
using Sptr = std::shared_ptr<T>;
|
||||
|
||||
template <typename... T>
|
||||
using Tuple = std::tuple<T...>;
|
||||
|
||||
template <typename... T>
|
||||
using TupleElem = std::tuple_element<T...>;
|
||||
|
||||
template <typename K, typename V>
|
||||
using Map = std::map<K,V>;
|
||||
|
||||
typedef std::typeinfo TypeInfo;
|
||||
|
||||
/*********************
|
||||
* library types *
|
||||
*********************/
|
||||
|
||||
// definition: base/dtype.h
|
||||
class DType;
|
||||
|
||||
// definition: memory/allocator.h
|
||||
template <typename T>
|
||||
class Allocator;
|
||||
|
||||
// definition: ranges/range_base.h
|
||||
class RangeBase;
|
||||
|
||||
/*********************
|
||||
* derived types *
|
||||
*********************/
|
||||
|
||||
template <typename T>
|
||||
using Vector = std::vector<T,Allocator<T>>;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef __cxz_basic_types_h__
|
||||
#define __cxz_basic_types_h__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
// just to fix this forever:
|
||||
typedef int32_t Int;
|
||||
typedef uint64_t SizeT;
|
||||
typedef double Double;
|
||||
typedef Double Real;
|
||||
typedef std::string String;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,18 +1,5 @@
|
|||
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
|
||||
#include "container_index.cc.h"
|
||||
#include "dcontainer_index.cc.h"
|
||||
#include "cxz_operation.cc.h"
|
||||
#include "functional_array.cc.h"
|
||||
#include "helper_tools.cc.h"
|
||||
#include "map_range.cc.h"
|
||||
#include "cxz_array_base.cc.h"
|
||||
#include "cxz_array.cc.h"
|
||||
#include "cxz_darray_base.cc.h"
|
||||
#include "cxz_darray.cc.h"
|
||||
#include "slice.cc.h"
|
||||
#include "dynamic_operation.cc.h"
|
||||
#include "access.cc.h"
|
||||
#include "op_expressions.cc.h"
|
||||
|
||||
#include "base/base.cc.h"
|
||||
#include "memory/memory.cc.h"
|
||||
#include "ranges/ranges.cc.h"
|
||||
#include "array/array.cc.h"
|
||||
|
|
|
@ -3,20 +3,9 @@
|
|||
#ifndef __cxz_cnorxz_h__
|
||||
#define __cxz_cnorxz_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include "container_index.h"
|
||||
#include "dcontainer_index.h"
|
||||
#include "cxz_operation.h"
|
||||
#include "cxz_array_base.h"
|
||||
#include "cxz_array.h"
|
||||
#include "cxz_darray_base.h"
|
||||
#include "cxz_darray.h"
|
||||
#include "functional_array.h"
|
||||
#include "helper_tools.h"
|
||||
#include "operation_def.h"
|
||||
#include "map_range.h"
|
||||
#include "dynamic_operation.h"
|
||||
//#include "high_level_operation.h"
|
||||
#include "base/base.h"
|
||||
#include "memory/memory.h"
|
||||
#include "ranges/ranges.h"
|
||||
|
||||
#include "cnorxz.cc.h"
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#define MA_ERRTAG __FILE__ << '@' << __LINE__ << '(' << __func__ << "): error"
|
||||
#define MA_WARNTAG __FILE__ << '@' << __LINE__ << ": warning"
|
||||
#define MA_ERROR(errmsg) {\
|
||||
std::stringstream ss;\
|
||||
ss << MA_ERRTAG << ": " << errmsg << std::flush;\
|
||||
throw std::runtime_error(ss.str()); }
|
||||
|
||||
#define MA_WARNING(errmsg) {\
|
||||
std::cerr << MA_WARNTAG << ": " << errmsg << std::endl; }
|
||||
|
||||
#define MA_ASSERT(statement, errmsg) if(not (statement)) { MA_ERROR(errmsg); }
|
|
@ -1,182 +0,0 @@
|
|||
|
||||
#ifndef __dcontainer_index_h__
|
||||
#define __dcontainer_index_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/index_base.h"
|
||||
#include "mbase_def.h"
|
||||
#include "statics/static_for.h"
|
||||
#include "ranges/range_helper.h"
|
||||
#include "ranges/dynamic_meta.h"
|
||||
#include "xfor/xfor.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
// Future IndexWrapper
|
||||
class XIndexBase : public IndexInterface<XIndexBase,DType>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(XIndexBase);
|
||||
|
||||
constexpr IndexType type() const;
|
||||
|
||||
virtual XIndexBase& operator=(size_t pos) = 0;
|
||||
virtual XIndexBase& operator++() = 0;
|
||||
virtual XIndexBase& operator--() = 0;
|
||||
virtual int pp(std::intptr_t idxPtrNum) = 0;
|
||||
virtual int mm(std::intptr_t idxPtrNum) = 0;
|
||||
virtual size_t dim() const = 0;
|
||||
virtual size_t getStepSize(size_t n) const = 0;
|
||||
virtual std::string stringMeta() const = 0;
|
||||
virtual DType meta() const = 0;
|
||||
virtual XIndexBase& at(const DType& meta) = 0;
|
||||
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const = 0;
|
||||
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const = 0;
|
||||
// ...!!!
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<XIndexBase> XIndexPtr;
|
||||
|
||||
// MultiIndex Wrapper:
|
||||
template <class Index, typename Meta>
|
||||
class XIndex : public XIndexBase
|
||||
{
|
||||
private:
|
||||
IndexPtr<Index,Meta> mI;
|
||||
|
||||
public:
|
||||
DEFAULT_MEMBERS(XIndex);
|
||||
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>
|
||||
class DConstContainerIndex : public IndexInterface<DConstContainerIndex<T>,DType>
|
||||
{
|
||||
public:
|
||||
typedef IndexInterface<DConstContainerIndex<T>,DType> IB;
|
||||
|
||||
protected:
|
||||
YIndexPtr mI;
|
||||
const T* mCData = nullptr;
|
||||
|
||||
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>
|
||||
class DContainerIndex : public DConstContainerIndex<T>
|
||||
{
|
||||
public:
|
||||
typedef DConstContainerIndex<T> CCI;
|
||||
typedef typename CCI::IB IB;
|
||||
|
||||
private:
|
||||
T* mData = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
DEFAULT_MEMBERS(DContainerIndex);
|
||||
DContainerIndex(T* data, const RangePtr& range);
|
||||
DContainerIndex(T* data, const DConstContainerIndex<T>& cci);
|
||||
|
||||
T& operator*();
|
||||
T* operator->();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
46
src/include/memory/allocator.cc.h
Normal file
46
src/include/memory/allocator.cc.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
#ifndef __cxz_allocator_cc_h__
|
||||
#define __cxz_allocator_cc_h__
|
||||
|
||||
#include "allocator.h"
|
||||
#include "memcount.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
T* Allocator<T>::allocate(SizeT n)
|
||||
{
|
||||
const SizeT nn = n*type_size;
|
||||
MemCount::add(nn);
|
||||
const SizeT off = nn%N;
|
||||
const SizeT nnx = (off == 0) ? nn : nn + N - off;
|
||||
const SizeT nnd = nnx/N;
|
||||
VX* vx = new VX[nnd];
|
||||
return reinterpret_cast<T*>(vx);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Allocator<T>::deallocate(T* p, SizeT n)
|
||||
{
|
||||
const SizeT nn = n*type_size;
|
||||
MemCount::sub(nn);
|
||||
VX* vx = reinterpret_cast<VX*>(p);
|
||||
delete [] vx;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
bool operator==(const Allocator<T>& a, const Allocator<U>& b)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
bool operator!=(const Allocator<T>& a, const Allocator<U>& b)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
63
src/include/memory/allocator.h
Normal file
63
src/include/memory/allocator.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
#ifndef __cxz_allocator__
|
||||
#define __cxz_allocator__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include "base/types.h"
|
||||
|
||||
#define MIB_SIZE 1024*1024 // 1MiB
|
||||
#define WARN_SIZE MIB_SIZE*100 // 100 MiB
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
class Allocator
|
||||
{
|
||||
private:
|
||||
static SizeT sMemUsage;
|
||||
|
||||
public:
|
||||
static SizeT memUsage() { return sMemUsage; }
|
||||
|
||||
static constexpr SizeT type_size = sizeof(T);
|
||||
static constexpr SizeT N = 32; // get from environment!!!
|
||||
|
||||
struct VX
|
||||
{
|
||||
alignas(N) char x[N];
|
||||
};
|
||||
|
||||
Allocator() = default;
|
||||
|
||||
template <typename U>
|
||||
Allocator(const Allocator<U>& x) {}
|
||||
|
||||
T* allocate(SizeT n);
|
||||
void deallocate(T* p, SizeT n);
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
bool operator==(const Allocator<T>& a, const Allocator<U>& b);
|
||||
|
||||
template <class T, class U>
|
||||
bool operator!=(const Allocator<T>& a, const Allocator<U>& b);
|
||||
|
||||
template <typename T>
|
||||
SizeT Allocator<T>::sMemUsage = 0;
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline SizeT memUsage()
|
||||
{
|
||||
return Allocator<T>::memUsage();
|
||||
}
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
26
src/include/memory/memcount.h
Normal file
26
src/include/memory/memcount.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
#ifndef __cxz_memcount_h__
|
||||
#define __cxz_memcount_h__
|
||||
|
||||
#include "allocator_d.h"
|
||||
#include "base/types.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
class MemCount
|
||||
{
|
||||
private:
|
||||
static SizeT sMemUsage;
|
||||
static void add(SizeT x) { sMemUsage += x; }
|
||||
static void sub(SizeT x) { sMemUsage -= x; }
|
||||
|
||||
public:
|
||||
MemCount() = delete(); // static only
|
||||
static SizeT usage() { return sMemUsage; }
|
||||
|
||||
friend Allocator;
|
||||
};
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
2
src/include/memory/memory.cc.h
Normal file
2
src/include/memory/memory.cc.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
#include "allocator.cc.h"
|
3
src/include/memory/memory.h
Normal file
3
src/include/memory/memory.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
#include "allocator.h"
|
||||
#include "memcount.h"
|
|
@ -1,109 +0,0 @@
|
|||
|
||||
#ifndef __cxz_dynamic_meta_h__
|
||||
#define __cxz_dynamic_meta_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <any>
|
||||
#include <functional>
|
||||
|
||||
#include "allocator.h"
|
||||
#include "rbase_def.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
// DEP:
|
||||
typedef std::pair<const char*,size_t> DynamicMetaElem;
|
||||
|
||||
template <size_t N>
|
||||
struct DynamicMetaSetter
|
||||
{
|
||||
template <typename... Us>
|
||||
static inline void set(const std::tuple<Us...>& in, vector<DynamicMetaElem>& meta)
|
||||
{
|
||||
typedef typename std::tuple_element<N,std::tuple<Us...>>::type elemtype;
|
||||
meta[N].first = reinterpret_cast<const char*>( &std::get<N>(in) );
|
||||
meta[N].second = sizeof(elemtype);
|
||||
DynamicMetaSetter<N-1>::set(in,meta);
|
||||
}
|
||||
};
|
||||
|
||||
// DEP:
|
||||
template <>
|
||||
struct DynamicMetaSetter<0>
|
||||
{
|
||||
template <typename... Us>
|
||||
static inline void set(const std::tuple<Us...>& in, vector<DynamicMetaElem>& meta)
|
||||
{
|
||||
typedef typename std::tuple_element<0,std::tuple<Us...>>::type elemtype;
|
||||
meta[0].first = reinterpret_cast<const char*>( &std::get<0>(in) );
|
||||
meta[0].second = sizeof(elemtype);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// DEP:
|
||||
class DynamicMetaT
|
||||
{
|
||||
private:
|
||||
vector<DynamicMetaElem> mMeta;
|
||||
|
||||
public:
|
||||
DynamicMetaT() = default;
|
||||
DynamicMetaT(const DynamicMetaT& in) = default;
|
||||
DynamicMetaT(DynamicMetaT&& in) = default;
|
||||
DynamicMetaT& operator=(const DynamicMetaT& in) = default;
|
||||
DynamicMetaT& operator=(DynamicMetaT&& in) = default;
|
||||
|
||||
template <typename... Us>
|
||||
DynamicMetaT(const std::tuple<Us...>* meta) : mMeta(sizeof...(Us))
|
||||
{
|
||||
DynamicMetaSetter<sizeof...(Us)-1>::set(*meta,mMeta);
|
||||
}
|
||||
|
||||
bool operator==(const DynamicMetaT& in) const;
|
||||
bool operator!=(const DynamicMetaT& in) const;
|
||||
|
||||
size_t size() const;
|
||||
|
||||
DynamicMetaElem& operator[](size_t pos);
|
||||
const DynamicMetaElem& operator[](size_t pos) const;
|
||||
};
|
||||
|
||||
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:
|
||||
DEFAULT_MEMBERS(DType);
|
||||
|
||||
template <typename T>
|
||||
DType(const T& d);
|
||||
|
||||
template <typename T>
|
||||
DType& operator=(const T& d);
|
||||
|
||||
std::string str() const { return mToStr(); }
|
||||
const std::any& get() const { return mD; }
|
||||
|
||||
bool operator==(const DType& a) const { return mComp(a.mD) == 0; }
|
||||
bool operator!=(const DType& a) const { return mComp(a.mD) != 0; }
|
||||
bool operator<(const DType& a) const { return mComp(a.mD) == -1; }
|
||||
bool operator>(const DType& a) const { return mComp(a.mD) == 1; }
|
||||
bool operator<=(const DType& a) const { auto c = mComp(a.mD); return c <= 0; }
|
||||
bool operator>=(const DType& a) const { auto c = mComp(a.mD); return c == 1 or c == 0; }
|
||||
};
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
|
@ -3,121 +3,112 @@
|
|||
#ifndef __cxz_multi_range_h__
|
||||
#define __cxz_multi_range_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include "base/base.h"
|
||||
#include <map>
|
||||
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/index_base.h"
|
||||
#include "range_base.h"
|
||||
#include "index_base.h"
|
||||
|
||||
#include "ranges/range_helper.h"
|
||||
#include "ranges/multi_range_factory_product_map.h"
|
||||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
#include "range_helper.h"
|
||||
#include "multi_range_factory_product_map.h"
|
||||
|
||||
#include "statics/static_for.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
class MultiIndex : public IndexInterface<MultiIndex<Indices...>,
|
||||
std::tuple<typename Indices::MetaType...> >
|
||||
Tuple<typename Indices::MetaType...> >
|
||||
{
|
||||
public:
|
||||
|
||||
typedef IndexInterface<MultiIndex<Indices...>,
|
||||
std::tuple<typename Indices::MetaType...> > IB;
|
||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
||||
Tuple<typename Indices::MetaType...> > IB;
|
||||
typedef Tuple<Sptr<Indices>...> IndexPack;
|
||||
typedef Tuple<typename Indices::MetaType...> MetaType;
|
||||
typedef MultiRange<typename Indices::RangeType...> RangeType;
|
||||
typedef MultiIndex IType;
|
||||
|
||||
static constexpr IndexType sType() { return IndexType::MULTI; }
|
||||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||
static constexpr size_t totalDim() { return (... * Indices::totalDim()); }
|
||||
static constexpr SizeT sDim() { return sizeof...(Indices); }
|
||||
static constexpr SizeT totalDim() { return (... * Indices::totalDim()); }
|
||||
|
||||
static constexpr SpaceType STYPE = SpaceType::ANY;
|
||||
static constexpr bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
||||
static constexpr bool PARALLEL = TupleElem<0,Tuple<Indices...>>::type::PARALLEL;
|
||||
|
||||
private:
|
||||
|
||||
IndexPack mIPack;
|
||||
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
||||
Arr<SizeT,sizeof...(Indices)+1> mBlockSizes;
|
||||
MultiIndex() = default;
|
||||
|
||||
public:
|
||||
|
||||
const IndexPack& pack() const { return mIPack; }
|
||||
|
||||
MultiIndex() = delete;
|
||||
|
||||
// NO DEFAULT HERE !!!
|
||||
// ( have to assign sub-indices (ptr!) correctly )
|
||||
|
||||
template <class MRange>
|
||||
MultiIndex(const std::shared_ptr<MRange>& range);
|
||||
MultiIndex(const Sptr<MRange>& range);
|
||||
|
||||
template <size_t DIR>
|
||||
template <SizeT DIR>
|
||||
MultiIndex& up();
|
||||
|
||||
template <size_t DIR>
|
||||
template <SizeT DIR>
|
||||
MultiIndex& down();
|
||||
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
||||
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
||||
|
||||
template <size_t N>
|
||||
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
||||
template <SizeT N>
|
||||
SizeT getBlockSize() const { return std::get<N>(mBlockSizes); }
|
||||
|
||||
// raplace instances (in contrast to its analogon in ConstContainerIndex
|
||||
// MultiIndices CANNOT be influences be its subindices, so there is
|
||||
// NO foreign/external controll)
|
||||
// Do NOT share index instances between two or more MultiIndex instances
|
||||
MultiIndex& operator()(std::shared_ptr<Indices>&... indices);
|
||||
MultiIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& indices);
|
||||
MultiIndex& operator()(Sptr<Indices>&... indices);
|
||||
MultiIndex& operator()(const Tuple<Sptr<Indices>...>& indices);
|
||||
|
||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||
|
||||
IndexType type() const;
|
||||
|
||||
MultiIndex& operator=(size_t pos);
|
||||
MultiIndex& operator=(SizeT pos);
|
||||
|
||||
MultiIndex& operator++();
|
||||
MultiIndex& operator--();
|
||||
|
||||
int pp(std::intptr_t idxPtrNum);
|
||||
int mm(std::intptr_t idxPtrNum);
|
||||
int pp(PtrId idxPtrNum);
|
||||
int mm(PtrId idxPtrNum);
|
||||
|
||||
std::string stringMeta() const;
|
||||
MetaType meta() const;
|
||||
MultiIndex& at(const MetaType& metaPos);
|
||||
|
||||
size_t dim();
|
||||
SizeT dim();
|
||||
bool first();
|
||||
bool last();
|
||||
std::shared_ptr<RangeType> range();
|
||||
Sptr<RangeType> range();
|
||||
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
||||
|
||||
size_t getStepSize(size_t n);
|
||||
SizeT getStepSize(SizeT n);
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(size_t step, Exprs exs) const;
|
||||
auto ifor(SizeT step, Exprs exs) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto iforh(size_t step, Exprs exs) const;
|
||||
auto iforh(SizeT step, Exprs exs) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto pifor(size_t step, Exprs exs) const;
|
||||
auto pifor(SizeT step, Exprs exs) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -133,14 +124,14 @@ namespace CNORXZ
|
|||
typedef MultiRange<Ranges...> oType;
|
||||
|
||||
MultiRangeFactory() = delete;
|
||||
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
||||
MultiRangeFactory(const Sptr<Ranges>&... rs);
|
||||
MultiRangeFactory(const typename MultiRange<Ranges...>::Space& space);
|
||||
|
||||
virtual std::shared_ptr<RangeBase> create() override;
|
||||
virtual Sptr<RangeBase> create() override;
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<RangeBase> checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp);
|
||||
Sptr<RangeBase> checkIfCreated(const Tuple<Sptr<Ranges>...>& ptp);
|
||||
|
||||
};
|
||||
|
||||
|
@ -153,9 +144,9 @@ namespace CNORXZ
|
|||
{
|
||||
public:
|
||||
typedef RangeBase RB;
|
||||
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
||||
typedef Tuple<Sptr<Ranges>...> Space;
|
||||
typedef MultiIndex<typename Ranges::IndexType...> IndexType;
|
||||
typedef std::tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
||||
typedef Tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
||||
typedef MultiRange RangeType;
|
||||
typedef MultiRangeFactory<Ranges...> FType;
|
||||
|
||||
|
@ -164,36 +155,36 @@ namespace CNORXZ
|
|||
MultiRange(const MultiRange& in) = delete;
|
||||
MultiRange& operator=(const MultiRange& in) = delete;
|
||||
|
||||
MultiRange(const std::shared_ptr<Ranges>&... rs);
|
||||
MultiRange(const Sptr<Ranges>&... rs);
|
||||
MultiRange(const Space& space);
|
||||
|
||||
Space mSpace;
|
||||
|
||||
public:
|
||||
|
||||
static const size_t sdim = sizeof...(Ranges);
|
||||
static const SizeT sdim = sizeof...(Ranges);
|
||||
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
||||
|
||||
size_t getMeta(const MetaType& metaPos) const;
|
||||
SizeT getMeta(const MetaType& metaPos) const;
|
||||
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
||||
|
||||
virtual std::shared_ptr<RangeBase> sub(size_t num) const override;
|
||||
virtual Sptr<RangeBase> sub(SizeT num) const override;
|
||||
|
||||
virtual size_t dim() const final;
|
||||
virtual size_t size() const final;
|
||||
virtual SizeT dim() const final;
|
||||
virtual SizeT size() const final;
|
||||
|
||||
virtual SpaceType spaceType() const final;
|
||||
virtual DataHeader dataHeader() const final;
|
||||
|
||||
virtual vector<size_t> typeNum() const final;
|
||||
virtual size_t cmeta(char* target, size_t pos) const final;
|
||||
virtual size_t cmetaSize() const final;
|
||||
virtual std::string stringMeta(size_t pos) const final;
|
||||
virtual vector<char> data() const final;
|
||||
virtual Vector<SizeT> typeNum() const final;
|
||||
virtual SizeT cmeta(char* target, SizeT pos) const final;
|
||||
virtual SizeT cmetaSize() const final;
|
||||
virtual std::string stringMeta(SizeT pos) const final;
|
||||
virtual Vector<char> data() const final;
|
||||
|
||||
const Space& space() const;
|
||||
|
||||
|
@ -201,15 +192,15 @@ namespace CNORXZ
|
|||
virtual IndexType end() const final;
|
||||
|
||||
template <class... ERanges>
|
||||
auto cat(const std::shared_ptr<MultiRange<ERanges...> >& erange)
|
||||
-> std::shared_ptr<MultiRange<Ranges...,ERanges...> >;
|
||||
auto cat(const Sptr<MultiRange<ERanges...> >& erange)
|
||||
-> Sptr<MultiRange<Ranges...,ERanges...> >;
|
||||
|
||||
friend MultiRangeFactory<Ranges...>;
|
||||
|
||||
static constexpr bool HASMETACONT = false;
|
||||
static constexpr bool defaultable = false;
|
||||
static constexpr size_t ISSTATIC = (... & Ranges::ISSTATIC);
|
||||
static constexpr size_t SIZE = (... * Ranges::SIZE);
|
||||
static constexpr SizeT ISSTATIC = (... & Ranges::ISSTATIC);
|
||||
static constexpr SizeT SIZE = (... * Ranges::SIZE);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -227,7 +218,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
// -> define in range_base.cc
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
||||
Sptr<RangeFactoryBase> mkMULTI(const char** dp);
|
||||
|
||||
/******************
|
||||
* MultiIndex *
|
||||
|
@ -235,8 +226,8 @@ namespace CNORXZ
|
|||
|
||||
template <class... Indices>
|
||||
template <class MRange>
|
||||
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
||||
IndexInterface<MultiIndex<Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||
MultiIndex<Indices...>::MultiIndex(const Sptr<MRange>& range) :
|
||||
IndexInterface<MultiIndex<Indices...>,Tuple<typename Indices::MetaType...> >(range, 0)
|
||||
{
|
||||
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||
sfor_mn<sizeof...(Indices),0>
|
||||
|
@ -257,7 +248,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t DIR>
|
||||
template <SizeT DIR>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
|
@ -275,7 +266,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t DIR>
|
||||
template <SizeT DIR>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
|
@ -293,27 +284,27 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto MultiIndex<Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
|
||||
{
|
||||
return *std::get<N>(mIPack);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto MultiIndex<Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
||||
{
|
||||
return std::get<N>(mIPack);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(Sptr<Indices>&... indices)
|
||||
{
|
||||
return (*this)(std::make_tuple(indices...));
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const Tuple<Sptr<Indices>...>& indices)
|
||||
{
|
||||
sfor_pn<0,sizeof...(Indices)>
|
||||
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
|
||||
|
@ -328,7 +319,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(SizeT pos)
|
||||
{
|
||||
IB::mPos = pos;
|
||||
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
|
||||
|
@ -365,7 +356,7 @@ namespace CNORXZ
|
|||
|
||||
|
||||
template <class... Indices>
|
||||
int MultiIndex<Indices...>::pp(std::intptr_t idxPtrNum)
|
||||
int MultiIndex<Indices...>::pp(PtrId idxPtrNum)
|
||||
{
|
||||
const int tmp = RangeHelper::ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos += tmp;
|
||||
|
@ -373,7 +364,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
int MultiIndex<Indices...>::mm(std::intptr_t idxPtrNum)
|
||||
int MultiIndex<Indices...>::mm(PtrId idxPtrNum)
|
||||
{
|
||||
const int tmp = RangeHelper::mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||
IB::mPos -= tmp;
|
||||
|
@ -407,7 +398,7 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t MultiIndex<Indices...>::dim()
|
||||
SizeT MultiIndex<Indices...>::dim()
|
||||
{
|
||||
return sizeof...(Indices);
|
||||
}
|
||||
|
@ -425,21 +416,21 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Indices>
|
||||
std::shared_ptr<typename MultiIndex<Indices...>::RangeType>
|
||||
Sptr<typename MultiIndex<Indices...>::RangeType>
|
||||
MultiIndex<Indices...>::range()
|
||||
{
|
||||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto MultiIndex<Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
|
||||
{
|
||||
return std::get<N>(mIPack);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
size_t MultiIndex<Indices...>::getStepSize(size_t n)
|
||||
SizeT MultiIndex<Indices...>::getStepSize(SizeT n)
|
||||
{
|
||||
if(n >= sizeof...(Indices)){
|
||||
assert(0);
|
||||
|
@ -450,21 +441,21 @@ namespace CNORXZ
|
|||
|
||||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::ifor(size_t step, Exprs exs) const
|
||||
auto MultiIndex<Indices...>::ifor(SizeT step, Exprs exs) const
|
||||
{
|
||||
return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::iforh(size_t step, Exprs exs) const
|
||||
auto MultiIndex<Indices...>::iforh(SizeT step, Exprs exs) const
|
||||
{
|
||||
return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
template <class Exprs>
|
||||
auto MultiIndex<Indices...>::pifor(size_t step, Exprs exs) const
|
||||
auto MultiIndex<Indices...>::pifor(SizeT step, Exprs exs) const
|
||||
{
|
||||
return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs);
|
||||
}
|
||||
|
@ -474,19 +465,19 @@ namespace CNORXZ
|
|||
*************************/
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRangeFactory<Ranges...>::MultiRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
||||
MultiRangeFactory<Ranges...>::MultiRangeFactory(const Sptr<Ranges>&... rs)
|
||||
{
|
||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( rs... ) );
|
||||
mProd = Sptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( rs... ) );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRangeFactory<Ranges...>::MultiRangeFactory(const typename MultiRange<Ranges...>::Space& st)
|
||||
{
|
||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
||||
mProd = Sptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
||||
Sptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
||||
{
|
||||
mProd = checkIfCreated( std::dynamic_pointer_cast<oType>( mProd )->mSpace );
|
||||
setSelf();
|
||||
|
@ -494,14 +485,14 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& ptp)
|
||||
Sptr<RangeBase> MultiRangeFactory<Ranges...>::checkIfCreated(const Tuple<Sptr<Ranges>...>& ptp)
|
||||
{
|
||||
std::shared_ptr<RangeBase> out;
|
||||
Sptr<RangeBase> out;
|
||||
bool check = false;
|
||||
for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){
|
||||
if(x.second.size() == sizeof...(Ranges)){
|
||||
check = sfor_p<0,sizeof...(Ranges)>
|
||||
( [&](auto i) { return reinterpret_cast<std::intptr_t>( std::get<i>(ptp).get() ) == x.second[i]; },
|
||||
( [&](auto i) { return reinterpret_cast<PtrId>( std::get<i>(ptp).get() ) == x.second[i]; },
|
||||
[&](auto a, auto b) { return a and b; } );
|
||||
if(check){
|
||||
out = x.first;
|
||||
|
@ -510,9 +501,9 @@ namespace CNORXZ
|
|||
}
|
||||
}
|
||||
if(not check){
|
||||
vector<std::intptr_t> pv(sizeof...(Ranges));
|
||||
Vector<PtrId> pv(sizeof...(Ranges));
|
||||
sfor_pn<0,sizeof...(Ranges)>
|
||||
( [&](auto i) { pv[i] = reinterpret_cast<std::intptr_t>( std::get<i>(ptp).get() ); return 0; } );
|
||||
( [&](auto i) { pv[i] = reinterpret_cast<PtrId>( std::get<i>(ptp).get() ); return 0; } );
|
||||
MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
||||
out = mProd;
|
||||
}
|
||||
|
@ -524,33 +515,33 @@ namespace CNORXZ
|
|||
******************/
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...>::MultiRange(const std::shared_ptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {}
|
||||
MultiRange<Ranges...>::MultiRange(const Sptr<Ranges>&... rs) : mSpace(std::make_tuple(rs...)) {}
|
||||
|
||||
template <class... Ranges>
|
||||
MultiRange<Ranges...>::MultiRange(const Space& space) : mSpace( space ) {}
|
||||
|
||||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto MultiRange<Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
||||
{
|
||||
return *std::get<N>(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::getMeta(const MetaType& metaPos) const
|
||||
SizeT MultiRange<Ranges...>::getMeta(const MetaType& metaPos) const
|
||||
{
|
||||
return RangeHelper::getMeta<sizeof...(Ranges)-1>(mSpace,metaPos);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
template <size_t N>
|
||||
template <SizeT N>
|
||||
auto MultiRange<Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
||||
{
|
||||
return std::get<N>(mSpace);
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
std::shared_ptr<RangeBase> MultiRange<Indices...>::sub(size_t num) const
|
||||
Sptr<RangeBase> MultiRange<Indices...>::sub(SizeT num) const
|
||||
{
|
||||
assert(num < sizeof...(Indices));
|
||||
return sforx_p<0,sizeof...(Indices)>
|
||||
|
@ -559,13 +550,13 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::dim() const
|
||||
SizeT MultiRange<Ranges...>::dim() const
|
||||
{
|
||||
return sdim;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::size() const
|
||||
SizeT MultiRange<Ranges...>::size() const
|
||||
{
|
||||
return sfor_p<0,sizeof...(Ranges)>
|
||||
( [&](auto i) { return std::get<i>(mSpace)->size(); },
|
||||
|
@ -585,29 +576,29 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Ranges>
|
||||
vector<size_t> MultiRange<Ranges...>::typeNum() const
|
||||
Vector<SizeT> MultiRange<Ranges...>::typeNum() const
|
||||
{
|
||||
vector<size_t> o;
|
||||
Vector<SizeT> o;
|
||||
RangeHelper::getTypeNum<sizeof...(Ranges)-1>(o,mSpace);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::cmeta(char* target, size_t pos) const
|
||||
SizeT MultiRange<Ranges...>::cmeta(char* target, SizeT pos) const
|
||||
{
|
||||
const size_t off = cmetaSize();
|
||||
const SizeT off = cmetaSize();
|
||||
MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
||||
return RangeHelper::getCMeta<sizeof...(Ranges)-1>(xtarget,pos,mSpace,off);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
size_t MultiRange<Ranges...>::cmetaSize() const
|
||||
SizeT MultiRange<Ranges...>::cmetaSize() const
|
||||
{
|
||||
return RangeHelper::getCMetaSize<0>(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
std::string MultiRange<Ranges...>::stringMeta(size_t pos) const
|
||||
std::string MultiRange<Ranges...>::stringMeta(SizeT pos) const
|
||||
{
|
||||
auto i = begin();
|
||||
i = pos;
|
||||
|
@ -615,16 +606,16 @@ namespace CNORXZ
|
|||
}
|
||||
|
||||
template <class... Ranges>
|
||||
vector<char> MultiRange<Ranges...>::data() const
|
||||
Vector<char> MultiRange<Ranges...>::data() const
|
||||
{
|
||||
DataHeader h = dataHeader();
|
||||
vector<char> out;
|
||||
Vector<char> out;
|
||||
//out.reserve(h.metaSize + sizeof(DataHeader));
|
||||
char* hcp = reinterpret_cast<char*>(&h);
|
||||
out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
|
||||
sfor_pn<0,sizeof...(Ranges)>
|
||||
( [&](auto i) {
|
||||
vector<char> part = std::get<i>(mSpace)->data();
|
||||
Vector<char> part = std::get<i>(mSpace)->data();
|
||||
out.insert(out.end(), part.begin(), part.end());
|
||||
return 0;
|
||||
} );
|
||||
|
@ -646,7 +637,7 @@ namespace CNORXZ
|
|||
{
|
||||
MultiIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
||||
( Sptr<RangeBase>( RB::mThis ) ) );
|
||||
i = 0;
|
||||
return i;
|
||||
}
|
||||
|
@ -656,15 +647,15 @@ namespace CNORXZ
|
|||
{
|
||||
MultiIndex<typename Ranges::IndexType...>
|
||||
i( std::dynamic_pointer_cast<MultiRange<Ranges...> >
|
||||
( std::shared_ptr<RangeBase>( RB::mThis )) );
|
||||
( Sptr<RangeBase>( RB::mThis )) );
|
||||
i = size();
|
||||
return i;
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
template <class... ERanges>
|
||||
auto MultiRange<Ranges...>::cat(const std::shared_ptr<MultiRange<ERanges...> >& erange)
|
||||
-> std::shared_ptr<MultiRange<Ranges...,ERanges...> >
|
||||
auto MultiRange<Ranges...>::cat(const Sptr<MultiRange<ERanges...> >& erange)
|
||||
-> Sptr<MultiRange<Ranges...,ERanges...> >
|
||||
{
|
||||
auto crange = std::tuple_cat(mSpace, erange->space());
|
||||
MultiRangeFactory<Ranges...,ERanges...> rf(crange);
|
||||
|
|
|
@ -3,21 +3,12 @@
|
|||
#ifndef __cxz_range_base_h__
|
||||
#define __cxz_range_base_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "rbase_def.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
class RangeBase;
|
||||
}
|
||||
#include "base/base.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
size_t indexId();
|
||||
SizeT indexId();
|
||||
|
||||
enum class SpaceType
|
||||
{
|
||||
|
@ -33,17 +24,19 @@ namespace CNORXZ
|
|||
struct DataHeader
|
||||
{
|
||||
public:
|
||||
static constexpr size_t VERSION = 1; // fixed by version of this repository !
|
||||
static constexpr SizeT VERSION = 1; // fixed by version of this repository !
|
||||
private:
|
||||
size_t version = VERSION;
|
||||
SizeT version = VERSION;
|
||||
public:
|
||||
int spaceType = static_cast<int>( SpaceType::NONE );
|
||||
size_t metaSize = 0; // size of meta data
|
||||
SizeT metaSize = 0; // size of meta data
|
||||
int multiple = 0; // = 1 if multi range
|
||||
int metaType = 0; // type of meta data
|
||||
inline size_t v() const { return version; }
|
||||
inline SizeT v() const { return version; }
|
||||
};
|
||||
|
||||
typedef Sptr<RangeBase> RangePtr;
|
||||
|
||||
class RangeFactoryBase
|
||||
{
|
||||
public:
|
||||
|
@ -51,19 +44,25 @@ namespace CNORXZ
|
|||
RangeFactoryBase() = default;
|
||||
virtual ~RangeFactoryBase() = default;
|
||||
|
||||
// should return mProd !!
|
||||
virtual std::shared_ptr<RangeBase> create() = 0;
|
||||
RangePtr create();
|
||||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<RangeBase> mProd;
|
||||
virtual void make() = 0;
|
||||
|
||||
RangePtr fromCreated(const TypeInfo& info, const Vector<PtrId>& rids) const;
|
||||
void addToCreated(const TypeInfo& info, const Vector<PtrId>& rids, const RangePtr& r);
|
||||
|
||||
RangePtr mProd;
|
||||
|
||||
private:
|
||||
// also add single ranges here (PtrId -> own)
|
||||
static Map<TypeInfo,Map<Vector<PtrId>,RangePtr>> sCreated;
|
||||
|
||||
// call this function before returning product !!
|
||||
void setSelf();
|
||||
};
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(const char** dp);
|
||||
std::shared_ptr<RangeFactoryBase> createSingleRangeFactory(const vector<char>*& d, int metaType, size_t size);
|
||||
Sptr<RangeFactoryBase> createRangeFactory(const char** dp);
|
||||
Sptr<RangeFactoryBase> createSingleRangeFactory(const Vector<char>*& d, int metaType, SizeT size);
|
||||
|
||||
class RangeBase
|
||||
{
|
||||
|
@ -71,28 +70,28 @@ namespace CNORXZ
|
|||
|
||||
virtual ~RangeBase() = default;
|
||||
|
||||
virtual size_t size() const = 0;
|
||||
virtual size_t dim() const = 0;
|
||||
virtual SizeT size() const = 0;
|
||||
virtual SizeT dim() const = 0;
|
||||
|
||||
bool operator==(const RangeBase& in) const;
|
||||
bool operator!=(const RangeBase& in) const;
|
||||
|
||||
std::intptr_t id() const;
|
||||
virtual TypeInfo type() const = 0;
|
||||
PtrId id() const;
|
||||
|
||||
XIndexPtr beginX() const;
|
||||
XIndexPtr endX() const;
|
||||
|
||||
virtual vector<size_t> typeNum() const = 0;
|
||||
virtual size_t cmeta(char* target, size_t pos) const = 0;
|
||||
virtual size_t cmetaSize() const = 0;
|
||||
virtual std::string stringMeta(size_t pos) const = 0;
|
||||
virtual vector<char> data() const = 0; // usefull when writing to files, etc...
|
||||
virtual Vector<SizeT> typeNum() const = 0;
|
||||
virtual SizeT cmeta(char* target, SizeT pos) const = 0;
|
||||
virtual SizeT cmetaSize() const = 0;
|
||||
virtual String stringMeta(SizeT pos) const = 0;
|
||||
virtual Vector<char> data() const = 0; // usefull when writing to files, etc...
|
||||
|
||||
virtual SpaceType spaceType() const = 0;
|
||||
virtual DataHeader dataHeader() const = 0;
|
||||
|
||||
virtual std::shared_ptr<RangeBase> sub(size_t num) const { return std::shared_ptr<RangeBase>(); }
|
||||
virtual std::shared_ptr<IndexWrapperBase> aindex() const = 0;
|
||||
virtual RangePtr sub(SizeT num) const { return RangePtr(); }
|
||||
|
||||
friend RangeFactoryBase;
|
||||
|
||||
|
@ -103,7 +102,7 @@ namespace CNORXZ
|
|||
};
|
||||
|
||||
template <class Index>
|
||||
inline std::shared_ptr<IndexWrapperBase> mkIndexWrapper(const Index& i);
|
||||
inline Sptr<IndexWrapperBase> mkIndexWrapper(const Index& i);
|
||||
|
||||
template <class Index>
|
||||
class RangeInterface : public RangeBase
|
||||
|
@ -117,18 +116,15 @@ namespace CNORXZ
|
|||
|
||||
virtual Index begin() const = 0;
|
||||
virtual Index end() const = 0;
|
||||
std::shared_ptr<Index> beginPtr() const { return std::make_shared<Index>(this->begin()); }
|
||||
std::shared_ptr<Index> endPtr() const { return std::make_shared<Index>(this->end()); }
|
||||
virtual std::shared_ptr<IndexWrapperBase> aindex() const override final
|
||||
Sptr<Index> beginPtr() const { return std::make_shared<Index>(this->begin()); }
|
||||
Sptr<Index> endPtr() const { return std::make_shared<Index>(this->end()); }
|
||||
virtual Sptr<IndexWrapperBase> aindex() const override final
|
||||
{ return mkIndexWrapper(this->begin()); }
|
||||
//{ auto i = std::make_shared<Index>(this->begin()); return std::make_shared<IndexWrapper<Index>>(i); } //!!!
|
||||
//{ auto i = std::make_shared<Index>(this->begin()); return nullptr; } //!!!
|
||||
|
||||
protected:
|
||||
RangeInterface() = default;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<RangeBase> RangePtr;
|
||||
|
||||
RangePtr operator*(const RangePtr& a, const RangePtr& b); // -> Ptr to MultiRange
|
||||
}
|
||||
|
|
2
src/include/ranges/ranges.cc.h
Normal file
2
src/include/ranges/ranges.cc.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
#include "xindex.cc.h"
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue