fix some of the recently introduced compile errors

This commit is contained in:
Christian Zimmermann 2022-09-13 00:31:12 +02:00
parent 796bb50118
commit 0ec807c8fa
21 changed files with 210 additions and 303 deletions

View file

@ -4,3 +4,5 @@
#include "darray.h" #include "darray.h"
#include "dcontainer_index.h" #include "dcontainer_index.h"
//#include "functional_array.h" //#include "functional_array.h"
#include "array.cc.h"

View file

@ -11,4 +11,6 @@
#include "obj_handle.h" #include "obj_handle.h"
#include "dtype.h" #include "dtype.h"
#include "base.cc.h"
#endif #endif

View file

@ -14,14 +14,14 @@ namespace CNORXZ
template <typename T> template <typename T>
DType::DType(const T& d) : mD(d) DType::DType(const T& d) : mD(d)
{ {
_mkToStr(); _mkToStr<T>();
} }
template <typename T> template <typename T>
DType& DType::operator=(const T& d) DType& DType::operator=(const T& d)
{ {
mD = d; mD = d;
_mkToStr(); _mkToStr<T>();
return *this; return *this;
} }

View file

@ -8,29 +8,29 @@ namespace CNORXZ
{ {
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle() : mC(std::make_unique<T>()) {} ObjHandle<T>::ObjHandle() {}
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle(const T& a) : mC(std::make_unique<T>(a)) {} ObjHandle<T>::ObjHandle(const T& a) : mC(std::make_unique<T>(a)) {}
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle(const Uptr<T>& a) : mC(a) {} ObjHandle<T>::ObjHandle(Uptr<T>&& a) : mC(std::forward<Uptr<T>>(a)) {}
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle(const ObjHandle& a) : mC(std::make_unique<T>(*a.mC)) {} ObjHandle<T>::ObjHandle(const ObjHandle& a) : mC(a.mC->copy()) {}
template <typename T> template <typename T>
ObjHandle<T>::ObjHandle(ObjHandle&& a) : mC(a.mC) {} ObjHandle<T>::ObjHandle(ObjHandle&& a) : mC(a.mC) {}
template <typename T> template <typename T>
ObjHandle& ObjHandle<T>::operator=(const ObjHandle& a) ObjHandle<T>& ObjHandle<T>::operator=(const ObjHandle& a)
{ {
mC = std::make_unique<T>(*a.mC); mC = std::make_unique<T>(*a.mC);
return *this; return *this;
} }
template <typename T> template <typename T>
ObjHandle& ObjHandle<T>::operator=(ObjHandle&& a) ObjHandle<T>& ObjHandle<T>::operator=(ObjHandle&& a)
{ {
mC = a.mC; mC = a.mC;
return *this; return *this;

View file

@ -19,12 +19,12 @@ namespace CNORXZ
ObjHandle(); ObjHandle();
ObjHandle(const T& a); ObjHandle(const T& a);
ObjHandle(const Uptr<T>& a); ObjHandle(Uptr<T>&& a);
ObjHandle(const ObjHandle& a); ObjHandle(const ObjHandle& a);
ObjHandle(ObjHandle&& a); ObjHandle(ObjHandle&& a);
ObjHandle& operator=(const ObjHandle& a); ObjHandle& operator=(const ObjHandle& a);
ObjHandle& operator=(ObjHandle&& a); ObjHandle& operator=(ObjHandle&& a);
T& operator*(); T& operator*();
T* operator->(); T* operator->();
const T& operator*() const; const T& operator*() const;

View file

@ -8,7 +8,7 @@
namespace CNORXZ namespace CNORXZ
{ {
template <typename T> template <typename T>
String toString(const T& a) String ToString<T>::func(const T& a)
{ {
std::stringstream ss; std::stringstream ss;
ss << a; ss << a;
@ -16,7 +16,7 @@ namespace CNORXZ
} }
template <typename T> template <typename T>
String toString<vector<T>>(const vector& a) String ToString<vector<T>>::func(const vector& a)
{ {
std::stringstream ss; std::stringstream ss;
ss << "["; ss << "[";
@ -29,7 +29,7 @@ namespace CNORXZ
} }
template <typename T, size_t N> template <typename T, size_t N>
String toString<std::array<T,N>>(const std::array<T,N>& a) String ToString<std::array<T,N>>::func(const std::array<T,N>& a)
{ {
std::stringstream ss; std::stringstream ss;
ss << "("; ss << "(";
@ -42,11 +42,16 @@ namespace CNORXZ
} }
template <> template <>
String toString<DType>(const DType& a) String ToString<DType>::func(const DType& a)
{ {
return a.str(); return a.str();
} }
template <typename T>
String toString(const T& a)
{
return ToString::func(a);
}
} }
#endif #endif

View file

@ -3,21 +3,36 @@
#define __cxz_to_string_h__ #define __cxz_to_string_h__
#include "types.h" #include "types.h"
#include <array>
namespace CNORXZ namespace CNORXZ
{ {
template <typename T> template <typename T>
String toString(const T& a); struct ToString
{
static String func(const T& a);
};
template <typename T> template <typename T>
String toString<vector<T>>(const vector& a); struct ToString<Vector<T>>
{
static String func(const Vector<T>& a);
};
template <typename T, size_t N> template <typename T, SizeT N>
String toString<std::array<T,N>>(const std::array<T,N>& a); struct ToString<Arr<T,N>>
{
static String func(const Arr<T,N>& a);
};
template <> template <>
String toString<DType>(const DType& a); struct ToString<DType>
{
static String func(const DType& a);
};
template <typename T>
String toString(const T& a);
} }
#endif #endif

View file

@ -40,18 +40,32 @@ namespace CNORXZ
template <typename... T> template <typename... T>
using Tuple = std::tuple<T...>; using Tuple = std::tuple<T...>;
template <typename... T> template <SizeT I, typename... T>
using TupleElem = std::tuple_element<T...>; using TupleElem = std::tuple_element<I,Tuple<T...>>;
template <typename K, typename V> template <typename K, typename V>
using Map = std::map<K,V>; using Map = std::map<K,V>;
typedef std::typeinfo TypeInfo; typedef std::type_info TypeInfo;
/********************* /*********************
* library types * * library types *
*********************/ *********************/
/***
Naming Prefixes:
D = Y = Dynamic
V = X = Virtual
S = Static
P = Partial = Sub
C = Classic
M = Multi or !const
U = One(=Uni) dimensional
N = None = Null
T = Thread
R = Rank
***/
// definition: base/dtype.h // definition: base/dtype.h
class DType; class DType;
@ -74,6 +88,7 @@ namespace CNORXZ
class DPos; class DPos;
// definition: ranges/xfor/exttype.h // definition: ranges/xfor/exttype.h
template <class PosT>
class VPos; class VPos;
// definition: ranges/xfor/exttype.h // definition: ranges/xfor/exttype.h
@ -134,12 +149,16 @@ namespace CNORXZ
// definition: ranges/xindex.h // definition: ranges/xindex.h
class XIndexBase; // dynamic index wrapper class XIndexBase; // dynamic index wrapper
typedef Sptr<XIndexBase> XIndexPtr;
// definition: ranges/yrange.h // definition: ranges/yrange.h
class YRange; // dynamic multi range class YRange; // dynamic multi range
// definition: ranges/yrange.h // definition: ranges/yrange.h
class YIndex; class YIndex;
typedef Sptr<YIndex> YIndexPtr;
// definition: ranges/pindex.h // definition: ranges/pindex.h
template <class Index> template <class Index>
class PIndex; // partial index (index over sub-ranges and permutations) class PIndex; // partial index (index over sub-ranges and permutations)

View file

@ -19,11 +19,9 @@ namespace CNORXZ
template <typename T> template <typename T>
class Allocator class Allocator
{ {
private:
static SizeT sMemUsage;
public: public:
static SizeT memUsage() { return sMemUsage; }
typedef T value_type;
static constexpr SizeT type_size = sizeof(T); static constexpr SizeT type_size = sizeof(T);
static constexpr SizeT N = 32; // get from environment!!! static constexpr SizeT N = 32; // get from environment!!!
@ -48,15 +46,6 @@ namespace CNORXZ
template <class T, class U> template <class T, class U>
bool operator!=(const Allocator<T>& a, const Allocator<U>& b); 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 } // namespace CNORXZ

View file

@ -2,7 +2,6 @@
#ifndef __cxz_memcount_h__ #ifndef __cxz_memcount_h__
#define __cxz_memcount_h__ #define __cxz_memcount_h__
#include "allocator_d.h"
#include "base/types.h" #include "base/types.h"
namespace CNORXZ namespace CNORXZ
@ -15,10 +14,11 @@ namespace CNORXZ
static void sub(SizeT x) { sMemUsage -= x; } static void sub(SizeT x) { sMemUsage -= x; }
public: public:
MemCount() = delete(); // static only MemCount() = delete; // static only
static SizeT usage() { return sMemUsage; } static SizeT usage() { return sMemUsage; }
friend Allocator; template <typename T>
friend class Allocator;
}; };
} // namespace CNORXZ } // namespace CNORXZ

View file

@ -1,3 +1,5 @@
#include "allocator.h" #include "allocator.h"
#include "memcount.h" #include "memcount.h"
#include "memory.cc.h"

View file

@ -72,7 +72,7 @@ namespace CNORXZ
IndexInterface& operator=(IndexInterface&& in); IndexInterface& operator=(IndexInterface&& in);
IndexInterface(SizeT pos); IndexInterface(SizeT pos);
IndexPtr mRel = nullptr; IndexPtr<I,MetaType> mRel = nullptr;
SizeT mPos = 0; SizeT mPos = 0;
PtrId mPtrId = 0; PtrId mPtrId = 0;
}; };

