This commit is contained in:
Christian Zimmermann 2019-02-13 21:59:13 +01:00
parent 0326ebc505
commit 6d776f853d
48 changed files with 533 additions and 280 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 -O3 -g -march=native -fopenmp -funroll-loops -ftree-vectorize") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -g -Wpedantic -Ofast -mavx2 -funroll-loops -fopenmp")
enable_testing() enable_testing()

74
src/include/allocator.h Normal file
View file

@ -0,0 +1,74 @@
#ifndef __ma_allocator__
#define __ma_allocator__
#include <cstdlib>
#include <new>
#include <vector>
#include <cstdint>
#include <cassert>
#include <iostream>
namespace MultiArrayHelper
{
template <typename T>
struct Allocator
{
typedef T value_type;
static constexpr size_t type_size = sizeof(value_type);
static constexpr size_t N = 32;
Allocator() = default;
template <typename U>
Allocator(const Allocator<U>& x) {}
T* allocate(size_t n)
{
//constexpr size_t NN = N*type_size;
const size_t nn = n*type_size;
if(n > static_cast<size_t>(-1-N)) throw std::bad_alloc();
auto p = static_cast<char*>(std::malloc(nn + N));
if(not p) throw std::bad_alloc();
auto ip = reinterpret_cast<std::intptr_t>(p);
auto diff = N - (ip % N);
p += diff;
//auto ipx = reinterpret_cast<std::intptr_t>(p);
//std::cout << "ixp: " << ipx << std::endl;
//std::cout << "ixp %: " << ipx % N << std::endl;
auto ps = reinterpret_cast<std::intptr_t*>(p);
ps[-1] = diff;
return reinterpret_cast<T*>(p);
}
void deallocate(T* p, size_t n)
{
auto ps = reinterpret_cast<std::intptr_t*>(p);
std::free(reinterpret_cast<char*>(p)-ps[-1]);
}
};
template <class T, class U>
bool operator==(const Allocator<T>& a, const Allocator<U>& b)
{
return true;
}
template <class T, class U>
bool operator!=(const Allocator<T>& a, const Allocator<U>& b)
{
return false;
}
} // namespace MultiArrayHelper
namespace MultiArrayTools
{
template <typename T>
using vector = std::vector<T,MultiArrayHelper::Allocator<T>>;
} // namespace MultiArrayTools
#endif

62
src/include/allocator.h~ Normal file
View file

@ -0,0 +1,62 @@
#ifndef __ma_allocator__
#define __ma_allocator__
#include <cstdlib>
#include <new>
#include <vector>
namespace MultiArrayHelper
{
template <typename T, size_t N>
struct Allocator
{
typedef T value_type;
static constexpr type_size = sizeof(value_type);
Allocator() = default;
template <typename U>
Allocator(const Allocator<U>& x) {}
T* allocate(size_t n)
{
//constexpr size_t NN = N*type_size;
const size_t nn = n*type_size;
if(n > static_cast<size_t>(-1-NN)) throw std::bad_alloc();
auto p = static_cast<char*>(std::malloc(nn + N));
if(not p) throw std::bad_alloc();
auto ip = static_cast<std::intptr_t>(p);
mDiff = N - (ip % N);
p += mDiff;
return static_cast<T*>(p);
}
void deacllocate(T* p, size_t n)
{
std::free(p-mDiff);
}
private:
std::intptr_t mDiff;
};
template <class T, class U>
bool operator==(const Allocator<T>& a, const Allocator<T>& b)
{
return true;
}
template <class T, class U>
bool operator!=(const Allocator<T>& a, const Allocator<T>& b)
{
return false;
}
template <typename T>
using vector = vector<T,Allocator>;
} // namespace MultiArrayHelper
#endif

View file

@ -36,29 +36,87 @@ namespace MultiArrayTools
namespace namespace
{ {
template <typename C, typename T, size_t N> template <typename C, typename T, size_t N>
using SC = ConversionSizes::OrigSize<N>::template FromTo<C,T>; using SC = typename ConversionSizes::OrigSize<N>::template FromTo<C,T>;
template <typename C, typename T, class Range> template <typename C, typename T, class Range>
using SCR = SC<C,T,typename Range::SIZE>; using SCR = SC<C,T,Range::SIZE>;
template <typename C, typename T, class Range> template <typename C, typename T, class Range>
using SCRR = GenSingleRange<typename Range::value_type,SpaceType::NONE,SCR<C,T,typename Range::SIZE>; using SCRR = GenSingleRange<typename Range::MetaType,SpaceType::NONE,SCR<C,T,Range>::SIZE>;
} }
template <typename C, typename T, class Range, class... Ranges> template <size_t N>
Slice<C,Ranges...,SCRR<C,T,Range>> tcast(MultiArray<T,Ranges...,Range>& ma) struct SubTuple
{ {
return Slice<C,Ranges...,SCRR<C,T,Range>> template <class RTP, class... Ranges>
( ma.range()->space(), reinterpret_cast<C*>( ma.data() ) ); static inline auto mk(const RTP& rtp, const Ranges&... rs)
} -> decltype(SubTuple<N-1>::mk(rtp, std::get<N>(rtp), rs...))
{
return SubTuple<N-1>::mk(rtp, std::get<N>(rtp), rs...);
}
};
template <typename C, typename T, class Range, class... Ranges> template <>
ConstSlice<C,Ranges...,SCRR<C,T,Range>> tcast(const MultiArray<T,Ranges...,Range>& ma) struct SubTuple<0>
{ {
return ConstSlice<C,Ranges...,SCRR<C,T,Range>> template <class RTP, class... Ranges>
( ma.range()->space(), reinterpret_cast<const C*>( ma.data() ) ); static inline auto mk(const RTP& rtp, const Ranges&... rs)
-> decltype(std::make_tuple(std::get<0>(rtp), rs...))
{
return std::make_tuple(std::get<0>(rtp), rs...);
}
};
template <class... Ranges>
using LastR = typename std::tuple_element<sizeof...(Ranges)-1,std::tuple<Ranges...>>::type;
template <typename C, typename T, class... Ranges>
auto rtcast(const std::tuple<std::shared_ptr<Ranges>...>& rtp)
-> decltype(std::tuple_cat(SubTuple<sizeof...(Ranges)-2>::mk(rtp),
std::make_tuple( std::dynamic_pointer_cast<SCRR<C,T,LastR<Ranges...>>>
( SCRR<C,T,LastR<Ranges...>>::factory().create() ) ) ))
{
return std::tuple_cat(SubTuple<sizeof...(Ranges)-2>::mk(rtp),
std::make_tuple( std::dynamic_pointer_cast<SCRR<C,T,LastR<Ranges...>>>
( SCRR<C,T,LastR<Ranges...>>::factory().create() ) ) );
} }
template <typename T, class... Ranges>
inline Slice<T,Ranges...> rangeTpToSlice( const std::tuple<std::shared_ptr<Ranges>...>& rtp, T* data )
{
return Slice<T,Ranges...>(rtp, data);
}
template <typename T, class... Ranges>
inline ConstSlice<T,Ranges...> rangeTpToSlice( const std::tuple<std::shared_ptr<Ranges>...>& rtp, const T* data )
{
return ConstSlice<T,Ranges...>(rtp, data);
}
template <typename C, typename T, class... Ranges>
auto tcast(MultiArray<T,Ranges...>& ma)
-> decltype(rangeTpToSlice
( rtcast<C,T>( ma.range()->space() ),
reinterpret_cast<C*>( ma.data() ) ))
{
// VCHECK(reinterpret_cast<std::intptr_t>(ma.data()) % 32);
//VCHECK(reinterpret_cast<std::intptr_t>(reinterpret_cast<C*>(ma.data())) % 32);
return rangeTpToSlice
( rtcast<C,T>( ma.range()->space() ),
reinterpret_cast<C*>( ma.data() ) );
}
template <typename C, typename T, class... Ranges>
auto tcast(const MultiArray<T,Ranges...>& ma)
-> decltype(rangeTpToSlice
( rtcast<C,T>( ma.range()->space() ),
reinterpret_cast<const C*>( ma.data() ) ))
{
//VCHECK(reinterpret_cast<std::intptr_t>(ma.data()) % 32);
//VCHECK(reinterpret_cast<std::intptr_t>(reinterpret_cast<C*>(ma.data())) % 32);
return rangeTpToSlice
( rtcast<C,T>( ma.range()->space() ),
reinterpret_cast<const C*>( ma.data() ) );
}
} }
#endif #endif

View file

@ -15,7 +15,7 @@ namespace MultiArrayTools
static auto mk(const std::shared_ptr<Index>& i) static auto mk(const std::shared_ptr<Index>& i)
-> MultiArray<typename Index::MetaType, typename Index::RangeType> -> MultiArray<typename Index::MetaType, typename Index::RangeType>
{ {
std::vector<typename Index::MetaType> vv(i->range()->size()); vector<typename Index::MetaType> vv(i->range()->size());
for(Index j = (*i); j.pos() != j.max(); ++j){ for(Index j = (*i); j.pos() != j.max(); ++j){
vv[j.pos()] = j.meta(); vv[j.pos()] = j.meta();
} }

View file

@ -109,7 +109,7 @@ namespace MultiArrayTools
} }
template <class Range> template <class Range>
auto createRange(const std::vector<char>& cvec) auto createRange(const vector<char>& cvec)
-> std::shared_ptr<Range> -> std::shared_ptr<Range>
{ {
const char* dp = cvec.data(); const char* dp = cvec.data();

View file

@ -61,7 +61,7 @@ namespace MultiArrayTools
-> std::shared_ptr<typename RangeFactory::oType>; -> std::shared_ptr<typename RangeFactory::oType>;
template <class Range> template <class Range>
auto createRange(const std::vector<char>& cvec) auto createRange(const vector<char>& cvec)
-> std::shared_ptr<Range>; -> std::shared_ptr<Range>;
template <size_t N, class MArray> template <size_t N, class MArray>

View file

@ -347,7 +347,7 @@ namespace MultiArrayTools
} }
} }
if(not check){ if(not check){
std::vector<std::intptr_t> pv(sizeof...(Ranges)); vector<std::intptr_t> pv(sizeof...(Ranges));
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv); RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
pv.push_back( reinterpret_cast<std::intptr_t> pv.push_back( reinterpret_cast<std::intptr_t>
( &std::dynamic_pointer_cast<oType>( mProd )->mMapf ) ); ( &std::dynamic_pointer_cast<oType>( mProd )->mMapf ) );
@ -376,8 +376,8 @@ namespace MultiArrayTools
mult[mapf[ii]]++; mult[mapf[ii]]++;
} }
std::vector<typename MapF::value_type> outmeta(mult.size()); vector<typename MapF::value_type> outmeta(mult.size());
std::vector<size_t> outmult(mult.size()); vector<size_t> outmult(mult.size());
size_t cnt = 0; size_t cnt = 0;
for(auto& x: mult){ for(auto& x: mult){
@ -404,12 +404,12 @@ namespace MultiArrayTools
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) { for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
max = mapf[ii]+1 > max ? mapf[ii]+1 : max; max = mapf[ii]+1 > max ? mapf[ii]+1 : max;
} }
std::vector<size_t> mult(max,0); vector<size_t> mult(max,0);
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) { for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
mult[mapf[ii]]++; mult[mapf[ii]]++;
} }
std::vector<size_t> outmult(mult.size()); vector<size_t> outmult(mult.size());
size_t cnt = 0; size_t cnt = 0;
for(auto& x: mult){ for(auto& x: mult){
@ -505,10 +505,10 @@ namespace MultiArrayTools
} }
template <class MapF, SpaceType XSTYPE, class... Ranges> template <class MapF, SpaceType XSTYPE, class... Ranges>
std::vector<char> GenMapRange<MapF,XSTYPE,Ranges...>::data() const vector<char> GenMapRange<MapF,XSTYPE,Ranges...>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
//out.reserve(h.metaSize + sizeof(DataHeader)); //out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -259,7 +259,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
const Space& space() const; const Space& space() const;

