generalize single range (static size parameter, -> -1 if non-static size)

This commit is contained in:
Christian Zimmermann 2019-02-12 20:26:38 +01:00
parent 697aac6b94
commit f339778a59
14 changed files with 320 additions and 295 deletions

View file

@ -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 -O3 -g -march=native -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3 -g -march=native -fopenmp -funroll-loops -ftree-vectorize")
enable_testing()

View file

@ -14,12 +14,12 @@
namespace MultiArrayTools
{
typedef SingleIndex<size_t,SpaceType::ANON> AnonymousIndex;
typedef GenSingleIndex<size_t,SpaceType::ANON,-1> AnonymousIndex;
//template <class R>
//using SIZET = size_t;
typedef SingleRange<size_t,SpaceType::ANON> AnonymousRange;
typedef GenSingleRange<size_t,SpaceType::ANON,-1> AnonymousRange;
// NOT THREAD SAVE!!
class AnonymousRangeFactory : public RangeFactoryBase
@ -53,7 +53,7 @@ namespace MultiArrayTools
};
template <>
class SingleRange<size_t,SpaceType::ANON> : public RangeInterface<AnonymousIndex>
class GenSingleRange<size_t,SpaceType::ANON,-1> : public RangeInterface<AnonymousIndex>
{
public:
@ -64,7 +64,7 @@ namespace MultiArrayTools
typedef RangeBase RB;
typedef typename RangeInterface<AnonymousIndex>::IndexType IndexType;
typedef SingleRange<size_t,SpaceType::ANON> RangeType;
typedef GenSingleRange<size_t,SpaceType::ANON,-1> RangeType;
typedef size_t MetaType;
virtual size_t size() const final;
@ -105,16 +105,16 @@ namespace MultiArrayTools
protected:
SingleRange() = default;
SingleRange(const AnonymousRange& in) = default;
GenSingleRange() = default;
GenSingleRange(const AnonymousRange& in) = default;
template <class... RangeTypes>
SingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs);
template <class... RangeTypes>
SingleRange(std::shared_ptr<RangeTypes>... origs);
GenSingleRange(std::shared_ptr<RangeTypes>... origs);
SingleRange(const std::vector<std::shared_ptr<RangeBase>>& origs);
GenSingleRange(const std::vector<std::shared_ptr<RangeBase>>& origs);
size_t mSize = 1;
bool mEmpty = true;
@ -203,7 +203,7 @@ namespace MultiArrayTools
***********************/
template <class... RangeTypes>
SingleRange<size_t,SpaceType::ANON>::SingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
GenSingleRange<size_t,SpaceType::ANON,-1>::GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
RangeInterface<AnonymousIndex>()
{
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
@ -214,7 +214,7 @@ namespace MultiArrayTools
}
template <class... RangeTypes>
SingleRange<size_t,SpaceType::ANON>::SingleRange(std::shared_ptr<RangeTypes>... origs) :
GenSingleRange<size_t,SpaceType::ANON,-1>::GenSingleRange(std::shared_ptr<RangeTypes>... origs) :
RangeInterface<AnonymousIndex>()
{
auto rst = std::make_tuple(origs...);
@ -226,13 +226,13 @@ namespace MultiArrayTools
}
template <class Range>
std::shared_ptr<Range> SingleRange<size_t,SpaceType::ANON>::fullsub(size_t num) const
std::shared_ptr<Range> GenSingleRange<size_t,SpaceType::ANON,-1>::fullsub(size_t num) const
{
return std::dynamic_pointer_cast<Range>( mOrig.at(num) );
}
template <class... Ranges>
std::shared_ptr<MultiRange<Ranges...> > SingleRange<size_t,SpaceType::ANON>::scast(SIZET<Ranges>... sizes) const
std::shared_ptr<MultiRange<Ranges...> > GenSingleRange<size_t,SpaceType::ANON,-1>::scast(SIZET<Ranges>... sizes) const
{
std::tuple<std::shared_ptr<Ranges>...> rtp;
RPackNum<sizeof...(Ranges)-1>::resolveRangeType(mOrig, rtp, 0, sizes...);

View file

@ -12,29 +12,29 @@
namespace MultiArrayTools
{
typedef SingleIndex<size_t,SpaceType::NONE> ClassicIndex;
typedef GenSingleIndex<size_t,SpaceType::NONE,-1> ClassicIndex;
template <>
class SingleRangeFactory<size_t,SpaceType::NONE> : public RangeFactoryBase
class GenSingleRangeFactory<size_t,SpaceType::NONE,-1> : public RangeFactoryBase
{
public:
typedef SingleRange<size_t,SpaceType::NONE> oType;
typedef GenSingleRange<size_t,SpaceType::NONE,-1> oType;
SingleRangeFactory(size_t size = 0);
GenSingleRangeFactory(size_t size = 0);
std::shared_ptr<RangeBase> create();
};
template <>
class SingleRange<size_t,SpaceType::NONE> : public RangeInterface<ClassicIndex>
class GenSingleRange<size_t,SpaceType::NONE,-1> : public RangeInterface<ClassicIndex>
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<size_t,SpaceType::NONE> >::IndexType IndexType;
typedef SingleRange<size_t,SpaceType::NONE> RangeType;
typedef typename RangeInterface<GenSingleIndex<size_t,SpaceType::NONE,-1> >::IndexType IndexType;
typedef GenSingleRange<size_t,SpaceType::NONE,-1> RangeType;
typedef size_t MetaType;
typedef SingleRangeFactory<size_t,SpaceType::NONE> FType;
typedef GenSingleRangeFactory<size_t,SpaceType::NONE,-1> FType;
virtual size_t size() const final;
virtual size_t dim() const final;
@ -52,28 +52,28 @@ namespace MultiArrayTools
virtual IndexType end() const final;
//virtual std::shared_ptr<VIWB> index() const final;
friend SingleRangeFactory<size_t,SpaceType::NONE>;
friend GenSingleRangeFactory<size_t,SpaceType::NONE,-1>;
static constexpr bool defaultable = true;
static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1;
static constexpr bool HASMETACONT = false;
static SingleRangeFactory<size_t, SpaceType::NONE> factory(size_t size = 0)
{ return SingleRangeFactory<size_t, SpaceType::NONE>(size); }
static GenSingleRangeFactory<size_t,SpaceType::NONE,-1> factory(size_t size = 0)
{ return GenSingleRangeFactory<size_t,SpaceType::NONE,-1>(size); }
protected:
size_t mSize = 0;
SingleRange() = default;
SingleRange(const SingleRange& in) = delete;
GenSingleRange() = default;
GenSingleRange(const GenSingleRange& in) = delete;
SingleRange(size_t size);
GenSingleRange(size_t size);
};
typedef SingleRange<size_t,SpaceType::NONE> ClassicRange;
typedef SingleRangeFactory<size_t,SpaceType::NONE> ClassicRF;
typedef GenSingleRange<size_t,SpaceType::NONE,-1> ClassicRange;
typedef GenSingleRangeFactory<size_t,SpaceType::NONE,-1> ClassicRF;
}