View file

@ -4,6 +4,9 @@
#define __cxz_range_base_h__ #define __cxz_range_base_h__
#include "base/base.h" #include "base/base.h"
#include "base/base.cc.h"
#include "memory/memory.h"
#include "memory/memory.cc.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -29,7 +32,7 @@ namespace CNORXZ
private: private:
// also add single ranges here (PtrId -> own) // also add single ranges here (PtrId -> own)
// rangeCast: PtrId -> original Range // rangeCast: PtrId -> original Range
static Map<TypeInfo,Map<Vector<PtrId>,RangePtr>> sCreated; static Map<SizeT,Map<Vector<PtrId>,RangePtr>> sCreated;
}; };

View file

@ -8,3 +8,5 @@
//#include "value_range.h" //#include "value_range.h"
#include "xindex.h" #include "xindex.h"
#include "yindex.h" #include "yindex.h"
#include "ranges.cc.h"

View file

@ -2,9 +2,9 @@
#ifndef __cxz_exttype_h__ #ifndef __cxz_exttype_h__
#define __cxz_exttype_h__ #define __cxz_exttype_h__
#include <array> #include "base/base.h"
namespace CNORXZInternal namespace CNORXZ
{ {
// Dynamic Ext: ObjHandl<ExtBase> // Dynamic Ext: ObjHandl<ExtBase>
@ -14,7 +14,8 @@ namespace CNORXZInternal
{ {
public: public:
DEFAULT_MEMBERS(VPosBase); DEFAULT_MEMBERS(VPosBase);
virtual Uptr<VPosBase> copy() const = 0;
virtual SizeT vsize() const = 0; virtual SizeT vsize() const = 0;
virtual const SizeT& vval() const = 0; virtual const SizeT& vval() const = 0;
virtual VPosBase& vzero() = 0; virtual VPosBase& vzero() = 0;
@ -31,9 +32,9 @@ namespace CNORXZInternal
PosT& THIS() { return static_cast<PosT&>(*this); } PosT& THIS() { return static_cast<PosT&>(*this); }
const PosT& THIS() const { return static_cast<const PosT&>(*this); } const PosT& THIS() const { return static_cast<const PosT&>(*this); }
inline SizeT size() const { THIS().size(); } inline SizeT size() const { return THIS().size(); }
inline const SizeT& val() const { THIS().val(); } inline const SizeT& val() const { return THIS().val(); }
inline auto next() const { THIS().next(); } inline auto next() const { return THIS().next(); }
inline bool operator==(const PosInterface<PosT>& a) const { return val() == a.val() and next() == a.next(); } inline bool operator==(const PosInterface<PosT>& a) const { return val() == a.val() and next() == a.next(); }
inline bool operator!=(const PosInterface<PosT>& a) const { return val() != a.val() or next() != a.next(); } inline bool operator!=(const PosInterface<PosT>& a) const { return val() != a.val() or next() != a.next(); }
inline bool operator==(SizeT a) const { return val() == a and next() == a; } inline bool operator==(SizeT a) const { return val() == a and next() == a; }
@ -51,18 +52,18 @@ namespace CNORXZInternal
{ {
public: public:
DEFAULT_MEMBERS(DPos); DEFAULT_MEMBERS(DPos);
DPos(Uptr<VPosBase> a) : ObjHandle<VPosBase>(a) {} DPos(Uptr<VPosBase>&& a) : ObjHandle<VPosBase>(std::forward<Uptr<VPosBase>>(a)) {}
template <class PosT> template <class PosT>
DPos(const PosT& a) : ObjHandle<VPosBase>( std::make_unique<PosT>(a) ) {} DPos(const PosT& a) : ObjHandle<VPosBase>( std::make_unique<PosT>(a) ) {}
inline SizeT size() const { return mC->vsize(); } inline SizeT size() const { return mC->vsize(); }
inline const SizeT& val() const { return mC->vval(); } inline const SizeT& val() const { return mC->vval(); }
inline DPos& zero() { mC->vzero(); return *this; } inline DPos& zero() { mC->vzero(); return *this; }
template <class P> template <class P>
inline DPos extend(const PosInterface<P>& a) const inline DPos extend(const PosInterface<P>& a) const
{ /* append MPos<NPos> in static for loop over entries */ } { return DPos();/* append MPos<NPos> in static for loop over entries */ }
}; };
/* /*
@ -104,13 +105,14 @@ namespace CNORXZInternal
VPos(const PosInterface<PosT>& a) : PosT(a.THIS()) {} VPos(const PosInterface<PosT>& a) : PosT(a.THIS()) {}
virtual SizeT vsize() const override final { return THIS().size(); } virtual Uptr<VPosBase> copy() const override final { return std::make_unique<VPos>(*this); }
virtual const SizeT& vval() const override final { return THIS().val(); } virtual SizeT vsize() const override final { return PosT::THIS().size(); }
virtual VPos& vzero() override final { THIS().zero(); return *this; } virtual const SizeT& vval() const override final { return PosT::THIS().val(); }
virtual VPos& vzero() override final { PosT::THIS().zero(); return *this; }
virtual Uptr<VPosBase> vextend(const DPos& a) const override final virtual Uptr<VPosBase> vextend(const DPos& a) const override final
{ return std::make_unique<VPosBase>( THIS().extend(a) ); } { return std::make_unique<VPosBase>( PosT::THIS().extend(a) ); }
virtual Uptr<VPosBase> vextend(const MPos<NPos>& a) const override final virtual Uptr<VPosBase> vextend(const MPos<NPos>& a) const override final
{ return std::make_unique<VPosBase>( THIS().extend(a) ); } // ??? if that works it would be a miracle ??? { return std::make_unique<VPosBase>( PosT::THIS().extend(a) ); } // ??? if that works it would be a miracle ???
// .... probably I need to define a static instanciation limit... // .... probably I need to define a static instanciation limit...
}; };
@ -268,7 +270,7 @@ namespace CNORXZInternal
inline MPos<NPos> mkExt(SizeT s) { return MPos<NPos>(s); } inline MPos<NPos> mkExt(SizeT s) { return MPos<NPos>(s); }
/*
template <size_t I, class X> template <size_t I, class X>
auto getX(const MPos<X>& et) auto getX(const MPos<X>& et)
{ {
@ -315,6 +317,7 @@ namespace CNORXZInternal
{ {
return getX<I>(et).get(); return getX<I>(et).get();
} }
*/
} // end namespace CNORXZInternal } // end namespace CNORXZInternal
@ -322,17 +325,17 @@ namespace CNORXZInternal
* --- TEMPLATE CODE --- * * --- TEMPLATE CODE --- *
* ========================= */ * ========================= */
namespace CNORXZInternal namespace CNORXZ
{ {
template <class X> template <class X>
inline MPos<X>::MPos(size_t ext, X next) : mExt(ext), mNext(next) {} inline MPos<X>::MPos(size_t ext, X next) : mExt(ext), mNext(next) {}
/*
template <class X> template <class X>
template <size_t N> template <size_t N>
inline MPos<X>::MPos(const std::array<size_t,N>& arr) : inline MPos<X>::MPos(const std::array<size_t,N>& arr) :
mExt(std::get<NUM>(arr)), mNext(arr) {} mExt(std::get<NUM>(arr)), mNext(arr) {}
*/
template <class X> template <class X>
template <class Z> template <class Z>
inline MPos<X>::MPos(size_t y, const Z& z) : inline MPos<X>::MPos(size_t y, const Z& z) :
@ -366,14 +369,14 @@ namespace CNORXZInternal
mExt = 0u; mExt = 0u;
mNext.zero(); mNext.zero();
} }
/*
template <class X> template <class X>
template <size_t N> template <size_t N>
inline auto MPos<X>::nn() const inline auto MPos<X>::nn() const
{ {
return getX<N>(*this); return getX<N>(*this);
} }
*/
template <class X> template <class X>
inline MPos<X> MPos<X>::operator+(const MPos<X>& in) const inline MPos<X> MPos<X>::operator+(const MPos<X>& in) const
{ {
@ -407,12 +410,12 @@ namespace CNORXZInternal
inline MPos<NPos>::MPos(const Y& y, const Z& z) : inline MPos<NPos>::MPos(const Y& y, const Z& z) :
mExt(y.val()) {} mExt(y.val()) {}
/*
//template <> //template <>
template <size_t N> template <size_t N>
inline MPos<NPos>::MPos(const std::array<size_t,N>& arr) : inline MPos<NPos>::MPos(const std::array<size_t,N>& arr) :
mExt(std::get<NUM>(arr)) {} mExt(std::get<NUM>(arr)) {}
*/
template <class Y> template <class Y>
inline MPos<NPos>::MPos(const MPos<Y>& y) : inline MPos<NPos>::MPos(const MPos<Y>& y) :
mExt(y.val()) {} mExt(y.val()) {}
@ -422,13 +425,13 @@ namespace CNORXZInternal
{ {
mExt = 0u; mExt = 0u;
} }
/*
template <size_t N> template <size_t N>
inline auto MPos<NPos>::nn() const inline auto MPos<NPos>::nn() const
{ {
return getX<N>(*this); return getX<N>(*this);
} }
*/
inline const size_t& MPos<NPos>::val() const inline const size_t& MPos<NPos>::val() const
{ {
return mExt; return mExt;
@ -450,14 +453,14 @@ namespace CNORXZInternal
{ {
return MPos<NPos>(mExt * in); return MPos<NPos>(mExt * in);
} }
/*
template <class X> template <class X>
template <size_t N> template <size_t N>
inline auto DVPosX<X>::nn() const inline auto DVPosX<X>::nn() const
{ {
return getX<N>(*this); return getX<N>(*this);
} }
*/
} // end namespace CNORXZInternal } // end namespace CNORXZInternal

View file

@ -21,7 +21,7 @@ namespace CNORXZ
DEFAULT_MEMBERS(ExprInterface); DEFAULT_MEMBERS(ExprInterface);
Xpr& THIS() { return static_cast<Xpr&>(*this); } Xpr& THIS() { return static_cast<Xpr&>(*this); }
const Xpr& THIS() const { return static_cast<const Expr&>(*this); } const Xpr& THIS() const { return static_cast<const Xpr&>(*this); }
//Sptr<Expr> copy() const { THIS().copy(); } //Sptr<Expr> copy() const { THIS().copy(); }
@ -37,29 +37,34 @@ namespace CNORXZ
public: public:
DEFAULT_MEMBERS(VExprBase); DEFAULT_MEMBERS(VExprBase);
virtual void vexec(SizeT mlast, PosT last) = 0; virtual Uptr<VExprBase> copy() const = 0;
virtual void vexec(SizeT mlast, DPos last) = 0;
virtual void vexec(SizeT mlast) = 0; virtual void vexec(SizeT mlast) = 0;
virtual DPos vrootSteps(PtrId ptrId) const = 0; virtual DPos vrootSteps(PtrId ptrId) const = 0;
virtual DPos vextension() const = 0; virtual DPos vextension() const = 0;
}; };
template <class Xpr> template <class Xpr, class PosT>
class VExpr : public VExprBase, public Xpr class VExpr : public VExprBase, public Xpr
{ {
public: public:
typedef ExprInterface<Xpr,PosT> EI;
DEFAULT_MEMBERS(VExpr); DEFAULT_MEMBERS(VExpr);
VExpr(const ExprInterface<Xpr>& a) : Xpr(a.THIS()) {} VExpr(const ExprInterface<Xpr,PosT>& a) : Xpr(a.THIS()) {}
virtual void vexec(SizeT mlast, PosT last) override final { THIS()(mlast,last); } virtual Uptr<VExprBase> copy() const override final { return std::make_unique<VExpr>(*this); }
virtual void vexec(SizeT mlast) override final { THIS()(mlast); }
virtual DPos vrootSteps(PtrId ptrId) const override final { return THIS().rootSteps(ptrId); } virtual void vexec(SizeT mlast, DPos last) override final { EI::THIS()(mlast,last); }
virtual DPos vextension() const override final { return THIS().extension(); } virtual void vexec(SizeT mlast) override final { EI::THIS()(mlast); }
virtual DPos vrootSteps(PtrId ptrId) const override final { return EI::THIS().rootSteps(ptrId); }
virtual DPos vextension() const override final { return EI::THIS().extension(); }
}; };
class DExpr : public ObjHandle<VExprBase>, class DExpr : public ObjHandle<VExprBase>,
public ExprInterface<DExpr> public ExprInterface<DExpr,DPos>
{ {
public: public:
DEFAULT_MEMBERS(DExpr); DEFAULT_MEMBERS(DExpr);
@ -70,7 +75,7 @@ namespace CNORXZ
inline DPos rootSteps(PtrId ptrId) const { return mC->vrootSteps(ptrId); } inline DPos rootSteps(PtrId ptrId) const { return mC->vrootSteps(ptrId); }
inline DPos extension() const { return mC->vextension(); } inline DPos extension() const { return mC->vextension(); }
}; };
/*
template <ForType FT = ForType::DEFAULT> template <ForType FT = ForType::DEFAULT>
struct PosForward struct PosForward
{ {
@ -106,7 +111,7 @@ namespace CNORXZ
SubExpr() = default; SubExpr() = default;
const IndexClass* mIndPtr; const IndexClass* mIndPtr;
std::intptr_t mSIPtr; PtrId mSIPtr;
size_t mSPos; size_t mSPos;
size_t mMax; size_t mMax;
@ -114,7 +119,7 @@ namespace CNORXZ
typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType; typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType;
ExtType mExt; ExtType mExt;
const vector<size_t>* mSubSet; const Vector<SizeT>* mSubSet;
mutable ExtType mRootSteps; mutable ExtType mRootSteps;
@ -144,7 +149,7 @@ namespace CNORXZ
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType; auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
auto extension() const -> ExtType; auto extension() const -> ExtType;
}; };
/*
template <ForType FT, size_t LAYER> template <ForType FT, size_t LAYER>
struct NHLayer struct NHLayer
{ {
@ -174,7 +179,7 @@ namespace CNORXZ
return Expr::LAYER; return Expr::LAYER;
} }
}; };
*/
template <class IndexClass, class Expr, ForType FT, size_t DIV> template <class IndexClass, class Expr, ForType FT, size_t DIV>
class For : public ExpressionBase class For : public ExpressionBase
{ {
@ -290,26 +295,21 @@ namespace CNORXZ
}; };
*/
} }
/* ========================= * /* ========================= *
* --- TEMPLATE CODE --- * * --- TEMPLATE CODE --- *
* ========================= */ * ========================= */
#include <iostream>
namespace CNORXZInternal namespace CNORXZ
{ {
template <class ExtType>
const ExtType& ExtBase::expl() const
{
return dynamic_cast<const ExtT<ExtType>*>(this)->ext();
}
/***************** /*****************
* F o r * * F o r *
*****************/ *****************/
/*
template <class IndexClass, class Expr, ForType FT, size_t DIV> template <class IndexClass, class Expr, ForType FT, size_t DIV>
For<IndexClass,Expr,FT,DIV>::For(const Sptr<IndexClass>& indPtr, For<IndexClass,Expr,FT,DIV>::For(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr) : size_t step, Expr expr) :
@ -402,11 +402,11 @@ namespace CNORXZInternal
static_assert(FT == ForType::DEFAULT, "hidden for not parallelizable"); static_assert(FT == ForType::DEFAULT, "hidden for not parallelizable");
return PFor<IndexClass,Expr,DIV>(mIndPtr, mStep, mExpr); return PFor<IndexClass,Expr,DIV>(mIndPtr, mStep, mExpr);
} }
*/
/****************** /******************
* P F o r * * P F o r *
******************/ ******************/
/*
template <class IndexClass, class Expr, size_t DIV> template <class IndexClass, class Expr, size_t DIV>
PFor<IndexClass,Expr,DIV>::PFor(const Sptr<IndexClass>& indPtr, PFor<IndexClass,Expr,DIV>::PFor(const Sptr<IndexClass>& indPtr,
size_t step, Expr expr) : size_t step, Expr expr) :
@ -508,98 +508,12 @@ namespace CNORXZInternal
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt), //return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t)); // sizeof(ExtType)/sizeof(size_t));
} }
*/
/************************
* SingleExpression *
************************/
template <class IndexClass, class Expr>
SingleExpression<IndexClass,Expr>::SingleExpression(const Sptr<IndexClass>& indPtr,
Expr expr) :
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mIndPtr != nullptr);
//VCHECK(mIndPtr->id());
//VCHECK(mIndPtr->max());
}
template <class IndexClass, class Expr>
SingleExpression<IndexClass,Expr>::SingleExpression(const IndexClass* indPtr,
Expr expr) :
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
{
assert(mIndPtr != nullptr);
//VCHECK(mIndPtr->id());
//VCHECK(mIndPtr->max());
}
template <class IndexClass, class Expr>
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast, DExt last)
{
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
}
template <class IndexClass, class Expr>
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast,
ExtType last)
{
//typedef typename IndexClass::RangeType RangeType;
const size_t pos = mIndPtr->pos();
const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos);
const ExtType npos = last + mExt*pos;
mExpr(mnpos, npos);
}
template <class IndexClass, class Expr>
inline void SingleExpression<IndexClass,Expr>::operator()(size_t mlast)
{
//typedef typename IndexClass::RangeType RangeType;
ExtType last = rootSteps();
last.zero();
const size_t pos = mIndPtr->pos();
const size_t mnpos = PosForward<ForType::DEFAULT>::value(mlast, mMax, pos);
const ExtType npos = last + mExt*pos;
mExpr(mlast, last);
}
template <class IndexClass, class Expr>
auto SingleExpression<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return mExpr.rootSteps(iPtrNum);
}
template <class IndexClass, class Expr>
auto SingleExpression<IndexClass,Expr>::extension() const
-> ExtType
{
return mExt;
}
template <class IndexClass, class Expr>
DExt SingleExpression<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
{
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
//mRootSteps = rootSteps(iPtrNum);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mRootSteps),
// sizeof(ExtType)/sizeof(size_t));
}
template <class IndexClass, class Expr>
DExt SingleExpression<IndexClass,Expr>::dExtension() const
{
return std::make_shared<ExtT<ExtType>>(mExt);
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t));
}
/**************** /****************
* SubExpr * * SubExpr *
****************/ ****************/
/*
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const Sptr<IndexClass>& indPtr, SubExpr<IndexClass,Expr>::SubExpr(const Sptr<IndexClass>& indPtr,
std::intptr_t siptr, std::intptr_t siptr,
@ -682,11 +596,11 @@ namespace CNORXZInternal
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt), //return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
// sizeof(ExtType)/sizeof(size_t)); // sizeof(ExtType)/sizeof(size_t));
} }
*/
/*************************** /***************************
* DynamicExpression * * DynamicExpression *
***************************/ ***************************/
/*
inline void DynamicExpression::operator()(size_t mlast, DExt last) inline void DynamicExpression::operator()(size_t mlast, DExt last)
{ {
(*mNext)(mlast,last); (*mNext)(mlast,last);
@ -707,62 +621,7 @@ namespace CNORXZInternal
return mNext->dExtension(); return mNext->dExtension();
} }
/************************ */
* ExpressionHolder *
************************/
template <class Expr>
ExpressionHolder<Expr>::ExpressionHolder(DynamicExpression expr) : mExpr(expr) {}
template <class Expr>
inline void ExpressionHolder<Expr>::operator()(size_t mlast, DExt last)
{
mExpr(mlast,last);
}
template <class Expr>
inline void ExpressionHolder<Expr>::operator()(size_t mlast, ExtType last)
{
mExpr(mlast,
std::make_shared<ExtT<ExtType>>(last));
}
template <class Expr>
inline void ExpressionHolder<Expr>::operator()(size_t mlast)
{
mExpr(mlast);
}
template <class Expr>
DExt ExpressionHolder<Expr>::dRootSteps(std::intptr_t iPtrNum) const
{
return mExpr.dRootSteps(iPtrNum);
}
template <class Expr>
DExt ExpressionHolder<Expr>::dExtension() const
{
return mExpr.dExtension();
}
template <class Expr>
auto ExpressionHolder<Expr>::rootSteps(std::intptr_t iPtrNum) const
-> ExtType
{
return std::dynamic_pointer_cast<ExtT<ExtType>>(mExpr.dRootSteps(iPtrNum))->ext();
//return *reinterpret_cast<ExtType const*>( mExpr.dRootSteps(iPtrNum).first );
}
template <class Expr>
auto ExpressionHolder<Expr>::extension() const
-> ExtType
{
return std::dynamic_pointer_cast<ExtT<ExtType>>(mExpr.dExtension())->ext();
//return *reinterpret_cast<ExtType const*>( mExpr.dExtension().first );
}
} // namespace CNORXZInternal } // namespace CNORXZInternal
#endif #endif

