im com (not finished)

This commit is contained in:
Christian Zimmermann 2022-10-21 17:35:23 +02:00
parent 483e3b4286
commit f68c02565d
8 changed files with 143 additions and 54 deletions

View file

@ -0,0 +1,54 @@
#ifndef __cxz_op_utility_cc_h__
#define __cxz_op_utility_cc_h__
#include "op_utility.h"
#include "xpr/pos_type.h"
#include "operation/op_type.h"
namespace CNORXZ
{
template <SizeT I, class PosT>
constexpr decltype(auto) pos_get(const PosT& pos)
{
static_assert(I < static_pos_size<PosT>::value, "index out of range");
if constexpr(I == 0){
return pos;
}
else {
return pos_get<I-1>(pos.next());
}
}
template <SizeT J, SizeT I, SizeT... Is>
constexpr SizeT sum_index_sequence(std::index_sequence<I,Is...> is)
{
static_assert(J < sizeof...(Is)+1, "index out of range");
if constexpr(J == 0){
return 0;
}
else {
return sum_index_sequence<J-1>(std::index_sequence<Is...>{}) + I;
}
}
template <class F, class PosT, class OpTuple, class OpSizes, SizeT... Is>
inline void pos_unpack_args_i(const F& f, const PosT& pos, const OpTuple& args,
OpSizes opsizes, std::index_sequence<Is...> is)
{
f(std::get<Is>(args).get(pos_get<sum_index_sequence<Is>(opsizes)>(pos))...);
}
template <class F, class PosT, class... Ops>
inline void pos_unpack_args(const F& f, const PosT& pos, const Tuple<Ops...>& args)
{
static_assert(is_pos_type<PosT>::value, "got non-pos-type");
static_assert((is_operation<Ops>::value and ...), "got non-operation type");
typedef std::make_index_sequence<sizeof...Ops> Idxs;
typedef std::index_sequence<op_size<Ops>::value...> OpSizes;
pos_unpack_args_i(f, pos, args, OpSizes{}, Idx{});
}
}
#endif

View file

@ -0,0 +1,25 @@
#ifndef __cxz_op_utility_h__
#define __cxz_op_utility_h__
#include "base/base.h"
namespace CNORXZ
{
template <SizeT I, class PosT>
constexpr decltype(auto) pos_get(const PosT& pos);
template <SizeT J, SizeT... Is>
constexpr SizeT sum_index_sequence(std::index_sequence<Is...> is);
template <class F, class PosT, class OpTuple, class OpSizes, SizeT... Is>
inline void pos_unpack_args_i(const F& f, const PosT& pos, const OpTuple& args,
OpSizes opsizes, std::index_sequence<Is...> is);
template <class F, class PosT, class... Ops>
inline void pos_unpack_args(const F& f, const PosT& pos, const Tuple<Ops...>& args);
}
#endif

View file