View file

@ -12,19 +12,19 @@ include_range_type(NUL,-2)
namespace MultiArrayTools
{
typedef SingleIndex<size_t,SpaceType::NUL> NullIndex;
typedef GenSingleIndex<size_t,SpaceType::NUL,0> NullIndex;
std::shared_ptr<SingleRange<size_t,SpaceType::NUL> > nullr();
std::shared_ptr<GenSingleRange<size_t,SpaceType::NUL,0> > nullr();
std::shared_ptr<NullIndex> nulli();
template <>
class SingleRangeFactory<size_t,SpaceType::NUL> : public RangeFactoryBase
class GenSingleRangeFactory<size_t,SpaceType::NUL,0> : public RangeFactoryBase
{
public:
typedef SingleRange<size_t,SpaceType::NUL> oType;
typedef GenSingleRange<size_t,SpaceType::NUL,0> oType;
SingleRangeFactory();
GenSingleRangeFactory();
std::shared_ptr<RangeBase> create();
friend std::shared_ptr<oType> nullr();
@ -34,14 +34,14 @@ namespace MultiArrayTools
};
template <>
class SingleRange<size_t,SpaceType::NUL> : public RangeInterface<NullIndex>
class GenSingleRange<size_t,SpaceType::NUL,0> : public RangeInterface<NullIndex>
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<size_t,SpaceType::NUL> >::IndexType IndexType;
typedef SingleRange<size_t,SpaceType::NUL> RangeType;
typedef typename RangeInterface<GenSingleIndex<size_t,SpaceType::NUL,0> >::IndexType IndexType;
typedef GenSingleRange<size_t,SpaceType::NUL,0> RangeType;
typedef size_t MetaType;
typedef SingleRangeFactory<size_t,SpaceType::NUL> FType;
typedef GenSingleRangeFactory<size_t,SpaceType::NUL,0> FType;
virtual size_t size() const final;
virtual size_t dim() const final;
@ -59,7 +59,7 @@ namespace MultiArrayTools
virtual IndexType end() const final;
//virtual std::shared_ptr<VIWB> index() const final;
friend SingleRangeFactory<size_t,SpaceType::NUL>;
friend GenSingleRangeFactory<size_t,SpaceType::NUL,0>;
static constexpr bool defaultable = true;
@ -67,19 +67,19 @@ namespace MultiArrayTools
static constexpr size_t SIZE = 1;
static constexpr bool HASMETACONT = false;
static SingleRangeFactory<size_t,SpaceType::NUL> factory()
{ return SingleRangeFactory<size_t,SpaceType::NUL>(); }
static GenSingleRangeFactory<size_t,SpaceType::NUL,0> factory()
{ return GenSingleRangeFactory<size_t,SpaceType::NUL,0>(); }
protected:
SingleRange() = default;
SingleRange(const SingleRange& in) = delete;
GenSingleRange() = default;
GenSingleRange(const GenSingleRange& in) = delete;
//SingleRange(size_t spinNum);
//GenSingleRange(size_t spinNum);
};
typedef SingleRange<size_t,SpaceType::NUL> NullRange;
typedef SingleRangeFactory<size_t,SpaceType::NUL> NullRF;
typedef GenSingleRange<size_t,SpaceType::NUL,0> NullRange;
typedef GenSingleRangeFactory<size_t,SpaceType::NUL,0> NullRF;
std::shared_ptr<NullRF> mkNUL(const char* dp, size_t size);

View file

@ -11,29 +11,29 @@ include_range_type(PSPACE,3) // Periodic 1dim space
namespace MultiArrayTools
{
// Periodic 1dim space
typedef SingleIndex<int,SpaceType::PSPACE> XSpaceIndex;
typedef GenSingleIndex<int,SpaceType::PSPACE,-1> XSpaceIndex;
template <>
class SingleRangeFactory<int,SpaceType::PSPACE> : public RangeFactoryBase
class GenSingleRangeFactory<int,SpaceType::PSPACE,-1> : public RangeFactoryBase
{
public:
typedef SingleRange<int,SpaceType::PSPACE> oType;
typedef GenSingleRange<int,SpaceType::PSPACE,-1> oType;
SingleRangeFactory(size_t size = 0);
GenSingleRangeFactory(size_t size = 0);
std::shared_ptr<RangeBase> create();
};
template <>
class SingleRange<int,SpaceType::PSPACE> : public RangeInterface<XSpaceIndex>
class GenSingleRange<int,SpaceType::PSPACE,-1> : public RangeInterface<XSpaceIndex>
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<int,SpaceType::PSPACE> >::IndexType IndexType;
typedef SingleRange<int,SpaceType::PSPACE> RangeType;
typedef typename RangeInterface<GenSingleIndex<int,SpaceType::PSPACE,-1> >::IndexType IndexType;
typedef GenSingleRange<int,SpaceType::PSPACE,-1> RangeType;
typedef int MetaType;
typedef SingleRangeFactory<int,SpaceType::PSPACE> FType;
typedef GenSingleRangeFactory<int,SpaceType::PSPACE,-1> FType;
virtual size_t size() const final;
virtual size_t dim() const final;
@ -50,28 +50,28 @@ namespace MultiArrayTools
virtual IndexType begin() const final;
virtual IndexType end() const final;
friend SingleRangeFactory<int,SpaceType::PSPACE>;
friend GenSingleRangeFactory<int,SpaceType::PSPACE,-1>;
static constexpr bool defaultable = true;
static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1;
static constexpr bool HASMETACONT = false;
static SingleRangeFactory<int, SpaceType::PSPACE> factory(size_t size = 0)
{ return SingleRangeFactory<int, SpaceType::PSPACE>(size); }
static GenSingleRangeFactory<int,SpaceType::PSPACE,-1> factory(size_t size = 0)
{ return GenSingleRangeFactory<int,SpaceType::PSPACE,-1>(size); }
protected:
size_t mSize = 0;
SingleRange() = default;
SingleRange(const SingleRange& in) = delete;
GenSingleRange() = default;
GenSingleRange(const GenSingleRange& in) = delete;
SingleRange(size_t size);
GenSingleRange(size_t size);
};
typedef SingleRange<int,SpaceType::PSPACE> PSpaceRange;
typedef SingleRangeFactory<int,SpaceType::PSPACE> PSpaceRF;
typedef GenSingleRange<int,SpaceType::PSPACE,-1> PSpaceRange;
typedef GenSingleRangeFactory<int,SpaceType::PSPACE,-1> PSpaceRF;
std::shared_ptr<PSpaceRF> mkPSPACE(const char* dp, size_t size);

View file