View file

@ -14,7 +14,7 @@ namespace CNORXZ
XIndex<Index,Meta>::XIndex(const IndexPtr<Index,Meta>& i) : mI(i) {} XIndex<Index,Meta>::XIndex(const IndexPtr<Index,Meta>& i) : mI(i) {}
template <class Index, typename Meta> template <class Index, typename Meta>
XIndex<Index,Meta>& XIndex<Index,Meta>::operator=(size_t pos) XIndex<Index,Meta>& XIndex<Index,Meta>::operator=(SizeT pos)
{ {
*mI = pos; *mI = pos;
return *this; return *this;
@ -35,31 +35,31 @@ namespace CNORXZ
} }
template <class Index, typename Meta> template <class Index, typename Meta>
int XIndex<Index,Meta>::pp(std::intptr_t idxPtrNum) Int XIndex<Index,Meta>::pp(PtrId idxPtrNum)
{ {
return mI->pp(idxPtrNum); return mI->pp(idxPtrNum);
} }
template <class Index, typename Meta> template <class Index, typename Meta>
int XIndex<Index,Meta>::mm(std::intptr_t idxPtrNum) Int XIndex<Index,Meta>::mm(PtrId idxPtrNum)
{ {
return mI->mm(idxPtrNum); return mI->mm(idxPtrNum);
} }
template <class Index, typename Meta> template <class Index, typename Meta>
size_t XIndex<Index,Meta>::dim() const SizeT XIndex<Index,Meta>::dim() const
{ {
return mI->dim(); return mI->dim();
} }
template <class Index, typename Meta> template <class Index, typename Meta>
size_t XIndex<Index,Meta>::getStepSize(size_t n) const SizeT XIndex<Index,Meta>::getStepSize(SizeT n) const
{ {
return mI->getStepSize(n); return mI->getStepSize(n);
} }
template <class Index, typename Meta> template <class Index, typename Meta>
std::string XIndex<Index,Meta>::stringMeta() const String XIndex<Index,Meta>::stringMeta() const
{ {
return mI->stringMeta(); return mI->stringMeta();
} }
@ -79,13 +79,13 @@ namespace CNORXZ
} }
template <class Index, typename Meta> template <class Index, typename Meta>
DynamicExpression XIndex<Index,Meta>::ifor(size_t step, DynamicExpression ex) const DExpr XIndex<Index,Meta>::ifor(SizeT step, DExpr ex) const
{ {
return mI->ifor(step, ex); return mI->ifor(step, ex);
} }
template <class Index, typename Meta> template <class Index, typename Meta>
DynamicExpression XIndex<Index,Meta>::iforh(size_t step, DynamicExpression ex) const DExpr XIndex<Index,Meta>::iforh(SizeT step, DExpr ex) const
{ {
return mI->iforh(step, ex); return mI->iforh(step, ex);
} }

