im com (slice)

This commit is contained in:
Christian Zimmermann 2018-03-05 18:46:29 +01:00
parent 4df82f263e
commit 058d7503d7
3 changed files with 22 additions and 90 deletions

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(multi_array) 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() enable_testing()

View file

@ -168,13 +168,13 @@ namespace MultiArrayTools
template <size_t N> template <size_t N>
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&; auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
virtual size_t dim() const override; virtual size_t dim() const final;
virtual size_t size() const override; virtual size_t size() const final;
const SpaceType& space() const; const SpaceType& space() const;
virtual IndexType begin() const override; virtual IndexType begin() const final;
virtual IndexType end() const override; virtual IndexType end() const final;
friend MultiRangeFactory<Ranges...>; friend MultiRangeFactory<Ranges...>;

View file

@ -3,10 +3,10 @@
#define __slice_h__ #define __slice_h__
#include "multi_array_base.h" #include "multi_array_base.h"
#include "multi_array_operation.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {
template <typename T, class... SRanges> template <typename T, class... SRanges>
class Slice : public MutableMultiArrayBase<T,SRanges...> class Slice : public MutableMultiArrayBase<T,SRanges...>
{ {
@ -14,14 +14,11 @@ namespace MultiArrayTools
typedef ContainerRange<T,SRanges...> CRange; typedef ContainerRange<T,SRanges...> CRange;
typedef MultiArrayBase<T,SRanges...> MAB; typedef MultiArrayBase<T,SRanges...> MAB;
typedef typename CRange::IndexType IType; typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
DEFAULT_MEMBERS(Slice); DEFAULT_MEMBERS(Slice);
// RITypes = Range XOR Index depending on whether const XOR opern Slice(T* data, const std::shared_ptr<SRanges>&... ranges);
template <class... RITypes>
Slice(MutableMultiArrayBase<T,typename RITypes::RangeType...>& ma,
const std::shared_ptr<RITypes>&... ris);
virtual const T& operator[](const IType& i) const override; virtual const T& operator[](const IType& i) const override;
virtual T& operator[](const IType& i) override; virtual T& operator[](const IType& i) override;
@ -36,6 +33,10 @@ namespace MultiArrayTools
virtual auto begin() const -> IType override; virtual auto begin() const -> IType override;
virtual auto end() const -> IType override; virtual auto end() const -> IType override;
template <class... MARanges>
auto define(const std::shared_ptr<typename SRanges::IType>&... inds)
-> SliceDef<T,OperationRoot<T,MARanges...> >;
private: private:
T* mData; T* mData;
}; };
@ -49,83 +50,14 @@ namespace MultiArrayTools
namespace MultiArrayTools namespace MultiArrayTools
{ {
namespace
{
//size_t sum(size_t arg)
//{
// return arg;
//}
template <typename... SizeTypes>
size_t sum(size_t arg, SizeTypes... args)
{
return arg + sum(args...);
}
template <bool ISINDEX>
struct XX
{
template <class RI>
static auto ri_to_tuple(const std::shared_ptr<RI>& ri)
-> std::tuple<RI>
{
return std::make_tuple(ri);
}
template <class RI>
static size_t ri_to_start_pos(const std::shared_ptr<RI>& ri)
{
return 0;
}
};
template <>
struct XX<true>
{
template <class RI>
static auto ri_to_tuple(const std::shared_ptr<RI>& ri)
-> std::tuple<>
{
return std::make_tuple();
}
template <class RI>
static size_t ri_to_start_pos(const std::shared_ptr<RI>& ri)
{
return ri->pos();
}
};
template <class... RITypes>
auto mkSliceRange(const std::shared_ptr<RITypes>&... ris)
-> decltype(std::tuple_cat(XX<RITypes::ISINDEX>::ri_to_tuple(ris)...))
{
return std::tuple_cat(XX<RITypes::ISINDEX>::ri_to_tuple(ris)...);
}
template <class... RITypes>
size_t mkStartPos(const std::shared_ptr<RITypes>&... ris)
{
return sum(ri_to_start_pos(ris)...);
}
}
/************* /*************
* Slice * * Slice *
*************/ *************/
template <typename T, class... SRanges> template <typename T, class... SRanges>
template <class... RITypes> Slice<T,SRanges...>::Slice(T* data, const std::shared_ptr<SRanges>&... ranges) :
Slice<T,SRanges...>::Slice(MutableMultiArrayBase<T,typename RITypes::RangeType...>& ma, MutableMultiArrayBase<T,SRanges...>(ranges...),
const std::shared_ptr<RITypes>&... ris) : mData(data) {}
MutableMultiArrayBase<T,SRanges...>( mkSliceRange(ris...) ),
mData(ma.data() + mkStartPos(ris...))
{
MAB::mProtoI.format( mBlockSizes(mkSliceBlocks(ris...)) );
}
template <typename T, class... SRanges> template <typename T, class... SRanges>
const T& Slice<T,SRanges...>::operator[](const IType& i) const const T& Slice<T,SRanges...>::operator[](const IType& i) const