index xpr + h5 table header file

This commit is contained in:
Christian Zimmermann 2023-01-20 01:05:24 +01:00
parent 02174f8371
commit 66d5e5b741
24 changed files with 145 additions and 37 deletions

View file

@ -4,7 +4,7 @@
#include "op_types.h" #include "op_types.h"
//#include "xpr/xpr.h" //#include "xpr/xpr.h"
//#include "op_utility.h" #include "op_utility.h"
#include "extensions/extensions.h" #include "extensions/extensions.h"
namespace CNORXZ namespace CNORXZ
@ -33,7 +33,7 @@ namespace CNORXZ
template <class F, class... Args> template <class F, class... Args>
constexpr decltype(auto) COpInterface<OpT>::o(F&& f, Args&&... args) const constexpr decltype(auto) COpInterface<OpT>::o(F&& f, Args&&... args) const
{ {
return mkOperation(std::forward<F>(f), THIS().r(), args...); return operation(std::forward<F>(f), THIS().r(), args...);
} }
@ -45,7 +45,7 @@ namespace CNORXZ
template <class IndexT, class F, class... Args> template <class IndexT, class F, class... Args>
constexpr decltype(auto) OpInterface<OpT>::ax(const Sptr<IndexT>& ind, F&& f, const Args&... args) constexpr decltype(auto) OpInterface<OpT>::ax(const Sptr<IndexT>& ind, F&& f, const Args&... args)
{ {
return ind->ifor( mkOperation(f, OI::THIS().r(), args...), NoF {} ); return ind->ifor( operation(f, OI::THIS().r(), args...), NoF {} );
} }
template <class OpT> template <class OpT>
@ -116,7 +116,13 @@ namespace CNORXZ
{ {
return COpRoot<T,IndexT>(a, ind); return COpRoot<T,IndexT>(a, ind);
} }
template <typename T, class IndexT>
constexpr decltype(auto) coproot(const T* a, const Sptr<IndexT>& ind)
{
return COpRoot<T,IndexT>(a, ind);
}
/**************** /****************
* OpCont * * OpCont *
****************/ ****************/
@ -364,7 +370,7 @@ namespace CNORXZ
} }
template <class F, class... Ops> template <class F, class... Ops>
constexpr decltype(auto) mkOperation(F&& f, const Ops&... ops) constexpr decltype(auto) operation(F&& f, const Ops&... ops)
{ {
return Operation<F,Ops...>(std::forward<F>(f), ops...); return Operation<F,Ops...>(std::forward<F>(f), ops...);
} }
@ -400,11 +406,21 @@ namespace CNORXZ
} }
template <class F, class Op, class IndexT> template <class F, class Op, class IndexT>
constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr<IndexT>& i) constexpr decltype(auto) contracion(F&& f, Op&& op, const Sptr<IndexT>& i)
{ {
typedef decltype(i->ifor( op, f )) CXprT; // TODO: implement ifor with func arg!!! typedef decltype(i->ifor( op, f )) CXprT; // TODO: implement ifor with func arg!!!
return Contraction<CXprT>( i->ifor( op, f ) ); return Contraction<CXprT>( i->ifor( op, f ) );
} }
/************************
* various functions *
************************/
template <class IndexT>
constexpr decltype(auto) indexOp(const Sptr<IndexT>& i)
{
return i->xpr(i);
}
} }
#endif #endif

View file

@ -93,7 +93,10 @@ namespace CNORXZ
template <typename T, class IndexT> template <typename T, class IndexT>
constexpr decltype(auto) coproot(const CArrayBase<T>& a, const Sptr<IndexT>& ind); constexpr decltype(auto) coproot(const CArrayBase<T>& a, const Sptr<IndexT>& ind);
template <typename T, class IndexT>
constexpr decltype(auto) coproot(const T* a, const Sptr<IndexT>& ind);
template <typename T, class IndexT> template <typename T, class IndexT>
class OpCont : public OpInterface<OpCont<T,IndexT>> class OpCont : public OpInterface<OpCont<T,IndexT>>
{ {
@ -207,7 +210,7 @@ namespace CNORXZ
}; };
template <class F, class... Ops> template <class F, class... Ops>
constexpr decltype(auto) mkOperation(F&& f, const Ops&... ops); constexpr decltype(auto) operation(F&& f, const Ops&... ops);
template <class F, class... Ops> template <class F, class... Ops>
struct op_size<Operation<F,Ops...>> struct op_size<Operation<F,Ops...>>
@ -236,7 +239,10 @@ namespace CNORXZ
}; };
template <class F, class Op, class IndexT> template <class F, class Op, class IndexT>
constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr<IndexT>& i); constexpr decltype(auto) contracion(F&& f, Op&& op, const Sptr<IndexT>& i);
template <class IndexT>
constexpr decltype(auto) indexOp(const Sptr<IndexT>& i);
} }
#endif #endif