View file

@ -14,25 +14,21 @@ namespace CNORXZ
public: public:
DEFAULT_MEMBERS(XIndexBase); DEFAULT_MEMBERS(XIndexBase);
constexpr IndexType type() const; virtual XIndexBase& operator=(SizeT pos) = 0;
virtual XIndexBase& operator=(size_t pos) = 0;
virtual XIndexBase& operator++() = 0; virtual XIndexBase& operator++() = 0;
virtual XIndexBase& operator--() = 0; virtual XIndexBase& operator--() = 0;
virtual int pp(std::intptr_t idxPtrNum) = 0; virtual Int pp(PtrId idxPtrNum) = 0;
virtual int mm(std::intptr_t idxPtrNum) = 0; virtual Int mm(PtrId idxPtrNum) = 0;
virtual size_t dim() const = 0; virtual size_t dim() const = 0;
virtual size_t getStepSize(size_t n) const = 0; virtual size_t getStepSize(SizeT n) const = 0;
virtual std::string stringMeta() const = 0; virtual String stringMeta() const = 0;
virtual DType meta() const = 0; virtual DType meta() const = 0;
virtual XIndexBase& at(const DType& meta) = 0; virtual XIndexBase& at(const DType& meta) = 0;
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const = 0; virtual DExpr ifor(SizeT step, DExpr ex) const = 0;
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const = 0; virtual DExpr iforh(SizeT step, DExpr ex) const = 0;
// ...!!! // ...!!!
}; };
typedef std::shared_ptr<XIndexBase> XIndexPtr;
// MultiIndex Wrapper: // MultiIndex Wrapper:
template <class Index, typename Meta> template <class Index, typename Meta>
class XIndex : public XIndexBase class XIndex : public XIndexBase
@ -44,18 +40,18 @@ namespace CNORXZ
DEFAULT_MEMBERS(XIndex); DEFAULT_MEMBERS(XIndex);
XIndex(const IndexPtr<Index,Meta>& i); XIndex(const IndexPtr<Index,Meta>& i);
virtual XIndex& operator=(size_t pos) override; virtual XIndex& operator=(SizeT pos) override;
virtual XIndex& operator++() override; virtual XIndex& operator++() override;
virtual XIndex& operator--() override; virtual XIndex& operator--() override;
virtual int pp(std::intptr_t idxPtrNum) override; virtual Int pp(PtrId idxPtrNum) override;
virtual int mm(std::intptr_t idxPtrNum) override; virtual Int mm(PtrId idxPtrNum) override;
virtual size_t dim() const override; virtual SizeT dim() const override;
virtual size_t getStepSize(size_t n) const override; virtual SizeT getStepSize(SizeT n) const override;
virtual std::string stringMeta() const override; virtual String stringMeta() const override;
virtual DType meta() const override; virtual DType meta() const override;
virtual XIndexBase& at(const DType& meta) override; virtual XIndexBase& at(const DType& meta) override;
virtual DynamicExpression ifor(size_t step, DynamicExpression ex) const override; virtual DExpr ifor(SizeT step, DExpr ex) const override;
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override; virtual DExpr iforh(SizeT step, DExpr ex) const override;
// ....!!!! // ....!!!!
}; };

