fix compile errors

This commit is contained in:
Christian Zimmermann 2022-12-20 00:07:59 +01:00
parent 0fbd2d6f5b
commit 34c45e3dd9
13 changed files with 209 additions and 175 deletions

View file

@ -3,9 +3,124 @@
#define __cxz_array_base_cc_h__
#include "array_base.h"
#include "slice.h"
namespace CNORXZ
{
/******************************
* CArrayBase (protected) *
******************************/
template <typename T>
template <class Index>
YIndex CArrayBase<T>::mkSliceIndex(const YIndex& yi, const Index& ind) const
{
// TODO: if ind.dim() < iy.dim: assume Null-Indices on missing positions;
static_assert(has_sub<Index>::value, "got non-mutliple index");
CXZ_ASSERT(yi.dim() == ind.dim(), "got index of incompatible dimension = "
<< ind.dim() << ", expected: " << yi.dim());
Vector<XIndexPtr> npack;
Vector<SizeT> nbs;
auto ypack = yi.pack();
auto ipack = ind.pack();
const auto& bs = yi.blockSizes();
if constexpr(has_static_sub<Index>::value){
constexpr SizeT ID = index_dim<Index>::value;
npack.reserve(ID);
nbs.reserve(ID);
iter<0,ID>( [&](auto i) {
const auto& ii1 = ypack[i];
const auto& ii2 = std::get<i>(ipack);
if(ii2->dim() != 0){
npack.push_back( mkSliceIndex(ii1, ii2) );
nbs.push_back(bs[i]);
}
}, NoF {} );
}
else {
const SizeT idim = ind.dim();
npack.reserve(idim);
nbs.reserve(idim);
for(SizeT i = 0; i != idim; ++i){
const auto& ii1 = ypack[i];
const auto& ii2 = ipack[i];
if(ii2->dim() != 0){
npack.push_back( mkSliceIndex(ii1, ii2) );
nbs.push_back(bs[i]);
}
}
}
return yindex(npack);
}
template <typename T>
template <class Index>
XIndexPtr CArrayBase<T>::mkSliceIndex(const XIndexPtr& xi, const Sptr<Index>& ind) const
{
// TODO: if ind.dim() < iy.dim: assume Null-Indices on missing positions;
CXZ_ASSERT(xi->dim() == ind->dim(), "got index of incompatible dimension = "
<< ind->dim() << ", expected: " << xi->dim());
Vector<XIndexPtr> npack;
Vector<SizeT> nbs;
auto xpack = xi->pack();
const auto& bs = xi->blockSizes();
if constexpr(has_static_sub<Index>::value){
auto ipack = ind->pack();
constexpr SizeT ID = index_dim<Index>::value;
npack.reserve(ID);
nbs.reserve(ID);
iter<0,ID>( [&](auto i) {
const auto& ii1 = xpack[i];
const auto& ii2 = std::get<i>(ipack);
const XIndexPtr si = mkSliceIndex(ii1, ii2);
if(si != nullptr){
npack.push_back( si );
nbs.push_back(bs[i]);
}
}, NoF {} );
}
else if constexpr(has_static_sub<Index>::value){
auto ipack = ind->pack();
const SizeT idim = ind->dim();
const SizeT xdim = xi->dim();
const SizeT isize = ipack.size();
const SizeT xsize = xpack.size();
if(isize == 0 or xsize == 0){
if(idim == 0){
return xi->copy();
}
else {
return nullptr;
}
}
CXZ_ASSERT(isize == idim and xsize == xdim, "index error");
npack.reserve(idim);
nbs.reserve(idim);
for(SizeT i = 0; i != idim; ++i){
const auto& ii1 = xpack[i];
const auto& ii2 = ipack[i];
const XIndexPtr si = mkSliceIndex(ii1, ii2);
if(si != nullptr){
npack.push_back( si );
nbs.push_back(bs[i]);
}
}
}
else {
const SizeT idim = ind->dim();
if(idim == 0){
return xi->copy();
}
else {
return nullptr;
}
}
if(npack.size() == 0){
return nullptr;
}
return mkXIndex(yindexPtr(npack));
}
/******************
* CArrayBase *
******************/
@ -39,13 +154,11 @@ namespace CNORXZ
template <typename I, typename M>
Sptr<CArrayBase<T>> CArrayBase<T>::sl(const IndexInterface<I,M>& i) const
{
////auto r = mkSliceRange(i.range());
//auto beg = this->begin();
//assertCompatible(i,beg);
////auto bs = mkSliceBlockSizes(i, beg);
//auto it = beg + i.lex();
////return std::make_shared<CSlice>(r, this, bs, it.pos());
return std::make_shared<CSlice>();
auto beg = this->begin();
auto si = mkSliceIndex(beg, i);
auto it = beg + i.lex();
return std::make_shared<CSlice>(this, si, it.pos());
//return std::make_shared<CSlice>();
}
template <typename T>

View file

@ -22,6 +22,12 @@ namespace CNORXZ
protected:
RangePtr mRange;
template <class Index>
YIndex mkSliceIndex(const YIndex& yi, const Index& i) const;
template <class Index>
XIndexPtr mkSliceIndex(const XIndexPtr& xi, const Sptr<Index>& i) const;
public:
CArrayBase(const RangePtr& range);
@ -92,34 +98,6 @@ namespace CNORXZ
};
// to extra header file !!!:
template <class... Indices>
constexpr decltype(auto) flattenIndexPack(const Tuple<Sptr<Indices>...>& ipack)
{
constexpr SizeT D = sizeof...(Indices);
}
inline Vector<XIndexPtr> flattenIndexPack(const Vector<XIndexPtr>& ipack)
{
}
template <class... Indices>
inline SizeT indexPackDim(Tuple<Sptr<Indices>...> ipack)
{
constexpr SizeT D = sizeof...(Indices);
return iter<0,D>([&](const auto& i) { return std::get<i>(ipack)->dim(); },
[](const auto&... e) { return (e + ...); });
}
inline SizeT indexPackDim(const Vector<XIndexPtr>& ipack)
{
return std::accumulate(ipack.begin(), ipack.end(), ipack[0]->dim(),
[](auto a, auto b) { return a->dim() + b->dim(); });
}
}
#endif