View file

@ -18,7 +18,7 @@ namespace MultiArrayTools
friend class GenMapRangeFactory; friend class GenMapRangeFactory;
private: private:
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated; static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
}; };
} }

View file

@ -3,6 +3,7 @@
#define __mbase_def_h__ #define __mbase_def_h__
#include "ranges/rbase_def.h" #include "ranges/rbase_def.h"
#include "allocator.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {

View file

@ -7,7 +7,7 @@ namespace MultiArrayTools
Scalar<T> scalar(const T& in) Scalar<T> scalar(const T& in)
{ {
NullRF nrf; NullRF nrf;
return Scalar<T>( std::dynamic_pointer_cast<NullRange>( nrf.create() ), std::vector<T>( { in } ) ); return Scalar<T>( std::dynamic_pointer_cast<NullRange>( nrf.create() ), vector<T>( { in } ) );
} }
/******************* /*******************
@ -24,7 +24,7 @@ namespace MultiArrayTools
template <typename T, class... SRanges> template <typename T, class... SRanges>
MultiArray<T,SRanges...>::MultiArray(const typename CRange::Space& space, MultiArray<T,SRanges...>::MultiArray(const typename CRange::Space& space,
std::vector<T>&& vec) : vector<T>&& vec) :
MutableMultiArrayBase<T,SRanges...>(space), MutableMultiArrayBase<T,SRanges...>(space),
mCont(vec) mCont(vec)
{ {
@ -52,7 +52,7 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const std::vector<T>& vec) : MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const vector<T>& vec) :
MutableMultiArrayBase<T,SRanges...>(ranges...), MutableMultiArrayBase<T,SRanges...>(ranges...),
mCont(vec) mCont(vec)
{ {
@ -63,7 +63,7 @@ namespace MultiArrayTools
} }
template <typename T, class... SRanges> template <typename T, class... SRanges>
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec) : MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec) :
MutableMultiArrayBase<T,SRanges...>(ranges...), MutableMultiArrayBase<T,SRanges...>(ranges...),
mCont(vec) mCont(vec)
{ {

View file

@ -25,7 +25,6 @@ namespace MultiArrayTools
} }
}; };
template <typename T, class... SRanges> template <typename T, class... SRanges>
class MultiArray : public MutableMultiArrayBase<T,SRanges...> class MultiArray : public MutableMultiArrayBase<T,SRanges...>
{ {
@ -41,15 +40,15 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(MultiArray); DEFAULT_MEMBERS(MultiArray);
MultiArray(const std::shared_ptr<SRanges>&... ranges); MultiArray(const std::shared_ptr<SRanges>&... ranges);
MultiArray(const std::shared_ptr<SRanges>&... ranges, const T& val); MultiArray(const std::shared_ptr<SRanges>&... ranges, const T& val);
MultiArray(const std::shared_ptr<SRanges>&... ranges, const std::vector<T>& vec); MultiArray(const std::shared_ptr<SRanges>&... ranges, const vector<T>& vec);
MultiArray(const std::shared_ptr<SRanges>&... ranges, std::vector<T>&& vec); MultiArray(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec);
MultiArray(const typename CRange::Space& space); MultiArray(const typename CRange::Space& space);
MultiArray(const typename CRange::Space& space, std::vector<T>&& vec); MultiArray(const typename CRange::Space& space, vector<T>&& vec);
MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes); MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes);
// Only if ALL ranges have default extensions: // Only if ALL ranges have default extensions:
//MultiArray(const std::vector<T>& vec); //MultiArray(const vector<T>& vec);
//MultiArray(std::vector<T>&& vec); //MultiArray(vector<T>&& vec);
// template <class Range2, class Range3> // template <class Range2, class Range3>
// MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in); // MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
@ -76,8 +75,8 @@ namespace MultiArrayTools
virtual const T* data() const override; virtual const T* data() const override;
virtual T* data() override; virtual T* data() override;
virtual std::vector<T>& vdata() { return mCont; } virtual vector<T>& vdata() { return mCont; }
virtual const std::vector<T>& vdata() const { return mCont; } virtual const vector<T>& vdata() const { return mCont; }
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override; virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
@ -99,7 +98,7 @@ namespace MultiArrayTools
private: private:
std::vector<T> mCont; vector<T> mCont;
}; };
template <typename T> template <typename T>
@ -119,7 +118,7 @@ namespace MultiArrayTools
const size_t smas = sma.size(); const size_t smas = sma.size();
const size_t mas = ma.size(); const size_t mas = ma.size();
auto cr = ma.range()->cat(sma.range()); auto cr = ma.range()->cat(sma.range());
std::vector<T> ov; vector<T> ov;
ov.reserve(mas * smas); ov.reserve(mas * smas);
for(auto& x: ma){ for(auto& x: ma){

View file

@ -36,7 +36,7 @@ namespace MultiArrayTools
template <class... RangeTypes> template <class... RangeTypes>
AnonymousRangeFactory(std::shared_ptr<RangeTypes>... origs); AnonymousRangeFactory(std::shared_ptr<RangeTypes>... origs);
AnonymousRangeFactory(const std::vector<std::shared_ptr<RangeBase>>& origs); AnonymousRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs);
template <class Range> template <class Range>
void append(std::shared_ptr<Range> r); void append(std::shared_ptr<Range> r);
@ -45,9 +45,9 @@ namespace MultiArrayTools
private: private:
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec); std::shared_ptr<RangeBase> checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec);
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated; static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
bool mProductCreated = false; bool mProductCreated = false;
}; };
@ -81,7 +81,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
std::shared_ptr<RangeBase> sub(size_t num) const; std::shared_ptr<RangeBase> sub(size_t num) const;
@ -91,10 +91,10 @@ namespace MultiArrayTools
template <class... Ranges> template <class... Ranges>
std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast
const std::vector<std::shared_ptr<RangeBase> >& orig() const; const vector<std::shared_ptr<RangeBase> >& orig() const;
std::shared_ptr<AnonymousRange> sreplace(const std::shared_ptr<RangeBase> in, size_t num) const; std::shared_ptr<AnonymousRange> sreplace(const std::shared_ptr<RangeBase> in, size_t num) const;
std::shared_ptr<AnonymousRange> sreplace(const std::vector<std::shared_ptr<RangeBase>>& in, size_t num) const; std::shared_ptr<AnonymousRange> sreplace(const vector<std::shared_ptr<RangeBase>>& in, size_t num) const;
bool isEmpty() const; bool isEmpty() const;
@ -114,12 +114,12 @@ namespace MultiArrayTools
template <class... RangeTypes> template <class... RangeTypes>
GenSingleRange(std::shared_ptr<RangeTypes>... origs); GenSingleRange(std::shared_ptr<RangeTypes>... origs);
GenSingleRange(const std::vector<std::shared_ptr<RangeBase>>& origs); GenSingleRange(const vector<std::shared_ptr<RangeBase>>& origs);
size_t mSize = 1; size_t mSize = 1;
bool mEmpty = true; bool mEmpty = true;
std::vector<std::shared_ptr<RangeBase> > mOrig; vector<std::shared_ptr<RangeBase> > mOrig;
}; };
} }
@ -172,7 +172,7 @@ namespace MultiArrayHelper
template <> template <>
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange>& rp, inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange>& rp,
const std::vector<std::shared_ptr<RangeBase> >& orig, const vector<std::shared_ptr<RangeBase> >& orig,
size_t origpos, size_t size) size_t origpos, size_t size)
{ {
AnonymousRangeFactory arf; AnonymousRangeFactory arf;
@ -184,7 +184,7 @@ namespace MultiArrayHelper
} }
template <> template <>
inline void setRangeToVec<AnonymousRange>(std::vector<std::shared_ptr<RangeBase> >& v, inline void setRangeToVec<AnonymousRange>(vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<AnonymousRange> r) std::shared_ptr<AnonymousRange> r)
{ {
if(not r->isEmpty()){ if(not r->isEmpty()){

View file

@ -5,6 +5,8 @@
#include <cstdlib> #include <cstdlib>
#include <utility> #include <utility>
#include "allocator.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {
@ -14,7 +16,7 @@ namespace MultiArrayTools
struct DynamicMetaSetter struct DynamicMetaSetter
{ {
template <typename... Us> template <typename... Us>
static inline void set(const std::tuple<Us...>& in, std::vector<DynamicMetaElem>& meta) static inline void set(const std::tuple<Us...>& in, vector<DynamicMetaElem>& meta)
{ {
typedef typename std::tuple_element<N,std::tuple<Us...>>::type elemtype; typedef typename std::tuple_element<N,std::tuple<Us...>>::type elemtype;
meta[N].first = reinterpret_cast<const char*>( &std::get<N>(in) ); meta[N].first = reinterpret_cast<const char*>( &std::get<N>(in) );
@ -27,7 +29,7 @@ namespace MultiArrayTools
struct DynamicMetaSetter<0> struct DynamicMetaSetter<0>
{ {
template <typename... Us> template <typename... Us>
static inline void set(const std::tuple<Us...>& in, std::vector<DynamicMetaElem>& meta) static inline void set(const std::tuple<Us...>& in, vector<DynamicMetaElem>& meta)
{ {
typedef typename std::tuple_element<0,std::tuple<Us...>>::type elemtype; typedef typename std::tuple_element<0,std::tuple<Us...>>::type elemtype;
meta[0].first = reinterpret_cast<const char*>( &std::get<0>(in) ); meta[0].first = reinterpret_cast<const char*>( &std::get<0>(in) );
@ -39,7 +41,7 @@ namespace MultiArrayTools
class DynamicMetaT class DynamicMetaT
{ {
private: private:
std::vector<DynamicMetaElem> mMeta; vector<DynamicMetaElem> mMeta;
public: public:
DynamicMetaT() = default; DynamicMetaT() = default;

View file

@ -72,7 +72,7 @@ namespace MultiArrayTools
} }
template <class EC> template <class EC>
DynamicRangeFactory<EC>::DynamicRangeFactory(const std::vector<std::shared_ptr<RangeBase>>& origs) DynamicRangeFactory<EC>::DynamicRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs)
{ {
mProd = std::shared_ptr<oType>( new DynamicRange<EC>( origs ) ); mProd = std::shared_ptr<oType>( new DynamicRange<EC>( origs ) );
} }
@ -99,10 +99,10 @@ namespace MultiArrayTools
// INSTANCIATE IF NEEDED!! // INSTANCIATE IF NEEDED!!
template <class EC> template <class EC>
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > DynamicRangeFactory<EC>::mAleadyCreated; std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > DynamicRangeFactory<EC>::mAleadyCreated;
template <class EC> template <class EC>
std::shared_ptr<RangeBase> DynamicRangeFactory<EC>::checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec) std::shared_ptr<RangeBase> DynamicRangeFactory<EC>::checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec)
{ {
std::shared_ptr<RangeBase> out; std::shared_ptr<RangeBase> out;
bool check = false; bool check = false;
@ -122,7 +122,7 @@ namespace MultiArrayTools
} }
} }
if(not check){ if(not check){
std::vector<std::intptr_t> app(pvec.size()); vector<std::intptr_t> app(pvec.size());
for(size_t i = 0; i != app.size(); ++i){ for(size_t i = 0; i != app.size(); ++i){
app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() ); app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() );
} }
@ -223,7 +223,7 @@ namespace MultiArrayTools
} }
template <class EC> template <class EC>
DynamicIndex<EC>& DynamicIndex<EC>::operator()(const std::vector<std::shared_ptr<IndexW<EC>>>& ivec) DynamicIndex<EC>& DynamicIndex<EC>::operator()(const vector<std::shared_ptr<IndexW<EC>>>& ivec)
{ {
assert(mIVec.size() == ivec.size()); assert(mIVec.size() == ivec.size());
for(size_t i = 0; i != mIVec.size(); ++i){ for(size_t i = 0; i != mIVec.size(); ++i){
@ -237,7 +237,7 @@ namespace MultiArrayTools
template <class... Indices> template <class... Indices>
DynamicIndex<EC>& DynamicIndex<EC>::operator()(const std::shared_ptr<Indices>&... is) DynamicIndex<EC>& DynamicIndex<EC>::operator()(const std::shared_ptr<Indices>&... is)
{ {
std::vector<std::shared_ptr<IndexW<EC>>> tmp = vector<std::shared_ptr<IndexW<EC>>> tmp =
{ std::make_shared<IndexWrapper<Indices,EC>>(is)... }; { std::make_shared<IndexWrapper<Indices,EC>>(is)... };
assert(mIVec.size() == tmp.size()); assert(mIVec.size() == tmp.size());
@ -489,10 +489,10 @@ namespace MultiArrayTools
} }
template <class EC> template <class EC>
std::vector<char> DynamicRange<EC>::data() const vector<char> DynamicRange<EC>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
for(auto& x: mOrig){ for(auto& x: mOrig){
@ -571,7 +571,7 @@ namespace MultiArrayTools
} }
template <class EC> template <class EC>
DynamicRange<EC>::DynamicRange(const std::vector<std::shared_ptr<RangeBase>>& origs) : DynamicRange<EC>::DynamicRange(const vector<std::shared_ptr<RangeBase>>& origs) :
RangeInterface<DynamicIndex<EC>>(), RangeInterface<DynamicIndex<EC>>(),
mOrig(origs) mOrig(origs)
{ {
@ -602,7 +602,7 @@ namespace MultiArrayTools
} }
template <class EC> template <class EC>
const std::vector<std::shared_ptr<RangeBase> >& DynamicRange<EC>::orig() const const vector<std::shared_ptr<RangeBase> >& DynamicRange<EC>::orig() const
{ {
return mOrig; return mOrig;
} }

View file

@ -172,7 +172,7 @@ namespace MultiArrayTools
class DynamicIndex : public IndexInterface<DynamicIndex<EC>,DynamicMetaT> class DynamicIndex : public IndexInterface<DynamicIndex<EC>,DynamicMetaT>
{ {
private: private:
typedef std::vector<std::pair<std::shared_ptr<IndexW<EC>>,size_t>> IVecT; typedef vector<std::pair<std::shared_ptr<IndexW<EC>>,size_t>> IVecT;
IVecT mIVec; IVecT mIVec;
@ -197,7 +197,7 @@ namespace MultiArrayTools
DynamicIndex& operator--(); DynamicIndex& operator--();
DynamicIndex& operator()(const IVecT& ivec); DynamicIndex& operator()(const IVecT& ivec);
DynamicIndex& operator()(const std::vector<std::shared_ptr<IndexW<EC>>>& ivec); DynamicIndex& operator()(const vector<std::shared_ptr<IndexW<EC>>>& ivec);
template <class... Indices> template <class... Indices>
DynamicIndex& operator()(const std::shared_ptr<Indices>&... is); DynamicIndex& operator()(const std::shared_ptr<Indices>&... is);
@ -259,7 +259,7 @@ namespace MultiArrayTools
template <class... RangeTypes> template <class... RangeTypes>
DynamicRangeFactory(std::shared_ptr<RangeTypes>... origs); DynamicRangeFactory(std::shared_ptr<RangeTypes>... origs);
DynamicRangeFactory(const std::vector<std::shared_ptr<RangeBase>>& origs); DynamicRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs);
template <class Range> template <class Range>
void append(std::shared_ptr<Range> r); void append(std::shared_ptr<Range> r);
@ -268,9 +268,9 @@ namespace MultiArrayTools
private: private:
std::shared_ptr<RangeBase> checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec); std::shared_ptr<RangeBase> checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec);
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated; static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
bool mProductCreated = false; bool mProductCreated = false;
}; };
@ -299,12 +299,12 @@ namespace MultiArrayTools
template <class... RangeTypes> template <class... RangeTypes>
DynamicRange(std::shared_ptr<RangeTypes>... origs); DynamicRange(std::shared_ptr<RangeTypes>... origs);
DynamicRange(const std::vector<std::shared_ptr<RangeBase>>& origs); DynamicRange(const vector<std::shared_ptr<RangeBase>>& origs);
size_t mSize = 1; size_t mSize = 1;
bool mEmpty = true; bool mEmpty = true;
std::vector<std::shared_ptr<RangeBase> > mOrig; vector<std::shared_ptr<RangeBase> > mOrig;
public: public:
virtual size_t size() const final; virtual size_t size() const final;
@ -320,7 +320,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
std::shared_ptr<RangeBase> sub(size_t num) const; std::shared_ptr<RangeBase> sub(size_t num) const;
@ -330,7 +330,7 @@ namespace MultiArrayTools
template <class... Ranges> template <class... Ranges>
std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast std::shared_ptr<MultiRange<Ranges...> > scast(SIZET<Ranges>... sizes) const; // save cast
const std::vector<std::shared_ptr<RangeBase> >& orig() const; const vector<std::shared_ptr<RangeBase> >& orig() const;
void sreplace(const std::shared_ptr<RangeBase> in, size_t num); void sreplace(const std::shared_ptr<RangeBase> in, size_t num);
@ -352,7 +352,7 @@ namespace MultiArrayHelper
template <class EC> template <class EC>
inline void resolveSetRange(std::shared_ptr<DynamicRange<EC>>& rp, inline void resolveSetRange(std::shared_ptr<DynamicRange<EC>>& rp,
const std::vector<std::shared_ptr<RangeBase> >& orig, const vector<std::shared_ptr<RangeBase> >& orig,
size_t origpos, size_t size) size_t origpos, size_t size)
{ {
DynamicRangeFactory<EC> arf; DynamicRangeFactory<EC> arf;
@ -364,7 +364,7 @@ namespace MultiArrayHelper
} }
template <class EC> template <class EC>
inline void setRangeToVec(std::vector<std::shared_ptr<RangeBase> >& v, inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<DynamicRange<EC>> r) std::shared_ptr<DynamicRange<EC>> r)
{ {
if(not r->isEmpty()){ if(not r->isEmpty()){

View file

@ -201,7 +201,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
const Space& space() const; const Space& space() const;
@ -519,7 +519,7 @@ namespace MultiArrayTools
} }
} }
if(not check){ if(not check){
std::vector<std::intptr_t> pv(sizeof...(Ranges)); vector<std::intptr_t> pv(sizeof...(Ranges));
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv); RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv; MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
out = mProd; out = mProd;
@ -590,10 +590,10 @@ namespace MultiArrayTools
} }
template <class... Ranges> template <class... Ranges>
std::vector<char> MultiRange<Ranges...>::data() const vector<char> MultiRange<Ranges...>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
//out.reserve(h.metaSize + sizeof(DataHeader)); //out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -17,7 +17,7 @@ namespace MultiArrayTools
friend class MultiRangeFactory; friend class MultiRangeFactory;
private: private:
static std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > mAleadyCreated; static std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > mAleadyCreated;
}; };
} }

View file

@ -81,7 +81,7 @@ namespace MultiArrayTools
std::intptr_t id() const; std::intptr_t id() const;
virtual std::string stringMeta(size_t pos) const = 0; virtual std::string stringMeta(size_t pos) const = 0;
virtual std::vector<char> data() const = 0; // usefull when writing to files, etc... virtual vector<char> data() const = 0; // usefull when writing to files, etc...
virtual SpaceType spaceType() const = 0; virtual SpaceType spaceType() const = 0;
virtual DataHeader dataHeader() const = 0; virtual DataHeader dataHeader() const = 0;

View file

@ -43,7 +43,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
size_t get(size_t pos) const; size_t get(size_t pos) const;
size_t getMeta(size_t metaPos) const; size_t getMeta(size_t metaPos) const;

View file

@ -47,7 +47,7 @@ namespace MultiArrayTools
virtual size_t dim() const final; virtual size_t dim() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
virtual SpaceType spaceType() const final; virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;

View file

@ -39,7 +39,7 @@ namespace MultiArrayTools
virtual size_t dim() const final; virtual size_t dim() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
virtual SpaceType spaceType() const final; virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;

View file

@ -40,7 +40,7 @@ namespace MultiArrayTools
virtual size_t dim() const final; virtual size_t dim() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
virtual SpaceType spaceType() const final; virtual SpaceType spaceType() const final;
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;

View file

@ -14,7 +14,7 @@
<< " in " << __func__ << ": " << #a << " = " << a << std::endl; << " in " << __func__ << ": " << #a << " = " << a << std::endl;
#endif #endif
#include "allocator.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {

View file

@ -46,7 +46,7 @@ namespace MultiArrayHelper
template <class Range> template <class Range>
inline void resolveSetRange(std::shared_ptr<Range>& rp, const std::vector<std::shared_ptr<RangeBase> >& orig, inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
size_t origpos, size_t size) size_t origpos, size_t size)
{ {
assert(size == 1); assert(size == 1);
@ -54,7 +54,7 @@ namespace MultiArrayHelper
} }
template <class Range> template <class Range>
inline void setRangeToVec(std::vector<std::shared_ptr<RangeBase> >& v, inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
std::shared_ptr<Range> r) std::shared_ptr<Range> r)
{ {
v.insert(v.begin(), r); v.insert(v.begin(), r);
@ -251,7 +251,7 @@ namespace MultiArrayHelper
template <class... Ranges> template <class... Ranges>
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst, static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<std::shared_ptr<RangeBase> >& v) vector<std::shared_ptr<RangeBase> >& v)
{ {
setRangeToVec(v, std::get<N>(rst)); setRangeToVec(v, std::get<N>(rst));
RPackNum<N-1>::RangesToVec(rst, v); RPackNum<N-1>::RangesToVec(rst, v);
@ -259,7 +259,7 @@ namespace MultiArrayHelper
template <class... Ranges> template <class... Ranges>
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst, static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<std::intptr_t>& v) vector<std::intptr_t>& v)
{ {
v[N] = reinterpret_cast<std::intptr_t>( std::get<N>(rst).get() ); v[N] = reinterpret_cast<std::intptr_t>( std::get<N>(rst).get() );
RPackNum<N-1>::RangesToVec(rst, v); RPackNum<N-1>::RangesToVec(rst, v);
@ -324,7 +324,7 @@ namespace MultiArrayHelper
} }
template <class RangeTuple, typename... SIZET> template <class RangeTuple, typename... SIZET>
static inline void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> >& orig, static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes) RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
{ {
constexpr size_t tps = std::tuple_size<RangeTuple>::value; constexpr size_t tps = std::tuple_size<RangeTuple>::value;
@ -334,7 +334,7 @@ namespace MultiArrayHelper
template <class... Ranges> template <class... Ranges>
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p, static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
const std::vector<std::intptr_t>& a) const vector<std::intptr_t>& a)
{ {
return reinterpret_cast<std::intptr_t>( std::get<N>(p).get() ) == a[N] and return reinterpret_cast<std::intptr_t>( std::get<N>(p).get() ) == a[N] and
RPackNum<N-1>::checkIfCreated(p,a); RPackNum<N-1>::checkIfCreated(p,a);
@ -347,22 +347,22 @@ namespace MultiArrayHelper
} }
template <class... Ranges> template <class... Ranges>
static inline void fillRangeDataVec(std::vector<char>& out, static inline void fillRangeDataVec(vector<char>& out,
const std::tuple<std::shared_ptr<Ranges>...>& tp) const std::tuple<std::shared_ptr<Ranges>...>& tp)
{ {
std::vector<char> part = std::get<sizeof...(Ranges)-N-1>(tp)->data(); vector<char> part = std::get<sizeof...(Ranges)-N-1>(tp)->data();
out.insert(out.end(), part.begin(), part.end()); out.insert(out.end(), part.begin(), part.end());
RPackNum<N-1>::fillRangeDataVec(out, tp); RPackNum<N-1>::fillRangeDataVec(out, tp);
} }
template <size_t SIZE, class Range, class... Ranges> template <size_t SIZE, class Range, class... Ranges>
static inline bool compareSpaceTypes(const std::vector<std::shared_ptr<RangeBase> >& rbvec) static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
{ {
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and RPackNum<N-1>::template compareSpaceTypes<SIZE,Ranges...>(rbvec); return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and RPackNum<N-1>::template compareSpaceTypes<SIZE,Ranges...>(rbvec);
} }
template <class... Ranges> template <class... Ranges>
static inline void setSpace(const std::vector<std::shared_ptr<RangeBase> >& rbvec, static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
std::tuple<std::shared_ptr<Ranges>...>& stp) std::tuple<std::shared_ptr<Ranges>...>& stp)
{ {
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType; typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
@ -529,14 +529,14 @@ namespace MultiArrayHelper
template <class... Ranges> template <class... Ranges>
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst, static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<std::intptr_t>& v) vector<std::intptr_t>& v)
{ {
v[0] = reinterpret_cast<std::intptr_t>( std::get<0>(rst).get() );; v[0] = reinterpret_cast<std::intptr_t>( std::get<0>(rst).get() );;
} }
template <class... Ranges> template <class... Ranges>
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst, static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
std::vector<std::shared_ptr<RangeBase> >& v) vector<std::shared_ptr<RangeBase> >& v)
{ {
setRangeToVec(v, std::get<0>(rst)); setRangeToVec(v, std::get<0>(rst));
} }
@ -596,7 +596,7 @@ namespace MultiArrayHelper
} }
template <class RangeTuple, typename... SIZET> template <class RangeTuple, typename... SIZET>
static inline void resolveRangeType(const std::vector<std::shared_ptr<RangeBase> >& orig, static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
RangeTuple& rtp, size_t off, size_t size) RangeTuple& rtp, size_t off, size_t size)
{ {
constexpr size_t tps = std::tuple_size<RangeTuple>::value; constexpr size_t tps = std::tuple_size<RangeTuple>::value;
@ -605,7 +605,7 @@ namespace MultiArrayHelper
template <class... Ranges> template <class... Ranges>
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p, static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
const std::vector<std::intptr_t>& a) const vector<std::intptr_t>& a)
{ {
return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0]; return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0];
} }
@ -617,21 +617,21 @@ namespace MultiArrayHelper
} }
template <class... Ranges> template <class... Ranges>
static inline void fillRangeDataVec(std::vector<char>& out, static inline void fillRangeDataVec(vector<char>& out,
const std::tuple<std::shared_ptr<Ranges>...>& tp) const std::tuple<std::shared_ptr<Ranges>...>& tp)
{ {
std::vector<char> part = std::get<sizeof...(Ranges)-1>(tp)->data(); vector<char> part = std::get<sizeof...(Ranges)-1>(tp)->data();
out.insert(out.end(), part.begin(), part.end()); out.insert(out.end(), part.begin(), part.end());
} }
template <size_t SIZE, class Range> template <size_t SIZE, class Range>
static inline bool compareSpaceTypes(const std::vector<std::shared_ptr<RangeBase> >& rbvec) static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
{ {
return rbvec[SIZE-1]->spaceType() == Range::STYPE; return rbvec[SIZE-1]->spaceType() == Range::STYPE;
} }
template <class... Ranges> template <class... Ranges>
static inline void setSpace(const std::vector<std::shared_ptr<RangeBase> >& rbvec, static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
std::tuple<std::shared_ptr<Ranges>...>& stp) std::tuple<std::shared_ptr<Ranges>...>& stp)
{ {
typedef typename std::remove_reference<decltype(*std::get<0>( stp ))>::type RType; typedef typename std::remove_reference<decltype(*std::get<0>( stp ))>::type RType;

View file

@ -107,9 +107,8 @@ namespace MultiArrayTools
typedef GenSingleRange<U,TYPE,S> oType; typedef GenSingleRange<U,TYPE,S> oType;
GenSingleRangeFactory() = delete; GenSingleRangeFactory() = delete;
GenSingleRangeFactory(const std::vector<U>& space); GenSingleRangeFactory(const vector<U>& space);
std::shared_ptr<RangeBase> create(); std::shared_ptr<RangeBase> create();
}; };
template <typename U> template <typename U>
@ -125,7 +124,7 @@ namespace MultiArrayTools
MetaMap& operator=(MetaMap&& in) = default; MetaMap& operator=(MetaMap&& in) = default;
//MetaMap(const std::map<U,size_t>& in) : mMap(in) {} //MetaMap(const std::map<U,size_t>& in) : mMap(in) {}
MetaMap(const std::vector<U>& in) MetaMap(const vector<U>& in)
{ {
for(size_t i = 0; i != in.size(); ++i){ for(size_t i = 0; i != in.size(); ++i){
mMap[in[i]] = i; mMap[in[i]] = i;
@ -140,7 +139,7 @@ namespace MultiArrayTools
class MetaMap<std::array<int,2> > class MetaMap<std::array<int,2> >
{ {
private: private:
std::vector<size_t> mMap; vector<size_t> mMap;
int min1; int min1;
int min2; int min2;
int max1; int max1;
@ -156,7 +155,7 @@ namespace MultiArrayTools
MetaMap& operator=(const MetaMap& in) = default; MetaMap& operator=(const MetaMap& in) = default;
MetaMap& operator=(MetaMap&& in) = default; MetaMap& operator=(MetaMap&& in) = default;
MetaMap(const std::vector<U>& in) : min1(in[0][0]), MetaMap(const vector<U>& in) : min1(in[0][0]),
min2(in[0][1]), min2(in[0][1]),
max1(in[0][0]), max1(in[0][0]),
max2(in[0][1]) max2(in[0][1])
@ -201,6 +200,20 @@ namespace MultiArrayTools
static constexpr size_t SIZE = -1; static constexpr size_t SIZE = -1;
}; };
template <SpaceType TYPE>
struct CheckDefault
{
static constexpr size_t ISDEFAULT = false;
static constexpr size_t HASMETACONT = true;
};
template <>
struct CheckDefault<SpaceType::NONE>
{
static constexpr size_t ISDEFAULT = true;
static constexpr size_t HASMETACONT = false;
};
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
class GenSingleRange : public RangeInterface<GenSingleIndex<U,TYPE,S> > class GenSingleRange : public RangeInterface<GenSingleIndex<U,TYPE,S> >
{ {
@ -219,7 +232,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
bool isMeta(const U& metaPos) const; bool isMeta(const U& metaPos) const;
@ -231,19 +244,26 @@ namespace MultiArrayTools
friend GenSingleRangeFactory<U,TYPE,S>; friend GenSingleRangeFactory<U,TYPE,S>;
static constexpr bool defaultable = false; static GenSingleRangeFactory<U,TYPE,S> factory()
{
static_assert( not CheckDefault<TYPE>::HASMETACONT,
"asked for default factory for meta data containing range" );
return GenSingleRangeFactory<U,TYPE,S>(vector<U>());
}
static constexpr bool defaultable = CheckDefault<TYPE>::ISDEFAULT;
static constexpr size_t ISSTATIC = CheckStatic<S>::ISSTATIC; static constexpr size_t ISSTATIC = CheckStatic<S>::ISSTATIC;
static constexpr size_t SIZE = CheckStatic<S>::SIZE; static constexpr size_t SIZE = CheckStatic<S>::SIZE;
static constexpr bool HASMETACONT = true; static constexpr bool HASMETACONT = CheckDefault<TYPE>::HASMETACONT;
protected: protected:
GenSingleRange() = delete; GenSingleRange() = delete;
GenSingleRange(const GenSingleRange& in) = delete; GenSingleRange(const GenSingleRange& in) = delete;
GenSingleRange(const std::vector<U>& space); GenSingleRange(const vector<U>& space);
std::vector<U> mSpace; vector<U> mSpace;
//std::map<U,size_t> mMSpace; //std::map<U,size_t> mMSpace;
MetaMap<U> mMSpace; MetaMap<U> mMSpace;
}; };
@ -471,7 +491,7 @@ namespace MultiArrayTools
********************/ ********************/
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
GenSingleRangeFactory<U,TYPE,S>::GenSingleRangeFactory(const std::vector<U>& space) GenSingleRangeFactory<U,TYPE,S>::GenSingleRangeFactory(const vector<U>& space)
{ {
mProd = std::shared_ptr<oType>( new GenSingleRange<U,TYPE,S>( space ) ); mProd = std::shared_ptr<oType>( new GenSingleRange<U,TYPE,S>( space ) );
} }
@ -488,7 +508,7 @@ namespace MultiArrayTools
********************/ ********************/
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
GenSingleRange<U,TYPE,S>::GenSingleRange(const std::vector<U>& space) : GenSingleRange<U,TYPE,S>::GenSingleRange(const vector<U>& space) :
RangeInterface<GenSingleIndex<U,TYPE,S> >(), RangeInterface<GenSingleIndex<U,TYPE,S> >(),
mSpace(space), mMSpace(mSpace) mSpace(space), mMSpace(mSpace)
{ {
@ -509,10 +529,22 @@ namespace MultiArrayTools
return mMSpace.at(metaPos); return mMSpace.at(metaPos);
} }
template <size_t SIZE>
inline size_t getStatSizeOrDyn(size_t size)
{
return SIZE;
}
template <>
inline size_t getStatSizeOrDyn<-1>(size_t size)
{
return size;
}
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
size_t GenSingleRange<U,TYPE,S>::size() const size_t GenSingleRange<U,TYPE,S>::size() const
{ {
return mSpace.size(); return getStatSizeOrDyn<S>(mSpace.size());
} }
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
@ -540,10 +572,10 @@ namespace MultiArrayTools
} }
template <typename U, SpaceType TYPE, size_t S> template <typename U, SpaceType TYPE, size_t S>
std::vector<char> GenSingleRange<U,TYPE,S>::data() const vector<char> GenSingleRange<U,TYPE,S>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -100,7 +100,7 @@ namespace MultiArrayTools
SubRangeFactory() = delete; SubRangeFactory() = delete;
SubRangeFactory(const std::shared_ptr<Range>& fullRange, SubRangeFactory(const std::shared_ptr<Range>& fullRange,
const std::vector<size_t>& subset); const vector<size_t>& subset);
std::shared_ptr<RangeBase> create(); std::shared_ptr<RangeBase> create();
}; };
@ -121,7 +121,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
bool isMeta(const MetaType& metaPos) const; bool isMeta(const MetaType& metaPos) const;
@ -132,7 +132,7 @@ namespace MultiArrayTools
virtual IndexType end() const final; virtual IndexType end() const final;
std::shared_ptr<Range> fullRange() const; std::shared_ptr<Range> fullRange() const;
const std::vector<size_t>& subset() const; const vector<size_t>& subset() const;
std::shared_ptr<SingleRange<MetaType,SpaceType::ANY>> outRange() const; std::shared_ptr<SingleRange<MetaType,SpaceType::ANY>> outRange() const;
friend SubRangeFactory<Range>; friend SubRangeFactory<Range>;
@ -147,10 +147,10 @@ namespace MultiArrayTools
SubRange() = delete; SubRange() = delete;
SubRange(const SubRange& in) = delete; SubRange(const SubRange& in) = delete;
SubRange(const std::shared_ptr<Range>& fullRange, const std::vector<size_t>& subset); SubRange(const std::shared_ptr<Range>& fullRange, const vector<size_t>& subset);
std::shared_ptr<Range> mFullRange; std::shared_ptr<Range> mFullRange;
std::vector<size_t> mSubSet; vector<size_t> mSubSet;
}; };
} // namespace MultiArrayTools } // namespace MultiArrayTools
@ -350,7 +350,7 @@ namespace MultiArrayTools
template <class Range> template <class Range>
SubRangeFactory<Range>::SubRangeFactory(const std::shared_ptr<Range>& fullRange, SubRangeFactory<Range>::SubRangeFactory(const std::shared_ptr<Range>& fullRange,
const std::vector<size_t>& subset) const vector<size_t>& subset)
{ {
mProd = std::shared_ptr<oType>( new SubRange<Range>( fullRange, subset ) ); mProd = std::shared_ptr<oType>( new SubRange<Range>( fullRange, subset ) );
} }
@ -368,7 +368,7 @@ namespace MultiArrayTools
template <class Range> template <class Range>
SubRange<Range>::SubRange(const std::shared_ptr<Range>& fullRange, SubRange<Range>::SubRange(const std::shared_ptr<Range>& fullRange,
const std::vector<size_t>& subset) : const vector<size_t>& subset) :
RangeInterface<SubIndex<typename Range::IndexType>>(), RangeInterface<SubIndex<typename Range::IndexType>>(),
mFullRange(fullRange), mSubSet(subset) {} mFullRange(fullRange), mSubSet(subset) {}
@ -408,14 +408,14 @@ namespace MultiArrayTools
} }
template <class Range> template <class Range>
std::vector<char> SubRange<Range>::data() const vector<char> SubRange<Range>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
std::vector<MetaType> subvec(mSubSet.size()); vector<MetaType> subvec(mSubSet.size());
size_t i = 0; size_t i = 0;
for(auto& x: mSubSet){ for(auto& x: mSubSet){
subvec[i++] = mFullRange->get(x); subvec[i++] = mFullRange->get(x);
@ -477,7 +477,7 @@ namespace MultiArrayTools
} }
template <class Range> template <class Range>
const std::vector<size_t>& SubRange<Range>::subset() const const vector<size_t>& SubRange<Range>::subset() const
{ {
return mSubSet; return mSubSet;
} }
@ -485,7 +485,7 @@ namespace MultiArrayTools
template <class Range> template <class Range>
std::shared_ptr<SingleRange<typename SubRange<Range>::MetaType,SpaceType::ANY>> SubRange<Range>::outRange() const std::shared_ptr<SingleRange<typename SubRange<Range>::MetaType,SpaceType::ANY>> SubRange<Range>::outRange() const
{ {
std::vector<MetaType> ometa(mSubSet.size()); vector<MetaType> ometa(mSubSet.size());
size_t i = 0; size_t i = 0;
for(auto& x: mSubSet){ for(auto& x: mSubSet){
ometa[i++] = mFullRange->get(x); ometa[i++] = mFullRange->get(x);

View file

@ -7,6 +7,8 @@
#include <array> #include <array>
#include <iostream> #include <iostream>
#include "allocator.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {
@ -23,7 +25,7 @@ namespace MultiArrayTools
}; };
template <typename T> template <typename T>
inline void stringCat(std::vector<char>& out, const std::vector<T>& in) inline void stringCat(vector<char>& out, const vector<T>& in)
{ {
//for(auto& x: in) { std::cout << x << std::endl; } //for(auto& x: in) { std::cout << x << std::endl; }
const char* scp = reinterpret_cast<const char*>(in.data()); const char* scp = reinterpret_cast<const char*>(in.data());
@ -31,20 +33,20 @@ namespace MultiArrayTools
} }
template <typename T> template <typename T>
inline size_t metaSize(const std::vector<T>& in) inline size_t metaSize(const vector<T>& in)
{ {
return in.size() * sizeof(T); return in.size() * sizeof(T);
} }
template <typename T> template <typename T>
inline void metaCat(std::vector<T>& vec, const char* begin, size_t size) inline void metaCat(vector<T>& vec, const char* begin, size_t size)
{ {
const T* tp = reinterpret_cast<const T*>( begin ); const T* tp = reinterpret_cast<const T*>( begin );
vec.insert(vec.end(), tp, tp + size / sizeof(T)); vec.insert(vec.end(), tp, tp + size / sizeof(T));
} }
template <> template <>
inline void stringCat<std::string>(std::vector<char>& out, const std::vector<std::string>& in) inline void stringCat<std::string>(vector<char>& out, const vector<std::string>& in)
{ {
//for(auto& x: in) { std::cout << x << std::endl; } //for(auto& x: in) { std::cout << x << std::endl; }
std::string tmp = ""; std::string tmp = "";
@ -56,7 +58,7 @@ namespace MultiArrayTools
} }
template <> template <>
inline size_t metaSize<std::string>(const std::vector<std::string>& in) inline size_t metaSize<std::string>(const vector<std::string>& in)
{ {
size_t out = 0; size_t out = 0;
for(auto& x: in){ for(auto& x: in){
@ -66,7 +68,7 @@ namespace MultiArrayTools
} }
template <> template <>
inline void metaCat<std::string>(std::vector<std::string>& vec, const char* begin, size_t size) inline void metaCat<std::string>(vector<std::string>& vec, const char* begin, size_t size)
{ {
std::string tmp(begin, size); std::string tmp(begin, size);
@ -92,10 +94,10 @@ namespace MultiArrayTools
include_type(float,4) include_type(float,4)
include_type(double,5) include_type(double,5)
include_type(std::string,6) include_type(std::string,6)
include_type(std::vector<size_t>,101) include_type(vector<size_t>,101)
include_type(std::vector<int>,102) include_type(vector<int>,102)
include_type(std::vector<double>,105) include_type(vector<double>,105)
include_type(std::vector<std::string>,106) include_type(vector<std::string>,106)
include_type(std::array<size_t XCOMMAX() 2>,201) include_type(std::array<size_t XCOMMAX() 2>,201)
include_type(std::array<int XCOMMAX() 2>,202) include_type(std::array<int XCOMMAX() 2>,202)
include_type(std::array<size_t XCOMMAX() 3>,301) include_type(std::array<size_t XCOMMAX() 3>,301)

View file

@ -112,7 +112,7 @@ namespace MultiArrayTools
virtual DataHeader dataHeader() const final; virtual DataHeader dataHeader() const final;
virtual std::string stringMeta(size_t pos) const final; virtual std::string stringMeta(size_t pos) const final;
virtual std::vector<char> data() const final; virtual vector<char> data() const final;
U get(size_t pos) const; U get(size_t pos) const;
@ -361,11 +361,11 @@ namespace MultiArrayTools
} }
template <typename U> template <typename U>
std::vector<char> ValueRange<U>::data() const vector<char> ValueRange<U>::data() const
{ {
assert(0); assert(0);
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -27,7 +27,7 @@ namespace MultiArrayHelper
inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x); inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x);
template <typename T> template <typename T>
inline std::string xToString(const std::vector<T>& x); inline std::string xToString(const vector<T>& x);
template <typename T, size_t N> template <typename T, size_t N>
inline std::string xToString(const std::array<T,N>& x); inline std::string xToString(const std::array<T,N>& x);
@ -90,7 +90,7 @@ namespace MultiArrayHelper
} }
template <typename T> template <typename T>
inline std::string xToString(const std::vector<T>& x) inline std::string xToString(const vector<T>& x)
{ {
std::string out = "[ "; std::string out = "[ ";
for(auto& y: x){ for(auto& y: x){

View file

@ -116,6 +116,15 @@ namespace MultiArrayTools
MutableMultiArrayBase<T,SRanges...>(ranges...), MutableMultiArrayBase<T,SRanges...>(ranges...),
mData(data) {} mData(data) {}
template <typename T, class... SRanges>
Slice<T,SRanges...>::Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
T* data) :
MutableMultiArrayBase<T,SRanges...>(ranges),
mData(data)
{
MAB::mInit = true;
}
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
{ {

View file

@ -66,6 +66,8 @@ namespace MultiArrayTools
DEFAULT_MEMBERS(Slice); DEFAULT_MEMBERS(Slice);
Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
T* data = nullptr);
Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr); Slice(const std::shared_ptr<SRanges>&... ranges, T* data = nullptr);
virtual const T& operator[](const IType& i) const final; virtual const T& operator[](const IType& i) const final;

View file

@ -70,77 +70,77 @@ namespace MultiArrayTools
getter(size_t i) : mPos(i) {} getter(size_t i) : mPos(i) {}
inline T operator()(const std::vector<T>& in) inline T operator()(const vector<T>& in)
{ {
return in[mPos]; return in[mPos];
} }
}; };
template <typename T> template <typename T>
std::vector<T>& operator+=(std::vector<T>& a, const std::vector<T>& b) vector<T>& operator+=(vector<T>& a, const vector<T>& b)
{ {
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus<T>()); std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus<T>());
return a; return a;
} }
template <typename T> template <typename T>
std::vector<T>& operator-=(std::vector<T>& a, const std::vector<T>& b) vector<T>& operator-=(vector<T>& a, const vector<T>& b)
{ {
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::minus<T>()); std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::minus<T>());
return a; return a;
} }
template <typename T> template <typename T>
std::vector<T>& operator*=(std::vector<T>& a, const std::vector<T>& b) vector<T>& operator*=(vector<T>& a, const vector<T>& b)
{ {
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::multiplies<T>()); std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::multiplies<T>());
return a; return a;
} }
template <typename T> template <typename T>
std::vector<T>& operator/=(std::vector<T>& a, const std::vector<T>& b) vector<T>& operator/=(vector<T>& a, const vector<T>& b)
{ {
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::divides<T>()); std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::divides<T>());
return a; return a;
} }
template <typename T> template <typename T>
std::vector<T> operator+(std::vector<T>& a, const std::vector<T>& b) vector<T> operator+(vector<T>& a, const vector<T>& b)
{ {
std::vector<T> out(a.size()); vector<T> out(a.size());
std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::plus<T>()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::plus<T>());
return out; return out;
} }
template <typename T> template <typename T>
std::vector<T> operator-(std::vector<T>& a, const std::vector<T>& b) vector<T> operator-(vector<T>& a, const vector<T>& b)
{ {
std::vector<T> out(a.size()); vector<T> out(a.size());
std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::minus<T>()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::minus<T>());
return out; return out;
} }
template <typename T> template <typename T>
std::vector<T> operator*(std::vector<T>& a, const std::vector<T>& b) vector<T> operator*(vector<T>& a, const vector<T>& b)
{ {
std::vector<T> out(a.size()); vector<T> out(a.size());
std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::multiplies<T>()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::multiplies<T>());
return out; return out;
} }
template <typename T> template <typename T>
std::vector<T> operator/(std::vector<T>& a, const std::vector<T>& b) vector<T> operator/(vector<T>& a, const vector<T>& b)
{ {
std::vector<T> out(a.size()); vector<T> out(a.size());
std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::divides<T>()); std::transform(a.begin(), a.end(), b.begin(), out.begin(), std::divides<T>());
return out; return out;
} }
template <class OperationClass, typename T> template <class OperationClass, typename T>
class OperationTemplate<std::vector<T>,OperationClass> : public OperationBase<std::vector<T>,OperationClass> class OperationTemplate<vector<T>,OperationClass> : public OperationBase<vector<T>,OperationClass>
{ {
public: public:
typedef OperationBase<std::vector<T>,OperationClass> OB; typedef OperationBase<vector<T>,OperationClass> OB;
auto operator[](size_t i) auto operator[](size_t i)
-> Operation<T,getter<T>,OperationClass> -> Operation<T,getter<T>,OperationClass>
@ -154,46 +154,55 @@ namespace MultiArrayTools
friend OperationClass; friend OperationClass;
}; };
template <typename T, size_t N> typedef struct v256 { double _x[4]; } v256;
inline std::array<T,N> operator+(std::array<T,N>& a, const std::array<T,N>& b)
template <int N>
inline void xadd(double* o, const double* a, const double* b)
{ {
std::array<T,N> out; //#pragma omp simd aligned(o, a, b: 16)
for(size_t i = 0; i != N; ++i){ for(int i = 0; i < N; i++) {
out[i] = a[i] + b[i]; o[i] = a[i] + b[i];
}
}
inline v256 operator+(const v256& a, const v256& b)
{
alignas(32) v256 out;
xadd<4>( reinterpret_cast<double*>(&out), reinterpret_cast<const double*>(&a),
reinterpret_cast<const double*>(&b) );
return out;
}
/*
inline v256 operator-(const v256& a, const v256& b)
{
alignas(32) v256 out;
#pragma omp simd aligned(outp, ap, bp: 32)
for(int i = 0; i < IN; ++i){
outp[i] = ap[i] - bp[i];
} }
return out; return out;
} }
template <typename T, size_t N> inline v256 operator*(const v256& a, const v256& b)
inline std::array<T,N> operator-(std::array<T,N>& a, const std::array<T,N>& b)
{ {
std::array<T,N> out; alignas(32) v256 out;
for(size_t i = 0; i != N; ++i){ #pragma omp simd aligned(outp, ap, bp: 32)
out[i] = a[i] - b[i]; for(int i = 0; i < IN; ++i){
outp[i] = ap[i] * bp[i];
} }
return out; return out;
} }
template <typename T, size_t N> inline v256 operator/(const v256& a, const v256& b)
inline std::array<T,N> operator*(std::array<T,N>& a, const std::array<T,N>& b)
{ {
std::array<T,N> out; alignas(32) v256 out;
for(size_t i = 0; i != N; ++i){ #pragma omp simd aligned(outp, ap, bp: 32)
out[i] = a[i] * b[i]; for(int i = 0; i < IN; ++i){
outp[i] = ap[i] / bp[i];
} }
return out; return out;
} }
*/
template <typename T, size_t N>
inline std::array<T,N> operator/(std::array<T,N>& a, const std::array<T,N>& b)
{
std::array<T,N> out;
for(size_t i = 0; i != N; ++i){
out[i] = a[i] / b[i];
}
return out;
}
} // namespace MultiArrayTools } // namespace MultiArrayTools

View file

@ -9,6 +9,7 @@
#include "xfor/for_utils.h" #include "xfor/for_utils.h"
#include "xfor/exttype.h" #include "xfor/exttype.h"
#include "allocator.h"
#include <omp.h> #include <omp.h>
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \ #define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
@ -16,7 +17,7 @@
namespace MultiArrayHelper namespace MultiArrayHelper
{ {
using namespace MultiArrayTools;
// 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o. // 'HIDDEN FOR' CLASS for nested for loops in contractions a.s.o.
// (NO COUNTING OF MASTER POSITION !!!!!) // (NO COUNTING OF MASTER POSITION !!!!!)
@ -152,7 +153,7 @@ namespace MultiArrayHelper
typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType; typedef decltype(mkExt(0).extend(mExpr.rootSteps())) ExtType;
ExtType mExt; ExtType mExt;
const std::vector<size_t>* mSubSet; const vector<size_t>* mSubSet;
mutable ExtType mRootSteps; mutable ExtType mRootSteps;
@ -169,10 +170,10 @@ namespace MultiArrayHelper
SubExpr(const std::shared_ptr<IndexClass>& indPtr, SubExpr(const std::shared_ptr<IndexClass>& indPtr,
std::intptr_t siptr, std::intptr_t siptr,
const std::vector<size_t>* subset, Expr expr); const vector<size_t>* subset, Expr expr);
SubExpr(const IndexClass* indPtr, std::intptr_t siptr, SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const std::vector<size_t>* subset, Expr expr); const vector<size_t>* subset, Expr expr);
inline void operator()(size_t mlast, DExt last) const override final; inline void operator()(size_t mlast, DExt last) const override final;
@ -650,7 +651,7 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr, SubExpr<IndexClass,Expr>::SubExpr(const std::shared_ptr<IndexClass>& indPtr,
std::intptr_t siptr, std::intptr_t siptr,
const std::vector<size_t>* subset, Expr expr) : const vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mIndPtr(indPtr.get()), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr), mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ), mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),
@ -661,7 +662,7 @@ namespace MultiArrayHelper
template <class IndexClass, class Expr> template <class IndexClass, class Expr>
SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, std::intptr_t siptr, SubExpr<IndexClass,Expr>::SubExpr(const IndexClass* indPtr, std::intptr_t siptr,
const std::vector<size_t>* subset, Expr expr) : const vector<size_t>* subset, Expr expr) :
mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mIndPtr(indPtr), mSIPtr(siptr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()),
mExpr(expr), mExpr(expr),
mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ), mExt( mkExt(0).extend( mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )) ) ),

