From 6597ac6cb0a1b2b7a6334133b4c6cd45f0abae55 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Sat, 18 Aug 2018 16:24:13 +0200 Subject: [PATCH] fix compile errors in map range --- src/include/map_range.h | 62 +++++++++++---------- src/include/map_range_factory_product_map.h | 26 +++++++++ src/include/mbase_def.h | 12 ++++ src/include/multi_array_header.h | 1 + src/lib/CMakeLists.txt | 1 + src/lib/map_range_factory_product_map.cc | 7 +++ 6 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 src/include/map_range_factory_product_map.h create mode 100644 src/lib/map_range_factory_product_map.cc diff --git a/src/include/map_range.h b/src/include/map_range.h index bfad766..e434641 100644 --- a/src/include/map_range.h +++ b/src/include/map_range.h @@ -8,12 +8,12 @@ #include #include -//#include "base_def.h" +#include "mbase_def.h" #include "ranges/range_base.h" #include "ranges/index_base.h" #include "ranges/rpack_num.h" -#include "ranges/multi_range_factory_product_map.h" +#include "map_range_factory_product_map.h" #include "ranges/x_to_string.h" #include "ranges/type_map.h" @@ -29,7 +29,7 @@ namespace MultiArrayTools template auto mkMapOp(const MA& ma, const std::tuple...>& itp) - -> ConstOperation + -> ConstOperationRoot { return PackNum::mkMapOp(ma, itp); } @@ -38,25 +38,25 @@ namespace MultiArrayTools class OpExpr { public: - typedef SingleIndex OIType; - typedef MapF::IndexPack IndexPack; + typedef SingleIndex OIType; + typedef typename MapF::IndexPack IndexPack; static constexpr size_t LAYER = Expr::LAYER + 1; static constexpr size_t SIZE = Expr::SIZE; private: OpExpr() = default; - const IndexClass* mIndPtr; + const OIType* mIndPtr; size_t mSPos; size_t mMax; Expr mExpr; - typedef decltype(mOp.rootSteps(iPtrNum).extend( mExpr.rootSteps(iPtrNum) )) ExtType; - ExtType mExt; - typedef decltype(mkMapOp(std::declval(), std::declval())) Op; Op mOp; + typedef decltype(mOp.rootSteps(std::declval()).extend( mExpr.rootSteps(std::declval()) )) ExtType; + ExtType mExt; + public: OpExpr(const OpExpr& in) = default; OpExpr(OpExpr&& in) = default; @@ -84,7 +84,7 @@ namespace MultiArrayTools typedef std::tuple MetaType; typedef MapRange RangeType; typedef MapIndex IType; - typedef SingleIndex OIType; + typedef SingleIndex OIType; static constexpr IndexType sType() { return IndexType::MULTI; } static constexpr size_t sDim() { return sizeof...(Indices); } @@ -163,8 +163,9 @@ namespace MultiArrayTools template auto ifor(Exprs exs) const - -> decltype(RPackNum::mkFor(mIPack, OpExpr( range()->map() , mOutIndex, exs ) )); - + -> decltype(RPackNum::mkFor + (mIPack, OpExpr( range()->map(), mIPack, mOutIndex, exs ) ) ); + /* template auto iforh(Exprs exs) const @@ -173,7 +174,7 @@ namespace MultiArrayTools }; template - auto mapResult >(const std::shared_ptr >& ind) + auto mapResult/* >*/(const std::shared_ptr >& ind) -> decltype(ind->outIndex()) { return ind->outIndex(); @@ -214,8 +215,8 @@ namespace MultiArrayTools typedef std::tuple...> Space; typedef MapIndex IndexType; typedef MapRange RangeType; - typedef SingleRange ORType; - typedef SingleRangeFactory ORFType; + typedef SingleRange ORType; + typedef SingleRangeFactory ORFType; //typedef typename RangeInterface >::IndexType IndexType; protected: @@ -228,7 +229,7 @@ namespace MultiArrayTools Space mSpace; const MapF& mMapf; - shred_ptr mOutRange; + std::shared_ptr mOutRange; public: @@ -240,7 +241,7 @@ namespace MultiArrayTools template auto getPtr() const -> decltype( std::get( mSpace ) )&; - shred_ptr outRange() const; + std::shared_ptr outRange() const; const MapF& map() const; virtual size_t dim() const final; @@ -289,8 +290,8 @@ namespace MultiArrayTools template OpExpr::OpExpr(const MapF& mapf, const IndexPack& ipack, const std::shared_ptr oind, Expr ex) : - mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(expr), - mExt(expr.rootSteps( reinterpret_cast( mIndPtr.get() ))), + mIndPtr(oind.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mExpr(ex), + mExt(ex.rootSteps( reinterpret_cast( mIndPtr.get() ))), mOp(mapf, ipack) { assert(mIndPtr != nullptr); @@ -302,8 +303,8 @@ namespace MultiArrayTools inline void OpExpr::operator()(size_t mlast, ExtType last) const { - const ExtType npos = last + mExt*pos; constexpr size_t NEXT = Op::SIZE; + const ExtType npos = last; const size_t pos = mIndPtr->getMeta( mOp.get( npos ) ); const size_t mnpos = PosForward::value(mlast, mMax, pos); mExpr(mnpos, Getter::template getX( npos ) ); @@ -313,8 +314,8 @@ namespace MultiArrayTools inline void OpExpr::operator()(size_t mlast) const { const ExtType last; - const ExtType npos = last + mExt*pos; constexpr size_t NEXT = Op::SIZE; + const ExtType npos = last; const size_t pos = mIndPtr->at( mOp.get( npos ) ).pos(); const size_t mnpos = PosForward::value(mlast, mMax, pos); mExpr(mnpos, Getter::template getX( npos )); @@ -363,7 +364,7 @@ namespace MultiArrayTools IB::mPos = RPackNum::makePos(mIPack); std::get(mBlockSizes) = 1; RPackNum::initBlockSizes(mBlockSizes, mIPack); // has one more element! - mOutIndex = std::dynamic_pointer_cast( IB::mRangePtr )->outRange()->begin(); + mOutIndex = std::dynamic_pointer_cast( IB::mRangePtr )->outRange()->begin(); } template @@ -401,7 +402,7 @@ namespace MultiArrayTools } template - std::shared_ptr MapIndex::outIndex() const + auto MapIndex::outIndex() const -> std::shared_ptr { return mOutIndex; } @@ -546,9 +547,10 @@ namespace MultiArrayTools template auto MapIndex::ifor(Exprs exs) const -> decltype(RPackNum::mkFor - (mIPack, OpExpr( range()->map(), mIPack, mOutIndex, exs ) ) ) + (mIPack, OpExpr( range()->map(), mIPack, mOutIndex, exs ) ) ) { - return RPackNum::mkFor(mIPack, OpExpr( range()->map(), mIPack, mOutIndex, exs ) ); + return RPackNum::mkFor + (mIPack, OpExpr( range()->map(), mIPack, mOutIndex, exs ) ); } /* template @@ -600,6 +602,8 @@ namespace MultiArrayTools if(not check){ std::vector pv(sizeof...(Ranges)); RPackNum::RangesToVec(ptp, pv); + pv.push_back( reinterpret_cast + ( &std::dynamic_pointer_cast( mProd ).mMapf ) ); MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv; out = mProd; } @@ -615,7 +619,7 @@ namespace MultiArrayTools mSpace(std::make_tuple(rs...)), mMapf(mapf) { - std::vector outmeta; + std::vector outmeta; // set !!!! ORFType orf(outmeta); mOutRange = std::dynamic_pointer_cast( orf.create() ); @@ -626,7 +630,7 @@ namespace MultiArrayTools mSpace( space ), mMapf(mapf) { - std::vector outmeta; + std::vector outmeta; // set !!!! ORFType orf(outmeta); mOutRange = std::dynamic_pointer_cast( orf.create() ); @@ -647,13 +651,13 @@ namespace MultiArrayTools } template - shred_ptr MapRange::outRange() const + auto MapRange::outRange() const -> std::shared_ptr { return mOutRange; } template - const MapF& map() const + const MapF& MapRange::map() const { return mMapf; } diff --git a/src/include/map_range_factory_product_map.h b/src/include/map_range_factory_product_map.h new file mode 100644 index 0000000..fea4cba --- /dev/null +++ b/src/include/map_range_factory_product_map.h @@ -0,0 +1,26 @@ + +#ifndef __map_range_factory_product_map_h__ +#define __map_range_factory_product_map_h__ + +#include +#include +#include +#include "ranges/rbase_def.h" +#include "mbase_def.h" + +namespace MultiArrayTools +{ + class MapRangeFactoryProductMap + { + public: + + template + friend class MapRangeFactory; + + private: + static std::map,std::vector > mAleadyCreated; + }; + +} + +#endif diff --git a/src/include/mbase_def.h b/src/include/mbase_def.h index 886ddcc..891c47b 100644 --- a/src/include/mbase_def.h +++ b/src/include/mbase_def.h @@ -66,6 +66,18 @@ namespace MultiArrayTools // slice.h template class SliceDef; + + // map_range.h + template + class MapIndex; + + // map_range.h + template + class MapRangeFactory; + + // map_range.h + template + class MapRange; } #endif diff --git a/src/include/multi_array_header.h b/src/include/multi_array_header.h index 0879676..61effc1 100644 --- a/src/include/multi_array_header.h +++ b/src/include/multi_array_header.h @@ -17,6 +17,7 @@ #include "functional_multi_array.h" #include "helper_tools.h" #include "operation_def.h" +#include "map_range.h" //#include "slice.h" //#include "manipulator.h" //#include "range_transformer.h" diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c2c6a05..fcbfd9f 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -3,6 +3,7 @@ set(libmultiarray_a_SOURCES ${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/anonymous_range.cc ${CMAKE_SOURCE_DIR}/src/lib/ranges/multi_range_factory_product_map.cc + ${CMAKE_SOURCE_DIR}/src/lib/map_range_factory_product_map.cc ) file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc") diff --git a/src/lib/map_range_factory_product_map.cc b/src/lib/map_range_factory_product_map.cc new file mode 100644 index 0000000..563ec74 --- /dev/null +++ b/src/lib/map_range_factory_product_map.cc @@ -0,0 +1,7 @@ + +#include "map_range_factory_product_map.h" + +namespace MultiArrayTools +{ + std::map,std::vector > MapRangeFactoryProductMap::mAleadyCreated; +}