View file

@ -3,46 +3,47 @@
#define __cxz_yindex_h__ #define __cxz_yindex_h__
#include "base/base.h" #include "base/base.h"
#include "ranges/range_base.h" #include "range_base.h"
#include "ranges/index_base.h" #include "index_base.h"
#include "xindex.h"
#include "xfor/xfor.h" #include "xfor/xfor.h"
namespace CNORXZ namespace CNORXZ
{ {
// Future DynamicIndex // Future DynamicIndex
//class YIndex : public IndexInterface<YIndex,DType> //class YIndex : public XIndexBase
class YIndex : public XIndexBase class YIndex : public IndexInterface<YIndex,DType>
{ {
public: public:
typedef IndexInterface<YIndex,DType> IB; typedef IndexInterface<YIndex,DType> IB;
private: private:
RangePtr mRange; RangePtr mRange;
vector<XIndexPtr> mIs; Vector<XIndexPtr> mIs;
std::vector<size_t> mBlockSizes; // dim() elements only!!! Vector<SizeT> mBlockSizes; // dim() elements only!!!
bool mExternalControl = false; bool mExternalControl = false;
public: public:
DEFAULT_MEMBERS(YIndex); DEFAULT_MEMBERS(YIndex);
YIndex(const RangePtr& range); YIndex(const RangePtr& range);
YIndex(const RangePtr& range, const std::vector<XIndexPtr>& is); YIndex(const RangePtr& range, const Vector<XIndexPtr>& is);
YIndex& operator=(size_t pos); YIndex& sync();
YIndex& operator=(SizeT pos);
YIndex& operator++(); YIndex& operator++();
YIndex& operator--(); YIndex& operator--();
int pp(std::intptr_t idxPtrNum); int pp(PtrId idxPtrNum);
int mm(std::intptr_t idxPtrNum); int mm(PtrId idxPtrNum);
size_t dim() const; size_t dim() const;
size_t getStepSize(size_t n) const; size_t getStepSize(SizeT n) const;
std::string stringMeta() const; String stringMeta() const;
DType meta() const; DType meta() const;
YIndex& at(const DType& meta); YIndex& at(const DType& meta);
DynamicExpression ifor(size_t step, DynamicExpression ex) const; DExpr ifor(SizeT step, DExpr ex) const;
DynamicExpression iforh(size_t step, DynamicExpression ex) const; DExpr iforh(SizeT step, DExpr ex) const;
}; };
typedef std::shared_ptr<YIndex> YIndexPtr;
} }
#endif #endif