View file

@ -33,20 +33,20 @@ namespace CNORXZ
} }
template <class F, class PosT, class OpTuple, class OpSizes, SizeT... 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, inline auto pos_unpack_args_i(const F& f, const PosT& pos, const OpTuple& args,
OpSizes opsizes, std::index_sequence<Is...> is) OpSizes opsizes, std::index_sequence<Is...> is)
{ {
f(std::get<Is>(args)(pos_get<sum_index_sequence<Is>(opsizes)>(pos))...); return f(std::get<Is>(args)(pos_get<sum_index_sequence<Is>(opsizes)>(pos))...);
} }
template <class F, class PosT, class... Ops> template <class F, class PosT, class... Ops>
inline void pos_unpack_args(const F& f, const PosT& pos, const Tuple<Ops...>& args) inline auto 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_pos_type<PosT>::value, "got non-pos-type");
static_assert((is_operation<Ops>::value and ...), "got non-operation type"); static_assert((is_operation<Ops>::value and ...), "got non-operation type");
typedef std::make_index_sequence<sizeof...(Ops)> Idxs; typedef std::make_index_sequence<sizeof...(Ops)> Idxs;
typedef std::index_sequence<op_size<Ops>::value...> OpSizes; typedef std::index_sequence<op_size<Ops>::value...> OpSizes;
pos_unpack_args_i(f, pos, args, OpSizes{}, Idxs{}); return pos_unpack_args_i(f, pos, args, OpSizes{}, Idxs{});
} }
} }

View file

@ -13,11 +13,11 @@ namespace CNORXZ
constexpr SizeT sum_index_sequence(std::index_sequence<Is...> is); constexpr SizeT sum_index_sequence(std::index_sequence<Is...> is);
template <class F, class PosT, class OpTuple, class OpSizes, SizeT... 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, inline auto pos_unpack_args_i(const F& f, const PosT& pos, const OpTuple& args,
OpSizes opsizes, std::index_sequence<Is...> is); OpSizes opsizes, std::index_sequence<Is...> is);
template <class F, class PosT, class... Ops> template <class F, class PosT, class... Ops>
inline void pos_unpack_args(const F& f, const PosT& pos, const Tuple<Ops...>& args); inline auto pos_unpack_args(const F& f, const PosT& pos, const Tuple<Ops...>& args);
} }

View file

@ -41,6 +41,7 @@ namespace CNORXZ
String stringMeta() const; String stringMeta() const;
SizeT meta() const; SizeT meta() const;
CIndex& at(const SizeT& metaPos); CIndex& at(const SizeT& metaPos);
COpRoot<SizeT,CIndex> xpr(const Sptr<CIndex>& _this) const;
template <class Index> template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const; decltype(auto) format(const Sptr<Index>& ind) const;

View file

@ -53,7 +53,8 @@ namespace CNORXZ
String stringMeta() const; String stringMeta() const;
DType meta() const; DType meta() const;
DIndex& at(const DType& meta); DIndex& at(const DType& meta);
DXpr<SizeT> xpr(const Sptr<DIndex>& _this) const;
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const; DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;
const XIndexPtr& xptr() const; const XIndexPtr& xptr() const;

View file

@ -53,6 +53,7 @@ namespace CNORXZ
String stringMeta() const { return THIS().stringMeta(); } String stringMeta() const { return THIS().stringMeta(); }
decltype(auto) meta() const { return THIS().meta(); } decltype(auto) meta() const { return THIS().meta(); }
I& at(const MetaType& meta) { return THIS().at(meta); } I& at(const MetaType& meta) { return THIS().at(meta); }
decltype(auto) xpr(const Sptr<I>& _this) const { return THIS().xpr(_this); }
//template <class Index> //template <class Index>
//decltype(auto) format(const Sptr<Index>& ind) const { return THIS().format(ind); } //decltype(auto) format(const Sptr<Index>& ind) const { return THIS().format(ind); }

View file

@ -3,6 +3,9 @@
#define __cxz_mrange_cc_h__ #define __cxz_mrange_cc_h__
#include "mrange.h" #include "mrange.h"
#include "operation/op_types.h"
#include "operation/op_types.cc.h" // -> do .cc files
#include "operation/op_utility.cc.h" // -> do .cc files
namespace CNORXZ namespace CNORXZ
{ {
@ -408,6 +411,17 @@ namespace CNORXZ
[](const auto&... xs) { return (xs + ...); }); [](const auto&... xs) { return (xs + ...); });
return *this; return *this;
} }
template <class FormatT, class... Indices>
decltype(auto) GMIndex<FormatT,Indices...>::xpr(const Sptr<MIndex<Indices...>>& _this) const
{
return iter<0,NI>( [&](auto i) { return _this->pack()[i]->xpr( _this->pack()[i] ); },
[](const auto&... x) {
return operation( [](const auto&... e) {
return std::make_tuple(e...);
}, x... );
} );
}
template <class FormatT, class... Indices> template <class FormatT, class... Indices>
template <class Xpr, class F> template <class Xpr, class F>