@ -3,6 +3,7 @@
#define __cxz_op_expr_cc_h__
#include "op_expr.h"
#include "op_utility.h"
namespace CNORXZ
{
@ -18,7 +19,7 @@ namespace CNORXZ
template <class PosT1, class PosT2>
inline SizeT OpXpr<F,Ops...>::operator()(const PosT& last) const
{
pos_unpack_args(mF,mOps,last); // utility function (to be implemented)
pos_unpack_args(mF,last,mOps); // utility function (to be implemented)
// depending on whether Ops[N] is static or not call statically or dynamically .next()
return 0;
}

View file

@ -373,7 +373,8 @@ namespace CNORXZ
return mC->vval();
}
inline DPosRef DPos::next() const
//inline DPosRef DPos::next() const
inline DPosRef DPos::sub() const
{
return DPosRef(mC->vnext());
}
@ -416,9 +417,10 @@ namespace CNORXZ
}
template <class PosT>
inline DPos DPos::extend(const PosT& a) const
inline decltype(auto) DPos::extend(const PosT& a) const
{
return DPos(mC->vextend( a ));
//return DPos(mC->vextend( a ));
return MPos<DPos,PosT>(*this,a);
}
/***************
@ -447,7 +449,8 @@ namespace CNORXZ
return mP->vval();
}
inline DPosRef DPosRef::next() const
//inline DPosRef DPosRef::next() const
inline DPosRef DPosRef::sub() const
{
return DPosRef(mP->vnext());
}
@ -490,9 +493,10 @@ namespace CNORXZ
}
template <class PosT>
inline DPos DPosRef::extend(const PosT& a) const
inline decltype(auto) DPosRef::extend(const PosT& a) const
{
return DPos(mP->vextend( a ));
//return DPos(mP->vextend( a ));
return MPos<DPos,PosT>(*this,a);
}
/************

View file

@ -154,6 +154,7 @@ namespace CNORXZ
constexpr auto extend(const PosT& a) const;
};
// treat as scalar pos!!!
class DPos : public ObjHandle<VPosBase>
{
public:
@ -172,7 +173,8 @@ namespace CNORXZ
inline const VPosBase* vpos() const;
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;
inline DPosRef sub() const;
//inline DPosRef next() const;
template <class PosT>
inline DPos operator+(const PosT& a) const;
@ -185,7 +187,7 @@ namespace CNORXZ
inline DPos operator()(const PosT& a) const;
template <class PosT>
inline DPos extend(const PosT& a) const;
inline decltype(auto) extend(const PosT& a) const;
};
class DPosRef
@ -202,7 +204,8 @@ namespace CNORXZ
inline const VPosBase* vpos() const;
inline SizeT size() const;
inline SizeT val() const;
inline DPosRef next() const;
inline DPosRef sub() const;
//inline DPosRef next() const;
template <class PosT>
inline DPos operator+(const PosT& a) const;
@ -215,7 +218,7 @@ namespace CNORXZ
inline DPos operator()(const PosT& a) const;
template <class PosT>
inline DPos extend(const PosT& a) const;
inline decltype(auto) extend(const PosT& a) const;
};
// for common call of extension vector elements
@ -261,7 +264,7 @@ namespace CNORXZ
struct is_epos_type { CXZ_CVAL_FALSE; };
template <class PosT>
struct pos_depth
struct static_pos_size
{
static constexpr SizeT value = is_pos_type<PosT>::value ? 1 : 0;
};
@ -322,6 +325,8 @@ namespace CNORXZ
template <> struct is_pos_type<DPos> { CXZ_CVAL_TRUE; };
template <> struct is_pos_type<DPosRef> { CXZ_CVAL_TRUE; };
template <> struct is_scalar_pos_type<DPos> { CXZ_CVAL_TRUE; };
template <> struct is_scalar_pos_type<DPosRef> { CXZ_CVAL_TRUE; };
template <class BPosT, class... OPosTs> struct is_pos_type<EPos<BPosT,OPosTs...>> { CXZ_CVAL_TRUE; };
template <class BPosT, class... OPosTs> struct is_scalar_pos_type<EPos<BPosT,OPosTs...>>
@ -331,9 +336,9 @@ namespace CNORXZ
template <class BPosT, class... OPosTs> struct is_epos_type<EPos<BPosT,OPosTs...>> { CXZ_CVAL_TRUE; };
template <class BPosT, class NPosT>
struct pos_depth<MPos<BPosT,NPosT>>
struct static_pos_size<MPos<BPosT,NPosT>>
{
static constexpr SizeT value = pos_depth<NPosT>::value + 1;
static constexpr SizeT value = static_pos_size<NPosT>::value + 1;
};
template <class BPosT, class... OPosTs>

View file

@ -10,7 +10,7 @@ namespace CNORXZ
/****************
* VPosBase *
****************/
/*
template <SizeT N>
inline Uptr<VPosBase> VPosBase::vextend(const SPos<N>& a) const
{
@ -28,7 +28,7 @@ namespace CNORXZ
{
return this->vextend(static_cast<const PosT1&>(a))->vextend(a.next());
}
*/
/************
* VPos *
************/
@ -88,7 +88,7 @@ namespace CNORXZ
typedef decltype((*this)(UPos(a->vval()))) OPosT;
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
}
/*
template <class PosT>
Uptr<VPosBase> VPos<PosT>::vextend(const UPos& a) const
{
@ -116,7 +116,7 @@ namespace CNORXZ
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
*/
/******************
* VPos<MPos> *
******************/
@ -207,7 +207,7 @@ namespace CNORXZ
typedef decltype( (*this)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*this)(UPos(a->vval())) );
}
/*
template <class PosT1, class PosT2>
Uptr<VPosBase> VPos<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{
@ -235,7 +235,7 @@ namespace CNORXZ
typedef decltype(this->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(this->extend(DPos(a)));
}
*/
/***************
* VPosRef *
***************/
@ -295,7 +295,7 @@ namespace CNORXZ
typedef decltype( (*mC)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
}
/*
template <class PosT>
Uptr<VPosBase> VPosRef<PosT>::vextend(const UPos& a) const
{
@ -323,7 +323,7 @@ namespace CNORXZ
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
}
*/
/*********************
* VPosRef<MPos> *
*********************/
@ -393,7 +393,7 @@ namespace CNORXZ
typedef decltype( (*mC)(UPos(a->vval())) ) OPosT;
return std::make_unique<VPos<OPosT>>( (*mC)(UPos(a->vval())) );
}
/*
template <class PosT1, class PosT2>
Uptr<VPosBase> VPosRef<MPos<PosT1,PosT2>>::vextend(const UPos& a) const
{
@ -421,7 +421,7 @@ namespace CNORXZ
typedef decltype(mC->extend(DPos(a))) OPosT;
return std::make_unique<VPos<OPosT>>(mC->extend(DPos(a)));
}
*/
}
#endif