View file

@ -3,5 +3,5 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > MapRangeFactoryProductMap::mAleadyCreated; std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MapRangeFactoryProductMap::mAleadyCreated;
} }

View file

@ -13,14 +13,14 @@ namespace MultiArrayTools
} }
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > AnonymousRangeFactory::mAleadyCreated; std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > AnonymousRangeFactory::mAleadyCreated;
AnonymousRangeFactory::AnonymousRangeFactory(const std::vector<std::shared_ptr<RangeBase>>& origs) AnonymousRangeFactory::AnonymousRangeFactory(const vector<std::shared_ptr<RangeBase>>& origs)
{ {
mProd = std::shared_ptr<oType>( new AnonymousRange( origs ) ); mProd = std::shared_ptr<oType>( new AnonymousRange( origs ) );
} }
std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const std::vector<std::shared_ptr<RangeBase> >& pvec) std::shared_ptr<RangeBase> AnonymousRangeFactory::checkIfCreated(const vector<std::shared_ptr<RangeBase> >& pvec)
{ {
std::shared_ptr<RangeBase> out; std::shared_ptr<RangeBase> out;
bool check = false; bool check = false;
@ -40,7 +40,7 @@ namespace MultiArrayTools
} }
} }
if(not check){ if(not check){
std::vector<std::intptr_t> app(pvec.size()); vector<std::intptr_t> app(pvec.size());
for(size_t i = 0; i != app.size(); ++i){ for(size_t i = 0; i != app.size(); ++i){
app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() ); app[i] = reinterpret_cast<std::intptr_t>( pvec[i].get() );
} }
@ -108,10 +108,10 @@ namespace MultiArrayTools
return out; return out;
} }
std::vector<char> AnonymousRange::data() const vector<char> AnonymousRange::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));
for(auto& x: mOrig){ for(auto& x: mOrig){
@ -168,7 +168,7 @@ namespace MultiArrayTools
return std::dynamic_pointer_cast<AnonymousRange>(arf.create()); return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
} }
std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const std::vector<std::shared_ptr<RangeBase>>& in, size_t num) const std::shared_ptr<AnonymousRange> AnonymousRange::sreplace(const vector<std::shared_ptr<RangeBase>>& in, size_t num) const
{ {
size_t nsize = 1; size_t nsize = 1;
for(auto& x: in){ for(auto& x: in){
@ -191,12 +191,12 @@ namespace MultiArrayTools
return std::dynamic_pointer_cast<AnonymousRange>(arf.create()); return std::dynamic_pointer_cast<AnonymousRange>(arf.create());
} }
const std::vector<std::shared_ptr<RangeBase> >& AnonymousRange::orig() const const vector<std::shared_ptr<RangeBase> >& AnonymousRange::orig() const
{ {
return mOrig; return mOrig;
} }
GenSingleRange<size_t,SpaceType::ANON,-1>::GenSingleRange(const std::vector<std::shared_ptr<RangeBase>>& origs) : GenSingleRange<size_t,SpaceType::ANON,-1>::GenSingleRange(const vector<std::shared_ptr<RangeBase>>& origs) :
RangeInterface<AnonymousIndex>(), RangeInterface<AnonymousIndex>(),
mOrig(origs) mOrig(origs)
{ {

View file

@ -3,5 +3,5 @@
namespace MultiArrayTools namespace MultiArrayTools
{ {
std::map<std::shared_ptr<RangeBase>,std::vector<std::intptr_t> > MultiRangeFactoryProductMap::mAleadyCreated; std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MultiRangeFactoryProductMap::mAleadyCreated;
} }

View file

@ -15,7 +15,7 @@ namespace MultiArrayTools
template <class... Ranges> template <class... Ranges>
using STP = std::tuple<std::shared_ptr<Ranges>...>; using STP = std::tuple<std::shared_ptr<Ranges>...>;
typedef std::vector<std::shared_ptr<RangeBase> > RVEC; typedef vector<std::shared_ptr<RangeBase> > RVEC;
template <class... Ranges> template <class... Ranges>
inline bool compareSpaceTypes(const RVEC& rvec) inline bool compareSpaceTypes(const RVEC& rvec)
@ -127,7 +127,7 @@ namespace MultiArrayTools
assert(0); assert(0);
} }
#define register_type(x) else if(x == h.metaType) { \ #define register_type(x) else if(x == h.metaType) { \
std::vector<TypeMap<x>::type> vd;\ vector<TypeMap<x>::type> vd;\
metaCat(vd, *dp, h.metaSize); \ metaCat(vd, *dp, h.metaSize); \
out = std::make_shared<SingleRangeFactory<TypeMap<x>::type, \ out = std::make_shared<SingleRangeFactory<TypeMap<x>::type, \
SpaceType::ANY> >(vd); } SpaceType::ANY> >(vd); }