View file

@ -87,6 +87,14 @@ namespace CNORXZ
struct index_dim
{ static constexpr SizeT value = 1; };
template <class T>
struct has_sub
{ static constexpr bool value = false; };
template <class T>
struct has_static_sub
{ static constexpr bool value = false; };
template <class I, typename MetaType>
IndexPtr<I,MetaType>& operator++(const IndexPtr<I,MetaType>& i);

View file

@ -6,71 +6,6 @@
namespace CNORZX
{
inline decltype(auto) getPack(const XIndexPtr& i)
{
typedef Vector<XIndexPtr> OutT;
OutT p = i.pack();
while(p.size() == 1u){
p = p[0]->pack();
}
return p;
}
// -> base
template <typename... T>
Vector<T> mkVector(const T&... t) { return Vector<T>({t...}); }
template <class F>
inline decltype(auto) indexZip(const XIndexPtr& a, const XIndexPtr& b, F&& f)
{
const auto ap = getPack(a);
const auto bp = getPack(b);
if(ap.size() == 1u or bp.size() == 1u){
return mkVector( f(a, b) );
}
else {
return indexPackZip(ap, bp, std::forward<F>(f));
}
}
template <class F>
inline decltype(auto) indexPackZip(const Vector<XIndexPtr>& a, const Vector<XIndexPtr>& b, F&& f)
{
if(a.size() > b.size()) {
Vector<XIndexPtr> bn;
for(const auto& x: b){
auto p = getPack(x);
if(p.size() == 0){
bn.push_back(x);
}
else {
bn.insert(bn.end(), p.begin(), p.end());
}
}
return indexPackZip(a, bn, std::forward<F>(f));
}
else if(a.size() < b.size()) {
Vector<XIndexPtr> an;
for(const auto& x: a){
auto p = getPack(x);
if(p.size() == 0){
an.push_back(x);
}
else {
an.insert(bn.end(), p.begin(), p.end());
}
}
return indexPackZip(an, b, std::forward<F>(f));
}
else {
typedef decltype(indexZip(a[0], b[0], std::forward<T>(f))) OutT;
OutT o(a.size());
std::transform(o.begin(), o.end(), a.begin(), b.begin(),
[](const auto& ax, const auto& bx) { F fc = f; return indexZip(ax, bx, std::move(fc)); });
return o;
}
}
template <class Index>
constexpr decltype(auto) getIndexDepth(const Index& ind)
{

View file

@ -6,19 +6,13 @@
namespace CNORZX
{
inline decltype(auto) getPack(const XIndexPtr& i);
template <class F>
inline decltype(auto) indexZip(const XIndexPtr& a, const XIndexPtr& b, F&& f);
template <class F>
inline decltype(auto) indexPackZip(const Vector<XIndexPtr>& a, const Vector<XIndexPtr>& b, F&& f);
template <class Index>
constexpr decltype(auto) getIndexDepth(const Index& ind);
template <class Index, typename IntT>
constexpr decltype(auto) getDimension(const Index& ind, IntT depth);
}
#endif

View file

@ -434,50 +434,6 @@ namespace CNORXZ
return mIPack;
}
template <class BlockType, class... Indices>
template <class Index, class F, class G>
constexpr decltype(auto) GMIndex<BlockType,Indices...>::zip(const Index& ind, const F& f, const G& g) const
{
static_assert(is_index<Index>::value, "got non-index type");
if constexpr(has_static_sub<Index>::value){
static_assert(index_dim<Index>::value == NI,
"got static-dimensional index with wrong dimension");
if constexpr(std::is_same<G,NoF>::value or std::is_same<F,NoF>::value){
iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*std::get<i>(ind.pack()), f); },
NoF {} );
f(*this, ind);
return;
}
else {
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*std::get<i>(ind.pack()), f); },
[](auto... e) { return g(std::make_tuple(e...), f(*this, ind)); } );
}
}
else if constexpr(has_sub<Index>::value){
CXZ_ASSERT(ind.dim() == NI, "got index with wrong dimension = " << ind.dim()
<< ", expected: " << NI);
if constexpr(std::is_same<G,NoF>::value or std::is_same<F,NoF>::value){
iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*ind.pack()[i],f); },
NoF {} );
f(*this, ind);
return;
}
else {
return iter<0,NI>( [&](auto i) { return std::get<i>(mIPack)->zip(*ind.pack()[i],f); },
[](auto... e) { return g(std::make_tuple(e...), f(*this, ind)); } );
}
}
else {
if constexpr(std::is_same<F,NoF>::value){
f(*this, ind);
return;
}
else {
return f(*this, ind);
}
}
}
template <class BlockType, class... Indices>
const auto& GMIndex<BlockType,Indices...>::blockSizes() const
{
@ -496,7 +452,7 @@ namespace CNORXZ
}
template <class BlockType, class... Indices>
GMIndex& GMIndex<BlockType,Indices...>::setBlockSizes(const BlockType& bs)
GMIndex<BlockType,Indices...>& GMIndex<BlockType,Indices...>::setBlockSizes(const BlockType& bs)
{
if constexpr(not std::is_same<BlockType,None>::value){
mBlockSizes = bs;
@ -505,10 +461,20 @@ namespace CNORXZ
}
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSize(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi)
decltype(auto) replaceBlockSizes(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi)
{
return iter<0,sizeof...(Indices)>
( [&](auto i) { return std::get<i>(gmi.pack()); },
( [&](auto i) { return std::get<i>(gmi->pack()); },
[&](const auto&... e) { return std::make_shared<GMIndex<BT1,Indices...>>
( bs1, e... ); } );
}
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSizes(const BT1& bs1,
const Sptr<IndexInterface<GMIndex<BT2,Indices...>,typename GMIndex<BT2,Indices...>::MetaType>>& gmi)
{
return iter<0,sizeof...(Indices)>
( [&](auto i) { return std::get<i>(gmi->THIS().pack()); },
[&](const auto&... e) { return std::make_shared<GMIndex<BT1,Indices...>>
( bs1, e... ); } );
}

View file

@ -70,9 +70,6 @@ namespace CNORXZ
GMIndex& operator()(const Sptr<MIndex<Indices...>>& mi);
GMIndex& operator()();
template <class Index, class F = NoF, class G = NoF>
constexpr decltype(auto) zip(const Index& ind, const F& f, const G& g) const; // also non-const version !!!
const IndexPack& pack() const;
const auto& blockSizes() const;
const auto& lexBlockSizes() const;
@ -113,7 +110,11 @@ namespace CNORXZ
};
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSize(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi);
decltype(auto) replaceBlockSizes(const BT1& bs1, const Sptr<GMIndex<BT2,Indices...>>& gmi);
template <class BT1, class BT2, class... Indices>
decltype(auto) replaceBlockSizes(const BT1& bs1,
const Sptr<IndexInterface<GMIndex<BT2,Indices...>,typename GMIndex<BT2,Indices...>::MetaType>>& gmi);
template <class BT1, class... Is1, class BT2, class... Is2>
decltype(auto) operator*(const Sptr<GMIndex<BT1,Is1...>>& a, const Sptr<GMIndex<BT2,Is2...>>& b);
@ -132,6 +133,14 @@ namespace CNORXZ
struct index_dim<MIndex<Indices...>>
{ static constexpr SizeT value = sizeof...(Indices); };
template <class... Indices>
struct has_sub<MIndex<Indices...>>
{ static constexpr bool value = true; };
template <class... Indices>
struct has_static_sub<MIndex<Indices...>>
{ static constexpr bool value = true; };
template <class... Indices>
constexpr decltype(auto) mindex(const Sptr<Indices>&... is);

View file

@ -133,14 +133,14 @@ namespace CNORXZ
if constexpr(has_static_sub<Index>::value){
constexpr SizeT D = index_dim<Index>::value;
return iter<0,D>
( [&](auto i) { return mkXIndex(std::get<i>(mI->pack())); },
[](const auto&... e) { return { e ... }; } );
( [&](auto i) { return mkXIndex(std::get<i>(mI->THIS().pack())); },
[](const auto&... e) { return Vector<XIndexPtr>({ e ... }); } );
}
else if constexpr(has_sub<Index>::value){
return mI->pack();
return mI->THIS().pack();
}
else {
return {};
return Vector<XIndexPtr>();
}
}
@ -149,15 +149,16 @@ namespace CNORXZ
{
if constexpr(has_static_sub<Index>::value){
constexpr SizeT D = index_dim<Index>::value;
const auto& bs = mI->THIS().blockSizes();
return iter<0,D>
( [&](auto i) { return std::get<i>(mI->blockSizes()); },
[](const auto&... e) { return Vector<SizeT>( { e... } ); } );
( [&](auto i) { return std::get<i>(bs); },
[](const auto&... e) { return Vector<SizeT>( { static_cast<SizeT>(e)... } ); } );
}
else if constexpr(has_sub<Index>::value) {
return mI->blockSizes();
return mI->THIS().blockSizes();
}
else {
return {};
return Vector<SizeT>();
}
}
@ -168,19 +169,19 @@ namespace CNORXZ
constexpr SizeT D = index_dim<Index>::value;
CXZ_ASSERT(bs.size() == D,
"got block sizes of wrong dimension: " << bs.size() << " vs " << D);
typedef decltype(mI->blockSizes()) BT;
Arr<SizeT,D> arr;
typedef decltype(mI->THIS().blockSizes()) BT;
Arr<UPos,D> arr;
std::copy_n(bs.begin(), D, arr.begin());
if constexpr(std::is_same<BT,Arr<SizeT,D>>::value){
mI->setBlockSizes(arr);
if constexpr(std::is_same<BT,Arr<UPos,D>>::value){
mI->THIS().setBlockSizes(arr);
return nullptr;
}
else {
return replaceBlockSizes(arr, mI);
return mkXIndex(replaceBlockSizes(arr, mI));
}
}
else if constexpr(has_sub<Index>::value) {
mI->setBlockSizes(bs);
mI->THIS().setBlockSizes(bs);
return nullptr;
}
else {

View file

@ -46,6 +46,7 @@ namespace CNORXZ
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const = 0;
};
//Sptr<XIndexBase>& operator++(Sptr<XIndexBase>& i);
@ -103,6 +104,10 @@ namespace CNORXZ
};
template <>
struct has_sub<XIndexBase>
{ static constexpr bool value = true; };
template <class Index>
XIndexPtr mkXIndex(const Sptr<Index>& i);