View file

@ -21,11 +21,11 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const = 0;
virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
//virtual Uptr<VPosBase> vextend(const UPos& a) const = 0;
//virtual Uptr<VPosBase> vextend(const FPos& a) const = 0;
//virtual Uptr<VPosBase> vextend(const DPos& a) const = 0;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const = 0;
/*
template <SizeT N>
inline Uptr<VPosBase> vextend(const SPos<N>& a) const;
@ -34,7 +34,7 @@ namespace CNORXZ
template <class PosT1, class PosT2>
inline Uptr<VPosBase> vextend(const MPos<PosT1,PosT2>& a) const;
*/
};
template <class PosT>
@ -53,10 +53,10 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
template <class PosT1, class PosT2>
@ -81,10 +81,10 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
template <class PosT>
@ -105,10 +105,10 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};
@ -133,10 +133,10 @@ namespace CNORXZ
virtual Uptr<VPosBase> vplus(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vtimes(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vexec(const VPosBase* a) const override final;
virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
//virtual Uptr<VPosBase> vextend(const UPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const FPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPos& a) const override final;
//virtual Uptr<VPosBase> vextend(const DPosRef& a) const override final;
};

View file

@ -144,21 +144,21 @@ namespace
EXPECT_EQ(dp5.size(), 2u);
EXPECT_EQ(dp1.val(), mS2p.val());
EXPECT_EQ(dp1.next().val(), mUp1.val());
EXPECT_EQ(dp1.sub().val(), mUp1.val());
EXPECT_EQ(dp2.val(), mUp2.val());
EXPECT_EQ(dp2.next().val(), mS4p.val());
EXPECT_EQ(dp2.sub().val(), mS4p.val());
EXPECT_EQ(dp3a.val(), mS2p.val() + mUp2.val());
EXPECT_EQ(dp3a.next().val(), mUp1.val() + mS4p.val());
EXPECT_EQ(dp3a.sub().val(), mUp1.val() + mS4p.val());
EXPECT_EQ(dp3b.val(), mS2p.val() + mUp2.val());
EXPECT_EQ(dp3b.next().val(), mUp1.val() + mS4p.val());
EXPECT_EQ(dp3b.sub().val(), mUp1.val() + mS4p.val());
EXPECT_EQ(dp4.val(), mS2p.val() * mS2p.val());
EXPECT_EQ(dp4.next().val(), mUp1.val() * mS2p.val());
EXPECT_EQ(dp4.sub().val(), mUp1.val() * mS2p.val());
EXPECT_EQ(dp5.val(), mUp2.val() * mUp1.val());
EXPECT_EQ(dp5.next().val(), mS4p.val() * mUp1.val());
EXPECT_EQ(dp5.sub().val(), mS4p.val() * mUp1.val());
}
TEST_F(Pos_Test, DynExtend)
{
{/*
DPos dp1(mkMPos(static_cast<UPos>(mS2p), mUp1));
DPos dp2(mkMPos(mUp2, static_cast<UPos>(mS4p)));
auto dp3 = dp1.extend(mUp2);
@ -188,7 +188,7 @@ namespace
EXPECT_EQ( dp6.val(), dp3.val() * dp01.val() );
EXPECT_EQ( dp6.next().val(), dp3.next().val() * dp01.val() );
EXPECT_EQ( dp6.next().next().val(), dp3.next().next().val() * dp01.val() );
}
*/}
}
int main(int argc, char** argv)