From 058d7503d798ec43745a9151c4b8ab30d5f10eee Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 5 Mar 2018 18:46:29 +0100 Subject: [PATCH] im com (slice) --- CMakeLists.txt | 2 +- src/include/ranges/multi_range.h | 8 +-- src/include/slice.h | 102 ++++++------------------------- 3 files changed, 22 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a31b83..0342bcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) project(multi_array) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -Wno-uninitialized -O3 -g") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3 -g") enable_testing() diff --git a/src/include/ranges/multi_range.h b/src/include/ranges/multi_range.h index 8ce6396..4fded25 100644 --- a/src/include/ranges/multi_range.h +++ b/src/include/ranges/multi_range.h @@ -168,13 +168,13 @@ namespace MultiArrayTools template auto getPtr() const -> decltype( std::get( mSpace ) )&; - virtual size_t dim() const override; - virtual size_t size() const override; + virtual size_t dim() const final; + virtual size_t size() const final; const SpaceType& space() const; - virtual IndexType begin() const override; - virtual IndexType end() const override; + virtual IndexType begin() const final; + virtual IndexType end() const final; friend MultiRangeFactory; diff --git a/src/include/slice.h b/src/include/slice.h index f68d340..cf8d0d7 100644 --- a/src/include/slice.h +++ b/src/include/slice.h @@ -3,10 +3,10 @@ #define __slice_h__ #include "multi_array_base.h" +#include "multi_array_operation.h" namespace MultiArrayTools { - template class Slice : public MutableMultiArrayBase { @@ -14,15 +14,12 @@ namespace MultiArrayTools typedef ContainerRange CRange; typedef MultiArrayBase MAB; - typedef typename CRange::IndexType IType; + typedef ContainerIndex IType; DEFAULT_MEMBERS(Slice); - // RITypes = Range XOR Index depending on whether const XOR opern - template - Slice(MutableMultiArrayBase& ma, - const std::shared_ptr&... ris); - + Slice(T* data, const std::shared_ptr&... ranges); + virtual const T& operator[](const IType& i) const override; virtual T& operator[](const IType& i) override; virtual const T& at(const typename IType::MetaType& meta) const override; @@ -35,6 +32,10 @@ namespace MultiArrayTools virtual auto begin() const -> IType override; virtual auto end() const -> IType override; + + template + auto define(const std::shared_ptr&... inds) + -> SliceDef >; private: T* mData; @@ -48,84 +49,15 @@ namespace MultiArrayTools namespace MultiArrayTools { - - namespace - { - - //size_t sum(size_t arg) - //{ - // return arg; - //} - - template - size_t sum(size_t arg, SizeTypes... args) - { - return arg + sum(args...); - } - - template - struct XX - { - template - static auto ri_to_tuple(const std::shared_ptr& ri) - -> std::tuple - { - return std::make_tuple(ri); - } - - template - static size_t ri_to_start_pos(const std::shared_ptr& ri) - { - return 0; - } - }; - - template <> - struct XX - { - template - static auto ri_to_tuple(const std::shared_ptr& ri) - -> std::tuple<> - { - return std::make_tuple(); - } - - template - static size_t ri_to_start_pos(const std::shared_ptr& ri) - { - return ri->pos(); - } - - }; - - template - auto mkSliceRange(const std::shared_ptr&... ris) - -> decltype(std::tuple_cat(XX::ri_to_tuple(ris)...)) - { - return std::tuple_cat(XX::ri_to_tuple(ris)...); - } - - template - size_t mkStartPos(const std::shared_ptr&... ris) - { - return sum(ri_to_start_pos(ris)...); - } - - } /************* - * Slice * + * Slice * *************/ - + template - template - Slice::Slice(MutableMultiArrayBase& ma, - const std::shared_ptr&... ris) : - MutableMultiArrayBase( mkSliceRange(ris...) ), - mData(ma.data() + mkStartPos(ris...)) - { - MAB::mProtoI.format( mBlockSizes(mkSliceBlocks(ris...)) ); - } + Slice::Slice(T* data, const std::shared_ptr&... ranges) : + MutableMultiArrayBase(ranges...), + mData(data) {} template const T& Slice::operator[](const IType& i) const @@ -134,7 +66,7 @@ namespace MultiArrayTools assert(i.container() == reinterpret_cast(this)); return mData[ i.pos() ]; } - + template T& Slice::operator[](const IType& i) { @@ -142,19 +74,19 @@ namespace MultiArrayTools assert(i.container() == reinterpret_cast(this)); return mData[ i.pos() ]; } - + template const T& Slice::at(const typename IType::MetaType& meta) const { return mData[ begin().at(meta).pos() ]; } - + template T& Slice::at(const typename IType::MetaType& meta) { return mData[ begin().at(meta).pos() ]; } - + template const T* Slice::data() const {