View file

@ -58,10 +58,10 @@ namespace MultiArrayTools
return std::to_string(get(pos)); return std::to_string(get(pos));
} }
std::vector<char> GenSingleRange<size_t,SpaceType::NONE,-1>::data() const vector<char> GenSingleRange<size_t,SpaceType::NONE,-1>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -81,10 +81,10 @@ namespace MultiArrayTools
return std::to_string(get(pos)); return std::to_string(get(pos));
} }
std::vector<char> GenSingleRange<size_t,SpaceType::NUL,0>::data() const vector<char> GenSingleRange<size_t,SpaceType::NUL,0>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -64,10 +64,10 @@ namespace MultiArrayTools
return std::to_string(get(pos)); return std::to_string(get(pos));
} }
std::vector<char> GenSingleRange<int,SpaceType::PSPACE,-1>::data() const vector<char> GenSingleRange<int,SpaceType::PSPACE,-1>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -61,10 +61,10 @@ namespace MultiArrayTools
return std::to_string(get(pos)); return std::to_string(get(pos));
} }
std::vector<char> GenSingleRange<size_t,SpaceType::SPIN,4>::data() const vector<char> GenSingleRange<size_t,SpaceType::SPIN,4>::data() const
{ {
DataHeader h = dataHeader(); DataHeader h = dataHeader();
std::vector<char> out; vector<char> out;
out.reserve(h.metaSize + sizeof(DataHeader)); out.reserve(h.metaSize + sizeof(DataHeader));
char* hcp = reinterpret_cast<char*>(&h); char* hcp = reinterpret_cast<char*>(&h);
out.insert(out.end(), hcp, hcp + sizeof(DataHeader)); out.insert(out.end(), hcp, hcp + sizeof(DataHeader));

View file

@ -15,7 +15,7 @@ namespace {
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }
@ -50,7 +50,7 @@ namespace {
std::shared_ptr<RangeFactoryBase> rfbptr; std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> srptr; std::shared_ptr<SRange> srptr;
std::vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 }; vector<double> vv = { 3.141, 2.718, 1.618, 0.693, 0.577 };
}; };
@ -91,7 +91,7 @@ namespace {
std::shared_ptr<SRange> sr3ptr; std::shared_ptr<SRange> sr3ptr;
std::shared_ptr<SRange> sr4ptr; std::shared_ptr<SRange> sr4ptr;
std::shared_ptr<MRange> mrptr; std::shared_ptr<MRange> mrptr;
std::vector<double> vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280, vector<double> vv = { 2.917, 9.436, 0.373, 7.192, 7.315, 1.536, 4.892, 0.280,
8.870, 4.790, 8.215, 5.063, 1.530, 3.084, 1.609, 4.847, 8.870, 4.790, 8.215, 5.063, 1.530, 3.084, 1.609, 4.847,
8.175, 0.112, 6.712, 6.408, 1.959, 0.331, 4.209, 2.951 }; 8.175, 0.112, 6.712, 6.408, 1.959, 0.331, 4.209, 2.951 };
}; };
@ -114,7 +114,7 @@ namespace {
TEST_F(MATest_1Dim, ForLoop) TEST_F(MATest_1Dim, ForLoop)
{ {
std::vector<double> v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 }; vector<double> v2 = { 0.693 , 2.718, 3.141, 1.618, 9.98 };
MultiArray<double,MATest_1Dim::SRange> ma(srptr, std::move( v2 ) ); MultiArray<double,MATest_1Dim::SRange> ma(srptr, std::move( v2 ) );
size_t cnt = 0; size_t cnt = 0;
for(auto el: ma){ for(auto el: ma){

View file

@ -5,6 +5,7 @@
#include <cassert> #include <cassert>
#include "multi_array_header.h" #include "multi_array_header.h"
#include "conversions.h"
#include <ctime> #include <ctime>
#include <cmath> #include <cmath>
@ -32,15 +33,15 @@ namespace {
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::vector<T>& ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, vector<T>& ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }
@ -78,14 +79,14 @@ namespace {
OpTest_Performance() OpTest_Performance()
{ {
std::vector<size_t> initvec1(vs1); vector<size_t> initvec1(vs1);
cv1.resize(vs1); cv1.resize(vs1);
for(size_t i = 0; i != vs1; ++i){ for(size_t i = 0; i != vs1; ++i){
initvec1[i] = i; initvec1[i] = i;
cv1[i] = sqrt( static_cast<double>(i)*0.53 ); cv1[i] = sqrt( static_cast<double>(i)*0.53 );
} }
std::vector<size_t> initvec2(vs2); vector<size_t> initvec2(vs2);
cv2.resize(vs2*vs1); cv2.resize(vs2*vs1);
for(size_t i = 0; i != vs2; ++i){ for(size_t i = 0; i != vs2; ++i){
initvec2[i] = i; initvec2[i] = i;
@ -118,8 +119,8 @@ namespace {
std::shared_ptr<SRange> sr2ptr; std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<MRange> mrptr; std::shared_ptr<MRange> mrptr;
std::vector<double> cv1; vector<double> cv1;
std::vector<double> cv2; vector<double> cv2;
}; };
#endif #endif
class OpTest_Spin class OpTest_Spin
@ -132,11 +133,11 @@ namespace {
typedef SpinRF SRF; typedef SpinRF SRF;
typedef SpinRange SR; typedef SpinRange SR;
typedef MultiRangeFactory<SR,SR,SR,SR,SR,SR,SR,SR> SR8F; typedef MultiRangeFactory<SR,SR,SR,SR,SR,SR,SR,SR> SR8F;
typedef SR8F::oType SR8; typedef SR8F::oType SR8;
static const size_t os = 30; static const size_t os = 300;
static const size_t is = 65536; static const size_t is = 65536;
static const size_t s = is*os; static const size_t s = is*os;
OpTest_Spin() OpTest_Spin()
{ {
@ -152,11 +153,11 @@ namespace {
cr = std::dynamic_pointer_cast<CR>(cf.create()); cr = std::dynamic_pointer_cast<CR>(cf.create());
} }
void contract(); void contract();
private: private:
std::vector<double> data; vector<double> data;
std::shared_ptr<SR> sr; std::shared_ptr<SR> sr;
std::shared_ptr<CR> cr; std::shared_ptr<CR> cr;
}; };
@ -172,20 +173,21 @@ namespace {
auto beta = MAT::getIndex<SR>(); auto beta = MAT::getIndex<SR>();
auto gamma = MAT::getIndex<SR>(); auto gamma = MAT::getIndex<SR>();
auto delta = MAT::getIndex<SR>(); auto delta = MAT::getIndex<SR>();
auto deltap = MAT::getIndex<SR>(); //auto deltap = MAT::getIndex<SR>();
auto deltap = MAT::getIndex<GenSingleRange<size_t,SpaceType::NONE,1>>();
auto mix = MAT::mkMIndex( alpha, beta, gamma, jj ); auto mix = MAT::mkMIndex( alpha, beta, gamma, jj );
std::clock_t begin = std::clock(); std::clock_t begin = std::clock();
//for(size_t i = 0; i != os; ++i){ //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); tcast<v256>(res1)(ii ,delta, deltap) += tcast<v256>(ma)(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(mix);
//} //}
std::clock_t end = std::clock(); std::clock_t end = std::clock();
std::cout << "MultiArray time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC std::cout << "MultiArray time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC
<< std::endl; << std::endl;
std::vector<double> vres(4*4*os); vector<double> vres(4*4*os);
for(size_t d = 0; d != 4; ++d){ for(size_t d = 0; d != 4; ++d){
for(size_t p = 0; p != 4; ++p){ for(size_t p = 0; p != 4; ++p){
const size_t tidx = d*4 + p; const size_t tidx = d*4 + p;
@ -232,7 +234,7 @@ namespace {
assert( xround(res1.at(mkts(0,3,2))) == xround(vres[14]) ); assert( xround(res1.at(mkts(0,3,2))) == xround(vres[14]) );
assert( xround(res1.at(mkts(0,3,3))) == xround(vres[15]) ); assert( xround(res1.at(mkts(0,3,3))) == xround(vres[15]) );
std::cout << "std::vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC std::cout << "vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC
<< std::endl; << std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl; std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;
} }
@ -256,7 +258,7 @@ namespace {
std::cout << "MultiArray time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC std::cout << "MultiArray time: " << static_cast<double>( end - begin ) / CLOCKS_PER_SEC
<< std::endl; << std::endl;
std::vector<double> res2(vs1*vs2); vector<double> res2(vs1*vs2);
std::clock_t begin2 = std::clock(); std::clock_t begin2 = std::clock();
for(size_t i = 0; i != vs2; ++i){ for(size_t i = 0; i != vs2; ++i){
@ -266,7 +268,7 @@ namespace {
} }
std::clock_t end2 = std::clock(); std::clock_t end2 = std::clock();
std::cout << "std::vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC std::cout << "vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC
<< std::endl; << std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl; std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;

View file

@ -31,15 +31,15 @@ namespace {
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::vector<T>& ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, vector<T>& ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }
@ -106,8 +106,8 @@ namespace {
std::shared_ptr<RangeFactoryBase> rfbptr; std::shared_ptr<RangeFactoryBase> rfbptr;
std::shared_ptr<SRange> srptr; std::shared_ptr<SRange> srptr;
std::vector<double> v1 = { 2.917, 9.436, 0.373, 7.192 }; vector<double> v1 = { 2.917, 9.436, 0.373, 7.192 };
std::vector<double> v2 = { 8.870, 4.790, 8.215, 5.063 }; vector<double> v2 = { 8.870, 4.790, 8.215, 5.063 };
}; };
class OpTest_MDim : public ::testing::Test class OpTest_MDim : public ::testing::Test
@ -151,11 +151,11 @@ namespace {
std::shared_ptr<SRange> sr4ptr; std::shared_ptr<SRange> sr4ptr;
std::shared_ptr<MRange> mr1ptr; std::shared_ptr<MRange> mr1ptr;
std::shared_ptr<MRange> mr2ptr; std::shared_ptr<MRange> mr2ptr;
std::vector<double> v1 = { 2.917, 9.436, 0.373 }; vector<double> v1 = { 2.917, 9.436, 0.373 };
std::vector<double> v2 = { 8.870, 4.790 }; vector<double> v2 = { 8.870, 4.790 };
std::vector<double> v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; vector<double> v3 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 };
std::vector<double> v4 = { 1.470, 2.210 }; vector<double> v4 = { 1.470, 2.210 };
std::vector<double> v5 = { 30.932, -33.693, -26.205, -15.504, 21.227, 17.829, vector<double> v5 = { 30.932, -33.693, -26.205, -15.504, 21.227, 17.829,
-14.364, -1.868, -25.703, 13.836, 23.563, 41.339 }; -14.364, -1.868, -25.703, 13.836, 23.563, 41.339 };
}; };
@ -184,10 +184,10 @@ namespace {
std::shared_ptr<SRange> sr2ptr; std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<SRange> sr3ptr; std::shared_ptr<SRange> sr3ptr;
std::vector<double> v1 = { 2.917, 9.436, 0.373, 0.353, 4.005, 1.070, vector<double> v1 = { 2.917, 9.436, 0.373, 0.353, 4.005, 1.070,
-14.364, -1.868, -25.703, 13.836, 23.563, 41.339 }; -14.364, -1.868, -25.703, 13.836, 23.563, 41.339 };
std::vector<double> v2 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 }; vector<double> v2 = { 0.353, 4.005, 1.070, 2.310, 9.243, 2.911 };
}; };
@ -222,7 +222,7 @@ namespace {
std::shared_ptr<SRange> sr1ptr; std::shared_ptr<SRange> sr1ptr;
std::shared_ptr<SRange> sr2ptr; std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<MpRange> mpr1ptr; std::shared_ptr<MpRange> mpr1ptr;
std::vector<double> v1 = { -31.71, -77.16, -18.81, vector<double> v1 = { -31.71, -77.16, -18.81,
-67.06, 72.31, -54.48, -67.06, 72.31, -54.48,
-50.91, -11.62, -59.57, -50.91, -11.62, -59.57,
-42.53, 80.41, 6.35 }; -42.53, 80.41, 6.35 };
@ -241,14 +241,14 @@ namespace {
OpTest_Performance() OpTest_Performance()
{ {
std::vector<size_t> initvec1(vs1); vector<size_t> initvec1(vs1);
cv1.resize(vs1); cv1.resize(vs1);
for(size_t i = 0; i != vs1; ++i){ for(size_t i = 0; i != vs1; ++i){
initvec1[i] = i; initvec1[i] = i;
cv1[i] = sqrt( static_cast<double>(i)*0.53 ); cv1[i] = sqrt( static_cast<double>(i)*0.53 );
} }
std::vector<size_t> initvec2(vs2); vector<size_t> initvec2(vs2);
cv2.resize(vs2*vs1); cv2.resize(vs2*vs1);
for(size_t i = 0; i != vs2; ++i){ for(size_t i = 0; i != vs2; ++i){
initvec2[i] = i; initvec2[i] = i;
@ -277,8 +277,8 @@ namespace {
std::shared_ptr<SRange> sr2ptr; std::shared_ptr<SRange> sr2ptr;
std::shared_ptr<MRange> mrptr; std::shared_ptr<MRange> mrptr;
std::vector<double> cv1; vector<double> cv1;
std::vector<double> cv2; vector<double> cv2;
}; };
class OpTest_Spin : public ::testing::Test class OpTest_Spin : public ::testing::Test
@ -303,7 +303,7 @@ namespace {
sr = std::dynamic_pointer_cast<SR>(f.create()); sr = std::dynamic_pointer_cast<SR>(f.create());
} }
std::vector<double> data; vector<double> data;
std::shared_ptr<SR> sr; std::shared_ptr<SR> sr;
}; };
@ -337,8 +337,8 @@ namespace {
std::shared_ptr<SR> sr1ptr; std::shared_ptr<SR> sr1ptr;
std::shared_ptr<SR> sr2ptr; std::shared_ptr<SR> sr2ptr;
std::vector<double> mv1; vector<double> mv1;
std::vector<double> mv2; vector<double> mv2;
double vcontract(size_t i) double vcontract(size_t i)
{ {
@ -458,7 +458,7 @@ namespace {
res2(delta, deltap).par() += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(alpha).c(beta).c(gamma); res2(delta, deltap).par() += ma(delta, alpha, alpha, beta, beta, gamma, gamma, deltap).c(alpha).c(beta).c(gamma);
std::vector<double> vres(4*4); vector<double> vres(4*4);
std::clock_t begin2 = std::clock(); std::clock_t begin2 = std::clock();
for(size_t d = 0; d != 4; ++d){ for(size_t d = 0; d != 4; ++d){
@ -517,7 +517,7 @@ namespace {
EXPECT_EQ( xround(res2.at(mkts(3,2))), xround(vres[14]) ); EXPECT_EQ( xround(res2.at(mkts(3,2))), xround(vres[14]) );
EXPECT_EQ( xround(res2.at(mkts(3,3))), xround(vres[15]) ); EXPECT_EQ( xround(res2.at(mkts(3,3))), xround(vres[15]) );
std::cout << "std::vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC std::cout << "vector - for loop time: " << static_cast<double>( end2 - begin2 ) / CLOCKS_PER_SEC
<< std::endl; << std::endl;
std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl; std::cout << "ratio: " << static_cast<double>( end - begin ) / static_cast<double>( end2 - begin2 ) << std::endl;
} }
@ -543,7 +543,7 @@ namespace {
MultiArray<double,SRange,SRange,SRange> ma1(sr1ptr, sr2ptr, sr3ptr, v1); MultiArray<double,SRange,SRange,SRange> ma1(sr1ptr, sr2ptr, sr3ptr, v1);
MultiArray<double,SRange,SRange> ma2(sr3ptr, sr2ptr, v2); MultiArray<double,SRange,SRange> ma2(sr3ptr, sr2ptr, v2);
SubRangeFactory<SRange> subf(sr2ptr, std::vector<size_t>({0,2})); SubRangeFactory<SRange> subf(sr2ptr, vector<size_t>({0,2}));
auto subptr = MAT::createExplicit(subf); auto subptr = MAT::createExplicit(subf);
MultiArray<double,SRange,SRange> res(sr3ptr,sr1ptr,0.); MultiArray<double,SRange,SRange> res(sr3ptr,sr1ptr,0.);

View file

@ -18,7 +18,7 @@ namespace {
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }
@ -160,7 +160,7 @@ namespace {
TEST_F(AnonymousTest, ToString1) TEST_F(AnonymousTest, ToString1)
{ {
std::vector<char> vv = sr1ptr->data(); vector<char> vv = sr1ptr->data();
const char* dp = vv.data(); const char* dp = vv.data();
auto ff = createRangeFactory(&dp); auto ff = createRangeFactory(&dp);
auto ss = std::dynamic_pointer_cast<SRange>( ff->create() ); auto ss = std::dynamic_pointer_cast<SRange>( ff->create() );
@ -183,9 +183,9 @@ namespace {
auto sr = std::dynamic_pointer_cast<SpinRange>( srf.create() ); auto sr = std::dynamic_pointer_cast<SpinRange>( srf.create() );
auto nr = std::dynamic_pointer_cast<NameRange>( nrf.create() ); auto nr = std::dynamic_pointer_cast<NameRange>( nrf.create() );
std::vector<char> cv = cr->data(); vector<char> cv = cr->data();
std::vector<char> sv = sr->data(); vector<char> sv = sr->data();
std::vector<char> nv = nr->data(); vector<char> nv = nr->data();
const char* cp = cv.data(); const char* cp = cv.data();
const char* sp = sv.data(); const char* sp = sv.data();
const char* np = nv.data(); const char* np = nv.data();
@ -212,7 +212,7 @@ namespace {
TEST_F(AnonymousTest, ToStringMulti) TEST_F(AnonymousTest, ToStringMulti)
{ {
std::vector<char> vv = m3rptr->data(); vector<char> vv = m3rptr->data();
const char* dp = vv.data(); const char* dp = vv.data();
auto ff2 = std::dynamic_pointer_cast<M3RF>( createRangeFactory(&dp) ); auto ff2 = std::dynamic_pointer_cast<M3RF>( createRangeFactory(&dp) );
@ -235,7 +235,7 @@ namespace {
{ {
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
auto ar = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() ); auto ar = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
std::vector<char> vv = ar->data(); vector<char> vv = ar->data();
const char* dp = vv.data(); const char* dp = vv.data();
auto ff2 = std::dynamic_pointer_cast<AnonymousRangeFactory>( createRangeFactory(&dp) ); auto ff2 = std::dynamic_pointer_cast<AnonymousRangeFactory>( createRangeFactory(&dp) );

View file

@ -17,7 +17,7 @@ namespace {
template <class Factory, typename T> template <class Factory, typename T>
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist) void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
{ {
std::vector<T> tmp = ilist; vector<T> tmp = ilist;
auto nptr = std::make_shared<Factory>( tmp ); auto nptr = std::make_shared<Factory>( tmp );
fptr = nptr; fptr = nptr;
} }