@ -12,29 +12,29 @@ include_range_type(SPIN,2)
namespace MultiArrayTools
{
typedef SingleIndex<size_t,SpaceType::SPIN> SpinIndex;
typedef GenSingleIndex<size_t,SpaceType::SPIN,4> SpinIndex;
template <>
class SingleRangeFactory<size_t,SpaceType::SPIN> : public RangeFactoryBase
class GenSingleRangeFactory<size_t,SpaceType::SPIN,4> : public RangeFactoryBase
{
public:
typedef SingleRange<size_t,SpaceType::SPIN> oType;
typedef GenSingleRange<size_t,SpaceType::SPIN,4> oType;
SingleRangeFactory();
GenSingleRangeFactory();
std::shared_ptr<RangeBase> create();
};
template <>
class SingleRange<size_t,SpaceType::SPIN> : public RangeInterface<SpinIndex>
class GenSingleRange<size_t,SpaceType::SPIN,4> : public RangeInterface<SpinIndex>
{
public:
typedef RangeBase RB;
typedef typename RangeInterface<SingleIndex<size_t,SpaceType::SPIN> >::IndexType IndexType;
typedef SingleRange<size_t,SpaceType::SPIN> RangeType;
typedef typename RangeInterface<GenSingleIndex<size_t,SpaceType::SPIN,4> >::IndexType IndexType;
typedef GenSingleRange<size_t,SpaceType::SPIN,4> RangeType;
typedef size_t MetaType;
typedef SingleRangeFactory<size_t,SpaceType::SPIN> FType;
typedef GenSingleRangeFactory<size_t,SpaceType::SPIN,4> FType;
virtual size_t size() const final;
virtual size_t dim() const final;
@ -52,7 +52,7 @@ namespace MultiArrayTools
virtual IndexType end() const final;
//virtual std::shared_ptr<VIWB> index() const final;
friend SingleRangeFactory<size_t,SpaceType::SPIN>;
friend GenSingleRangeFactory<size_t,SpaceType::SPIN,4>;
static constexpr bool defaultable = true;
static constexpr size_t mSpinNum = 4;
@ -61,19 +61,19 @@ namespace MultiArrayTools
static constexpr size_t SIZE = mSpinNum;
static constexpr bool HASMETACONT = false;
static SingleRangeFactory<size_t, SpaceType::SPIN> factory()
{ return SingleRangeFactory<size_t, SpaceType::SPIN>(); }
static GenSingleRangeFactory<size_t,SpaceType::SPIN,4> factory()
{ return GenSingleRangeFactory<size_t,SpaceType::SPIN,4>(); }
protected:
SingleRange() = default;
SingleRange(const SingleRange& in) = delete;
GenSingleRange() = default;
GenSingleRange(const GenSingleRange& in) = delete;
//SingleRange(size_t spinNum);
//GenSingleRange(size_t spinNum);
};
typedef SingleRange<size_t,SpaceType::SPIN> SpinRange;
typedef SingleRangeFactory<size_t,SpaceType::SPIN> SpinRF;
typedef GenSingleRange<size_t,SpaceType::SPIN,4> SpinRange;
typedef GenSingleRangeFactory<size_t,SpaceType::SPIN,4> SpinRF;
std::shared_ptr<SpinRF> mkSPIN(const char* dp, size_t size);
}

View file

@ -44,16 +44,16 @@ namespace MultiArrayTools
class IndexInterface;
// single_range.h
template <typename U, SpaceType TYPE>
class SingleRange;
template <typename U, SpaceType TYPE, size_t S>
class GenSingleRange;
// single_range.h
template <typename U, SpaceType TYPE>
class SingleRangeFactory;
template <typename U, SpaceType TYPE, size_t S>
class GenSingleRangeFactory;
// single_range.h
template <typename U, SpaceType TYPE>
class SingleIndex;
template <typename U, SpaceType TYPE, size_t S>
class GenSingleIndex;
// subrange.h
template <class Index>

View file