View file

@ -65,6 +65,7 @@ namespace CNORXZ
String stringMeta() const; String stringMeta() const;
MetaType meta() const; MetaType meta() const;
GMIndex& at(const MetaType& metaPos); GMIndex& at(const MetaType& metaPos);
decltype(auto) xpr(const Sptr<MIndex<Indices...>>& _this) const;
template <class Xpr, class F> template <class Xpr, class F>
constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const;

View file

@ -8,6 +8,8 @@
#include "urange.h" #include "urange.h"
#include "index_mul.h" #include "index_mul.h"
#include "xpr/for.h" #include "xpr/for.h"
#include "operation/op_types.h"
#include "operation/op_types.cc.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -118,6 +120,12 @@ namespace CNORXZ
return *this; return *this;
} }
template <typename MetaType>
decltype(auto) UIndex<MetaType>::xpr(const Sptr<UIndex<MetaType>>& _this) const
{
return coproot(mMetaPtr,_this);
}
template <typename MetaType> template <typename MetaType>
size_t UIndex<MetaType>::dim() const // = 1 size_t UIndex<MetaType>::dim() const // = 1
{ {

View file

@ -46,6 +46,7 @@ namespace CNORXZ
String stringMeta() const; String stringMeta() const;
const MetaT& meta() const; const MetaT& meta() const;
UIndex& at(const MetaT& metaPos); UIndex& at(const MetaT& metaPos);
decltype(auto) xpr(const Sptr<UIndex<MetaType>>& _this) const;
template <class Index> template <class Index>
decltype(auto) format(const Sptr<Index>& ind) const; decltype(auto) format(const Sptr<Index>& ind) const;

View file

@ -209,6 +209,13 @@ namespace CNORXZ
return *this; return *this;
} }
template <class Index, typename Meta>
DXpr<SizeT> XIndex<Index,Meta>::xpr(const XIndexPtr& _this) const
{
auto xthis = std::dynamic_pointer_cast<Index>(_this);
return DXpr<SizeT>( mI->xpr(xthis) );
}
template <class Index, typename Meta> template <class Index, typename Meta>
DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr, DXpr<SizeT> XIndex<Index,Meta>::ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const std::function<SizeT(SizeT,SizeT)>&& f) const

View file

@ -45,6 +45,7 @@ namespace CNORXZ
virtual 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 DXpr<SizeT> xpr(const XIndexPtr& _this) const = 0;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const = 0; std::function<SizeT(SizeT,SizeT)>&& f) const = 0;
@ -97,6 +98,7 @@ namespace CNORXZ
virtual String stringMeta() const override final; virtual String stringMeta() const override final;
virtual DType meta() const override final; virtual DType meta() const override final;
virtual XIndexBase& at(const DType& meta) override final; virtual XIndexBase& at(const DType& meta) override final;
virtual DXpr<SizeT> xpr(const XIndexPtr& _this) const override final;
virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, virtual DXpr<SizeT> ifor(const DXpr<SizeT>& xpr,
std::function<SizeT(SizeT,SizeT)>&& f) const override final; std::function<SizeT(SizeT,SizeT)>&& f) const override final;

View file

@ -53,6 +53,7 @@ namespace CNORXZ
String stringMeta() const; String stringMeta() const;
Vector<DType> meta() const; Vector<DType> meta() const;
YIndex& at(const Vector<DType>& meta); YIndex& at(const Vector<DType>& meta);
DXpr<SizeT> xpr(const Sptr<YIndex>& _this) const;
DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const; DXpr<SizeT> ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const;

View file

@ -25,13 +25,17 @@ namespace CNORXZ
template <typename T, class Xpr> template <typename T, class Xpr>
T VXpr<T,Xpr>::vexec(const DPos& last) const T VXpr<T,Xpr>::vexec(const DPos& last) const
{ {
return (*this)(last); CXZ_ERROR("IMPLEMENT!!!" << last.val());
//(*this)(last);
return T();
} }
template <typename T, class Xpr> template <typename T, class Xpr>
T VXpr<T,Xpr>::vexec() const T VXpr<T,Xpr>::vexec() const
{ {
return (*this)(); CXZ_ERROR("IMPLEMENT!!!");
//(*this)();
return T();
} }
template <typename T, class Xpr> template <typename T, class Xpr>

View file

