diff --git a/src/include/operation/op_types.cc.h b/src/include/operation/op_types.cc.h index f09cd97..800855b 100644 --- a/src/include/operation/op_types.cc.h +++ b/src/include/operation/op_types.cc.h @@ -4,7 +4,7 @@ #include "op_types.h" //#include "xpr/xpr.h" -//#include "op_utility.h" +#include "op_utility.h" #include "extensions/extensions.h" namespace CNORXZ @@ -33,7 +33,7 @@ namespace CNORXZ template constexpr decltype(auto) COpInterface::o(F&& f, Args&&... args) const { - return mkOperation(std::forward(f), THIS().r(), args...); + return operation(std::forward(f), THIS().r(), args...); } @@ -45,7 +45,7 @@ namespace CNORXZ template constexpr decltype(auto) OpInterface::ax(const Sptr& 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 @@ -116,7 +116,13 @@ namespace CNORXZ { return COpRoot(a, ind); } - + + template + constexpr decltype(auto) coproot(const T* a, const Sptr& ind) + { + return COpRoot(a, ind); + } + /**************** * OpCont * ****************/ @@ -364,7 +370,7 @@ namespace CNORXZ } template - constexpr decltype(auto) mkOperation(F&& f, const Ops&... ops) + constexpr decltype(auto) operation(F&& f, const Ops&... ops) { return Operation(std::forward(f), ops...); } @@ -400,11 +406,21 @@ namespace CNORXZ } template - constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr& i) + constexpr decltype(auto) contracion(F&& f, Op&& op, const Sptr& i) { typedef decltype(i->ifor( op, f )) CXprT; // TODO: implement ifor with func arg!!! return Contraction( i->ifor( op, f ) ); } + + /************************ + * various functions * + ************************/ + + template + constexpr decltype(auto) indexOp(const Sptr& i) + { + return i->xpr(i); + } } #endif diff --git a/src/include/operation/op_types.h b/src/include/operation/op_types.h index 0624425..827f4ad 100644 --- a/src/include/operation/op_types.h +++ b/src/include/operation/op_types.h @@ -93,7 +93,10 @@ namespace CNORXZ template constexpr decltype(auto) coproot(const CArrayBase& a, const Sptr& ind); - + + template + constexpr decltype(auto) coproot(const T* a, const Sptr& ind); + template class OpCont : public OpInterface> { @@ -207,7 +210,7 @@ namespace CNORXZ }; template - constexpr decltype(auto) mkOperation(F&& f, const Ops&... ops); + constexpr decltype(auto) operation(F&& f, const Ops&... ops); template struct op_size> @@ -236,7 +239,10 @@ namespace CNORXZ }; template - constexpr decltype(auto) mkContracion(F&& f, Op&& op, const Sptr& i); + constexpr decltype(auto) contracion(F&& f, Op&& op, const Sptr& i); + + template + constexpr decltype(auto) indexOp(const Sptr& i); } #endif diff --git a/src/include/operation/op_utility.cc.h b/src/include/operation/op_utility.cc.h index fa4462e..ed8fa45 100644 --- a/src/include/operation/op_utility.cc.h +++ b/src/include/operation/op_utility.cc.h @@ -33,20 +33,20 @@ namespace CNORXZ } template - 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) { - f(std::get(args)(pos_get(opsizes)>(pos))...); + return f(std::get(args)(pos_get(opsizes)>(pos))...); } template - inline void pos_unpack_args(const F& f, const PosT& pos, const Tuple& args) + inline auto pos_unpack_args(const F& f, const PosT& pos, const Tuple& args) { static_assert(is_pos_type::value, "got non-pos-type"); static_assert((is_operation::value and ...), "got non-operation type"); typedef std::make_index_sequence Idxs; typedef std::index_sequence::value...> OpSizes; - pos_unpack_args_i(f, pos, args, OpSizes{}, Idxs{}); + return pos_unpack_args_i(f, pos, args, OpSizes{}, Idxs{}); } } diff --git a/src/include/operation/op_utility.h b/src/include/operation/op_utility.h index 05be1a0..dfabab4 100644 --- a/src/include/operation/op_utility.h +++ b/src/include/operation/op_utility.h @@ -13,11 +13,11 @@ namespace CNORXZ constexpr SizeT sum_index_sequence(std::index_sequence is); template - 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); template - inline void pos_unpack_args(const F& f, const PosT& pos, const Tuple& args); + inline auto pos_unpack_args(const F& f, const PosT& pos, const Tuple& args); } diff --git a/src/include/ranges/crange.h b/src/include/ranges/crange.h index 549bca6..0f5e7a8 100644 --- a/src/include/ranges/crange.h +++ b/src/include/ranges/crange.h @@ -41,6 +41,7 @@ namespace CNORXZ String stringMeta() const; SizeT meta() const; CIndex& at(const SizeT& metaPos); + COpRoot xpr(const Sptr& _this) const; template decltype(auto) format(const Sptr& ind) const; diff --git a/src/include/ranges/dindex.h b/src/include/ranges/dindex.h index 2a0df57..f5cbfde 100644 --- a/src/include/ranges/dindex.h +++ b/src/include/ranges/dindex.h @@ -53,7 +53,8 @@ namespace CNORXZ String stringMeta() const; DType meta() const; DIndex& at(const DType& meta); - + DXpr xpr(const Sptr& _this) const; + DXpr ifor(const DXpr& xpr, std::function&& f) const; const XIndexPtr& xptr() const; diff --git a/src/include/ranges/index_base.h b/src/include/ranges/index_base.h index d2925ef..74e6f7a 100644 --- a/src/include/ranges/index_base.h +++ b/src/include/ranges/index_base.h @@ -53,6 +53,7 @@ namespace CNORXZ String stringMeta() const { return THIS().stringMeta(); } decltype(auto) meta() const { return THIS().meta(); } I& at(const MetaType& meta) { return THIS().at(meta); } + decltype(auto) xpr(const Sptr& _this) const { return THIS().xpr(_this); } //template //decltype(auto) format(const Sptr& ind) const { return THIS().format(ind); } diff --git a/src/include/ranges/mrange.cc.h b/src/include/ranges/mrange.cc.h index 32225f3..980ec22 100644 --- a/src/include/ranges/mrange.cc.h +++ b/src/include/ranges/mrange.cc.h @@ -3,6 +3,9 @@ #define __cxz_mrange_cc_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 { @@ -408,6 +411,17 @@ namespace CNORXZ [](const auto&... xs) { return (xs + ...); }); return *this; } + + template + decltype(auto) GMIndex::xpr(const Sptr>& _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 template diff --git a/src/include/ranges/mrange.h b/src/include/ranges/mrange.h index dd80c28..f9a950c 100644 --- a/src/include/ranges/mrange.h +++ b/src/include/ranges/mrange.h @@ -65,6 +65,7 @@ namespace CNORXZ String stringMeta() const; MetaType meta() const; GMIndex& at(const MetaType& metaPos); + decltype(auto) xpr(const Sptr>& _this) const; template constexpr decltype(auto) ifor(const Xpr& xpr, F&& f) const; diff --git a/src/include/ranges/urange.cc.h b/src/include/ranges/urange.cc.h index f9d51e8..db64eec 100644 --- a/src/include/ranges/urange.cc.h +++ b/src/include/ranges/urange.cc.h @@ -8,6 +8,8 @@ #include "urange.h" #include "index_mul.h" #include "xpr/for.h" +#include "operation/op_types.h" +#include "operation/op_types.cc.h" namespace CNORXZ { @@ -118,6 +120,12 @@ namespace CNORXZ return *this; } + template + decltype(auto) UIndex::xpr(const Sptr>& _this) const + { + return coproot(mMetaPtr,_this); + } + template size_t UIndex::dim() const // = 1 { diff --git a/src/include/ranges/urange.h b/src/include/ranges/urange.h index 39e5471..5fdbcf2 100644 --- a/src/include/ranges/urange.h +++ b/src/include/ranges/urange.h @@ -46,6 +46,7 @@ namespace CNORXZ String stringMeta() const; const MetaT& meta() const; UIndex& at(const MetaT& metaPos); + decltype(auto) xpr(const Sptr>& _this) const; template decltype(auto) format(const Sptr& ind) const; diff --git a/src/include/ranges/xindex.cc.h b/src/include/ranges/xindex.cc.h index 589c3ec..6fd6601 100644 --- a/src/include/ranges/xindex.cc.h +++ b/src/include/ranges/xindex.cc.h @@ -209,6 +209,13 @@ namespace CNORXZ return *this; } + template + DXpr XIndex::xpr(const XIndexPtr& _this) const + { + auto xthis = std::dynamic_pointer_cast(_this); + return DXpr( mI->xpr(xthis) ); + } + template DXpr XIndex::ifor(const DXpr& xpr, std::function&& f) const diff --git a/src/include/ranges/xindex.h b/src/include/ranges/xindex.h index 02eca13..9940b4a 100644 --- a/src/include/ranges/xindex.h +++ b/src/include/ranges/xindex.h @@ -45,6 +45,7 @@ namespace CNORXZ virtual String stringMeta() const = 0; virtual DType meta() const = 0; virtual XIndexBase& at(const DType& meta) = 0; + virtual DXpr xpr(const XIndexPtr& _this) const = 0; virtual DXpr ifor(const DXpr& xpr, std::function&& f) const = 0; @@ -97,6 +98,7 @@ namespace CNORXZ virtual String stringMeta() const override final; virtual DType meta() const override final; virtual XIndexBase& at(const DType& meta) override final; + virtual DXpr xpr(const XIndexPtr& _this) const override final; virtual DXpr ifor(const DXpr& xpr, std::function&& f) const override final; diff --git a/src/include/ranges/yrange.h b/src/include/ranges/yrange.h index 14d4f4b..43f6f8b 100644 --- a/src/include/ranges/yrange.h +++ b/src/include/ranges/yrange.h @@ -53,6 +53,7 @@ namespace CNORXZ String stringMeta() const; Vector meta() const; YIndex& at(const Vector& meta); + DXpr xpr(const Sptr& _this) const; DXpr ifor(const DXpr& xpr, std::function&& f) const; diff --git a/src/include/xpr/xpr_base.cc.h b/src/include/xpr/xpr_base.cc.h index dcc24c5..71421c8 100644 --- a/src/include/xpr/xpr_base.cc.h +++ b/src/include/xpr/xpr_base.cc.h @@ -25,13 +25,17 @@ namespace CNORXZ template T VXpr::vexec(const DPos& last) const { - return (*this)(last); + CXZ_ERROR("IMPLEMENT!!!" << last.val()); + //(*this)(last); + return T(); } template T VXpr::vexec() const { - return (*this)(); + CXZ_ERROR("IMPLEMENT!!!"); + //(*this)(); + return T(); } template diff --git a/src/lib/ranges/crange.cc b/src/lib/ranges/crange.cc index 2d4182d..0e44f03 100644 --- a/src/lib/ranges/crange.cc +++ b/src/lib/ranges/crange.cc @@ -1,5 +1,6 @@ #include "ranges/ranges.h" +#include "operation/operation.h" namespace CNORXZ { @@ -106,6 +107,19 @@ namespace CNORXZ IB::mPos = metaPos; return *this; } + + COpRoot CIndex::xpr(const Sptr& _this) const + { + // preliminary solution (TODO: implement xpr that simply returns PosT value): + static Vector 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); + } /********************** diff --git a/src/lib/ranges/dindex.cc b/src/lib/ranges/dindex.cc index 4af6bfb..3c420c1 100644 --- a/src/lib/ranges/dindex.cc +++ b/src/lib/ranges/dindex.cc @@ -161,7 +161,12 @@ namespace CNORXZ IB::mPos = mI->pos(); return *this; } - + + DXpr DIndex::xpr(const Sptr& _this) const + { + return mI->xpr(_this->xptr()); + } + DXpr DIndex::ifor(const DXpr& xpr, std::function&& f) const { return DXpr(mI->ifor(xpr, std::forward>(f)) ); diff --git a/src/lib/ranges/yrange.cc b/src/lib/ranges/yrange.cc index 25eeec8..634d9fe 100644 --- a/src/lib/ranges/yrange.cc +++ b/src/lib/ranges/yrange.cc @@ -338,6 +338,12 @@ namespace CNORXZ return *this; } + DXpr YIndex::xpr(const Sptr& _this) const + { + CXZ_ERROR("IMPLEMENT!!!" << _this->lmax().val()); + return DXpr(); + } + DXpr YIndex::ifor(const DXpr& xpr, std::function&& f) const { return mkIFor(0, xpr, std::forward>(f)); diff --git a/src/opt/hdf5/include/h5_content_base.h b/src/opt/hdf5/include/h5_content_base.h index 3685936..ce77097 100644 --- a/src/opt/hdf5/include/h5_content_base.h +++ b/src/opt/hdf5/include/h5_content_base.h @@ -28,7 +28,6 @@ namespace CNORXZ virtual ContentType type() const = 0; virtual bool ro() const = 0; virtual ContentBase& open() = 0; - virtual ContentBase& write() = 0; virtual ContentBase& close() = 0; virtual String path() const = 0; virtual String filename() const = 0; diff --git a/src/opt/hdf5/include/h5_file.h b/src/opt/hdf5/include/h5_file.h index 5c0a5f7..52c2849 100644 --- a/src/opt/hdf5/include/h5_file.h +++ b/src/opt/hdf5/include/h5_file.h @@ -23,7 +23,6 @@ namespace CNORXZ virtual ContentType type() const override final; virtual bool ro() const override final; virtual File& open() override final; - virtual File& write() override final; virtual File& close() override final; virtual String path() const override final; virtual String filename() const override final; diff --git a/src/opt/hdf5/include/h5_group.h b/src/opt/hdf5/include/h5_group.h index da870c5..0196028 100644 --- a/src/opt/hdf5/include/h5_group.h +++ b/src/opt/hdf5/include/h5_group.h @@ -18,7 +18,6 @@ namespace CNORXZ virtual ContentType type() const override; virtual bool ro() const override; virtual Group& open() override; // load group if existing, else create new group - virtual Group& write() override; virtual Group& close() override; virtual String path() const override; virtual String filename() const override; diff --git a/src/opt/hdf5/include/h5_table.h b/src/opt/hdf5/include/h5_table.h new file mode 100644 index 0000000..c1feb64 --- /dev/null +++ b/src/opt/hdf5/include/h5_table.h @@ -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 + decltype(auto) readRecords(F&& f) const; + + private: + RangePtr mRecords; + RangePtr mFields; // -> FIndex (position -> offset) + MArray mSizes; + MArray mOffsets; + MArray mTypes; + }; + } +} + +#endif diff --git a/src/opt/hdf5/lib/h5_file.cc b/src/opt/hdf5/lib/h5_file.cc index 96fffd3..ec1452e 100644 --- a/src/opt/hdf5/lib/h5_file.cc +++ b/src/opt/hdf5/lib/h5_file.cc @@ -49,15 +49,6 @@ namespace CNORXZ 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() { if(mCont.range() != nullptr){ diff --git a/src/opt/hdf5/lib/h5_group.cc b/src/opt/hdf5/lib/h5_group.cc index 28de33c..c909808 100644 --- a/src/opt/hdf5/lib/h5_group.cc +++ b/src/opt/hdf5/lib/h5_group.cc @@ -40,12 +40,6 @@ namespace CNORXZ return *this; } - Group& Group::write() - { - // ...!!! - return *this; - } - Group& Group::close() { if(mId != 0){