@ -28,19 +28,19 @@ namespace MultiArrayTools
}
template <typename U, SpaceType TYPE>
class SingleIndex : public IndexInterface<SingleIndex<U,TYPE>,U>
template <typename U, SpaceType TYPE, size_t S>
class GenSingleIndex : public IndexInterface<GenSingleIndex<U,TYPE,S>,U>
{
public:
typedef IndexInterface<SingleIndex<U,TYPE>,U> IB;
typedef IndexInterface<GenSingleIndex<U,TYPE,S>,U> IB;
typedef U MetaType;
typedef SingleRange<U,TYPE> RangeType;
typedef SingleIndex IType;
typedef GenSingleRange<U,TYPE,S> RangeType;
typedef GenSingleIndex IType;
//DEFAULT_MEMBERS_X(SingleIndex);
//DEFAULT_MEMBERS_X(GenSingleIndex);
SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range);
GenSingleIndex(const std::shared_ptr<GenSingleRange<U,TYPE,S> >& range);
static constexpr IndexType sType() { return IndexType::SINGLE; }
static constexpr size_t totalDim() { return 1; }
@ -53,9 +53,9 @@ namespace MultiArrayTools
IndexType type() const;
SingleIndex& operator=(size_t pos);
SingleIndex& operator++();
SingleIndex& operator--();
GenSingleIndex& operator=(size_t pos);
GenSingleIndex& operator++();
GenSingleIndex& operator--();
int pp(std::intptr_t idxPtrNum);
int mm(std::intptr_t idxPtrNum);
@ -63,7 +63,7 @@ namespace MultiArrayTools
std::string stringMeta() const;
U meta() const;
const U* metaPtr() const;
SingleIndex& at(const U& metaPos);
GenSingleIndex& at(const U& metaPos);
size_t posAt(const U& metaPos) const;
bool isMeta(const U& metaPos) const;
@ -84,30 +84,30 @@ namespace MultiArrayTools
template <class Expr>
auto ifor(size_t step, Expr ex) const
-> For<SingleIndex<U,TYPE>,Expr>;
-> For<GenSingleIndex<U,TYPE,S>,Expr>;
template <class Expr>
auto iforh(size_t step, Expr ex) const
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>;
-> For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>;
template <class Expr>
auto pifor(size_t step, Expr ex) const
-> PFor<SingleIndex<U,TYPE>,Expr>;
-> PFor<GenSingleIndex<U,TYPE,S>,Expr>;
private:
std::shared_ptr<RangeType> mExplicitRangePtr;
const U* mMetaPtr;
};
template <typename U, SpaceType TYPE>
class SingleRangeFactory : public RangeFactoryBase
template <typename U, SpaceType TYPE, size_t S>
class GenSingleRangeFactory : public RangeFactoryBase
{
public:
typedef SingleRange<U,TYPE> oType;
typedef GenSingleRange<U,TYPE,S> oType;
SingleRangeFactory() = delete;
SingleRangeFactory(const std::vector<U>& space);
GenSingleRangeFactory() = delete;
GenSingleRangeFactory(const std::vector<U>& space);
std::shared_ptr<RangeBase> create();
};
@ -187,16 +187,30 @@ namespace MultiArrayTools
};
template <typename U, SpaceType TYPE>
class SingleRange : public RangeInterface<SingleIndex<U,TYPE> >
template <size_t S>
struct CheckStatic
{
static constexpr size_t ISSTATIC = true;
static constexpr size_t SIZE = S;
};
template <>
struct CheckStatic<-1>
{
static constexpr size_t ISSTATIC = false;
static constexpr size_t SIZE = -1;
};
template <typename U, SpaceType TYPE, size_t S>
class GenSingleRange : public RangeInterface<GenSingleIndex<U,TYPE,S> >
{
public:
typedef RangeBase RB;
typedef SingleIndex<U,TYPE> IndexType;
typedef SingleRange RangeType;
typedef GenSingleIndex<U,TYPE,S> IndexType;
typedef GenSingleRange RangeType;
typedef U MetaType;
typedef SingleRangeFactory<U,TYPE> FType;
//typedef typename RangeInterface<SingleIndex<U,TYPE> >::IndexType IndexType;
typedef GenSingleRangeFactory<U,TYPE,S> FType;
//typedef typename RangeInterface<GenSingleIndex<U,TYPE,S> >::IndexType IndexType;
virtual size_t size() const final;
virtual size_t dim() const final;
@ -215,25 +229,34 @@ namespace MultiArrayTools
virtual IndexType begin() const final;
virtual IndexType end() const final;
friend SingleRangeFactory<U,TYPE>;
friend GenSingleRangeFactory<U,TYPE,S>;
static constexpr bool defaultable = false;
static constexpr size_t ISSTATIC = 0;
static constexpr size_t SIZE = -1;
static constexpr size_t ISSTATIC = CheckStatic<S>::ISSTATIC;
static constexpr size_t SIZE = CheckStatic<S>::SIZE;
static constexpr bool HASMETACONT = true;
protected:
SingleRange() = delete;
SingleRange(const SingleRange& in) = delete;
GenSingleRange() = delete;
GenSingleRange(const GenSingleRange& in) = delete;
SingleRange(const std::vector<U>& space);
GenSingleRange(const std::vector<U>& space);
std::vector<U> mSpace;
//std::map<U,size_t> mMSpace;
MetaMap<U> mMSpace;
};
template <typename U, SpaceType TYPE>
using SingleRange = GenSingleRange<U,TYPE,-1>;
template <typename U, SpaceType TYPE>
using SingleIndex = GenSingleIndex<U,TYPE,-1>;
template <typename U, SpaceType TYPE>
using SingleRangeFactory = GenSingleRangeFactory<U,TYPE,-1>;
}
/* ========================= *
@ -243,7 +266,7 @@ namespace MultiArrayTools
namespace MultiArrayTools
{
/******************
* SingleIndex *
* GenSingleIndex *
******************/
template <bool HASMETACONT>
@ -278,134 +301,134 @@ namespace MultiArrayTools
}
};
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>::SingleIndex(const std::shared_ptr<SingleRange<U,TYPE> >& range) :
IndexInterface<SingleIndex<U,TYPE>,U>(range, 0),
template <typename U, SpaceType TYPE, size_t S>
GenSingleIndex<U,TYPE,S>::GenSingleIndex(const std::shared_ptr<GenSingleRange<U,TYPE,S> >& range) :
IndexInterface<GenSingleIndex<U,TYPE,S>,U>(range, 0),
mExplicitRangePtr(std::dynamic_pointer_cast<RangeType>(IB::mRangePtr)),
mMetaPtr(MetaPtrHandle<SingleIndex<U,TYPE>::RangeType::HASMETACONT>::set
mMetaPtr(MetaPtrHandle<GenSingleIndex<U,TYPE,S>::RangeType::HASMETACONT>::set
( dynamic_cast<RangeType*>(IB::mRangePtr.get() ) ) ) {}
template <typename U, SpaceType TYPE>
IndexType SingleIndex<U,TYPE>::type() const
template <typename U, SpaceType TYPE, size_t S>
IndexType GenSingleIndex<U,TYPE,S>::type() const
{
return IndexType::SINGLE;
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator=(size_t pos)
template <typename U, SpaceType TYPE, size_t S>
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::operator=(size_t pos)
{
IB::mPos = pos;
return *this;
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator++()
template <typename U, SpaceType TYPE, size_t S>
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::operator++()
{
++IB::mPos;
return *this;
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::operator--()
template <typename U, SpaceType TYPE, size_t S>
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::operator--()
{
--IB::mPos;
return *this;
}
template <typename U, SpaceType TYPE>
int SingleIndex<U,TYPE>::pp(std::intptr_t idxPtrNum)
template <typename U, SpaceType TYPE, size_t S>
int GenSingleIndex<U,TYPE,S>::pp(std::intptr_t idxPtrNum)
{
++(*this);
return 1;
}
template <typename U, SpaceType TYPE>
int SingleIndex<U,TYPE>::mm(std::intptr_t idxPtrNum)
template <typename U, SpaceType TYPE, size_t S>
int GenSingleIndex<U,TYPE,S>::mm(std::intptr_t idxPtrNum)
{
--(*this);
return 1;
}
template <typename U, SpaceType TYPE>
std::string SingleIndex<U,TYPE>::stringMeta() const
template <typename U, SpaceType TYPE, size_t S>
std::string GenSingleIndex<U,TYPE,S>::stringMeta() const
{
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->stringMeta(IB::mPos);
return std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> const>( IB::mRangePtr )->stringMeta(IB::mPos);
}
template <typename U, SpaceType TYPE>
U SingleIndex<U,TYPE>::meta() const
template <typename U, SpaceType TYPE, size_t S>
U GenSingleIndex<U,TYPE,S>::meta() const
{
return MetaPtrHandle<SingleIndex<U,TYPE>::RangeType::HASMETACONT>::getMeta
return MetaPtrHandle<GenSingleIndex<U,TYPE,S>::RangeType::HASMETACONT>::getMeta
( mMetaPtr, IB::mPos, mExplicitRangePtr );
}
template <typename U, SpaceType TYPE>
const U* SingleIndex<U,TYPE>::metaPtr() const
template <typename U, SpaceType TYPE, size_t S>
const U* GenSingleIndex<U,TYPE,S>::metaPtr() const
{
return mMetaPtr;
}
template <typename U, SpaceType TYPE>
bool SingleIndex<U,TYPE>::isMeta(const U& metaPos) const
template <typename U, SpaceType TYPE, size_t S>
bool GenSingleIndex<U,TYPE,S>::isMeta(const U& metaPos) const
{
return mExplicitRangePtr->isMeta(metaPos);
}
template <typename U, SpaceType TYPE>
SingleIndex<U,TYPE>& SingleIndex<U,TYPE>::at(const U& metaPos)
template <typename U, SpaceType TYPE, size_t S>
GenSingleIndex<U,TYPE,S>& GenSingleIndex<U,TYPE,S>::at(const U& metaPos)
{
(*this) = std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos );
(*this) = std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> const>( IB::mRangePtr )->getMeta( metaPos );
return *this;
}
template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::posAt(const U& metaPos) const
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleIndex<U,TYPE,S>::posAt(const U& metaPos) const
{
return std::dynamic_pointer_cast<SingleRange<U,TYPE> const>( IB::mRangePtr )->getMeta( metaPos );
return std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> const>( IB::mRangePtr )->getMeta( metaPos );
}
template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::dim() // = 1
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleIndex<U,TYPE,S>::dim() // = 1
{
return 1;
}
template <typename U, SpaceType TYPE>
bool SingleIndex<U,TYPE>::last()
template <typename U, SpaceType TYPE, size_t S>
bool GenSingleIndex<U,TYPE,S>::last()
{
return IB::mPos == IB::mMax - 1;
}
template <typename U, SpaceType TYPE>
bool SingleIndex<U,TYPE>::first()
template <typename U, SpaceType TYPE, size_t S>
bool GenSingleIndex<U,TYPE,S>::first()
{
return IB::mPos == 0;
}
template <typename U, SpaceType TYPE>
std::shared_ptr<typename SingleIndex<U,TYPE>::RangeType> SingleIndex<U,TYPE>::range()
template <typename U, SpaceType TYPE, size_t S>
std::shared_ptr<typename GenSingleIndex<U,TYPE,S>::RangeType> GenSingleIndex<U,TYPE,S>::range()
{
return mExplicitRangePtr;
}
template <typename U, SpaceType TYPE>
template <typename U, SpaceType TYPE, size_t S>
template <size_t N>
void SingleIndex<U,TYPE>::getPtr() {}
void GenSingleIndex<U,TYPE,S>::getPtr() {}
template <typename U, SpaceType TYPE>
size_t SingleIndex<U,TYPE>::getStepSize(size_t n)
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleIndex<U,TYPE,S>::getStepSize(size_t n)
{
return 1;
}
template <typename U, SpaceType TYPE>
std::string SingleIndex<U,TYPE>::id() const
template <typename U, SpaceType TYPE, size_t S>
std::string GenSingleIndex<U,TYPE,S>::id() const
{
return std::string("sin") + std::to_string(IB::mId);
}
template <typename U, SpaceType TYPE>
void SingleIndex<U,TYPE>::print(size_t offset)
template <typename U, SpaceType TYPE, size_t S>
void GenSingleIndex<U,TYPE,S>::print(size_t offset)
{
if(offset == 0){
std::cout << " === " << std::endl;
@ -415,31 +438,31 @@ namespace MultiArrayTools
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
}
template <typename U, SpaceType TYPE>
template <typename U, SpaceType TYPE, size_t S>
template <class Expr>
auto SingleIndex<U,TYPE>::ifor(size_t step, Expr ex) const
-> For<SingleIndex<U,TYPE>,Expr>
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
-> For<GenSingleIndex<U,TYPE,S>,Expr>
{
//static const size_t LAYER = typename Expr::LAYER;
return For<SingleIndex<U,TYPE>,Expr>(this, step, ex);
return For<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex);
}
template <typename U, SpaceType TYPE>
template <typename U, SpaceType TYPE, size_t S>
template <class Expr>
auto SingleIndex<U,TYPE>::iforh(size_t step, Expr ex) const
-> For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>
auto GenSingleIndex<U,TYPE,S>::iforh(size_t step, Expr ex) const
-> For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>
{
//static const size_t LAYER = typename Expr::LAYER;
return For<SingleIndex<U,TYPE>,Expr,ForType::HIDDEN>(this, step, ex);
return For<GenSingleIndex<U,TYPE,S>,Expr,ForType::HIDDEN>(this, step, ex);
}
template <typename U, SpaceType TYPE>
template <typename U, SpaceType TYPE, size_t S>
template <class Expr>
auto SingleIndex<U,TYPE>::pifor(size_t step, Expr ex) const
-> PFor<SingleIndex<U,TYPE>,Expr>
auto GenSingleIndex<U,TYPE,S>::pifor(size_t step, Expr ex) const
-> PFor<GenSingleIndex<U,TYPE,S>,Expr>
{
//static const size_t LAYER = typename Expr::LAYER;
return PFor<SingleIndex<U,TYPE>,Expr>(this, step, ex);
return PFor<GenSingleIndex<U,TYPE,S>,Expr>(this, step, ex);
}
@ -447,14 +470,14 @@ namespace MultiArrayTools
* SingleRange *
********************/
template <typename U, SpaceType TYPE>
SingleRangeFactory<U,TYPE>::SingleRangeFactory(const std::vector<U>& space)
template <typename U, SpaceType TYPE, size_t S>
GenSingleRangeFactory<U,TYPE,S>::GenSingleRangeFactory(const std::vector<U>& space)
{
mProd = std::shared_ptr<oType>( new SingleRange<U,TYPE>( space ) );
mProd = std::shared_ptr<oType>( new GenSingleRange<U,TYPE,S>( space ) );
}
template <typename U, SpaceType TYPE>
std::shared_ptr<RangeBase> SingleRangeFactory<U,TYPE>::create()
template <typename U, SpaceType TYPE, size_t S>
std::shared_ptr<RangeBase> GenSingleRangeFactory<U,TYPE,S>::create()
{
setSelf();
return mProd;
@ -464,9 +487,9 @@ namespace MultiArrayTools
* SingleRange *
********************/
template <typename U, SpaceType TYPE>
SingleRange<U,TYPE>::SingleRange(const std::vector<U>& space) :
RangeInterface<SingleIndex<U,TYPE> >(),
template <typename U, SpaceType TYPE, size_t S>
GenSingleRange<U,TYPE,S>::GenSingleRange(const std::vector<U>& space) :
RangeInterface<GenSingleIndex<U,TYPE,S> >(),
mSpace(space), mMSpace(mSpace)
{
//for(size_t i = 0; i != mSpace.size(); ++i){
@ -474,50 +497,50 @@ namespace MultiArrayTools
//}
}
template <typename U, SpaceType TYPE>
const U& SingleRange<U,TYPE>::get(size_t pos) const
template <typename U, SpaceType TYPE, size_t S>
const U& GenSingleRange<U,TYPE,S>::get(size_t pos) const
{
return mSpace[pos];
}
template <typename U, SpaceType TYPE>
size_t SingleRange<U,TYPE>::getMeta(const U& metaPos) const
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::getMeta(const U& metaPos) const
{
return mMSpace.at(metaPos);
}
template <typename U, SpaceType TYPE>
size_t SingleRange<U,TYPE>::size() const
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::size() const
{
return mSpace.size();
}
template <typename U, SpaceType TYPE>
size_t SingleRange<U,TYPE>::dim() const
template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::dim() const
{
return 1;
}
template <typename U, SpaceType TYPE>
bool SingleRange<U,TYPE>::isMeta(const U& metaPos) const
template <typename U, SpaceType TYPE, size_t S>
bool GenSingleRange<U,TYPE,S>::isMeta(const U& metaPos) const
{
return mMSpace.count(metaPos) != 0;
}
template <typename U, SpaceType TYPE>
SpaceType SingleRange<U,TYPE>::spaceType() const
template <typename U, SpaceType TYPE, size_t S>
SpaceType GenSingleRange<U,TYPE,S>::spaceType() const
{
return TYPE;
}
template <typename U, SpaceType TYPE>
std::string SingleRange<U,TYPE>::stringMeta(size_t pos) const
template <typename U, SpaceType TYPE, size_t S>
std::string GenSingleRange<U,TYPE,S>::stringMeta(size_t pos) const
{
return xToString(get(pos));
}
template <typename U, SpaceType TYPE>
std::vector<char> SingleRange<U,TYPE>::data() const
template <typename U, SpaceType TYPE, size_t S>
std::vector<char> GenSingleRange<U,TYPE,S>::data() const
{
DataHeader h = dataHeader();
std::vector<char> out;
@ -530,8 +553,8 @@ namespace MultiArrayTools
return out;
}
template <typename U, SpaceType TYPE>
DataHeader SingleRange<U,TYPE>::dataHeader() const
template <typename U, SpaceType TYPE, size_t S>
DataHeader GenSingleRange<U,TYPE,S>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( TYPE );
@ -541,19 +564,19 @@ namespace MultiArrayTools
return h;
}
template <typename U, SpaceType TYPE>
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::begin() const
template <typename U, SpaceType TYPE, size_t S>
typename GenSingleRange<U,TYPE,S>::IndexType GenSingleRange<U,TYPE,S>::begin() const
{
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
GenSingleIndex<U,TYPE,S> i( std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
template <typename U, SpaceType TYPE>
typename SingleRange<U,TYPE>::IndexType SingleRange<U,TYPE>::end() const
template <typename U, SpaceType TYPE, size_t S>
typename GenSingleRange<U,TYPE,S>::IndexType GenSingleRange<U,TYPE,S>::end() const
{
SingleIndex<U,TYPE> i( std::dynamic_pointer_cast<SingleRange<U,TYPE> >
GenSingleIndex<U,TYPE,S> i( std::dynamic_pointer_cast<GenSingleRange<U,TYPE,S> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;

View file

@ -196,7 +196,7 @@ namespace MultiArrayTools
return mOrig;
}
SingleRange<size_t,SpaceType::ANON>::SingleRange(const std::vector<std::shared_ptr<RangeBase>>& origs) :
GenSingleRange<size_t,SpaceType::ANON,-1>::GenSingleRange(const std::vector<std::shared_ptr<RangeBase>>& origs) :
RangeInterface<AnonymousIndex>(),
mOrig(origs)
{

View file

@ -5,60 +5,60 @@
namespace MultiArrayTools
{
/********************
* SingleRange *
* GenSingleRange *
********************/
SingleRangeFactory<size_t,SpaceType::NONE>::SingleRangeFactory(size_t size)
GenSingleRangeFactory<size_t,SpaceType::NONE,-1>::GenSingleRangeFactory(size_t size)
{
// Quasi Singleton
if(not mProd){
mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::NONE>(size) );
mProd = std::shared_ptr<oType>( new GenSingleRange<size_t,SpaceType::NONE,-1>(size) );
setSelf();
}
}
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,SpaceType::NONE>::create()
std::shared_ptr<RangeBase> GenSingleRangeFactory<size_t,SpaceType::NONE,-1>::create()
{
return mProd;
}
/********************
* SingleRange *
* GenSingleRange *
********************/
SingleRange<size_t,SpaceType::NONE>::SingleRange(size_t size) : mSize(size) {}
GenSingleRange<size_t,SpaceType::NONE,-1>::GenSingleRange(size_t size) : mSize(size) {}
size_t SingleRange<size_t,SpaceType::NONE>::get(size_t pos) const
size_t GenSingleRange<size_t,SpaceType::NONE,-1>::get(size_t pos) const
{
return pos;
}
size_t SingleRange<size_t,SpaceType::NONE>::getMeta(size_t metaPos) const
size_t GenSingleRange<size_t,SpaceType::NONE,-1>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t SingleRange<size_t,SpaceType::NONE>::size() const
size_t GenSingleRange<size_t,SpaceType::NONE,-1>::size() const
{
return mSize;
}
size_t SingleRange<size_t,SpaceType::NONE>::dim() const
size_t GenSingleRange<size_t,SpaceType::NONE,-1>::dim() const
{
return 1;
}
SpaceType SingleRange<size_t,SpaceType::NONE>::spaceType() const
SpaceType GenSingleRange<size_t,SpaceType::NONE,-1>::spaceType() const
{
return SpaceType::NONE;
}
std::string SingleRange<size_t,SpaceType::NONE>::stringMeta(size_t pos) const
std::string GenSingleRange<size_t,SpaceType::NONE,-1>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));
}
std::vector<char> SingleRange<size_t,SpaceType::NONE>::data() const
std::vector<char> GenSingleRange<size_t,SpaceType::NONE,-1>::data() const
{
DataHeader h = dataHeader();
std::vector<char> out;
@ -70,7 +70,7 @@ namespace MultiArrayTools
return out;
}
DataHeader SingleRange<size_t,SpaceType::NONE>::dataHeader() const
DataHeader GenSingleRange<size_t,SpaceType::NONE,-1>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NONE );
@ -80,17 +80,17 @@ namespace MultiArrayTools
}
typename SingleRange<size_t,SpaceType::NONE>::IndexType SingleRange<size_t,SpaceType::NONE>::begin() const
typename GenSingleRange<size_t,SpaceType::NONE,-1>::IndexType GenSingleRange<size_t,SpaceType::NONE,-1>::begin() const
{
SingleIndex<size_t,SpaceType::NONE> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NONE> >
GenSingleIndex<size_t,SpaceType::NONE,-1> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NONE,-1> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename SingleRange<size_t,SpaceType::NONE>::IndexType SingleRange<size_t,SpaceType::NONE>::end() const
typename GenSingleRange<size_t,SpaceType::NONE,-1>::IndexType GenSingleRange<size_t,SpaceType::NONE,-1>::end() const
{
SingleIndex<size_t,SpaceType::NONE> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NONE> >
GenSingleIndex<size_t,SpaceType::NONE,-1> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NONE,-1> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;

View file

@ -10,11 +10,11 @@ namespace MultiArrayTools
}
/********************
* SingleRange *
* GenSingleRange *
********************/
std::shared_ptr<SingleRange<size_t,SpaceType::NUL>>
SingleRangeFactory<size_t,SpaceType::NUL>::mRInstance = nullptr;
std::shared_ptr<GenSingleRange<size_t,SpaceType::NUL,0>>
GenSingleRangeFactory<size_t,SpaceType::NUL,0>::mRInstance = nullptr;
std::shared_ptr<NullRange> nullr()
{
@ -28,12 +28,12 @@ namespace MultiArrayTools
return std::make_shared<NullIndex>(nullr());
}
SingleRangeFactory<size_t,SpaceType::NUL>::SingleRangeFactory()
GenSingleRangeFactory<size_t,SpaceType::NUL,0>::GenSingleRangeFactory()
{
// Singleton
if(not mRInstance){
if(not mProd){
mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::NUL>() );
mProd = std::shared_ptr<oType>( new GenSingleRange<size_t,SpaceType::NUL,0>() );
setSelf();
}
mRInstance = std::dynamic_pointer_cast<NullRange>( mProd );
@ -42,46 +42,46 @@ namespace MultiArrayTools
}
}
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,SpaceType::NUL>::create()
std::shared_ptr<RangeBase> GenSingleRangeFactory<size_t,SpaceType::NUL,0>::create()
{
return mProd;
}
/********************
* SingleRange *
* GenSingleRange *
********************/
size_t SingleRange<size_t,SpaceType::NUL>::get(size_t pos) const
size_t GenSingleRange<size_t,SpaceType::NUL,0>::get(size_t pos) const
{
return 0;
}
size_t SingleRange<size_t,SpaceType::NUL>::getMeta(size_t metapos) const
size_t GenSingleRange<size_t,SpaceType::NUL,0>::getMeta(size_t metapos) const
{
return 0;
}
size_t SingleRange<size_t,SpaceType::NUL>::size() const
size_t GenSingleRange<size_t,SpaceType::NUL,0>::size() const
{
return 1;
}
size_t SingleRange<size_t,SpaceType::NUL>::dim() const
size_t GenSingleRange<size_t,SpaceType::NUL,0>::dim() const
{
return 1;
}
SpaceType SingleRange<size_t,SpaceType::NUL>::spaceType() const
SpaceType GenSingleRange<size_t,SpaceType::NUL,0>::spaceType() const
{
return SpaceType::NUL;
}
std::string SingleRange<size_t,SpaceType::NUL>::stringMeta(size_t pos) const
std::string GenSingleRange<size_t,SpaceType::NUL,0>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));
}
std::vector<char> SingleRange<size_t,SpaceType::NUL>::data() const
std::vector<char> GenSingleRange<size_t,SpaceType::NUL,0>::data() const
{
DataHeader h = dataHeader();
std::vector<char> out;
@ -91,7 +91,7 @@ namespace MultiArrayTools
return out;
}
DataHeader SingleRange<size_t,SpaceType::NUL>::dataHeader() const
DataHeader GenSingleRange<size_t,SpaceType::NUL,0>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::NUL );
@ -100,17 +100,17 @@ namespace MultiArrayTools
return h;
}
typename SingleRange<size_t,SpaceType::NUL>::IndexType SingleRange<size_t,SpaceType::NUL>::begin() const
typename GenSingleRange<size_t,SpaceType::NUL,0>::IndexType GenSingleRange<size_t,SpaceType::NUL,0>::begin() const
{
SingleIndex<size_t,SpaceType::NUL> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NUL> >
GenSingleIndex<size_t,SpaceType::NUL,0> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NUL,0> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename SingleRange<size_t,SpaceType::NUL>::IndexType SingleRange<size_t,SpaceType::NUL>::end() const
typename GenSingleRange<size_t,SpaceType::NUL,0>::IndexType GenSingleRange<size_t,SpaceType::NUL,0>::end() const
{
SingleIndex<size_t,SpaceType::NUL> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NUL> >
GenSingleIndex<size_t,SpaceType::NUL,0> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NUL,0> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
@ -118,12 +118,12 @@ namespace MultiArrayTools
// put this in the interface class !!!
/*
std::shared_ptr<VIWB> SingleRange<size_t,SpaceType::NUL>::index() const
std::shared_ptr<VIWB> GenSingleRange<size_t,SpaceType::NUL,0>::index() const
{
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
( std::make_shared<IndexType>
( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::NUL> >
( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::NUL,0> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}
*/

View file

@ -11,60 +11,60 @@ namespace MultiArrayTools
}
/********************
* SingleRange *
* GenSingleRange *
********************/
SingleRangeFactory<int,SpaceType::PSPACE>::SingleRangeFactory(size_t size)
GenSingleRangeFactory<int,SpaceType::PSPACE,-1>::GenSingleRangeFactory(size_t size)
{
// Quasi Singleton
if(not mProd){
mProd = std::shared_ptr<oType>( new SingleRange<int,SpaceType::PSPACE>(size) );
mProd = std::shared_ptr<oType>( new GenSingleRange<int,SpaceType::PSPACE,-1>(size) );
setSelf();
}
}
std::shared_ptr<RangeBase> SingleRangeFactory<int,SpaceType::PSPACE>::create()
std::shared_ptr<RangeBase> GenSingleRangeFactory<int,SpaceType::PSPACE,-1>::create()
{
return mProd;
}
/********************
* SingleRange *
* GenSingleRange *
********************/
SingleRange<int,SpaceType::PSPACE>::SingleRange(size_t size) : mSize(size) { }
GenSingleRange<int,SpaceType::PSPACE,-1>::GenSingleRange(size_t size) : mSize(size) { }
int SingleRange<int,SpaceType::PSPACE>::get(size_t pos) const
int GenSingleRange<int,SpaceType::PSPACE,-1>::get(size_t pos) const
{
return pos > mSize / 2 ? pos - mSize : pos;
}
size_t SingleRange<int,SpaceType::PSPACE>::getMeta(int metaPos) const
size_t GenSingleRange<int,SpaceType::PSPACE,-1>::getMeta(int metaPos) const
{
return metaPos < 0 ? metaPos + mSize : metaPos;
}
size_t SingleRange<int,SpaceType::PSPACE>::size() const
size_t GenSingleRange<int,SpaceType::PSPACE,-1>::size() const
{
return mSize;
}
size_t SingleRange<int,SpaceType::PSPACE>::dim() const
size_t GenSingleRange<int,SpaceType::PSPACE,-1>::dim() const
{
return 1;
}
SpaceType SingleRange<int,SpaceType::PSPACE>::spaceType() const
SpaceType GenSingleRange<int,SpaceType::PSPACE,-1>::spaceType() const
{
return SpaceType::PSPACE;
}
std::string SingleRange<int,SpaceType::PSPACE>::stringMeta(size_t pos) const
std::string GenSingleRange<int,SpaceType::PSPACE,-1>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));
}
std::vector<char> SingleRange<int,SpaceType::PSPACE>::data() const
std::vector<char> GenSingleRange<int,SpaceType::PSPACE,-1>::data() const
{
DataHeader h = dataHeader();
std::vector<char> out;
@ -76,7 +76,7 @@ namespace MultiArrayTools
return out;
}
DataHeader SingleRange<int,SpaceType::PSPACE>::dataHeader() const
DataHeader GenSingleRange<int,SpaceType::PSPACE,-1>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::PSPACE );
@ -85,17 +85,17 @@ namespace MultiArrayTools
return h;
}
typename SingleRange<int,SpaceType::PSPACE>::IndexType SingleRange<int,SpaceType::PSPACE>::begin() const
typename GenSingleRange<int,SpaceType::PSPACE,-1>::IndexType GenSingleRange<int,SpaceType::PSPACE,-1>::begin() const
{
SingleIndex<int,SpaceType::PSPACE> i( std::dynamic_pointer_cast<SingleRange<int,SpaceType::PSPACE> >
GenSingleIndex<int,SpaceType::PSPACE,-1> i( std::dynamic_pointer_cast<GenSingleRange<int,SpaceType::PSPACE,-1> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename SingleRange<int,SpaceType::PSPACE>::IndexType SingleRange<int,SpaceType::PSPACE>::end() const
typename GenSingleRange<int,SpaceType::PSPACE,-1>::IndexType GenSingleRange<int,SpaceType::PSPACE,-1>::end() const
{
SingleIndex<int,SpaceType::PSPACE> i( std::dynamic_pointer_cast<SingleRange<int,SpaceType::PSPACE> >
GenSingleIndex<int,SpaceType::PSPACE,-1> i( std::dynamic_pointer_cast<GenSingleRange<int,SpaceType::PSPACE,-1> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;

View file

@ -10,58 +10,58 @@ namespace MultiArrayTools
}
/********************
* SingleRange *
* GenSingleRange *
********************/
SingleRangeFactory<size_t,SpaceType::SPIN>::SingleRangeFactory()
GenSingleRangeFactory<size_t,SpaceType::SPIN,4>::GenSingleRangeFactory()
{
// Quasi Singleton
if(not mProd){
mProd = std::shared_ptr<oType>( new SingleRange<size_t,SpaceType::SPIN>() );
mProd = std::shared_ptr<oType>( new GenSingleRange<size_t,SpaceType::SPIN,4>() );
setSelf();
}
}
std::shared_ptr<RangeBase> SingleRangeFactory<size_t,SpaceType::SPIN>::create()
std::shared_ptr<RangeBase> GenSingleRangeFactory<size_t,SpaceType::SPIN,4>::create()
{
return mProd;
}
/********************
* SingleRange *
* GenSingleRange *
********************/
size_t SingleRange<size_t,SpaceType::SPIN>::get(size_t pos) const
size_t GenSingleRange<size_t,SpaceType::SPIN,4>::get(size_t pos) const
{
return pos;
}
size_t SingleRange<size_t,SpaceType::SPIN>::getMeta(size_t metaPos) const
size_t GenSingleRange<size_t,SpaceType::SPIN,4>::getMeta(size_t metaPos) const
{
return metaPos;
}
size_t SingleRange<size_t,SpaceType::SPIN>::size() const
size_t GenSingleRange<size_t,SpaceType::SPIN,4>::size() const
{
return mSpinNum;
}
size_t SingleRange<size_t,SpaceType::SPIN>::dim() const
size_t GenSingleRange<size_t,SpaceType::SPIN,4>::dim() const
{
return 1;
}
SpaceType SingleRange<size_t,SpaceType::SPIN>::spaceType() const
SpaceType GenSingleRange<size_t,SpaceType::SPIN,4>::spaceType() const
{
return SpaceType::SPIN;
}
std::string SingleRange<size_t,SpaceType::SPIN>::stringMeta(size_t pos) const
std::string GenSingleRange<size_t,SpaceType::SPIN,4>::stringMeta(size_t pos) const
{
return std::to_string(get(pos));
}
std::vector<char> SingleRange<size_t,SpaceType::SPIN>::data() const
std::vector<char> GenSingleRange<size_t,SpaceType::SPIN,4>::data() const
{
DataHeader h = dataHeader();
std::vector<char> out;
@ -71,7 +71,7 @@ namespace MultiArrayTools
return out;
}
DataHeader SingleRange<size_t,SpaceType::SPIN>::dataHeader() const
DataHeader GenSingleRange<size_t,SpaceType::SPIN,4>::dataHeader() const
{
DataHeader h;
h.spaceType = static_cast<int>( SpaceType::SPIN );
@ -80,17 +80,17 @@ namespace MultiArrayTools
return h;
}
typename SingleRange<size_t,SpaceType::SPIN>::IndexType SingleRange<size_t,SpaceType::SPIN>::begin() const
typename GenSingleRange<size_t,SpaceType::SPIN,4>::IndexType GenSingleRange<size_t,SpaceType::SPIN,4>::begin() const
{
SingleIndex<size_t,SpaceType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >
GenSingleIndex<size_t,SpaceType::SPIN,4> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::SPIN,4> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = 0;
return i;
}
typename SingleRange<size_t,SpaceType::SPIN>::IndexType SingleRange<size_t,SpaceType::SPIN>::end() const
typename GenSingleRange<size_t,SpaceType::SPIN,4>::IndexType GenSingleRange<size_t,SpaceType::SPIN,4>::end() const
{
SingleIndex<size_t,SpaceType::SPIN> i( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >
GenSingleIndex<size_t,SpaceType::SPIN,4> i( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::SPIN,4> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
i = size();
return i;
@ -98,12 +98,12 @@ namespace MultiArrayTools
// put this in the interface class !!!
/*
std::shared_ptr<VIWB> SingleRange<size_t,SpaceType::SPIN>::index() const
std::shared_ptr<VIWB> GenSingleRange<size_t,SpaceType::SPIN,4>::index() const
{
typedef IndexWrapper<IndexType> IW;
return std::make_shared<IW>
( std::make_shared<IndexType>
( std::dynamic_pointer_cast<SingleRange<size_t,SpaceType::SPIN> >
( std::dynamic_pointer_cast<GenSingleRange<size_t,SpaceType::SPIN,4> >
( std::shared_ptr<RangeBase>( RB::mThis ) ) ) );
}
*/

View file

@ -134,13 +134,14 @@ namespace {
typedef MultiRangeFactory<SR,SR,SR,SR,SR,SR,SR,SR> SR8F;
typedef SR8F::oType SR8;
static const size_t os = 3000;
static const size_t s = 65536*os;
static const size_t os = 30;
static const size_t is = 65536;
static const size_t s = is*os;
OpTest_Spin()
{
data.resize(s);
for(size_t i = 0; i != s; ++i){
data.resize(is);
for(size_t i = 0; i != is; ++i){
double arg = static_cast<double>( i - s ) - 0.1;
data[i] = sin(arg);
//VCHECK(data[i]);
@ -162,7 +163,7 @@ namespace {
void OpTest_Spin::contract()
{
MultiArray<double,CR,SR,SR,SR,SR,SR,SR,SR,SR> ma( cr, sr, sr, sr, sr, sr, sr, sr, sr, data);
MultiArray<double,SR,SR,SR,SR,SR,SR,SR,SR> ma( sr, sr, sr, sr, sr, sr, sr, sr, data);
MultiArray<double,CR,SR,SR> res1( cr, sr, sr );
auto ii = MAT::getIndex<CR>(cr);
@ -177,7 +178,8 @@ namespace {
std::clock_t begin = std::clock();
//for(size_t i = 0; i != os; ++i){
res1(ii ,delta, deltap).par() += ma(ii, delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix);
//res1(ii ,delta, deltap).par() += ma(ii, delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix);
res1(ii ,delta, deltap) += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix);
//}
std::clock_t end = std::clock();
std::cout << "MultiArray time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC
@ -199,7 +201,7 @@ namespace {
for(size_t d = 0; d != 4; ++d){
for(size_t p = 0; p != 4; ++p){
const size_t tidx = i*4*4 + d*4 + p;
const size_t sidx = i*65536 + d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + c*5*4 + p;
const size_t sidx = /*i*65536 +*/ d*4*4*4*4*4*4*4 + a*5*4*4*4*4*4 + b*5*4*4*4 + c*5*4 + p;
vres[tidx] += data[sidx];
}
}