View file

@ -85,6 +85,9 @@ namespace CNORXZ
UPos mLMax = 0;
};
YIndex yindex(const Vector<XIndexPtr>& is);
Sptr<YIndex> yindexPtr(const Vector<XIndexPtr>& is);
class YRangeFactory : public RangeFactoryBase
{
public:

View file

@ -111,6 +111,12 @@ namespace CNORXZ
return UPos(mExt + in.val());
}
template <class PosT>
constexpr UPos UPos::operator-(const PosT& in) const
{
return UPos(mExt - in.val());
}
constexpr SPos<0> UPos::operator*(const SPos<0>& a) const
{
return SPos<0>();

View file

@ -54,6 +54,9 @@ namespace CNORXZ
template <class PosT>
constexpr UPos operator+(const PosT& a) const;
template <class PosT>
constexpr UPos operator-(const PosT& a) const;
constexpr SPos<0> operator*(const SPos<0>& a) const;
template <class PosT>

View file

@ -378,6 +378,19 @@ namespace CNORXZ
return *this;
}
/****************************
* non-member functions *
****************************/
YIndex yindex(const Vector<XIndexPtr>& is)
{
return YIndex(is);
}
Sptr<YIndex> yindexPtr(const Vector<XIndexPtr>& is)
{
return std::make_shared<YIndex>(is);
}
/**********************
* YRangeFactory *