View file

@ -8,11 +8,11 @@ namespace CNORXZ
* RangeFactoryBase * * RangeFactoryBase *
*************************/ *************************/
static Map<TypeInfo,Map<Vector<PtrId>,RangePtr>> RangeFactoryBase::sCreated; Map<SizeT,Map<Vector<PtrId>,RangePtr>> RangeFactoryBase::sCreated;
RangePtr RangeFactoryBase::create() RangePtr RangeFactoryBase::create()
{ {
mProd = this->make(); this->make();
mProd->mThis = mProd; mProd->mThis = mProd;
return mProd; return mProd;
} }
@ -20,9 +20,9 @@ namespace CNORXZ
RangePtr RangeFactoryBase::fromCreated(const TypeInfo& info, const Vector<PtrId>& rids) const RangePtr RangeFactoryBase::fromCreated(const TypeInfo& info, const Vector<PtrId>& rids) const
{ {
RangePtr out = nullptr; RangePtr out = nullptr;
if(sCreated.count(info) != 0){ if(sCreated.count(info.hash_code()) != 0){
if(sCreated[info].count(rids) != 0){ if(sCreated[info.hash_code()].count(rids) != 0){
out = sCreated[info][rids]; out = sCreated[info.hash_code()][rids];
} }
} }
return out; return out;
@ -30,7 +30,7 @@ namespace CNORXZ
void RangeFactoryBase::addToCreated(const TypeInfo& info, const Vector<PtrId>& rids, const RangePtr& r) void RangeFactoryBase::addToCreated(const TypeInfo& info, const Vector<PtrId>& rids, const RangePtr& r)
{ {
sCreated[info][rids] = r; sCreated[info.hash_code()][rids] = r;
} }
/****************** /******************

View file

@ -4,19 +4,23 @@
namespace CNORXZ namespace CNORXZ
{ {
YIndex::YIndex(const RangePtr& range) : YIndex::YIndex(const RangePtr& range) :
mIs(mRange.dim()), mBlockSizes(mRange.dim()), mExternalControl(false) mRange(range), mIs(mRange->dim()),
mBlockSizes(mRange->dim()), mExternalControl(false)
{ {
assert(0);
// init ...!!! // init ...!!!
} }
YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is) : YIndex::YIndex(const RangePtr& range, const Vector<XIndexPtr>& is) :
mIs(is), mBlockSizes(mRange.dim()), mExternalControl(false) mRange(range), mIs(is),
mBlockSizes(mRange->dim()), mExternalControl(false)
{ {
CXZ_ASSERT(mIs.size() == mRange.dim(), "obtained wrong number of indices"); CXZ_ASSERT(mIs.size() == mRange->dim(), "obtained wrong number of indices");
assert(0);
// init ...!!! // init ...!!!
} }
YIndex& YIndex::operator=(size_t pos) YIndex& YIndex::operator=(SizeT pos)
{ {
IB::mPos = pos; IB::mPos = pos;
// sub inds... (LAZY!!!) !!! // sub inds... (LAZY!!!) !!!
@ -39,24 +43,27 @@ namespace CNORXZ
return *this; return *this;
} }
int YIndex::pp(std::intptr_t idxPtrNum) Int YIndex::pp(PtrId idxPtrNum)
{ {
assert(0);
return 0;
} }
int YIndex::mm(std::intptr_t idxPtrNum) Int YIndex::mm(PtrId idxPtrNum)
{ {
assert(0);
return 0;
} }
size_t YIndex::dim() const SizeT YIndex::dim() const
{ {
return mRange->dim(); return mRange->dim();
} }
size_t YIndex::getStepSize(size_t n) const SizeT YIndex::getStepSize(SizeT n) const
{ {
assert(0);
return 0;
} }
String YIndex::stringMeta() const String YIndex::stringMeta() const
@ -64,9 +71,9 @@ namespace CNORXZ
String out = "["; String out = "[";
auto it = mIs.begin(); auto it = mIs.begin();
for(; it != mIs.end()-1; ++it){ for(; it != mIs.end()-1; ++it){
out += it->stringMeta() + "," out += (*it)->stringMeta() + ",";
} }
out += it->stringMeta() + "]" out += (*it)->stringMeta() + "]";
return out; return out;
} }
@ -74,7 +81,7 @@ namespace CNORXZ
{ {
//this->sync(); //this->sync();
Vector<DType> v(mIs.size()); Vector<DType> v(mIs.size());
std::transform(mIs.begin(), mIs.end(), v.begin(), [](auto& x) { return x->meta() }); std::transform(mIs.begin(), mIs.end(), v.begin(), [](auto& x) { return x->meta(); });
return DType(v); return DType(v);
} }
@ -82,20 +89,22 @@ namespace CNORXZ
{ {
auto& v = std::any_cast<const Vector<DType>&>(meta.get()); auto& v = std::any_cast<const Vector<DType>&>(meta.get());
assert(v.size() == mIs.size()); assert(v.size() == mIs.size());
for(size_t i = 0; i != mIs.size()){ for(SizeT i = 0; i != mIs.size(); ++i){
mIs[i]->at(v[i]); mIs[i]->at(v[i]);
} }
return *this; return *this;
} }
DynamicExpression YIndex::ifor(size_t step, DynamicExpression ex) const DExpr YIndex::ifor(SizeT step, DExpr ex) const
{ {
assert(0);
return DExpr();
} }
DynamicExpression YIndex::iforh(size_t step, DynamicExpression ex) const DExpr YIndex::iforh(SizeT step, DExpr ex) const
{ {
assert(0);
return DExpr();
} }
} }