@ -1,5 +1,6 @@
#include "ranges/ranges.h" #include "ranges/ranges.h"
#include "operation/operation.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -106,6 +107,19 @@ namespace CNORXZ
IB::mPos = metaPos; IB::mPos = metaPos;
return *this; return *this;
} }
COpRoot<SizeT,CIndex> CIndex::xpr(const Sptr<CIndex>& _this) const
{
// preliminary solution (TODO: implement xpr that simply returns PosT value):
static Vector<SizeT> m;
if(m.size() < _this->lmax().val()){
m.resize(_this->lmax().val());
for(SizeT i = 0; i != m.size(); ++i) {
m[i] = i;
}
}
return coproot(m.data(), _this);
}
/********************** /**********************

View file

@ -161,7 +161,12 @@ namespace CNORXZ
IB::mPos = mI->pos(); IB::mPos = mI->pos();
return *this; return *this;
} }
DXpr<SizeT> DIndex::xpr(const Sptr<DIndex>& _this) const
{
return mI->xpr(_this->xptr());
}
DXpr<SizeT> DIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const DXpr<SizeT> DIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{ {
return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)) ); return DXpr<SizeT>(mI->ifor(xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)) );

View file

@ -338,6 +338,12 @@ namespace CNORXZ
return *this; return *this;
} }
DXpr<SizeT> YIndex::xpr(const Sptr<YIndex>& _this) const
{
CXZ_ERROR("IMPLEMENT!!!" << _this->lmax().val());
return DXpr<SizeT>();
}
DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const DXpr<SizeT> YIndex::ifor(const DXpr<SizeT>& xpr, std::function<SizeT(SizeT,SizeT)>&& f) const
{ {
return mkIFor(0, xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f)); return mkIFor(0, xpr, std::forward<std::function<SizeT(SizeT,SizeT)>>(f));

View file

@ -28,7 +28,6 @@ namespace CNORXZ
virtual ContentType type() const = 0; virtual ContentType type() const = 0;
virtual bool ro() const = 0; virtual bool ro() const = 0;
virtual ContentBase& open() = 0; virtual ContentBase& open() = 0;
virtual ContentBase& write() = 0;
virtual ContentBase& close() = 0; virtual ContentBase& close() = 0;
virtual String path() const = 0; virtual String path() const = 0;
virtual String filename() const = 0; virtual String filename() const = 0;

View file

@ -23,7 +23,6 @@ namespace CNORXZ
virtual ContentType type() const override final; virtual ContentType type() const override final;
virtual bool ro() const override final; virtual bool ro() const override final;
virtual File& open() override final; virtual File& open() override final;
virtual File& write() override final;
virtual File& close() override final; virtual File& close() override final;
virtual String path() const override final; virtual String path() const override final;
virtual String filename() const override final; virtual String filename() const override final;

View file

@ -18,7 +18,6 @@ namespace CNORXZ
virtual ContentType type() const override; virtual ContentType type() const override;
virtual bool ro() const override; virtual bool ro() const override;
virtual Group& open() override; // load group if existing, else create new group virtual Group& open() override; // load group if existing, else create new group
virtual Group& write() override;
virtual Group& close() override; virtual Group& close() override;
virtual String path() const override; virtual String path() const override;
virtual String filename() const override; virtual String filename() const override;

View file

@ -0,0 +1,38 @@
#ifndef __cxz_h5_table_h__
#define __cxz_h5_table_h__
#include "h5_content_base.h"
namespace CNORXZ
{
namespace hdf5
{
class Table : public ContentBase
{
public:
DEFAULT_MEMBERS(Table);
Table(const String& name, const ContentBase* _parent);
~Table();
virtual ContentType type() const override final;
virtual bool ro() const override final;
virtual Table& open() override final;
virtual Table& close() override final;
virtual String path() const override final;
virtual String filename() const override final;
template <class F>
decltype(auto) readRecords(F&& f) const;
private:
RangePtr mRecords;
RangePtr mFields; // -> FIndex (position -> offset)
MArray mSizes;
MArray mOffsets;
MArray mTypes;
};
}
}
#endif

View file

@ -49,15 +49,6 @@ namespace CNORXZ
return *this; return *this;
} }
File& File::write()
{
CXZ_ASSERT( not mRo, "could not write to file: opened as read-only" );
for(auto& x: mCont){
x->write();
}
return *this;
}
File& File::close() File& File::close()
{ {
if(mCont.range() != nullptr){ if(mCont.range() != nullptr){

View file

@ -40,12 +40,6 @@ namespace CNORXZ
return *this; return *this;
} }
Group& Group::write()
{
// ...!!!
return *this;
}
Group& Group::close() Group& Group::close()
{ {
if(mId != 0){ if(mId != 0){