Merge remote-tracking branch 'origin/restructure-rename'
This commit is contained in:
commit
3c6f9ea025
107 changed files with 4289 additions and 5039 deletions
|
@ -10,7 +10,7 @@ else()
|
||||||
message(WARNING "compiler ${CMAKE_CXX_COMPILER_ID} officially not supported")
|
message(WARNING "compiler ${CMAKE_CXX_COMPILER_ID} officially not supported")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -Wpedantic -Ofast -march=native -faligned-new -funroll-loops -fopenmp")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++17 -Wpedantic -Ofast -march=native -faligned-new -funroll-loops -fopenmp")
|
||||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -g -Wpedantic -Ofast -march=native -faligned-new -funroll-loops -fopenmp -ftemplate-backtrace-limit=0")
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -g -Wpedantic -Ofast -march=native -faligned-new -funroll-loops -fopenmp -ftemplate-backtrace-limit=0")
|
||||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -g -Wpedantic -O0 -march=native -faligned-new -funroll-loops -fopenmp")
|
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++14 -g -Wpedantic -O0 -march=native -faligned-new -funroll-loops -fopenmp")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __ma_allocator__
|
#ifndef __cxz_allocator__
|
||||||
#define __ma_allocator__
|
#define __cxz_allocator__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
#define MIB_SIZE 1024*1024 // 1MiB
|
#define MIB_SIZE 1024*1024 // 1MiB
|
||||||
#define WARN_SIZE MIB_SIZE*100 // 100 MiB
|
#define WARN_SIZE MIB_SIZE*100 // 100 MiB
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -65,12 +65,12 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace MultiArrayHelper
|
} // namespace CNORXZInternal
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using vector = std::vector<T,MultiArrayHelper::Allocator<T>>;
|
using vector = std::vector<T,CNORXZInternal::Allocator<T>>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::vector<T> toStdVec(const vector<T>& v)
|
inline std::vector<T> toStdVec(const vector<T>& v)
|
||||||
|
@ -84,6 +84,6 @@ namespace MultiArrayTools
|
||||||
return vector<T>(v.begin(), v.end());
|
return vector<T>(v.begin(), v.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
35
src/include/arith.cc.h
Normal file
35
src/include/arith.cc.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
#include "arith.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
template <class F>
|
||||||
|
template <class... Ops>
|
||||||
|
auto StaticFunctionBase<F>::mk(const Ops&... ops)
|
||||||
|
{
|
||||||
|
return Operation<typename F::value_type,F,Ops...>(ops...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class F>
|
||||||
|
template <size_t N, class Tuple, typename... As>
|
||||||
|
inline auto StaticFunctionBase<F>::xapply(const Tuple& tp, As... as)
|
||||||
|
{
|
||||||
|
if constexpr(N > 0){
|
||||||
|
return xapply<N-1>(tp, std::get<N>(tp), as...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return F::apply(std::get<0>(tp), as...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class F>
|
||||||
|
template <typename... As>
|
||||||
|
inline auto StaticFunctionBase<F>::apply(const std::tuple<As...>& arg)
|
||||||
|
{
|
||||||
|
return xapply<sizeof...(As)-1>(arg);
|
||||||
|
//return ArgPack<sizeof...(As)-1>::template mk<F,std::tuple<As...> >(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,79 +1,48 @@
|
||||||
|
|
||||||
#ifndef __arith_h__
|
#ifndef __cxz_arith_h__
|
||||||
#define __arith_h__
|
#define __cxz_arith_h__
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <size_t N>
|
//template <typename T, class F, typename... As>
|
||||||
struct ArgPack
|
template <class F>
|
||||||
{
|
|
||||||
template <class F, class Tuple, typename... As>
|
|
||||||
static inline auto mk(const Tuple& tp, As... as)
|
|
||||||
-> decltype(ArgPack<N-1>::template mk<F,Tuple,decltype(std::get<N>(tp)),As...>(tp, std::get<N>(tp), as...))
|
|
||||||
{
|
|
||||||
return ArgPack<N-1>::template mk<F,Tuple,decltype(std::get<N>(tp)),As...>(tp, std::get<N>(tp), as...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class F, class Tuple, typename... As>
|
|
||||||
static inline auto mkd(const F& ff, const Tuple& tp, As... as)
|
|
||||||
-> decltype(ArgPack<N-1>::template mkd<F,Tuple,decltype(std::get<N>(tp)),As...>(ff, tp, std::get<N>(tp), as...))
|
|
||||||
{
|
|
||||||
return ArgPack<N-1>::template mkd<F,Tuple,decltype(std::get<N>(tp)),As...>(ff, tp, std::get<N>(tp), as...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct ArgPack<0>
|
|
||||||
{
|
|
||||||
template <class F, class Tuple, typename... As>
|
|
||||||
static inline auto mk(const Tuple& tp, As... as)
|
|
||||||
-> decltype(F::apply(std::get<0>(tp), as...))
|
|
||||||
{
|
|
||||||
return F::apply(std::get<0>(tp), as...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class F, class Tuple, typename... As>
|
|
||||||
static inline auto mkd(const F& ff, const Tuple& tp, As... as)
|
|
||||||
-> decltype(ff(std::get<0>(tp), as...))
|
|
||||||
{
|
|
||||||
return ff(std::get<0>(tp), as...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, class F, typename... As>
|
|
||||||
struct StaticFunctionBase
|
struct StaticFunctionBase
|
||||||
{
|
{
|
||||||
static constexpr bool FISSTATIC = true;
|
static constexpr bool FISSTATIC = true;
|
||||||
typedef T value_type;
|
typedef F function;
|
||||||
|
//typedef typename F::value_type value_type;
|
||||||
template <class... Ops>
|
|
||||||
static auto mk(const Ops&... ops)
|
|
||||||
-> Operation<T,F,Ops...>
|
|
||||||
{
|
|
||||||
return Operation<T,F,Ops...>(ops...);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline T apply(const std::tuple<As...>& arg)
|
template <class... Ops>
|
||||||
{
|
static auto mk(const Ops&... ops);
|
||||||
return ArgPack<sizeof...(As)-1>::template mk<F,std::tuple<As...> >(arg);
|
|
||||||
}
|
template <size_t N, class Tuple, typename... As>
|
||||||
|
static inline auto xapply(const Tuple& tp, As... as);
|
||||||
|
|
||||||
|
template <typename... As>
|
||||||
|
static inline auto apply(const std::tuple<As...>& arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// OPERATIONS (STATIC)
|
// OPERATIONS (STATIC)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct identity : public StaticFunctionBase<T, identity<T>, T>
|
struct identity : public StaticFunctionBase<identity<T>>
|
||||||
{
|
{
|
||||||
//static constexpr bool FISSTATIC = true;
|
//static constexpr bool FISSTATIC = true;
|
||||||
using StaticFunctionBase<T, identity<T>, T>::apply;
|
using StaticFunctionBase<identity<T>>::apply;
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
static inline T apply(T a)
|
static inline T apply(T a)
|
||||||
{
|
{
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline T selfApply(T& a1, const T& a2)
|
||||||
|
{
|
||||||
|
return a1 = a2;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
|
@ -89,12 +58,13 @@ namespace MultiArrayTools
|
||||||
using dividesv = decltype(std::declval<T>()/std::declval<U>());
|
using dividesv = decltype(std::declval<T>()/std::declval<U>());
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
struct plusx : public StaticFunctionBase<plusv<T,U>, plusx<T,U>, T, U>
|
struct plusx : public StaticFunctionBase<plusx<T,U>>
|
||||||
{
|
{
|
||||||
static constexpr bool FISSTATIC = true;
|
static constexpr bool FISSTATIC = true;
|
||||||
using StaticFunctionBase<plusv<T,U>, plusx<T,U>, T, U>::apply;
|
using StaticFunctionBase<plusx<T,U>>::apply;
|
||||||
|
typedef plusv<T,U> value_type;
|
||||||
static inline plusv<T,U> apply(T a1, U a2)
|
|
||||||
|
static inline value_type apply(T a1, U a2)
|
||||||
{
|
{
|
||||||
return a1 + a2;
|
return a1 + a2;
|
||||||
}
|
}
|
||||||
|
@ -106,36 +76,39 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
struct minusx : public StaticFunctionBase<minusv<T,U>, minusx<T,U>, T, U>
|
struct minusx : public StaticFunctionBase<minusx<T,U>>
|
||||||
{
|
{
|
||||||
static constexpr bool FISSTATIC = true;
|
static constexpr bool FISSTATIC = true;
|
||||||
using StaticFunctionBase<minusv<T,U>, minusx<T,U>, T, U>::apply;
|
using StaticFunctionBase<minusx<T,U>>::apply;
|
||||||
|
typedef minusv<T,U> value_type;
|
||||||
|
|
||||||
static inline plusv<T,U> apply(T a1, U a2)
|
static inline value_type apply(T a1, U a2)
|
||||||
{
|
{
|
||||||
return a1 - a2;
|
return a1 - a2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
struct multipliesx : public StaticFunctionBase<multipliesv<T,U>, multipliesx<T,U>, T, U>
|
struct multipliesx : public StaticFunctionBase<multipliesx<T,U>>
|
||||||
{
|
{
|
||||||
static constexpr bool FISSTATIC = true;
|
static constexpr bool FISSTATIC = true;
|
||||||
using StaticFunctionBase<multipliesv<T,U>, multipliesx<T,U>, T, U>::apply;
|
using StaticFunctionBase<multipliesx<T,U>>::apply;
|
||||||
|
typedef multipliesv<T,U> value_type;
|
||||||
|
|
||||||
static inline multipliesv<T,U> apply(T a1, U a2)
|
static inline value_type apply(T a1, U a2)
|
||||||
{
|
{
|
||||||
return a1 * a2;
|
return a1 * a2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
struct dividesx : public StaticFunctionBase<dividesv<T,U>, dividesx<T,U>, T, U>
|
struct dividesx : public StaticFunctionBase<dividesx<T,U>>
|
||||||
{
|
{
|
||||||
static constexpr bool FISSTATIC = true;
|
static constexpr bool FISSTATIC = true;
|
||||||
using StaticFunctionBase<dividesv<T,U>, dividesx<T,U>, T, U>::apply;
|
using StaticFunctionBase<dividesx<T,U>>::apply;
|
||||||
|
typedef dividesv<T,U> value_type;
|
||||||
|
|
||||||
static inline dividesv<T,U> apply(T a1, U a2)
|
static inline value_type apply(T a1, U a2)
|
||||||
{
|
{
|
||||||
return a1 / a2;
|
return a1 / a2;
|
||||||
}
|
}
|
||||||
|
@ -143,11 +116,12 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct negate : public StaticFunctionBase<T, negate<T>, T>
|
struct negate : public StaticFunctionBase<negate<T>>
|
||||||
{
|
{
|
||||||
static constexpr bool FISSTATIC = true;
|
static constexpr bool FISSTATIC = true;
|
||||||
using StaticFunctionBase<T, negate<T>, T>::apply;
|
using StaticFunctionBase<negate<T>>::apply;
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
static inline T apply(T a)
|
static inline T apply(T a)
|
||||||
{
|
{
|
||||||
return -a;
|
return -a;
|
||||||
|
@ -167,60 +141,6 @@ namespace MultiArrayTools
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using divides = dividesx<T,T>;
|
using divides = dividesx<T,T>;
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename T>
|
|
||||||
struct plus : public StaticFunctionBase<T, plus<T>, T, T>
|
|
||||||
{
|
|
||||||
static constexpr bool FISSTATIC = true;
|
|
||||||
using StaticFunctionBase<T, plus<T>, T, T>::apply;
|
|
||||||
|
|
||||||
static inline T apply(T a1, T a2)
|
|
||||||
{
|
|
||||||
return a1 + a2;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline T& selfApply(T& a1, const T& a2)
|
|
||||||
{
|
|
||||||
return a1 += a2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct minus : public StaticFunctionBase<T, minus<T>, T, T>
|
|
||||||
{
|
|
||||||
static constexpr bool FISSTATIC = true;
|
|
||||||
using StaticFunctionBase<T, minus<T>, T, T>::apply;
|
|
||||||
|
|
||||||
static inline T apply(T a1, T a2)
|
|
||||||
{
|
|
||||||
return a1 - a2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct multiplies : public StaticFunctionBase<T, multiplies<T>, T, T>
|
|
||||||
{
|
|
||||||
static constexpr bool FISSTATIC = true;
|
|
||||||
using StaticFunctionBase<T, multiplies<T>, T, T>::apply;
|
|
||||||
|
|
||||||
static inline T apply(T a1, T a2)
|
|
||||||
{
|
|
||||||
return a1 * a2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct divides : public StaticFunctionBase<T, divides<T>, T, T>
|
|
||||||
{
|
|
||||||
static constexpr bool FISSTATIC = true;
|
|
||||||
using StaticFunctionBase<T, divides<T>, T, T>::apply;
|
|
||||||
|
|
||||||
static inline T apply(T a1, T a2)
|
|
||||||
{
|
|
||||||
return a1 / a2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
// OPERATIONS (STATIC)
|
// OPERATIONS (STATIC)
|
||||||
template <typename R, typename... Args>
|
template <typename R, typename... Args>
|
||||||
class function
|
class function
|
||||||
|
@ -241,16 +161,28 @@ namespace MultiArrayTools
|
||||||
return mF(args...);
|
return mF(args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t N, class Tuple, typename... As>
|
||||||
|
static inline auto xapply(const std::function<R(Args...)>& ff, const Tuple& tp, As... as)
|
||||||
|
{
|
||||||
|
if constexpr(N > 0){
|
||||||
|
return xapply<N-1>(ff, tp, std::get<N>(tp), as...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ff(std::get<0>(tp), as...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline R operator()(const std::tuple<Args...>& args)
|
inline R operator()(const std::tuple<Args...>& args)
|
||||||
{
|
{
|
||||||
return ArgPack<sizeof...(Args)-1>::template mkd<std::function<R(Args...)>,std::tuple<Args...>>>(mF, args);
|
return xapply<sizeof...(Args)-1>(mF, args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#define regFunc1(fff) template <typename T>\
|
#define regFunc1(fff) template <typename T>\
|
||||||
struct x_##fff : public StaticFunctionBase<T, x_##fff<T>, T> {\
|
struct x_##fff : public StaticFunctionBase<x_##fff<T>> {\
|
||||||
static constexpr bool FISSTATIC = true;\
|
static constexpr bool FISSTATIC = true;\
|
||||||
|
typedef T value_type; \
|
||||||
static inline T apply(T a){\
|
static inline T apply(T a){\
|
||||||
return fff(a); } };
|
return fff(a); } };
|
||||||
|
|
||||||
|
@ -265,35 +197,17 @@ namespace MultiArrayTools
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline T apply(T a)
|
static inline T apply(T a)
|
||||||
{
|
{
|
||||||
return a * x_ipow<N-1>::apply(a);
|
if constexpr(N > 0){
|
||||||
|
return a * x_ipow<N-1>::apply(a);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
} // end namespace CNORXZInternal
|
||||||
struct x_ipow<0>
|
|
||||||
{
|
#include "arith.cc.h"
|
||||||
static constexpr bool FISSTATIC = true;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static inline T apply(T a)
|
|
||||||
{
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename T, class Func>
|
|
||||||
struct dynamic_function
|
|
||||||
{
|
|
||||||
static constexpr bool FISSTATIC = false;
|
|
||||||
|
|
||||||
template <typename... Us>
|
|
||||||
inline T apply(Us... args)
|
|
||||||
{
|
|
||||||
return f(args...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
} // end namespace MultiArrayHelper
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __base_def_h__
|
#ifndef __cxz_base_def_h__
|
||||||
#define __base_def_h__
|
#define __cxz_base_def_h__
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
|
18
src/include/basic_types.h
Normal file
18
src/include/basic_types.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef __cxz_basic_types_h__
|
||||||
|
#define __cxz_basic_types_h__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
// just to fix this forever:
|
||||||
|
typedef int32_t Int;
|
||||||
|
typedef uint64_t SizeT;
|
||||||
|
typedef double Double;
|
||||||
|
typedef Double Real;
|
||||||
|
typedef std::string String;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
15
src/include/cnorxz.cc.h
Normal file
15
src/include/cnorxz.cc.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
|
#include "container_index.cc.h"
|
||||||
|
#include "cxz_operation.cc.h"
|
||||||
|
#include "functional_array.cc.h"
|
||||||
|
#include "helper_tools.cc.h"
|
||||||
|
#include "map_range.cc.h"
|
||||||
|
#include "cxz_array_base.cc.h"
|
||||||
|
#include "cxz_array.cc.h"
|
||||||
|
#include "slice.cc.h"
|
||||||
|
#include "dynamic_operation.cc.h"
|
||||||
|
//#include "high_level_operation.cc.h"
|
||||||
|
//#include "expressions.cc.h"
|
||||||
|
|
20
src/include/cnorxz.h
Normal file
20
src/include/cnorxz.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// -*- C++ -*-
|
||||||
|
|
||||||
|
#ifndef __cxz_cnorxz_h__
|
||||||
|
#define __cxz_cnorxz_h__
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include "container_index.h"
|
||||||
|
#include "cxz_operation.h"
|
||||||
|
#include "cxz_array_base.h"
|
||||||
|
#include "cxz_array.h"
|
||||||
|
#include "functional_array.h"
|
||||||
|
#include "helper_tools.h"
|
||||||
|
#include "operation_def.h"
|
||||||
|
#include "map_range.h"
|
||||||
|
#include "dynamic_operation.h"
|
||||||
|
//#include "high_level_operation.h"
|
||||||
|
|
||||||
|
#include "cnorxz.cc.h"
|
||||||
|
|
||||||
|
#endif
|
440
src/include/container_index.cc.h
Normal file
440
src/include/container_index.cc.h
Normal file
|
@ -0,0 +1,440 @@
|
||||||
|
|
||||||
|
#include "container_index.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>::ConstContainerIndex(const ConstContainerIndex& in, bool copy) :
|
||||||
|
IB(in),
|
||||||
|
mNonTrivialBlocks(in.mNonTrivialBlocks),
|
||||||
|
mExternControl(false),
|
||||||
|
mBlockSizes(in.mBlockSizes),
|
||||||
|
mData(in.mData),
|
||||||
|
mObjPtrNum(in.mObjPtrNum),
|
||||||
|
mCPos(in.mCPos)
|
||||||
|
{
|
||||||
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<i>(mIPack))>::type
|
||||||
|
SubType;
|
||||||
|
std::get<i>(mIPack) = std::make_shared<SubType>( in.template get<i>() ) ;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::copy(const ConstContainerIndex& in)
|
||||||
|
{
|
||||||
|
IB::operator=(in);
|
||||||
|
mNonTrivialBlocks = in.mNonTrivialBlocks;
|
||||||
|
mExternControl = false;
|
||||||
|
mBlockSizes = in.mBlockSizes;
|
||||||
|
mData = in.mData;
|
||||||
|
mObjPtrNum = in.mObjPtrNum;
|
||||||
|
mCPos = in.mCPos;
|
||||||
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<i>(mIPack))>::type
|
||||||
|
SubType;
|
||||||
|
std::get<i>(mIPack) = std::make_shared<SubType>( in.template get<i>() ) ;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <class MRange>
|
||||||
|
ConstContainerIndex<T,Indices...>::ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
||||||
|
std::intptr_t objPtrNum) :
|
||||||
|
IndexInterface<ConstContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
||||||
|
mObjPtrNum(objPtrNum)
|
||||||
|
{
|
||||||
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||||
|
sfor_mn<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto r = range->template getPtr<i>();
|
||||||
|
std::get<i>(mIPack) = r->beginPtr();
|
||||||
|
*std::get<i>(mIPack) = 0;
|
||||||
|
|
||||||
|
std::get<i>(mBlockSizes) = sfor_p<i,sizeof...(Indices)>
|
||||||
|
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
||||||
|
[&](auto a, auto b) { return a * b; });
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <class MRange>
|
||||||
|
ConstContainerIndex<T,Indices...>::ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
||||||
|
std::intptr_t objPtrNum,
|
||||||
|
const std::array<size_t,sizeof...(Indices)+1>& blockSizes) :
|
||||||
|
IndexInterface<ConstContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
||||||
|
mObjPtrNum(objPtrNum)
|
||||||
|
{
|
||||||
|
sfor_mn<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto r = range->template getPtr<i>();
|
||||||
|
std::get<i>(mIPack) = r->beginPtr();
|
||||||
|
*std::get<i>(mIPack) = 0;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
mNonTrivialBlocks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <typename X>
|
||||||
|
ConstContainerIndex<T,Indices...>&
|
||||||
|
ConstContainerIndex<T,Indices...>::operator=(const ConstContainerIndex<X,Indices...>& in)
|
||||||
|
{
|
||||||
|
mIPack = in.mIPack;
|
||||||
|
return (*this)();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::sync()
|
||||||
|
{
|
||||||
|
if(mExternControl){
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <size_t N>
|
||||||
|
auto& ConstContainerIndex<T,Indices...>::get() const
|
||||||
|
{
|
||||||
|
return *std::get<N>( mIPack );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <size_t N>
|
||||||
|
auto ConstContainerIndex<T,Indices...>::getPtr() const
|
||||||
|
{
|
||||||
|
return std::get<N>( mIPack );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
|
||||||
|
{
|
||||||
|
return (*this)(std::make_tuple(inds...));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
|
||||||
|
{
|
||||||
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(inds); return 0; } );
|
||||||
|
mExternControl = true;
|
||||||
|
return sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator()()
|
||||||
|
{
|
||||||
|
return sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
IndexType ConstContainerIndex<T,Indices...>::type() const { return IndexType::CONT; }
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator++()
|
||||||
|
{
|
||||||
|
if(mExternControl){
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
|
}
|
||||||
|
sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.last() and i != 0) { si = 0; return true; }
|
||||||
|
else { ++si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
++IB::mPos;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator--()
|
||||||
|
{
|
||||||
|
if(mExternControl){
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
|
}
|
||||||
|
sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||||
|
else { --si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
--IB::mPos;
|
||||||
|
return *this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator=(size_t pos)
|
||||||
|
{
|
||||||
|
IB::mPos = pos;
|
||||||
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
|
||||||
|
mCPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
int ConstContainerIndex<T,Indices...>::pp(std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
const int tmp = RangeHelper::ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||||
|
IB::mPos += tmp;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
int ConstContainerIndex<T,Indices...>::mm(std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
const int tmp = RangeHelper::mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||||
|
IB::mPos -= tmp;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
std::string ConstContainerIndex<T,Indices...>::stringMeta() const
|
||||||
|
{
|
||||||
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
typename ConstContainerIndex<T,Indices...>::MetaType ConstContainerIndex<T,Indices...>::meta() const
|
||||||
|
{
|
||||||
|
MetaType metaTuple;
|
||||||
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i) { std::get<i>(metaTuple) = std::get<i>(mIPack)->meta(); return 0; } );
|
||||||
|
return metaTuple;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::at(const MetaType& metaPos)
|
||||||
|
{
|
||||||
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); return 0; } );
|
||||||
|
IB::mPos = RangeHelper::makePos<sizeof...(Indices)-1>(mIPack, mBlockSizes);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
size_t ConstContainerIndex<T,Indices...>::dim() const
|
||||||
|
{
|
||||||
|
return sizeof...(Indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::first() const
|
||||||
|
{
|
||||||
|
return IB::pos() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::last() const
|
||||||
|
{
|
||||||
|
return IB::pos() == IB::mMax - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::sliceMode() const
|
||||||
|
{
|
||||||
|
return mNonTrivialBlocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
std::shared_ptr<typename ConstContainerIndex<T,Indices...>::RangeType>
|
||||||
|
ConstContainerIndex<T,Indices...>::range()
|
||||||
|
{
|
||||||
|
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
size_t ConstContainerIndex<T,Indices...>::getStepSize(size_t n)
|
||||||
|
{
|
||||||
|
if(n >= sizeof...(Indices)){
|
||||||
|
assert(0);
|
||||||
|
// throw !!
|
||||||
|
}
|
||||||
|
return mBlockSizes[n+1];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <class Exprs>
|
||||||
|
auto ConstContainerIndex<T,Indices...>::ifor(size_t step, Exprs exs) const
|
||||||
|
{
|
||||||
|
return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <class Exprs>
|
||||||
|
auto ConstContainerIndex<T,Indices...>::iforh(size_t step, Exprs exs) const
|
||||||
|
{
|
||||||
|
return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
template <class Exprs>
|
||||||
|
auto ConstContainerIndex<T,Indices...>::pifor(size_t step, Exprs exs) const
|
||||||
|
{
|
||||||
|
return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
std::intptr_t ConstContainerIndex<T,Indices...>::container() const
|
||||||
|
{
|
||||||
|
return mObjPtrNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::
|
||||||
|
format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
||||||
|
{
|
||||||
|
mBlockSizes = blocks;
|
||||||
|
mNonTrivialBlocks = true;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::setData(const T* data)
|
||||||
|
{
|
||||||
|
mData = data;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
const T& ConstContainerIndex<T,Indices...>::operator*() const
|
||||||
|
{
|
||||||
|
return mData[mCPos];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
const T* ConstContainerIndex<T,Indices...>::operator->() const
|
||||||
|
{
|
||||||
|
return &mData[mCPos];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator++(int)
|
||||||
|
{
|
||||||
|
auto tmp = *this;
|
||||||
|
++(*this);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator--(int)
|
||||||
|
{
|
||||||
|
auto tmp = *this;
|
||||||
|
--(*this);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator+=(int diff)
|
||||||
|
{
|
||||||
|
if(diff < 0){
|
||||||
|
for(int i = 0; i != diff; ++i){
|
||||||
|
(*this)--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = 0; i != diff; ++i){
|
||||||
|
(*this)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...>& ConstContainerIndex<T,Indices...>::operator-=(int diff)
|
||||||
|
{
|
||||||
|
if(diff < 0){
|
||||||
|
for(int i = 0; i != diff; ++i){
|
||||||
|
(*this)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = 0; i != diff; ++i){
|
||||||
|
(*this)--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator+(int num) const
|
||||||
|
{
|
||||||
|
auto tmp = *this;
|
||||||
|
return tmp += num;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
ConstContainerIndex<T,Indices...> ConstContainerIndex<T,Indices...>::operator-(int num) const
|
||||||
|
{
|
||||||
|
auto tmp = *this;
|
||||||
|
return tmp -= num;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
int ConstContainerIndex<T,Indices...>::operator-(const ConstContainerIndex<T,Indices...>& it) const
|
||||||
|
{
|
||||||
|
return static_cast<int>( IB::mPos ) - static_cast<int>( it.pos() );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
const T& ConstContainerIndex<T,Indices...>::operator[](int num) const
|
||||||
|
{
|
||||||
|
return mData[IB::mPos + num];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::operator<(const ConstContainerIndex<T,Indices...>& it) const
|
||||||
|
{
|
||||||
|
return IB::mPos < it.pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::operator>(const ConstContainerIndex<T,Indices...>& it) const
|
||||||
|
{
|
||||||
|
return IB::mPos > it.pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::operator<=(const ConstContainerIndex<T,Indices...>& it) const
|
||||||
|
{
|
||||||
|
return IB::mPos <= it.pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
bool ConstContainerIndex<T,Indices...>::operator>=(const ConstContainerIndex<T,Indices...>& it) const
|
||||||
|
{
|
||||||
|
return IB::mPos >= it.pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CNORXZ
|
307
src/include/container_index.h
Normal file
307
src/include/container_index.h
Normal file
|
@ -0,0 +1,307 @@
|
||||||
|
// -*- C++ -*-
|
||||||
|
|
||||||
|
#ifndef __cxz_container_index_h__
|
||||||
|
#define __cxz_container_index_h__
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <tuple>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "ranges/range_base.h"
|
||||||
|
#include "ranges/index_base.h"
|
||||||
|
#include "mbase_def.h"
|
||||||
|
#include "statics/static_for.h"
|
||||||
|
#include "ranges/range_helper.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
class ConstContainerIndex : public IndexInterface<ConstContainerIndex<T,Indices...>,
|
||||||
|
std::tuple<typename Indices::MetaType...> >,
|
||||||
|
public std::iterator<std::random_access_iterator_tag,T>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef IndexInterface<ConstContainerIndex<T,Indices...>,
|
||||||
|
std::tuple<typename Indices::MetaType...> > IB;
|
||||||
|
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
||||||
|
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
||||||
|
typedef ContainerRange<typename Indices::RangeType...> RangeType;
|
||||||
|
|
||||||
|
static constexpr IndexType sType() { return IndexType::CONT; }
|
||||||
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||||
|
static constexpr size_t totalDim() { return (... * Indices::totalDim()); }
|
||||||
|
|
||||||
|
static constexpr SpaceType STYPE = SpaceType::ANY;
|
||||||
|
static constexpr bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
using CIX = ConstContainerIndex<X,Indices...>;
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
friend class CIX;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
ConstContainerIndex() = default;
|
||||||
|
|
||||||
|
bool mNonTrivialBlocks = false;
|
||||||
|
bool mExternControl = false;
|
||||||
|
IndexPack mIPack;
|
||||||
|
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
||||||
|
const T* mData = nullptr;
|
||||||
|
std::intptr_t mObjPtrNum;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
size_t mCPos;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ConstContainerIndex(const ConstContainerIndex& in) = default;
|
||||||
|
ConstContainerIndex& operator=(const ConstContainerIndex& in) = default;
|
||||||
|
|
||||||
|
ConstContainerIndex(const ConstContainerIndex& in, bool copy);
|
||||||
|
|
||||||
|
ConstContainerIndex& copy(const ConstContainerIndex& in);
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
ConstContainerIndex& operator=(const ConstContainerIndex<X,Indices...>& in);
|
||||||
|
|
||||||
|
template <class MRange>
|
||||||
|
ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
||||||
|
std::intptr_t objPtrNum);
|
||||||
|
|
||||||
|
template <class MRange>
|
||||||
|
ConstContainerIndex(const std::shared_ptr<MRange>& range,
|
||||||
|
std::intptr_t objPtrNum,
|
||||||
|
const std::array<size_t,sizeof...(Indices)+1>& blockSizes);
|
||||||
|
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
||||||
|
|
||||||
|
const IndexPack& pack() const { return mIPack; }
|
||||||
|
|
||||||
|
ConstContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
|
||||||
|
ConstContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
||||||
|
ConstContainerIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& inds);
|
||||||
|
ConstContainerIndex& operator()(); // -> sync; just to shorten the code
|
||||||
|
|
||||||
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||||
|
|
||||||
|
IndexType type() const;
|
||||||
|
|
||||||
|
ConstContainerIndex& operator++();
|
||||||
|
ConstContainerIndex& operator--();
|
||||||
|
|
||||||
|
ConstContainerIndex& operator=(size_t pos);
|
||||||
|
|
||||||
|
int pp(std::intptr_t idxPtrNum);
|
||||||
|
int mm(std::intptr_t idxPtrNum);
|
||||||
|
|
||||||
|
std::string stringMeta() const;
|
||||||
|
MetaType meta() const;
|
||||||
|
ConstContainerIndex& at(const MetaType& metaPos);
|
||||||
|
|
||||||
|
size_t dim() const;
|
||||||
|
bool first() const;
|
||||||
|
bool last() const;
|
||||||
|
bool sliceMode() const;
|
||||||
|
|
||||||
|
std::shared_ptr<RangeType> range();
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
auto& get() const;
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
auto getPtr() const;
|
||||||
|
|
||||||
|
size_t getStepSize(size_t n);
|
||||||
|
|
||||||
|
template <class Exprs>
|
||||||
|
auto ifor(size_t step, Exprs exs) const;
|
||||||
|
|
||||||
|
template <class Exprs>
|
||||||
|
auto iforh(size_t step, Exprs exs) const;
|
||||||
|
|
||||||
|
template <class Exprs>
|
||||||
|
auto pifor(size_t step, Exprs exs) const;
|
||||||
|
|
||||||
|
std::intptr_t container() const;
|
||||||
|
ConstContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks);
|
||||||
|
|
||||||
|
// Iterator Stuff
|
||||||
|
|
||||||
|
ConstContainerIndex& setData(const T* data);
|
||||||
|
|
||||||
|
const T& operator*() const;
|
||||||
|
const T* operator->() const;
|
||||||
|
//T& operator*();
|
||||||
|
//T* operator->();
|
||||||
|
|
||||||
|
ConstContainerIndex operator++(int);
|
||||||
|
ConstContainerIndex operator--(int);
|
||||||
|
ConstContainerIndex& operator+=(int diff);
|
||||||
|
ConstContainerIndex& operator-=(int diff);
|
||||||
|
ConstContainerIndex operator+(int num) const;
|
||||||
|
ConstContainerIndex operator-(int num) const;
|
||||||
|
|
||||||
|
int operator-(const ConstContainerIndex& it) const;
|
||||||
|
const T& operator[](int num) const;
|
||||||
|
|
||||||
|
bool operator<(const ConstContainerIndex& it) const;
|
||||||
|
bool operator>(const ConstContainerIndex& it) const;
|
||||||
|
bool operator<=(const ConstContainerIndex& it) const;
|
||||||
|
bool operator>=(const ConstContainerIndex& it) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
class ContainerIndex : public ConstContainerIndex<T,Indices...>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef ConstContainerIndex<T,Indices...> CCI;
|
||||||
|
typedef CCI IB;
|
||||||
|
typedef typename CCI::MetaType MetaType;
|
||||||
|
typedef typename CCI::IndexPack IndexPack;
|
||||||
|
typedef typename CCI::RangeType RangeType;
|
||||||
|
|
||||||
|
static constexpr IndexType sType() { return CCI::sType(); }
|
||||||
|
static constexpr size_t sDim() { return CCI::sDim(); }
|
||||||
|
static constexpr size_t totalDim() { return CCI::totalDim(); }
|
||||||
|
|
||||||
|
static constexpr SpaceType STYPE = CCI::STYPE;
|
||||||
|
static constexpr bool PARALLEL = CCI::PARALLEL;
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
using CIX = ContainerIndex<X,Indices...>;
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
friend class CIX;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
ContainerIndex() = default;
|
||||||
|
|
||||||
|
T* mMData = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ContainerIndex(const ContainerIndex& in) = default;
|
||||||
|
ContainerIndex& operator=(const ContainerIndex& in) = default;
|
||||||
|
|
||||||
|
ContainerIndex(const ContainerIndex& in, bool copy) : CCI(in,copy)
|
||||||
|
{ mMData = in.mMData; }
|
||||||
|
|
||||||
|
ContainerIndex(const ConstContainerIndex<T,Indices...>& in, T* data) : CCI(in)
|
||||||
|
{ mMData = data; }
|
||||||
|
|
||||||
|
ContainerIndex(const ConstContainerIndex<T,Indices...>& in, T* data, bool copy) :
|
||||||
|
CCI(in,copy)
|
||||||
|
{ mMData = data; }
|
||||||
|
|
||||||
|
ContainerIndex& copy(const ContainerIndex& in)
|
||||||
|
{ CCI::copy(in); mMData = in.mMData; }
|
||||||
|
|
||||||
|
template <typename X>
|
||||||
|
ContainerIndex& operator=(const ContainerIndex<X,Indices...>& in)
|
||||||
|
{ CCI::operator=(in); return *this; }
|
||||||
|
|
||||||
|
template <class MRange>
|
||||||
|
ContainerIndex(const std::shared_ptr<MRange>& range,
|
||||||
|
std::intptr_t objPtrNum) : CCI(range, objPtrNum) {}
|
||||||
|
|
||||||
|
template <class MRange>
|
||||||
|
ContainerIndex(const std::shared_ptr<MRange>& range,
|
||||||
|
std::intptr_t objPtrNum,
|
||||||
|
const std::array<size_t,sizeof...(Indices)+1>& blockSizes)
|
||||||
|
: CCI(range, objPtrNum, blockSizes) {}
|
||||||
|
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
size_t getBlockSize() const { return CCI::template getBlockSize<N>(); }
|
||||||
|
|
||||||
|
const IndexPack& pack() const { CCI::pack(); return *this; }
|
||||||
|
|
||||||
|
ContainerIndex& sync() { return CCI::sync(); return *this; }
|
||||||
|
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds)
|
||||||
|
{ CCI::operator()(inds...); return *this; }
|
||||||
|
ContainerIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
|
||||||
|
{ CCI::operator()(inds); return *this; }
|
||||||
|
ContainerIndex& operator()() { CCI::operator()(); return *this; }
|
||||||
|
|
||||||
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||||
|
|
||||||
|
IndexType type() const { return CCI::type(); }
|
||||||
|
|
||||||
|
ContainerIndex& operator++() { CCI::operator++(); return *this; }
|
||||||
|
ContainerIndex& operator--() { CCI::operator--(); return *this; }
|
||||||
|
|
||||||
|
ContainerIndex& operator=(size_t pos) { CCI::operator=(pos); return *this; }
|
||||||
|
|
||||||
|
int pp(std::intptr_t idxPtrNum) { return CCI::pp(idxPtrNum); }
|
||||||
|
int mm(std::intptr_t idxPtrNum) { return CCI::mm(idxPtrNum); }
|
||||||
|
|
||||||
|
std::string stringMeta() const { return CCI::stringMeta; }
|
||||||
|
MetaType meta() const { return CCI::meta(); }
|
||||||
|
ContainerIndex& at(const MetaType& metaPos) { CCI::at(metaPos); return *this; }
|
||||||
|
|
||||||
|
size_t dim() const { return CCI::dim(); }
|
||||||
|
bool first() const { return CCI::first(); }
|
||||||
|
bool last() const { return CCI::last(); }
|
||||||
|
bool sliceMode() const { return CCI::sliceMode(); }
|
||||||
|
|
||||||
|
std::shared_ptr<RangeType> range() { return CCI::range(); }
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
auto& get() const { return CCI::template get<N>(); }
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
auto getPtr() const { return CCI::template getPtr<N>(); }
|
||||||
|
|
||||||
|
size_t getStepSize(size_t n) { return getStepSize(n); }
|
||||||
|
|
||||||
|
template <class Exprs>
|
||||||
|
auto ifor(size_t step, Exprs exs) const { return CCI::ifor(step, exs); }
|
||||||
|
|
||||||
|
template <class Exprs>
|
||||||
|
auto iforh(size_t step, Exprs exs) const { return CCI::iforh(step, exs); }
|
||||||
|
|
||||||
|
template <class Exprs>
|
||||||
|
auto pifor(size_t step, Exprs exs) const { return CCI::pifor(step, exs); }
|
||||||
|
|
||||||
|
std::intptr_t container() const { return CCI::container(); }
|
||||||
|
ContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
||||||
|
{ CCI::format(blocks); return *this; }
|
||||||
|
|
||||||
|
// Iterator Stuff
|
||||||
|
|
||||||
|
ContainerIndex& setData(T* data) { CCI::setData(data); mMData = data; return *this; }
|
||||||
|
|
||||||
|
const T& operator*() const { return CCI::operator*(); }
|
||||||
|
const T* operator->() const { return CCI::operator->(); }
|
||||||
|
T& operator*() { return mMData[CCI::mCPos]; }
|
||||||
|
T* operator->() { return &mMData[CCI::mCPos]; }
|
||||||
|
|
||||||
|
ContainerIndex operator++(int) { auto tmp = *this; ++(*this); return tmp; }
|
||||||
|
ContainerIndex operator--(int) { auto tmp = *this; --(*this); return tmp; }
|
||||||
|
ContainerIndex& operator+=(int diff) { CCI::operator+=(diff); return *this; }
|
||||||
|
ContainerIndex& operator-=(int diff) { CCI::operator-=(diff); return *this; }
|
||||||
|
ContainerIndex operator+(int num) const { CCI::operator+(num); return *this; }
|
||||||
|
ContainerIndex operator-(int num) const { CCI::operator-(num); return *this; }
|
||||||
|
|
||||||
|
int operator-(const ContainerIndex& it) const { return CCI::operator-(it); }
|
||||||
|
const T& operator[](int num) const { return CCI::operator[](num); }
|
||||||
|
|
||||||
|
bool operator<(const ContainerIndex& it) const { return CCI::operator<(it); }
|
||||||
|
bool operator>(const ContainerIndex& it) const { return CCI::operator>(it); }
|
||||||
|
bool operator<=(const ContainerIndex& it) const { return CCI::operator<=(it); }
|
||||||
|
bool operator>=(const ContainerIndex& it) const { return CCI::operator>=(it); }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace CNORXZ
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
#ifndef __ma_conversions_h__
|
#ifndef __cxz_conversions_h__
|
||||||
#define __ma_conversions_h__
|
#define __cxz_conversions_h__
|
||||||
|
|
||||||
#include "multi_array.h"
|
#include "cxz_array.h"
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace ConversionSizes
|
namespace ConversionSizes
|
||||||
|
@ -94,7 +94,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C, typename T, class... Ranges>
|
template <typename C, typename T, class... Ranges>
|
||||||
auto tcast(MultiArray<T,Ranges...>& ma)
|
auto tcast(Array<T,Ranges...>& ma)
|
||||||
-> decltype(rangeTpToSlice
|
-> decltype(rangeTpToSlice
|
||||||
( rtcast<C,T>( ma.range()->space() ),
|
( rtcast<C,T>( ma.range()->space() ),
|
||||||
reinterpret_cast<C*>( ma.data() ) ))
|
reinterpret_cast<C*>( ma.data() ) ))
|
||||||
|
@ -107,7 +107,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C, typename T, class... Ranges>
|
template <typename C, typename T, class... Ranges>
|
||||||
auto tcast(const MultiArray<T,Ranges...>& ma)
|
auto tcast(const Array<T,Ranges...>& ma)
|
||||||
-> decltype(rangeTpToSlice
|
-> decltype(rangeTpToSlice
|
||||||
( rtcast<C,T>( ma.range()->space() ),
|
( rtcast<C,T>( ma.range()->space() ),
|
||||||
reinterpret_cast<const C*>( ma.data() ) ))
|
reinterpret_cast<const C*>( ma.data() ) ))
|
||||||
|
|
269
src/include/cxz_array.cc.h
Normal file
269
src/include/cxz_array.cc.h
Normal file
|
@ -0,0 +1,269 @@
|
||||||
|
|
||||||
|
#include "cxz_array.h"
|
||||||
|
#include "statics/static_for.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
Scalar<T> scalar(const T& in)
|
||||||
|
{
|
||||||
|
NullRF nrf;
|
||||||
|
return Scalar<T>( std::dynamic_pointer_cast<NullRange>( nrf.create() ), vector<T>( { in } ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************
|
||||||
|
* Array *
|
||||||
|
*******************/
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(const typename CRange::Space& space) :
|
||||||
|
MutableArrayBase<T,SRanges...>(space),
|
||||||
|
mCont(MAB::mRange->size())
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(const typename CRange::Space& space,
|
||||||
|
const vector<T>& vec) :
|
||||||
|
MutableArrayBase<T,SRanges...>(space),
|
||||||
|
mCont(vec)
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
if(mCont.size() > MAB::mRange->size()){
|
||||||
|
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(const std::shared_ptr<SRanges>&... ranges) :
|
||||||
|
MutableArrayBase<T,SRanges...>(ranges...),
|
||||||
|
mCont(MAB::mRange->size())
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(const std::shared_ptr<SRanges>&... ranges, const T& val) :
|
||||||
|
MutableArrayBase<T,SRanges...>(ranges...),
|
||||||
|
mCont(MAB::mRange->size(), val)
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(const std::shared_ptr<SRanges>&... ranges, const vector<T>& vec) :
|
||||||
|
MutableArrayBase<T,SRanges...>(ranges...),
|
||||||
|
mCont(vec)
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
if(mCont.size() > MAB::mRange->size()){
|
||||||
|
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec) :
|
||||||
|
MutableArrayBase<T,SRanges...>(ranges...),
|
||||||
|
mCont(std::forward<vector<T>>(vec))
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
if(mCont.size() > MAB::mRange->size()){
|
||||||
|
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
template <class... Ranges>
|
||||||
|
Array<T,SRanges...>::Array(const std::shared_ptr<SRanges>&... ranges, Array<T,Ranges...>&& in) :
|
||||||
|
MutableArrayBase<T,SRanges...>(ranges...),
|
||||||
|
mCont( std::move( in.mCont ) )
|
||||||
|
{
|
||||||
|
// maybe some checks here in the future...
|
||||||
|
assert(mCont.size() == MAB::mRange->size());
|
||||||
|
MAB::mInit = true;
|
||||||
|
in.mInit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::Array(Array<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes) :
|
||||||
|
MutableArrayBase<T,SRanges...>
|
||||||
|
( ama.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
|
||||||
|
mCont( std::move( ama.mCont ) )
|
||||||
|
{
|
||||||
|
MAB::mInit = true;
|
||||||
|
ama.mInit = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
T& Array<T,SRanges...>::operator[](const IndexType& i)
|
||||||
|
{
|
||||||
|
return mCont[ i.pos() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
const T& Array<T,SRanges...>::operator[](const IndexType& i) const
|
||||||
|
{
|
||||||
|
return mCont[ i.pos() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
T& Array<T,SRanges...>::at(const typename IndexType::MetaType& meta)
|
||||||
|
{
|
||||||
|
return mCont[ MAB::cbegin().at(meta).pos() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
const T& Array<T,SRanges...>::at(const typename IndexType::MetaType& meta) const
|
||||||
|
{
|
||||||
|
return mCont[ MAB::cbegin().at(meta).pos() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
bool Array<T,SRanges...>::isConst() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
bool Array<T,SRanges...>::isSlice() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
template <class... SRanges2>
|
||||||
|
Array<T,SRanges2...> Array<T,SRanges...>::format(const std::shared_ptr<SRanges2>&... nrs)
|
||||||
|
{
|
||||||
|
//MAB::mInit = false;
|
||||||
|
return Array<T,SRanges2...>( nrs... , mCont );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
template <class... SRanges2>
|
||||||
|
Array<T,SRanges2...> Array<T,SRanges...>::format(const std::tuple<std::shared_ptr<SRanges2>...>& nrs)
|
||||||
|
{
|
||||||
|
//MAB::mInit = false;
|
||||||
|
return Array<T,SRanges2...>( nrs , mCont );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
template <class... SRanges2>
|
||||||
|
Slice<T,SRanges2...> Array<T,SRanges...>::slformat(const std::shared_ptr<SRanges2>&... nrs)
|
||||||
|
{
|
||||||
|
return Slice<T,SRanges2...>( nrs..., mCont.data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
template <class... SRanges2>
|
||||||
|
ConstSlice<T,SRanges2...> Array<T,SRanges...>::slformat(const std::shared_ptr<SRanges2>&... nrs) const
|
||||||
|
{
|
||||||
|
return ConstSlice<T,SRanges2...>( nrs..., mCont.data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
const T* Array<T,SRanges...>::data() const
|
||||||
|
{
|
||||||
|
return mCont.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
T* Array<T,SRanges...>::data()
|
||||||
|
{
|
||||||
|
return mCont.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
std::shared_ptr<ArrayBase<T,AnonymousRange> > Array<T,SRanges...>::anonymous(bool slice) const
|
||||||
|
{
|
||||||
|
AnonymousRangeFactory arf(MAB::mRange->space());
|
||||||
|
if(slice){
|
||||||
|
return std::make_shared<ConstSlice<T,AnonymousRange> >
|
||||||
|
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
||||||
|
data() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::make_shared<Array<T,AnonymousRange> >
|
||||||
|
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
||||||
|
mCont );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>& Array<T,SRanges...>::operator=(const T& in)
|
||||||
|
{
|
||||||
|
for(auto& x: mCont){
|
||||||
|
x = in;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>& Array<T,SRanges...>::operator+=(const Array& in)
|
||||||
|
{
|
||||||
|
if(not MAB::mInit){ // not initialized by default constructor !!
|
||||||
|
(*this) = in;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sfor_p<0,sizeof...(SRanges),0>
|
||||||
|
( [&](auto i) { return std::get<i>(MAB::mRange->space()).get() == std::get<i>(in.mRange->space()).get(); },
|
||||||
|
[&](auto a, auto b) { return a and b; });
|
||||||
|
for(size_t i = 0; i != mCont.size(); ++i){
|
||||||
|
mCont[i] += in.mCont[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>& Array<T,SRanges...>::operator-=(const Array& in)
|
||||||
|
{
|
||||||
|
if(not MAB::mInit){ // not initialized by default constructor !!
|
||||||
|
(*this) = in;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sfor_p<0,sizeof...(SRanges),0>
|
||||||
|
( [&](auto i) { return std::get<i>(MAB::mRange->space()).get() == std::get<i>(in.mRange->space()).get(); },
|
||||||
|
[&](auto a, auto b) { return a and b; });
|
||||||
|
for(size_t i = 0; i != mCont.size(); ++i){
|
||||||
|
mCont[i] -= in.mCont[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>& Array<T,SRanges...>::operator*=(const T& in)
|
||||||
|
{
|
||||||
|
for(auto& x: mCont){
|
||||||
|
x *= in;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>& Array<T,SRanges...>::operator/=(const T& in)
|
||||||
|
{
|
||||||
|
for(auto& x: mCont){
|
||||||
|
x /= in;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
Array<T,SRanges...>::operator T() const
|
||||||
|
{
|
||||||
|
//static_assert( sizeof...(SRanges) == 1, "try to cast non-scalar type into scalar" );
|
||||||
|
// TODO: check that SIZE is statically = 1 !!!
|
||||||
|
return mCont[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
auto Array<T,SRanges...>::cat() const
|
||||||
|
-> decltype(ArrayCatter<T>::cat(*this))
|
||||||
|
{
|
||||||
|
return ArrayCatter<T>::cat(*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
151
src/include/cxz_array.h
Normal file
151
src/include/cxz_array.h
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
// -*- C++ -*-
|
||||||
|
|
||||||
|
#ifndef __cxz_array_h__
|
||||||
|
#define __cxz_array_h__
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "cxz_array_base.h"
|
||||||
|
#include "ranges/anonymous_range.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
struct ArrayCatter;
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct ArrayCatter
|
||||||
|
{
|
||||||
|
template <class... Ranges>
|
||||||
|
static auto cat(const Array<T,Ranges...>& ma)
|
||||||
|
-> Array<T,Ranges...>
|
||||||
|
{
|
||||||
|
return ma;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
class Array : public MutableArrayBase<T,SRanges...>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef ContainerRange<SRanges...> CRange;
|
||||||
|
typedef ArrayBase<T,SRanges...> MAB;
|
||||||
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
||||||
|
|
||||||
|
using ArrayBase<T,SRanges...>::operator[];
|
||||||
|
using MutableArrayBase<T,SRanges...>::operator[];
|
||||||
|
|
||||||
|
DEFAULT_MEMBERS(Array);
|
||||||
|
Array(const std::shared_ptr<SRanges>&... ranges);
|
||||||
|
Array(const std::shared_ptr<SRanges>&... ranges, const T& val);
|
||||||
|
Array(const std::shared_ptr<SRanges>&... ranges, const vector<T>& vec);
|
||||||
|
Array(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec);
|
||||||
|
|
||||||
|
template <class... Ranges>
|
||||||
|
Array(const std::shared_ptr<SRanges>&... ranges, Array<T,Ranges...>&& in); // same effect as format
|
||||||
|
|
||||||
|
Array(const typename CRange::Space& space);
|
||||||
|
Array(const typename CRange::Space& space, const vector<T>& vec);
|
||||||
|
Array(Array<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes);
|
||||||
|
|
||||||
|
// Only if ALL ranges have default extensions:
|
||||||
|
//Array(const vector<T>& vec);
|
||||||
|
//Array(vector<T>&& vec);
|
||||||
|
|
||||||
|
// template <class Range2, class Range3>
|
||||||
|
// Array(const Array<Array<T,Range2>,Range3> in);
|
||||||
|
|
||||||
|
// implement contstructor using FunctionalArray as Input !!!
|
||||||
|
|
||||||
|
//template <class Range2, class Range3>
|
||||||
|
//Array& operator=(const Array<Array<T,Range2>,Range3> in);
|
||||||
|
|
||||||
|
virtual T& operator[](const IndexType& i) final;
|
||||||
|
virtual const T& operator[](const IndexType& i) const final;
|
||||||
|
virtual T& at(const typename IndexType::MetaType& meta) override;
|
||||||
|
virtual const T& at(const typename IndexType::MetaType& meta) const override;
|
||||||
|
|
||||||
|
virtual bool isConst() const override;
|
||||||
|
virtual bool isSlice() const override;
|
||||||
|
|
||||||
|
template <class... SRanges2>
|
||||||
|
Array<T,SRanges2...> format(const std::shared_ptr<SRanges2>&... nrs); // reformat array using 'nr' which in
|
||||||
|
// total must have the same size as mRange
|
||||||
|
|
||||||
|
template <class... SRanges2>
|
||||||
|
Array<T,SRanges2...> format(const std::tuple<std::shared_ptr<SRanges2>...>& nrs);
|
||||||
|
|
||||||
|
template <class... SRanges2>
|
||||||
|
Slice<T,SRanges2...> slformat(const std::shared_ptr<SRanges2>&... nrs);
|
||||||
|
|
||||||
|
template <class... SRanges2>
|
||||||
|
ConstSlice<T,SRanges2...> slformat(const std::shared_ptr<SRanges2>&... nrs) const;
|
||||||
|
|
||||||
|
virtual const T* data() const override;
|
||||||
|
virtual T* data() override;
|
||||||
|
virtual vector<T>& vdata() { return mCont; }
|
||||||
|
virtual const vector<T>& vdata() const { return mCont; }
|
||||||
|
vector<T>&& vmove() { MAB::mInit = false; return std::move(mCont); }
|
||||||
|
|
||||||
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||||
|
//virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||||
|
|
||||||
|
auto cat() const
|
||||||
|
-> decltype(ArrayCatter<T>::cat(*this));
|
||||||
|
|
||||||
|
operator T() const;
|
||||||
|
|
||||||
|
Array& operator=(const T& in);
|
||||||
|
|
||||||
|
Array& operator+=(const Array& in);
|
||||||
|
Array& operator-=(const Array& in);
|
||||||
|
Array& operator*=(const T& in);
|
||||||
|
Array& operator/=(const T& in);
|
||||||
|
|
||||||
|
template <typename U, class... SRanges2>
|
||||||
|
friend class Array;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
vector<T> mCont;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using Scalar = Array<T,NullRange>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
Scalar<T> scalar(const T& in);
|
||||||
|
|
||||||
|
template <typename T, class... ERanges>
|
||||||
|
struct ArrayCatter<Array<T,ERanges...> >
|
||||||
|
{
|
||||||
|
template <class... Ranges>
|
||||||
|
static auto cat(const Array<Array<T,ERanges...>,Ranges...>& ma)
|
||||||
|
-> Array<T,Ranges...,ERanges...>
|
||||||
|
{
|
||||||
|
auto sma = *ma.begin();
|
||||||
|
const size_t smas = sma.size();
|
||||||
|
const size_t mas = ma.size();
|
||||||
|
auto cr = ma.range()->cat(sma.range());
|
||||||
|
vector<T> ov;
|
||||||
|
ov.reserve(mas * smas);
|
||||||
|
|
||||||
|
for(auto& x: ma){
|
||||||
|
assert(x.size() == smas);
|
||||||
|
ov.insert(ov.end(), x.vdata().begin(), x.vdata().end());
|
||||||
|
}
|
||||||
|
return Array<T,Ranges...,ERanges...>(cr->space(), std::move(ov));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ========================= *
|
||||||
|
* --- TEMPLATE CODE --- *
|
||||||
|
* ========================= */
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,15 +1,15 @@
|
||||||
|
|
||||||
#include "multi_array_base.h"
|
#include "cxz_array_base.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MultiArrayBase *
|
* ArrayBase *
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(const MultiArrayBase& in) :
|
ArrayBase<T,SRanges...>::ArrayBase(const ArrayBase& in) :
|
||||||
mInit(in.mInit),
|
mInit(in.mInit),
|
||||||
mRange(in.mRange)
|
mRange(in.mRange)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(MultiArrayBase&& in) :
|
ArrayBase<T,SRanges...>::ArrayBase(ArrayBase&& in) :
|
||||||
mInit(in.mInit),
|
mInit(in.mInit),
|
||||||
mRange(in.mRange)
|
mRange(in.mRange)
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MultiArrayBase<T,SRanges...>& MultiArrayBase<T,SRanges...>::operator=(const MultiArrayBase& in)
|
ArrayBase<T,SRanges...>& ArrayBase<T,SRanges...>::operator=(const ArrayBase& in)
|
||||||
{
|
{
|
||||||
mInit = in.mInit;
|
mInit = in.mInit;
|
||||||
mRange = in.mRange;
|
mRange = in.mRange;
|
||||||
|
@ -41,7 +41,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MultiArrayBase<T,SRanges...>& MultiArrayBase<T,SRanges...>::operator=(MultiArrayBase&& in)
|
ArrayBase<T,SRanges...>& ArrayBase<T,SRanges...>::operator=(ArrayBase&& in)
|
||||||
{
|
{
|
||||||
mInit = in.mInit;
|
mInit = in.mInit;
|
||||||
mRange = in.mRange;
|
mRange = in.mRange;
|
||||||
|
@ -52,24 +52,24 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(const std::shared_ptr<SRanges>&... ranges)
|
ArrayBase<T,SRanges...>::ArrayBase(const std::shared_ptr<SRanges>&... ranges)
|
||||||
{
|
{
|
||||||
ContainerRangeFactory<T,SRanges...> crf(ranges...);
|
ContainerRangeFactory<SRanges...> crf(ranges...);
|
||||||
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
|
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
||||||
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(const typename CRange::Space& space)
|
ArrayBase<T,SRanges...>::ArrayBase(const typename CRange::Space& space)
|
||||||
{
|
{
|
||||||
ContainerRangeFactory<T,SRanges...> crf(space);
|
ContainerRangeFactory<SRanges...> crf(space);
|
||||||
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
|
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
||||||
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
template <typename X>
|
template <typename X>
|
||||||
const T& MultiArrayBase<T,SRanges...>::operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i)
|
const T& ArrayBase<T,SRanges...>::operator[](const ConstContainerIndex<X,typename SRanges::IndexType...>& i)
|
||||||
{
|
{
|
||||||
IndexType ii(*mProtoI);
|
IndexType ii(*mProtoI);
|
||||||
ii = i;
|
ii = i;
|
||||||
|
@ -77,7 +77,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
const T& MultiArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const
|
const T& ArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const
|
||||||
{
|
{
|
||||||
IndexType ii(*mProtoI);
|
IndexType ii(*mProtoI);
|
||||||
ii(is);
|
ii(is);
|
||||||
|
@ -85,70 +85,62 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
size_t MultiArrayBase<T,SRanges...>::size() const
|
size_t ArrayBase<T,SRanges...>::size() const
|
||||||
{
|
{
|
||||||
return mRange->size();
|
return mRange->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
typename MultiArrayBase<T,SRanges...>::IndexType MultiArrayBase<T,SRanges...>::begin() const
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::begin() const
|
||||||
{
|
{
|
||||||
IndexType i(*mProtoI,true);
|
return cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::end() const
|
||||||
|
{
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::cbegin() const
|
||||||
|
{
|
||||||
|
CIndexType i(*mProtoI,true);
|
||||||
i = 0;
|
i = 0;
|
||||||
return i.setData(data());
|
return i.setData(data());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
typename MultiArrayBase<T,SRanges...>::IndexType MultiArrayBase<T,SRanges...>::end() const
|
typename ArrayBase<T,SRanges...>::CIndexType ArrayBase<T,SRanges...>::cend() const
|
||||||
{
|
{
|
||||||
IndexType i(*mProtoI,true);
|
CIndexType i(*mProtoI,true);
|
||||||
i = i.max();
|
i = i.max();
|
||||||
//i = mRange->size();
|
|
||||||
return i.setData(data());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
typename MultiArrayBase<T,SRanges...>::IndexType
|
|
||||||
MultiArrayBase<T,SRanges...>::beginIndex() const
|
|
||||||
{
|
|
||||||
IndexType i(*mProtoI,true);
|
|
||||||
i = 0;
|
|
||||||
return i.setData(data());
|
return i.setData(data());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
typename MultiArrayBase<T,SRanges...>::IndexType
|
const std::shared_ptr<typename ArrayBase<T,SRanges...>::CRange>&
|
||||||
MultiArrayBase<T,SRanges...>::endIndex() const
|
ArrayBase<T,SRanges...>::range() const
|
||||||
{
|
|
||||||
IndexType i(*mProtoI,true);
|
|
||||||
i = i.max();
|
|
||||||
//i = mRange->size();
|
|
||||||
return i.setData(data());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
const std::shared_ptr<typename MultiArrayBase<T,SRanges...>::CRange>&
|
|
||||||
MultiArrayBase<T,SRanges...>::range() const
|
|
||||||
{
|
{
|
||||||
return mRange;
|
return mRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
bool MultiArrayBase<T,SRanges...>::isConst() const
|
bool ArrayBase<T,SRanges...>::isConst() const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstOperationRoot<T,SRanges...>
|
ConstOperationRoot<T,SRanges...>
|
||||||
MultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
ArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||||
{
|
{
|
||||||
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstOperationRoot<T,SRanges...>
|
ConstOperationRoot<T,SRanges...>
|
||||||
MultiArrayBase<T,SRanges...>::op(const std::shared_ptr<IndexType>& ind) const
|
ArrayBase<T,SRanges...>::op(const std::shared_ptr<CIndexType>& ind) const
|
||||||
{
|
{
|
||||||
return ConstOperationRoot<T,SRanges...>(data(), *ind);
|
return ConstOperationRoot<T,SRanges...>(data(), *ind);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +148,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
template <class... MappedRanges>
|
template <class... MappedRanges>
|
||||||
ConstOperationRoot<T,MappedRanges...>
|
ConstOperationRoot<T,MappedRanges...>
|
||||||
MultiArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
ArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
||||||
"number of mapped ranges must be equal to number of original ranges");
|
"number of mapped ranges must be equal to number of original ranges");
|
||||||
|
@ -164,14 +156,14 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
bool MultiArrayBase<T,SRanges...>::isInit() const
|
bool ArrayBase<T,SRanges...>::isInit() const
|
||||||
{
|
{
|
||||||
return mInit;
|
return mInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
auto MultiArrayBase<T,SRanges...>::getRangePtr() const
|
auto ArrayBase<T,SRanges...>::getRangePtr() const
|
||||||
-> decltype(mRange->template getPtr<N>())
|
-> decltype(mRange->template getPtr<N>())
|
||||||
{
|
{
|
||||||
return mRange->template getPtr<N>();
|
return mRange->template getPtr<N>();
|
||||||
|
@ -179,35 +171,20 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
* MutableMultiArrayBase *
|
* MutableArrayBase *
|
||||||
******************************/
|
******************************/
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MutableMultiArrayBase<T,SRanges...>::MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges) :
|
MutableArrayBase<T,SRanges...>::MutableArrayBase(const std::shared_ptr<SRanges>&... ranges) :
|
||||||
MultiArrayBase<T,SRanges...>(ranges...) {}
|
ArrayBase<T,SRanges...>(ranges...) {}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
MutableMultiArrayBase<T,SRanges...>::MutableMultiArrayBase(const typename CRange::Space& space) :
|
MutableArrayBase<T,SRanges...>::MutableArrayBase(const typename CRange::Space& space) :
|
||||||
MultiArrayBase<T,SRanges...>(space) {}
|
ArrayBase<T,SRanges...>(space) {}
|
||||||
/*
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
typename MutableMultiArrayBase<T,SRanges...>::IndexType MutableMultiArrayBase<T,SRanges...>::begin()
|
|
||||||
{
|
|
||||||
auto i = mRange->begin();
|
|
||||||
return i.setData(data());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
typename MutableMultiArrayBase<T,SRanges...>::IndexType MutableMultiArrayBase<T,SRanges...>::end()
|
|
||||||
{
|
|
||||||
auto i = mRange->end();
|
|
||||||
return i.setData(data());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
template <typename X>
|
template <typename X>
|
||||||
T& MutableMultiArrayBase<T,SRanges...>::operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i)
|
T& MutableArrayBase<T,SRanges...>::operator[](const ConstContainerIndex<X,typename SRanges::IndexType...>& i)
|
||||||
{
|
{
|
||||||
IndexType ii(*MAB::mProtoI);
|
IndexType ii(*MAB::mProtoI);
|
||||||
ii = i;
|
ii = i;
|
||||||
|
@ -215,44 +192,60 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
T& MutableMultiArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is)
|
T& MutableArrayBase<T,SRanges...>::operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is)
|
||||||
{
|
{
|
||||||
IndexType ii(*MAB::mProtoI);
|
IndexType ii(*MAB::mProtoI,this->data());
|
||||||
ii(is);
|
ii(is);
|
||||||
return (*this)[ii];
|
return (*this)[ii];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
typename MutableArrayBase<T,SRanges...>::IndexType MutableArrayBase<T,SRanges...>::begin()
|
||||||
|
{
|
||||||
|
IndexType i(*MAB::mProtoI,this->data(),true);
|
||||||
|
i = 0;
|
||||||
|
return i.setData(data());
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
bool MutableMultiArrayBase<T,SRanges...>::isConst() const
|
typename MutableArrayBase<T,SRanges...>::IndexType MutableArrayBase<T,SRanges...>::end()
|
||||||
|
{
|
||||||
|
IndexType i(*MAB::mProtoI,this->data(),true);
|
||||||
|
i = i.max();
|
||||||
|
return i.setData(data());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
bool MutableArrayBase<T,SRanges...>::isConst() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
OperationRoot<T,SRanges...>
|
OperationRoot<T,SRanges...>
|
||||||
MutableMultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
MutableArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||||
{
|
{
|
||||||
return OperationRoot<T,SRanges...>(*this, inds...);
|
return OperationRoot<T,SRanges...>(*this, inds...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
OperationRoot<T,SRanges...>
|
OperationRoot<T,SRanges...>
|
||||||
MutableMultiArrayBase<T,SRanges...>::op(const std::shared_ptr<IndexType>& ind)
|
MutableArrayBase<T,SRanges...>::op(const std::shared_ptr<CIndexType>& ind)
|
||||||
{
|
{
|
||||||
return OperationRoot<T,SRanges...>(data(), *ind);
|
return OperationRoot<T,SRanges...>(data(), *ind);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstOperationRoot<T,SRanges...>
|
ConstOperationRoot<T,SRanges...>
|
||||||
MutableMultiArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
MutableArrayBase<T,SRanges...>::operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||||
{
|
{
|
||||||
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
return ConstOperationRoot<T,SRanges...>(*this, inds...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstOperationRoot<T,SRanges...>
|
ConstOperationRoot<T,SRanges...>
|
||||||
MutableMultiArrayBase<T,SRanges...>::op(const std::shared_ptr<IndexType>& ind) const
|
MutableArrayBase<T,SRanges...>::op(const std::shared_ptr<CIndexType>& ind) const
|
||||||
{
|
{
|
||||||
return ConstOperationRoot<T,SRanges...>(data(), *ind);
|
return ConstOperationRoot<T,SRanges...>(data(), *ind);
|
||||||
}
|
}
|
||||||
|
@ -260,7 +253,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
template <class... MappedRanges>
|
template <class... MappedRanges>
|
||||||
OperationRoot<T,MappedRanges...>
|
OperationRoot<T,MappedRanges...>
|
||||||
MutableMultiArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds)
|
MutableArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds)
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
||||||
"number of mapped ranges must be equal to number of original ranges");
|
"number of mapped ranges must be equal to number of original ranges");
|
||||||
|
@ -270,12 +263,12 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
template <class... MappedRanges>
|
template <class... MappedRanges>
|
||||||
ConstOperationRoot<T,MappedRanges...>
|
ConstOperationRoot<T,MappedRanges...>
|
||||||
MutableMultiArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
MutableArrayBase<T,SRanges...>::m(const std::shared_ptr<typename MappedRanges::IndexType>&... inds) const
|
||||||
{
|
{
|
||||||
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
static_assert(sizeof...(SRanges) == sizeof...(MappedRanges),
|
||||||
"number of mapped ranges must be equal to number of original ranges");
|
"number of mapped ranges must be equal to number of original ranges");
|
||||||
return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
|
return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __multi_array_base_h__
|
#ifndef __cxz_array_base_h__
|
||||||
#define __multi_array_base_h__
|
#define __cxz_array_base_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
|
@ -51,38 +51,39 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
// Explicitely specify subranges in template argument !!!
|
// Explicitely specify subranges in template argument !!!
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
class MultiArrayBase
|
class ArrayBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
typedef ContainerRange<T,SRanges...> CRange;
|
typedef ContainerRange<SRanges...> CRange;
|
||||||
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> CIndexType;
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool mInit = false;
|
bool mInit = false;
|
||||||
std::shared_ptr<CRange> mRange;
|
std::shared_ptr<CRange> mRange;
|
||||||
std::shared_ptr<IndexType> mProtoI;
|
std::shared_ptr<CIndexType> mProtoI;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//DEFAULT_MEMBERS(MultiArrayBase);
|
//DEFAULT_MEMBERS(ArrayBase);
|
||||||
MultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
ArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||||
MultiArrayBase(const typename CRange::Space& space);
|
ArrayBase(const typename CRange::Space& space);
|
||||||
|
|
||||||
MultiArrayBase() = default;
|
ArrayBase() = default;
|
||||||
MultiArrayBase(const MultiArrayBase& in);
|
ArrayBase(const ArrayBase& in);
|
||||||
MultiArrayBase(MultiArrayBase&& in);
|
ArrayBase(ArrayBase&& in);
|
||||||
MultiArrayBase& operator=(const MultiArrayBase& in);
|
ArrayBase& operator=(const ArrayBase& in);
|
||||||
MultiArrayBase& operator=(MultiArrayBase&& in);
|
ArrayBase& operator=(ArrayBase&& in);
|
||||||
|
|
||||||
virtual ~MultiArrayBase() = default;
|
virtual ~ArrayBase() = default;
|
||||||
|
|
||||||
template <typename X>
|
template <typename X>
|
||||||
const T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
|
const T& operator[](const ConstContainerIndex<X,typename SRanges::IndexType...>& i);
|
||||||
const T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const;
|
const T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is) const;
|
||||||
|
|
||||||
virtual const T& operator[](const IndexType& i) const = 0;
|
virtual const T& operator[](const CIndexType& i) const = 0;
|
||||||
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0;
|
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const = 0;
|
||||||
|
|
||||||
virtual const T* data() const = 0;
|
virtual const T* data() const = 0;
|
||||||
|
@ -90,20 +91,19 @@ namespace MultiArrayTools
|
||||||
virtual size_t size() const;
|
virtual size_t size() const;
|
||||||
virtual bool isSlice() const = 0;
|
virtual bool isSlice() const = 0;
|
||||||
|
|
||||||
virtual IndexType begin() const;
|
virtual CIndexType begin() const;
|
||||||
virtual IndexType end() const;
|
virtual CIndexType end() const;
|
||||||
|
virtual CIndexType cbegin() const;
|
||||||
|
virtual CIndexType cend() const;
|
||||||
|
|
||||||
virtual IndexType beginIndex() const;
|
|
||||||
virtual IndexType endIndex() const;
|
|
||||||
|
|
||||||
virtual const std::shared_ptr<CRange>& range() const;
|
virtual const std::shared_ptr<CRange>& range() const;
|
||||||
|
|
||||||
virtual bool isConst() const;
|
virtual bool isConst() const;
|
||||||
|
|
||||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const = 0;
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const = 0;
|
||||||
|
|
||||||
virtual ConstOperationRoot<T,SRanges...>
|
virtual ConstOperationRoot<T,SRanges...>
|
||||||
op(const std::shared_ptr<IndexType>& ind) const;
|
op(const std::shared_ptr<CIndexType>& ind) const;
|
||||||
|
|
||||||
virtual ConstOperationRoot<T,SRanges...>
|
virtual ConstOperationRoot<T,SRanges...>
|
||||||
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const;
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const;
|
||||||
|
@ -121,48 +121,49 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
class MutableMultiArrayBase : public MultiArrayBase<T,SRanges...>
|
class MutableArrayBase : public ArrayBase<T,SRanges...>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef ContainerRange<T,SRanges...> CRange;
|
typedef ContainerRange<SRanges...> CRange;
|
||||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
typedef ArrayBase<T,SRanges...> MAB;
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
||||||
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> CIndexType;
|
||||||
|
|
||||||
using MultiArrayBase<T,SRanges...>::operator[];
|
using ArrayBase<T,SRanges...>::operator[];
|
||||||
using MultiArrayBase<T,SRanges...>::at;
|
using ArrayBase<T,SRanges...>::at;
|
||||||
using MultiArrayBase<T,SRanges...>::data;
|
using ArrayBase<T,SRanges...>::data;
|
||||||
using MultiArrayBase<T,SRanges...>::begin;
|
using ArrayBase<T,SRanges...>::begin;
|
||||||
using MultiArrayBase<T,SRanges...>::end;
|
using ArrayBase<T,SRanges...>::end;
|
||||||
|
using ArrayBase<T,SRanges...>::cbegin;
|
||||||
|
using ArrayBase<T,SRanges...>::cend;
|
||||||
|
|
||||||
DEFAULT_MEMBERS(MutableMultiArrayBase);
|
DEFAULT_MEMBERS(MutableArrayBase);
|
||||||
MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
MutableArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||||
MutableMultiArrayBase(const typename CRange::Space& space);
|
MutableArrayBase(const typename CRange::Space& space);
|
||||||
|
|
||||||
template <typename X>
|
template <typename X>
|
||||||
T& operator[](const ContainerIndex<X,typename SRanges::IndexType...>& i);
|
T& operator[](const ConstContainerIndex<X,typename SRanges::IndexType...>& i);
|
||||||
T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is);
|
T& operator[](const std::tuple<IPTR<typename SRanges::IndexType>...>& is);
|
||||||
|
|
||||||
virtual T& operator[](const IndexType& i) = 0;
|
virtual T& operator[](const CIndexType& i) = 0;
|
||||||
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
|
virtual T& at(const typename CRange::IndexType::MetaType& meta) = 0;
|
||||||
|
|
||||||
virtual T* data() = 0;
|
virtual T* data() = 0;
|
||||||
|
|
||||||
//virtual IndexType begin();
|
virtual IndexType begin();
|
||||||
//virtual IndexType end();
|
virtual IndexType end();
|
||||||
|
|
||||||
virtual bool isConst() const override;
|
virtual bool isConst() const override;
|
||||||
|
|
||||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() = 0;
|
|
||||||
|
|
||||||
virtual ConstOperationRoot<T,SRanges...>
|
virtual ConstOperationRoot<T,SRanges...>
|
||||||
op(const std::shared_ptr<IndexType>& ind) const override;
|
op(const std::shared_ptr<CIndexType>& ind) const override;
|
||||||
|
|
||||||
virtual ConstOperationRoot<T,SRanges...>
|
virtual ConstOperationRoot<T,SRanges...>
|
||||||
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
||||||
|
|
||||||
virtual OperationRoot<T,SRanges...>
|
virtual OperationRoot<T,SRanges...>
|
||||||
op(const std::shared_ptr<IndexType>& ind);
|
op(const std::shared_ptr<CIndexType>& ind);
|
||||||
|
|
||||||
virtual OperationRoot<T,SRanges...> operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds);
|
virtual OperationRoot<T,SRanges...> operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds);
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,7 @@
|
||||||
#include "dynamic_operation.h"
|
#include "dynamic_operation.h"
|
||||||
#include "helper_tools.h"
|
#include "helper_tools.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
template <typename T, class Operation>
|
template <typename T, class Operation>
|
||||||
T DynamicOperation<T,Operation>::get(const DExtT& pos) const
|
T DynamicOperation<T,Operation>::get(const DExtT& pos) const
|
||||||
|
@ -45,7 +45,7 @@ namespace MultiArrayTools
|
||||||
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const DynamicOuterOp& in) :
|
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const DynamicOuterOp& in) :
|
||||||
mThreadId(omp_get_thread_num()), mOp(in.mOp),
|
mThreadId(omp_get_thread_num()), mOp(in.mOp),
|
||||||
mIndices(in.mIndices),
|
mIndices(in.mIndices),
|
||||||
mMa((mThreadId != in.mThreadId) ? std::make_shared<MultiArray<T,Ranges...>>(*in.mMa) : in.mMa),
|
mMa((mThreadId != in.mThreadId) ? std::make_shared<Array<T,Ranges...>>(*in.mMa) : in.mMa),
|
||||||
mProto((mThreadId != in.mThreadId) ? OperationRoot<T,Ranges...>(*mMa,mIndices) : in.mProto),
|
mProto((mThreadId != in.mThreadId) ? OperationRoot<T,Ranges...>(*mMa,mIndices) : in.mProto),
|
||||||
mL((mThreadId != in.mThreadId) ?
|
mL((mThreadId != in.mThreadId) ?
|
||||||
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||||
|
@ -60,7 +60,7 @@ namespace MultiArrayTools
|
||||||
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(DynamicOuterOp&& in) :
|
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(DynamicOuterOp&& in) :
|
||||||
mThreadId(omp_get_thread_num()), mOp(in.mOp),
|
mThreadId(omp_get_thread_num()), mOp(in.mOp),
|
||||||
mIndices(in.mIndices),
|
mIndices(in.mIndices),
|
||||||
mMa((mThreadId != in.mThreadId) ? std::make_shared<MultiArray<T,Ranges...>>(*in.mMa) : in.mMa),
|
mMa((mThreadId != in.mThreadId) ? std::make_shared<Array<T,Ranges...>>(*in.mMa) : in.mMa),
|
||||||
mProto((mThreadId != in.mThreadId) ? OperationRoot<T,Ranges...>(*mMa,mIndices) : in.mProto),
|
mProto((mThreadId != in.mThreadId) ? OperationRoot<T,Ranges...>(*mMa,mIndices) : in.mProto),
|
||||||
mL((mThreadId != in.mThreadId) ?
|
mL((mThreadId != in.mThreadId) ?
|
||||||
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||||
|
@ -79,7 +79,7 @@ namespace MultiArrayTools
|
||||||
mOp = in.mOp;
|
mOp = in.mOp;
|
||||||
mIndices = in.mIndices;
|
mIndices = in.mIndices;
|
||||||
if(mThreadId != in.mThreadId){
|
if(mThreadId != in.mThreadId){
|
||||||
mMa = std::make_shared<MultiArray<T,Ranges...>>(in.mMa);
|
mMa = std::make_shared<Array<T,Ranges...>>(in.mMa);
|
||||||
mProto = OperationRoot<T,Ranges...>(*mMa,mIndices);
|
mProto = OperationRoot<T,Ranges...>(*mMa,mIndices);
|
||||||
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||||
std::make_tuple(mMa),
|
std::make_tuple(mMa),
|
||||||
|
@ -103,7 +103,7 @@ namespace MultiArrayTools
|
||||||
mOp = in.mOp;
|
mOp = in.mOp;
|
||||||
mIndices = in.mIndices;
|
mIndices = in.mIndices;
|
||||||
if(mThreadId != in.mThreadId){
|
if(mThreadId != in.mThreadId){
|
||||||
mMa = std::make_shared<MultiArray<T,Ranges...>>(in.mMa);
|
mMa = std::make_shared<Array<T,Ranges...>>(in.mMa);
|
||||||
mProto = OperationRoot<T,Ranges...>(*mMa,mIndices);
|
mProto = OperationRoot<T,Ranges...>(*mMa,mIndices);
|
||||||
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||||
std::make_tuple(mMa),
|
std::make_tuple(mMa),
|
||||||
|
@ -124,7 +124,7 @@ namespace MultiArrayTools
|
||||||
const std::shared_ptr<typename Ranges::IndexType>&... inds)
|
const std::shared_ptr<typename Ranges::IndexType>&... inds)
|
||||||
: mThreadId(omp_get_thread_num()), mOp(op),
|
: mThreadId(omp_get_thread_num()), mOp(op),
|
||||||
mIndices(inds...),
|
mIndices(inds...),
|
||||||
mMa(std::make_shared<MultiArray<T,Ranges...>>(mkArray<T>(inds->range()...))),
|
mMa(std::make_shared<Array<T,Ranges...>>(mkArray<T>(inds->range()...))),
|
||||||
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
|
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
|
||||||
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
|
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
|
||||||
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
|
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
|
||||||
|
@ -137,7 +137,7 @@ namespace MultiArrayTools
|
||||||
: mThreadId(omp_get_thread_num()),
|
: mThreadId(omp_get_thread_num()),
|
||||||
//mDyn(dyn),
|
//mDyn(dyn),
|
||||||
mOp(op), mIndices(inds...),
|
mOp(op), mIndices(inds...),
|
||||||
mMa(std::make_shared<MultiArray<T,Ranges...>>(mkArray<T>(inds->range()...))),
|
mMa(std::make_shared<Array<T,Ranges...>>(mkArray<T>(inds->range()...))),
|
||||||
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
|
mProto(OperationRoot<T,Ranges...>(*mMa,inds...)),
|
||||||
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
|
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(inds...),
|
||||||
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
|
std::make_tuple(mMa), std::make_tuple(mProto.mOp->assign( mOp, mkMIndex(inds...) )),
|
||||||
|
@ -195,4 +195,4 @@ namespace MultiArrayTools
|
||||||
return std::make_shared<DynamicOuterOp<T,Operation,Ranges...>>(*this);
|
return std::make_shared<DynamicOuterOp<T,Operation,Ranges...>>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
#ifndef __dynamic_operation_h__
|
#ifndef __cxz_dynamic_operation_h__
|
||||||
#define __dynamic_operation_h__
|
#define __cxz_dynamic_operation_h__
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "multi_array_operation.h"
|
#include "cxz_operation.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -17,6 +17,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
static constexpr size_t SIZE = 1;
|
static constexpr size_t SIZE = 1;
|
||||||
static constexpr bool CONT = true;
|
static constexpr bool CONT = true;
|
||||||
|
static constexpr bool VABLE = false;
|
||||||
|
|
||||||
DynamicOperationBase() = default;
|
DynamicOperationBase() = default;
|
||||||
DynamicOperationBase(const DynamicOperationBase& in) = default;
|
DynamicOperationBase(const DynamicOperationBase& in) = default;
|
||||||
|
@ -76,13 +77,13 @@ namespace MultiArrayTools
|
||||||
Operation mOp;
|
Operation mOp;
|
||||||
//OperationRoot<T,Ranges...> mProto;
|
//OperationRoot<T,Ranges...> mProto;
|
||||||
std::tuple<std::shared_ptr<typename Ranges::IndexType>...> mIndices;
|
std::tuple<std::shared_ptr<typename Ranges::IndexType>...> mIndices;
|
||||||
std::shared_ptr<MultiArray<T,Ranges...>> mMa;
|
std::shared_ptr<Array<T,Ranges...>> mMa;
|
||||||
OpH<OperationRoot<T,Ranges...>> mProto;
|
OpH<OperationRoot<T,Ranges...>> mProto;
|
||||||
|
|
||||||
|
|
||||||
typedef ILoop<std::tuple<OperationRoot<T,Ranges...>,Operation>,
|
typedef ILoop<std::tuple<OperationRoot<T,Ranges...>,Operation>,
|
||||||
std::tuple<std::shared_ptr<typename Ranges::IndexType>...>,
|
std::tuple<std::shared_ptr<typename Ranges::IndexType>...>,
|
||||||
std::tuple<std::shared_ptr<MultiArray<T,Ranges...>>>,
|
std::tuple<std::shared_ptr<Array<T,Ranges...>>>,
|
||||||
std::tuple<decltype(mProto.mOp->assign( mOp, mkMIndex(std::shared_ptr<typename Ranges::IndexType>()...) ))>> LoopT;
|
std::tuple<decltype(mProto.mOp->assign( mOp, mkMIndex(std::shared_ptr<typename Ranges::IndexType>()...) ))>> LoopT;
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,6 +126,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
static constexpr size_t SIZE = 1;
|
static constexpr size_t SIZE = 1;
|
||||||
static constexpr bool CONT = true;
|
static constexpr bool CONT = true;
|
||||||
|
static constexpr bool VABLE = false;
|
||||||
|
|
||||||
DynamicO() = default;
|
DynamicO() = default;
|
||||||
DynamicO(const DynamicO& in) : mOp(in.mOp ? in.mOp->deepCopy() : nullptr) {}
|
DynamicO(const DynamicO& in) : mOp(in.mOp ? in.mOp->deepCopy() : nullptr) {}
|
||||||
|
@ -144,6 +146,11 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
inline T get(const DExtTX<X>& pos) const { return mOp->get(pos.reduce()); }
|
inline T get(const DExtTX<X>& pos) const { return mOp->get(pos.reduce()); }
|
||||||
|
|
||||||
|
template <typename V,class X>
|
||||||
|
inline auto vget(const DExtTX<X>& pos) const
|
||||||
|
{ return mOp->template vget<V>(pos.reduce()); }
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
inline DynamicO& set(const DExtTX<X>& pos) { mOp->set(pos.reduce()); return *this; }
|
inline DynamicO& set(const DExtTX<X>& pos) { mOp->set(pos.reduce()); return *this; }
|
||||||
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return mOp->rootSteps(iPtrNum); }
|
inline DExtT rootSteps(std::intptr_t iPtrNum = 0) const { return mOp->rootSteps(iPtrNum); }
|
||||||
|
@ -197,6 +204,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,29 +2,5 @@
|
||||||
#ifdef regFunc1
|
#ifdef regFunc1
|
||||||
|
|
||||||
regFunc1(exp)
|
regFunc1(exp)
|
||||||
regFunc1(exp2)
|
|
||||||
regFunc1(expm1)
|
|
||||||
regFunc1(log)
|
|
||||||
regFunc1(log10)
|
|
||||||
regFunc1(log2)
|
|
||||||
regFunc1(log1p)
|
|
||||||
regFunc1(sqrt)
|
|
||||||
regFunc1(cbrt)
|
|
||||||
regFunc1(sin)
|
|
||||||
regFunc1(cos)
|
|
||||||
regFunc1(tan)
|
|
||||||
regFunc1(asin)
|
|
||||||
regFunc1(acos)
|
|
||||||
regFunc1(atan)
|
|
||||||
regFunc1(sinh)
|
|
||||||
regFunc1(cosh)
|
|
||||||
regFunc1(tanh)
|
|
||||||
regFunc1(asinh)
|
|
||||||
regFunc1(acosh)
|
|
||||||
regFunc1(atanh)
|
|
||||||
regFunc1(erf)
|
|
||||||
regFunc1(erfc)
|
|
||||||
regFunc1(tgamma)
|
|
||||||
regFunc1(lgamma)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
99
src/include/functional_array.cc.h
Normal file
99
src/include/functional_array.cc.h
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
|
||||||
|
#include "functional_array.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/****************************
|
||||||
|
* FunctionalArray *
|
||||||
|
****************************/
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const std::shared_ptr<SRanges>&... ranges,
|
||||||
|
const std::shared_ptr<Function>& func) :
|
||||||
|
ArrayBase<T,SRanges...>(ranges...), mFunc(func) {}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const std::shared_ptr<SRanges>&... ranges) :
|
||||||
|
ArrayBase<T,SRanges...>(ranges...) {}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const typename CRange::Space& space) :
|
||||||
|
ArrayBase<T,SRanges...>(space) {}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const typename CRange::Space& space,
|
||||||
|
const std::shared_ptr<Function>& func) :
|
||||||
|
ArrayBase<T,SRanges...>(space), mFunc(func) {}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
const T& FunctionalArray<T,Function,SRanges...>::operator[](const IndexType& i) const
|
||||||
|
{
|
||||||
|
if constexpr(Function::FISSTATIC){
|
||||||
|
mVal = Function::apply(i.meta());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mVal = (*mFunc)(i.meta());
|
||||||
|
}
|
||||||
|
return mVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
const T& FunctionalArray<T,Function,SRanges...>::at(const typename CRange::IndexType::MetaType& meta) const
|
||||||
|
{
|
||||||
|
if constexpr(Function::FISSTATIC){
|
||||||
|
mVal = Function::apply(meta);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mVal = (*mFunc)(meta);
|
||||||
|
}
|
||||||
|
return mVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
const T* FunctionalArray<T,Function,SRanges...>::data() const
|
||||||
|
{
|
||||||
|
return &mVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
bool FunctionalArray<T,Function,SRanges...>::isConst() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
bool FunctionalArray<T,Function,SRanges...>::isSlice() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
std::shared_ptr<ArrayBase<T,AnonymousRange> > FunctionalArray<T,Function,SRanges...>::anonymous(bool slice) const
|
||||||
|
{
|
||||||
|
assert(0); // think about it carefully
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
ConstOperationRoot<T,SRanges...> FunctionalArray<T,Function,SRanges...>::
|
||||||
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||||
|
{
|
||||||
|
if(not mMaPtr){
|
||||||
|
mMaPtr = std::make_shared<MAType>( MAB::mRange->space() );
|
||||||
|
(*mMaPtr)(inds...) = exec(inds...);
|
||||||
|
}
|
||||||
|
return ConstOperationRoot<T,SRanges...>( *mMaPtr, inds... );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
auto FunctionalArray<T,Function,SRanges...>::
|
||||||
|
exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||||
|
-> Operation<T,Function,MetaOperationRoot<SRanges>...>
|
||||||
|
{
|
||||||
|
return mkOperation( mFunc, MetaOperationRoot<SRanges>( inds ) ... );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CNORXZ
|
61
src/include/functional_array.h
Normal file
61
src/include/functional_array.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
|
||||||
|
#ifndef __cxz_functional_array__
|
||||||
|
#define __cxz_functional_array__
|
||||||
|
|
||||||
|
#include "cxz_array_base.h"
|
||||||
|
#include "slice.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T, class Function, class... SRanges>
|
||||||
|
class FunctionalArray : public ArrayBase<T,SRanges...>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef ContainerRange<SRanges...> CRange;
|
||||||
|
typedef ArrayBase<T,SRanges...> MAB;
|
||||||
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
||||||
|
typedef Array<T,SRanges...> MAType;
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable T mVal;
|
||||||
|
std::shared_ptr<Function> mFunc;
|
||||||
|
|
||||||
|
mutable std::shared_ptr<MAType> mMaPtr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
DEFAULT_MEMBERS(FunctionalArray);
|
||||||
|
FunctionalArray(const std::shared_ptr<SRanges>&... ranges, const std::shared_ptr<Function>& func);
|
||||||
|
FunctionalArray(const std::shared_ptr<SRanges>&... ranges);
|
||||||
|
FunctionalArray(const typename CRange::Space& space);
|
||||||
|
FunctionalArray(const typename CRange::Space& space, const std::shared_ptr<Function>& func);
|
||||||
|
|
||||||
|
virtual const T& operator[](const IndexType& i) const override;
|
||||||
|
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
|
||||||
|
virtual const T* data() const override;
|
||||||
|
|
||||||
|
virtual bool isConst() const override;
|
||||||
|
virtual bool isSlice() const override;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||||
|
|
||||||
|
auto exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
||||||
|
-> Operation<T,Function,MetaOperationRoot<SRanges>...>;
|
||||||
|
|
||||||
|
virtual ConstOperationRoot<T,SRanges...>
|
||||||
|
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace CNORXZ
|
||||||
|
|
||||||
|
/* ========================= *
|
||||||
|
* --- TEMPLATE CODE --- *
|
||||||
|
* ========================= */
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,109 +0,0 @@
|
||||||
|
|
||||||
#include "functional_multi_array.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/****************************
|
|
||||||
* FunctionalMultiArray *
|
|
||||||
****************************/
|
|
||||||
|
|
||||||
template <bool FISSTATIC>
|
|
||||||
struct Application
|
|
||||||
{
|
|
||||||
template <typename T, class Function, typename Meta>
|
|
||||||
static inline T apply(const std::shared_ptr<Function>& f, const Meta& m)
|
|
||||||
{
|
|
||||||
return (*f)(m);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct Application<true>
|
|
||||||
{
|
|
||||||
template <typename T, class Function, typename Meta>
|
|
||||||
static inline T apply(const std::shared_ptr<Function>& f, const Meta& m)
|
|
||||||
{
|
|
||||||
return Function::apply(m);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges,
|
|
||||||
const std::shared_ptr<Function>& func) :
|
|
||||||
MultiArrayBase<T,SRanges...>(ranges...), mFunc(func) {}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges) :
|
|
||||||
MultiArrayBase<T,SRanges...>(ranges...) {}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const typename CRange::Space& space) :
|
|
||||||
MultiArrayBase<T,SRanges...>(space) {}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
FunctionalMultiArray<T,Function,SRanges...>::FunctionalMultiArray(const typename CRange::Space& space,
|
|
||||||
const std::shared_ptr<Function>& func) :
|
|
||||||
MultiArrayBase<T,SRanges...>(space), mFunc(func) {}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
const T& FunctionalMultiArray<T,Function,SRanges...>::operator[](const IndexType& i) const
|
|
||||||
{
|
|
||||||
mVal = Application<Function::FISSTATIC>::template apply<T,Function,typename IndexType::MetaType>(mFunc, i.meta());
|
|
||||||
return mVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
const T& FunctionalMultiArray<T,Function,SRanges...>::at(const typename CRange::IndexType::MetaType& meta) const
|
|
||||||
{
|
|
||||||
mVal = Application<Function::FISSTATIC>::template apply<T,Function,typename IndexType::MetaType>(mFunc,meta);
|
|
||||||
return mVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
const T* FunctionalMultiArray<T,Function,SRanges...>::data() const
|
|
||||||
{
|
|
||||||
return &mVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
bool FunctionalMultiArray<T,Function,SRanges...>::isConst() const
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
bool FunctionalMultiArray<T,Function,SRanges...>::isSlice() const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > FunctionalMultiArray<T,Function,SRanges...>::anonymous(bool slice) const
|
|
||||||
{
|
|
||||||
assert(0); // think about it carefully
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
ConstOperationRoot<T,SRanges...> FunctionalMultiArray<T,Function,SRanges...>::
|
|
||||||
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
|
||||||
{
|
|
||||||
if(not mMaPtr){
|
|
||||||
mMaPtr = std::make_shared<MAType>( MAB::mRange->space() );
|
|
||||||
(*mMaPtr)(inds...) = exec(inds...);
|
|
||||||
}
|
|
||||||
return ConstOperationRoot<T,SRanges...>( *mMaPtr, inds... );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
auto FunctionalMultiArray<T,Function,SRanges...>::
|
|
||||||
exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
|
||||||
-> Operation<T,Function,MetaOperationRoot<SRanges>...>
|
|
||||||
{
|
|
||||||
return mkOperation( mFunc, MetaOperationRoot<SRanges>( inds ) ... );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
|
|
@ -1,127 +0,0 @@
|
||||||
|
|
||||||
#ifndef __functional_multi_array__
|
|
||||||
#define __functional_multi_array__
|
|
||||||
|
|
||||||
#include "multi_array_base.h"
|
|
||||||
#include "slice.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
|
|
||||||
template <bool HASMETACONT>
|
|
||||||
struct ToMAObject
|
|
||||||
{
|
|
||||||
template <class Index>
|
|
||||||
static auto mk(const std::shared_ptr<Index>& i)
|
|
||||||
-> MultiArray<typename Index::MetaType, typename Index::RangeType>
|
|
||||||
{
|
|
||||||
assert(0); // deprecated
|
|
||||||
vector<typename Index::MetaType> vv(i->range()->size());
|
|
||||||
for(Index j = (*i); j.pos() != j.max(); ++j){
|
|
||||||
vv[j.pos()] = j.meta();
|
|
||||||
}
|
|
||||||
return MultiArray<typename Index::MetaType, typename Index::RangeType>( i->range(), vv );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct ToMAObject<true>
|
|
||||||
{
|
|
||||||
template <class Index>
|
|
||||||
static auto mk(const std::shared_ptr<Index>& i)
|
|
||||||
-> ConstSlice<typename Index::MetaType, typename Index::RangeType>
|
|
||||||
{
|
|
||||||
return ConstSlice<typename Index::MetaType, typename Index::RangeType>( i->range(), i->metaPtr() );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
auto mkMAObject(const std::shared_ptr<Index>& i)
|
|
||||||
-> std::shared_ptr<decltype(ToMAObject<Index::RangeType::HASMETACONT>::mk(i))>
|
|
||||||
{
|
|
||||||
return std::make_shared<decltype(ToMAObject<Index::RangeType::HASMETACONT>::mk(i))>
|
|
||||||
(ToMAObject<Index::RangeType::HASMETACONT>::mk(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <bool HASMETACONT>
|
|
||||||
struct ToOpObject
|
|
||||||
{
|
|
||||||
template <class Index>
|
|
||||||
static auto mk(const std::shared_ptr<Index>& ind)
|
|
||||||
-> ConstOperationRoot<typename Index::MetaType,
|
|
||||||
typename Index::RangeType>
|
|
||||||
{
|
|
||||||
return ConstOperationRoot<typename Index::MetaType,
|
|
||||||
typename Index::RangeType>( mkMAObject(ind), ind);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct ToOpObject<false>
|
|
||||||
{
|
|
||||||
template <class Index>
|
|
||||||
static auto mk(const std::shared_ptr<Index>& ind)
|
|
||||||
-> MetaOperationRoot<typename Index::RangeType>
|
|
||||||
{
|
|
||||||
return MetaOperationRoot<typename Index::RangeType>( ind );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
auto mkOpObject(const std::shared_ptr<Index>& i)
|
|
||||||
-> decltype(ToOpObject<Index::RangeType::HASMETACONT>::mk(i))
|
|
||||||
{
|
|
||||||
return ToOpObject<Index::RangeType::HASMETACONT>::mk(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Function, class... SRanges>
|
|
||||||
class FunctionalMultiArray : public MultiArrayBase<T,SRanges...>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef ContainerRange<T,SRanges...> CRange;
|
|
||||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
|
||||||
typedef MultiArray<T,SRanges...> MAType;
|
|
||||||
typedef T value_type;
|
|
||||||
|
|
||||||
private:
|
|
||||||
mutable T mVal;
|
|
||||||
std::shared_ptr<Function> mFunc;
|
|
||||||
|
|
||||||
mutable std::shared_ptr<MAType> mMaPtr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DEFAULT_MEMBERS(FunctionalMultiArray);
|
|
||||||
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges, const std::shared_ptr<Function>& func);
|
|
||||||
FunctionalMultiArray(const std::shared_ptr<SRanges>&... ranges);
|
|
||||||
FunctionalMultiArray(const typename CRange::Space& space);
|
|
||||||
FunctionalMultiArray(const typename CRange::Space& space, const std::shared_ptr<Function>& func);
|
|
||||||
|
|
||||||
virtual const T& operator[](const IndexType& i) const override;
|
|
||||||
virtual const T& at(const typename CRange::IndexType::MetaType& meta) const override;
|
|
||||||
virtual const T* data() const override;
|
|
||||||
|
|
||||||
virtual bool isConst() const override;
|
|
||||||
virtual bool isSlice() const override;
|
|
||||||
|
|
||||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
|
||||||
|
|
||||||
auto exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
|
||||||
-> Operation<T,Function,MetaOperationRoot<SRanges>...>;
|
|
||||||
|
|
||||||
virtual ConstOperationRoot<T,SRanges...>
|
|
||||||
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
|
||||||
|
|
||||||
/* ========================= *
|
|
||||||
* --- TEMPLATE CODE --- *
|
|
||||||
* ========================= */
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,12 +1,13 @@
|
||||||
|
|
||||||
#include "helper_tools.h"
|
#include "helper_tools.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
|
std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& tp)
|
||||||
{
|
{
|
||||||
PackNum<sizeof...(T)-1>::printTuple(out, tp);
|
sfor_pn<0,sizeof...(T)-1>( [&](auto i){ out << std::get<i>(tp) << ", "; return 0; } );
|
||||||
|
out << std::get<sizeof...(T)-1>(tp);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +22,7 @@ namespace MultiArrayTools
|
||||||
auto getIndex()
|
auto getIndex()
|
||||||
-> std::shared_ptr<typename RangeType::IndexType>
|
-> std::shared_ptr<typename RangeType::IndexType>
|
||||||
{
|
{
|
||||||
static_assert( RangeType::defaultable,
|
static_assert( RangeType::defaultable, "Range not defaultable" );
|
||||||
/*typeid(typename RangeType).name() + */" is not defaultable" );
|
|
||||||
static auto f = RangeType::factory();
|
static auto f = RangeType::factory();
|
||||||
static auto r = std::dynamic_pointer_cast<RangeType>( f.create() );
|
static auto r = std::dynamic_pointer_cast<RangeType>( f.create() );
|
||||||
return std::make_shared<typename RangeType::IndexType>(r);
|
return std::make_shared<typename RangeType::IndexType>(r);
|
||||||
|
@ -237,7 +237,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class MArray>
|
template <class MArray>
|
||||||
auto dynamic(const MArray& ma, bool slice)
|
auto dynamic(const MArray& ma, bool slice)
|
||||||
-> std::shared_ptr<MultiArrayBase<typename MArray::value_type,DynamicRange>>
|
-> std::shared_ptr<ArrayBase<typename MArray::value_type,DynamicRange>>
|
||||||
{
|
{
|
||||||
DynamicRangeFactory drf(ma.range()->space());
|
DynamicRangeFactory drf(ma.range()->space());
|
||||||
if(slice){
|
if(slice){
|
||||||
|
@ -246,7 +246,7 @@ namespace MultiArrayTools
|
||||||
ma.data() );
|
ma.data() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return std::make_shared<MultiArray<typename MArray::value_type,DynamicRange>>
|
return std::make_shared<Array<typename MArray::value_type,DynamicRange>>
|
||||||
( std::dynamic_pointer_cast<DynamicRange>( drf.create() ),
|
( std::dynamic_pointer_cast<DynamicRange>( drf.create() ),
|
||||||
ma.vdata() );
|
ma.vdata() );
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class MArray>
|
template <class MArray>
|
||||||
auto mdynamic(MArray& ma, bool slice)
|
auto mdynamic(MArray& ma, bool slice)
|
||||||
-> std::shared_ptr<MutableMultiArrayBase<typename MArray::value_type,DynamicRange>>
|
-> std::shared_ptr<MutableArrayBase<typename MArray::value_type,DynamicRange>>
|
||||||
{
|
{
|
||||||
DynamicRangeFactory drf(ma.range()->space());
|
DynamicRangeFactory drf(ma.range()->space());
|
||||||
if(slice){
|
if(slice){
|
||||||
|
@ -263,7 +263,7 @@ namespace MultiArrayTools
|
||||||
ma.data() );
|
ma.data() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return std::make_shared<MultiArray<typename MArray::value_type,DynamicRange>>
|
return std::make_shared<Array<typename MArray::value_type,DynamicRange>>
|
||||||
( std::dynamic_pointer_cast<DynamicRange>( drf.create() ),
|
( std::dynamic_pointer_cast<DynamicRange>( drf.create() ),
|
||||||
ma.vdata() );
|
ma.vdata() );
|
||||||
}
|
}
|
||||||
|
@ -294,7 +294,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Range1, class... RangeTypes>
|
template <typename T, class Range1, class... RangeTypes>
|
||||||
auto anonToDynView(const MultiArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
auto anonToDynView(const ArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
||||||
-> ConstSlice<T,Range1,RangeTypes...,DynamicRange>
|
-> ConstSlice<T,Range1,RangeTypes...,DynamicRange>
|
||||||
{
|
{
|
||||||
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
||||||
|
@ -307,7 +307,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Range1, class... RangeTypes>
|
template <typename T, class Range1, class... RangeTypes>
|
||||||
auto anonToDynView(MutableMultiArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
auto anonToDynView(MutableArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
||||||
-> Slice<T,Range1,RangeTypes...,DynamicRange>
|
-> Slice<T,Range1,RangeTypes...,DynamicRange>
|
||||||
{
|
{
|
||||||
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
||||||
|
@ -320,8 +320,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Range1, class... RangeTypes>
|
template <typename T, class Range1, class... RangeTypes>
|
||||||
auto dynToAnonMove(MultiArray<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
auto dynToAnonMove(Array<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
||||||
-> MultiArray<T,Range1,RangeTypes...,AnonymousRange>
|
-> Array<T,Range1,RangeTypes...,AnonymousRange>
|
||||||
{
|
{
|
||||||
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
||||||
AnonymousRangeFactory arf(rptr<LAST>(ma)->orig());
|
AnonymousRangeFactory arf(rptr<LAST>(ma)->orig());
|
||||||
|
@ -333,7 +333,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto anonToDynView(const MultiArrayBase<T,AnonymousRange>& ma)
|
auto anonToDynView(const ArrayBase<T,AnonymousRange>& ma)
|
||||||
-> ConstSlice<T,DynamicRange>
|
-> ConstSlice<T,DynamicRange>
|
||||||
{
|
{
|
||||||
DynamicRangeFactory drf(rptr<0>(ma)->orig());
|
DynamicRangeFactory drf(rptr<0>(ma)->orig());
|
||||||
|
@ -342,7 +342,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto anonToDynView(MutableMultiArrayBase<T,AnonymousRange>& ma)
|
auto anonToDynView(MutableArrayBase<T,AnonymousRange>& ma)
|
||||||
-> Slice<T,DynamicRange>
|
-> Slice<T,DynamicRange>
|
||||||
{
|
{
|
||||||
DynamicRangeFactory drf(rptr<0>(ma)->orig());
|
DynamicRangeFactory drf(rptr<0>(ma)->orig());
|
||||||
|
@ -351,8 +351,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto dynToAnonMove(MultiArray<T,DynamicRange>&& ma)
|
auto dynToAnonMove(Array<T,DynamicRange>&& ma)
|
||||||
-> MultiArray<T,AnonymousRange>
|
-> Array<T,AnonymousRange>
|
||||||
{
|
{
|
||||||
AnonymousRangeFactory arf(rptr<0>(ma)->orig());
|
AnonymousRangeFactory arf(rptr<0>(ma)->orig());
|
||||||
auto mNSpace = std::make_tuple( createExplicit( arf ) );
|
auto mNSpace = std::make_tuple( createExplicit( arf ) );
|
||||||
|
@ -376,23 +376,23 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
auto mkArray(const std::shared_ptr<Ranges>&... rs)
|
auto mkArray(const std::shared_ptr<Ranges>&... rs)
|
||||||
-> MultiArray<T,Ranges...>
|
-> Array<T,Ranges...>
|
||||||
{
|
{
|
||||||
return MultiArray<T,Ranges...>(rs...);
|
return Array<T,Ranges...>(rs...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
auto mkArray(const std::shared_ptr<Ranges>&... rs, const T& val)
|
auto mkArray(const std::shared_ptr<Ranges>&... rs, const T& val)
|
||||||
-> MultiArray<T,Ranges...>
|
-> Array<T,Ranges...>
|
||||||
{
|
{
|
||||||
return MultiArray<T,Ranges...>(rs..., val);
|
return Array<T,Ranges...>(rs..., val);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
auto mkArrayPtr(const std::shared_ptr<Ranges>&... rs)
|
auto mkArrayPtr(const std::shared_ptr<Ranges>&... rs)
|
||||||
-> std::shared_ptr<MultiArray<T,Ranges...>>
|
-> std::shared_ptr<Array<T,Ranges...>>
|
||||||
{
|
{
|
||||||
return std::make_shared<MultiArray<T,Ranges...>>(rs...);
|
return std::make_shared<Array<T,Ranges...>>(rs...);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
|
|
||||||
#ifndef __helper_tools_h__
|
#ifndef __cxz_helper_tools_h__
|
||||||
#define __helper_tools_h__
|
#define __cxz_helper_tools_h__
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include "pack_num.h"
|
|
||||||
#include "map_range.h"
|
#include "map_range.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "xfor/iloop.h"
|
#include "xfor/iloop.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
|
@ -120,35 +119,35 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class MArray>
|
template <class MArray>
|
||||||
auto dynamic(const MArray& ma, bool slice = false)
|
auto dynamic(const MArray& ma, bool slice = false)
|
||||||
-> std::shared_ptr<MultiArrayBase<typename MArray::value_type,DynamicRange>>;
|
-> std::shared_ptr<ArrayBase<typename MArray::value_type,DynamicRange>>;
|
||||||
|
|
||||||
template <class MArray>
|
template <class MArray>
|
||||||
auto mdynamic(MArray& ma, bool slice)
|
auto mdynamic(MArray& ma, bool slice)
|
||||||
-> std::shared_ptr<MutableMultiArrayBase<typename MArray::value_type,DynamicRange>>;
|
-> std::shared_ptr<MutableArrayBase<typename MArray::value_type,DynamicRange>>;
|
||||||
|
|
||||||
template <typename T, class Range1, class... RangeTypes>
|
template <typename T, class Range1, class... RangeTypes>
|
||||||
auto anonToDynView(const MultiArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
auto anonToDynView(const ArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
||||||
-> ConstSlice<T,Range1,RangeTypes...,DynamicRange>;
|
-> ConstSlice<T,Range1,RangeTypes...,DynamicRange>;
|
||||||
|
|
||||||
template <typename T, class Range1, class... RangeTypes>
|
template <typename T, class Range1, class... RangeTypes>
|
||||||
auto anonToDynView(MutableMultiArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
auto anonToDynView(MutableArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
||||||
-> Slice<T,Range1,RangeTypes...,DynamicRange>;
|
-> Slice<T,Range1,RangeTypes...,DynamicRange>;
|
||||||
|
|
||||||
template <typename T, class Range1, class... RangeTypes>
|
template <typename T, class Range1, class... RangeTypes>
|
||||||
auto dynToAnonMove(MultiArray<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
auto dynToAnonMove(Array<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
||||||
-> MultiArray<T,Range1,RangeTypes...,AnonymousRange>;
|
-> Array<T,Range1,RangeTypes...,AnonymousRange>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto anonToDynView(const MultiArrayBase<T,AnonymousRange>& ma)
|
auto anonToDynView(const ArrayBase<T,AnonymousRange>& ma)
|
||||||
-> ConstSlice<T,DynamicRange>;
|
-> ConstSlice<T,DynamicRange>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto anonToDynView(MutableMultiArrayBase<T,AnonymousRange>& ma)
|
auto anonToDynView(MutableArrayBase<T,AnonymousRange>& ma)
|
||||||
-> Slice<T,DynamicRange>;
|
-> Slice<T,DynamicRange>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto dynToAnonMove(MultiArray<T,DynamicRange>&& ma)
|
auto dynToAnonMove(Array<T,DynamicRange>&& ma)
|
||||||
-> MultiArray<T,AnonymousRange>;
|
-> Array<T,AnonymousRange>;
|
||||||
|
|
||||||
template <class Range>
|
template <class Range>
|
||||||
auto metaSlice(const std::shared_ptr<Range>& r)
|
auto metaSlice(const std::shared_ptr<Range>& r)
|
||||||
|
@ -160,30 +159,30 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
auto mkArray(const std::shared_ptr<Ranges>&... rs)
|
auto mkArray(const std::shared_ptr<Ranges>&... rs)
|
||||||
-> MultiArray<T,Ranges...>;
|
-> Array<T,Ranges...>;
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
auto mkArrayPtr(const std::shared_ptr<Ranges>&... rs)
|
auto mkArrayPtr(const std::shared_ptr<Ranges>&... rs)
|
||||||
-> std::shared_ptr<MultiArray<T,Ranges...>>;
|
-> std::shared_ptr<Array<T,Ranges...>>;
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
auto mkArray(const std::shared_ptr<Ranges>&... rs, const T& val)
|
auto mkArray(const std::shared_ptr<Ranges>&... rs, const T& val)
|
||||||
-> MultiArray<T,Ranges...>;
|
-> Array<T,Ranges...>;
|
||||||
|
|
||||||
template <class OpTp, class IndTp, class VarTp, class LTp>
|
template <class OpTp, class IndTp, class VarTp, class LTp>
|
||||||
auto mkILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp,
|
auto mkILoop(const OpTp& opTp, const IndTp& indTp, const VarTp& varTp, const LTp& lTp,
|
||||||
const std::array<size_t,std::tuple_size<LTp>::value>& umpos,
|
const std::array<size_t,std::tuple_size<LTp>::value>& umpos,
|
||||||
const std::array<size_t,std::tuple_size<VarTp>::value>& setzero)
|
const std::array<size_t,std::tuple_size<VarTp>::value>& setzero)
|
||||||
-> MultiArrayHelper::ILoop<OpTp,IndTp,VarTp,LTp>
|
-> CNORXZInternal::ILoop<OpTp,IndTp,VarTp,LTp>
|
||||||
{
|
{
|
||||||
return MultiArrayHelper::ILoop<OpTp,IndTp,VarTp,LTp>(opTp, indTp, varTp, lTp, umpos, setzero);
|
return CNORXZInternal::ILoop<OpTp,IndTp,VarTp,LTp>(opTp, indTp, varTp, lTp, umpos, setzero);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class CF>
|
template <class CF>
|
||||||
auto mkPILoop(const CF& cf)
|
auto mkPILoop(const CF& cf)
|
||||||
-> MultiArrayHelper::PILoop<CF>
|
-> CNORXZInternal::PILoop<CF>
|
||||||
{
|
{
|
||||||
return MultiArrayHelper::PILoop<CF>(cf);
|
return CNORXZInternal::PILoop<CF>(cf);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
|
@ -215,11 +214,11 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
inline auto mkOp(const std::shared_ptr<Index>& i)
|
inline auto mkOp(const std::shared_ptr<Index>& i)
|
||||||
-> decltype(std::declval<FunctionalMultiArray<typename Index::MetaType,
|
-> decltype(std::declval<FunctionalArray<typename Index::MetaType,
|
||||||
identity<typename Index::MetaType>,typename Index::RangeType> >
|
identity<typename Index::MetaType>,typename Index::RangeType> >
|
||||||
().exec(i))
|
().exec(i))
|
||||||
{
|
{
|
||||||
FunctionalMultiArray<typename Index::MetaType,
|
FunctionalArray<typename Index::MetaType,
|
||||||
identity<typename Index::MetaType>,
|
identity<typename Index::MetaType>,
|
||||||
typename Index::RangeType> fma(i->range());
|
typename Index::RangeType> fma(i->range());
|
||||||
return fma.exec(i);
|
return fma.exec(i);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#include "high_level_operation.h"
|
#include "high_level_operation.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T, class Op>
|
template <typename T, class Op>
|
||||||
|
@ -114,82 +114,53 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template <size_t N>
|
template <size_t N, class... Indices>
|
||||||
struct Create
|
struct Create
|
||||||
{
|
{
|
||||||
template <class... Indices>
|
template <class ROP, class OpF, class... OPs>
|
||||||
struct cx
|
struct ccx
|
||||||
{
|
{
|
||||||
template <class ROP, class OpF, class... OPs>
|
template <size_t M, class... DOPs>
|
||||||
struct ccx
|
static inline void
|
||||||
{
|
cccx(typename HighLevelOpBase<ROP>::template RetT<Indices...>& res,
|
||||||
template <size_t M, class... DOPs>
|
const std::array<std::shared_ptr<HighLevelOpBase<ROP>>,M>& in,
|
||||||
static inline void
|
const std::shared_ptr<Indices>&... inds,
|
||||||
cccx(typename HighLevelOpBase<ROP>::template RetT<Indices...>& res,
|
const OPs&... ops,
|
||||||
const std::array<std::shared_ptr<HighLevelOpBase<ROP>>,M>& in,
|
const DOPs&... dops)
|
||||||
const std::shared_ptr<Indices>&... inds,
|
{
|
||||||
const OPs&... ops,
|
//static_assert(N > 0, "N > 0 failed");
|
||||||
const DOPs&... dops)
|
auto& inn = std::get<N>(in);
|
||||||
{
|
if(not inn->root()){
|
||||||
static_assert(N > 0, "N > 0 failed");
|
auto dop = inn->create(inds...);
|
||||||
auto& inn = std::get<N>(in);
|
auto op = *dop.op.data()->mOp;
|
||||||
if(not inn->root()){
|
res.appendOuter(dop);
|
||||||
auto dop = inn->create(inds...);
|
assert(dop.op.init());
|
||||||
auto op = *dop.op.data()->mOp;
|
if constexpr(N > 0){
|
||||||
typedef decltype(op) OP;
|
typedef decltype(op) OP;
|
||||||
res.appendOuter(dop);
|
Create<N-1,Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
|
||||||
assert(dop.op.init());
|
(res, in, inds..., op, ops..., dop, dops...);
|
||||||
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
|
}
|
||||||
(res, in, inds..., op, ops..., dop, dops...);
|
else {
|
||||||
}
|
res.op = mkDynOutOp(mkFOp<OpF>(op,ops...), inds...);
|
||||||
else {
|
res.appendOuterM(dop.op,dops.op...);
|
||||||
auto op = inn->get();
|
}
|
||||||
auto vop = inn->vget();
|
}
|
||||||
typedef typename std::remove_reference<decltype(*op)>::type OP;
|
else {
|
||||||
typedef typename std::remove_reference<decltype(*vop)>::type VOP;
|
auto op = inn->get();
|
||||||
|
auto vop = inn->vget();
|
||||||
|
if constexpr(N > 0){
|
||||||
|
typedef typename std::remove_reference<decltype(*op)>::type OP;
|
||||||
|
typedef typename std::remove_reference<decltype(*vop)>::type VOP;
|
||||||
if(op != nullptr){
|
if(op != nullptr){
|
||||||
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
|
Create<N-1,Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
|
||||||
(res, in, inds..., *op, ops..., dops...);
|
(res, in, inds..., *op, ops..., dops...);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,VOP,OPs...>::template cccx<M>
|
Create<N-1,Indices...>::template ccx<ROP,OpF,VOP,OPs...>::template cccx<M>
|
||||||
(res, in, inds..., *vop, ops..., dops...);
|
(res, in, inds..., *vop, ops..., dops...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct Create<0>
|
|
||||||
{
|
|
||||||
template <class... Indices>
|
|
||||||
struct cx
|
|
||||||
{
|
|
||||||
template <class ROP, class OpF, class... OPs>
|
|
||||||
struct ccx
|
|
||||||
{
|
|
||||||
template <size_t M, class... DOPs>
|
|
||||||
static inline void
|
|
||||||
cccx(typename HighLevelOpBase<ROP>::template RetT<Indices...>& res,
|
|
||||||
const std::array<std::shared_ptr<HighLevelOpBase<ROP>>,M>& in,
|
|
||||||
const std::shared_ptr<Indices>&... inds,
|
|
||||||
const OPs&... ops,
|
|
||||||
const DOPs&... dops)
|
|
||||||
{
|
|
||||||
auto& inn = std::get<0>(in);
|
|
||||||
if(not inn->root()){
|
|
||||||
auto dop = inn->create(inds...);
|
|
||||||
auto op = *dop.op.data()->mOp;
|
|
||||||
res.appendOuter(dop);
|
|
||||||
res.op = mkDynOutOp(mkFOp<OpF>(op,ops...), inds...);
|
|
||||||
assert(dop.op.init());
|
|
||||||
res.appendOuterM(dop.op,dops.op...);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
auto op = inn->get();
|
|
||||||
auto vop = inn->vget();
|
|
||||||
if(op != nullptr){
|
if(op != nullptr){
|
||||||
res.op = mkDynOutOp(mkFOp<OpF>(*op,ops...), inds...);
|
res.op = mkDynOutOp(mkFOp<OpF>(*op,ops...), inds...);
|
||||||
}
|
}
|
||||||
|
@ -197,11 +168,12 @@ namespace MultiArrayTools
|
||||||
res.op = mkDynOutOp(mkFOp<OpF>(*vop,ops...), inds...);
|
res.op = mkDynOutOp(mkFOp<OpF>(*vop,ops...), inds...);
|
||||||
}
|
}
|
||||||
res.appendOuterM(dops.op...);
|
res.appendOuterM(dops.op...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ROP, class OpF, size_t N>
|
template <class ROP, class OpF, size_t N>
|
||||||
|
@ -234,7 +206,7 @@ namespace MultiArrayTools
|
||||||
-> typename B::template RetT<Inds...>
|
-> typename B::template RetT<Inds...>
|
||||||
{
|
{
|
||||||
typename B::template RetT<Inds...> res;
|
typename B::template RetT<Inds...> res;
|
||||||
Create<N-1>::template cx<Inds...>::template ccx<ROP,OpF>::template cccx<N>
|
Create<N-1,Inds...>::template ccx<ROP,OpF>::template cccx<N>
|
||||||
(res,mIn,inds...);
|
(res,mIn,inds...);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
#ifndef __high_level_operation_h__
|
#ifndef __cxz_high_level_operation_h__
|
||||||
#define __high_level_operation_h__
|
#define __cxz_high_level_operation_h__
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "ranges/rheader.h"
|
#include "ranges/rheader.h"
|
||||||
#include "dynamic_operation.h"
|
#include "dynamic_operation.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef ClassicRange CR;
|
typedef ClassicRange CR;
|
||||||
|
@ -54,7 +54,10 @@ namespace MultiArrayTools
|
||||||
#define reg_ind3(I1,I2,I3) virtual RetT<I1,I2,I3> create \
|
#define reg_ind3(I1,I2,I3) virtual RetT<I1,I2,I3> create \
|
||||||
(const std::shared_ptr<I1>& ind1,const std::shared_ptr<I2>& ind2,const std::shared_ptr<I3>& ind3) = 0
|
(const std::shared_ptr<I1>& ind1,const std::shared_ptr<I2>& ind2,const std::shared_ptr<I3>& ind3) = 0
|
||||||
|
|
||||||
#include "hl_reg_ind.h"
|
//#include "hl_reg_ind.h"
|
||||||
|
reg_ind1(ClassicRange::IndexType);
|
||||||
|
reg_ind2(ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
reg_ind3(ClassicRange::IndexType,ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
|
||||||
#undef reg_ind1
|
#undef reg_ind1
|
||||||
#undef reg_ind2
|
#undef reg_ind2
|
||||||
|
@ -92,7 +95,10 @@ namespace MultiArrayTools
|
||||||
(const std::shared_ptr<I1>& ind1, const std::shared_ptr<I2>& ind2, const std::shared_ptr<I3>& ind3) \
|
(const std::shared_ptr<I1>& ind1, const std::shared_ptr<I2>& ind2, const std::shared_ptr<I3>& ind3) \
|
||||||
override final { return xcreate(ind1,ind2,ind3); }
|
override final { return xcreate(ind1,ind2,ind3); }
|
||||||
|
|
||||||
#include "hl_reg_ind.h"
|
//#include "hl_reg_ind.h"
|
||||||
|
reg_ind1(ClassicRange::IndexType);
|
||||||
|
reg_ind2(ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
reg_ind3(ClassicRange::IndexType,ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
|
||||||
virtual ROP* get() override final;
|
virtual ROP* get() override final;
|
||||||
virtual VOP* vget() override final;
|
virtual VOP* vget() override final;
|
||||||
|
@ -121,7 +127,10 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
virtual bool root() const override final;
|
virtual bool root() const override final;
|
||||||
|
|
||||||
#include "hl_reg_ind.h"
|
//#include "hl_reg_ind.h"
|
||||||
|
reg_ind1(ClassicRange::IndexType);
|
||||||
|
reg_ind2(ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
reg_ind3(ClassicRange::IndexType,ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
|
||||||
virtual ROP* get() override final;
|
virtual ROP* get() override final;
|
||||||
virtual VOP* vget() override final;
|
virtual VOP* vget() override final;
|
||||||
|
@ -158,7 +167,10 @@ namespace MultiArrayTools
|
||||||
virtual ROP* get() override final;
|
virtual ROP* get() override final;
|
||||||
virtual VOP* vget() override final;
|
virtual VOP* vget() override final;
|
||||||
|
|
||||||
#include "hl_reg_ind.h"
|
//#include "hl_reg_ind.h"
|
||||||
|
reg_ind1(ClassicRange::IndexType);
|
||||||
|
reg_ind2(ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
reg_ind3(ClassicRange::IndexType,ClassicRange::IndexType,ClassicRange::IndexType);
|
||||||
|
|
||||||
#undef reg_ind1
|
#undef reg_ind1
|
||||||
#undef reg_ind2
|
#undef reg_ind2
|
||||||
|
|
3
src/include/hl_cnorxz.h
Normal file
3
src/include/hl_cnorxz.h
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#include "high_level_operation.h"
|
||||||
|
|
||||||
|
#include "high_level_operation.cc.h"
|
|
@ -1,52 +0,0 @@
|
||||||
|
|
||||||
#ifndef __hl_reg_ind_h__
|
|
||||||
#define __hl_reg_ind_h__
|
|
||||||
|
|
||||||
#include "ranges/rheader.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
struct RegIndNum
|
|
||||||
{
|
|
||||||
static constexpr size_t VALUE = -1;
|
|
||||||
static constexpr size_t DEPTH = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct RegIndNum<ClassicRange::IndexType>
|
|
||||||
{
|
|
||||||
static constexpr size_t VALUE = 0;
|
|
||||||
static constexpr size_t DEPTH = 3;
|
|
||||||
};
|
|
||||||
|
|
||||||
// to be returned by IndexWrapper
|
|
||||||
struct RegIndInfo
|
|
||||||
{
|
|
||||||
size_t type;
|
|
||||||
size_t depth;
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
RegIndInfo& set(const std::shared_ptr<Index>& i)
|
|
||||||
{
|
|
||||||
type = RegIndNum<Index>::VALUE;
|
|
||||||
depth = RegIndNum<Index>::DEPTH;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef reg_ind1
|
|
||||||
#ifdef reg_ind2
|
|
||||||
#ifdef reg_ind3
|
|
||||||
|
|
||||||
reg_ind1(ClassicRange::IndexType);
|
|
||||||
reg_ind2(ClassicRange::IndexType,ClassicRange::IndexType);
|
|
||||||
reg_ind3(ClassicRange::IndexType,ClassicRange::IndexType,ClassicRange::IndexType);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -2,12 +2,12 @@
|
||||||
#include "map_range.h"
|
#include "map_range.h"
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************
|
/**************
|
||||||
|
@ -27,6 +27,18 @@ namespace MultiArrayTools
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Op, class Index, class Expr, SpaceType STYPE>
|
||||||
|
std::shared_ptr<ExpressionBase> OpExpr<Op,Index,Expr,STYPE>::deepCopy() const
|
||||||
|
{
|
||||||
|
return std::make_shared<OpExpr<Op,Index,Expr,STYPE>>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Op, class Index, class Expr, SpaceType STYPE>
|
||||||
|
inline void OpExpr<Op,Index,Expr,STYPE>::operator()(size_t mlast, DExt last)
|
||||||
|
{
|
||||||
|
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||||
|
}
|
||||||
|
|
||||||
template <class Op, class Index, class Expr, SpaceType STYPE>
|
template <class Op, class Index, class Expr, SpaceType STYPE>
|
||||||
inline void OpExpr<Op,Index,Expr,STYPE>::operator()(size_t mlast,
|
inline void OpExpr<Op,Index,Expr,STYPE>::operator()(size_t mlast,
|
||||||
ExtType last)
|
ExtType last)
|
||||||
|
@ -37,7 +49,7 @@ namespace MultiArrayTools
|
||||||
if(pos != mIndPtr->max()){
|
if(pos != mIndPtr->max()){
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
||||||
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ) );
|
mExpr(mnpos, getX<NEXT>( npos ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +63,7 @@ namespace MultiArrayTools
|
||||||
if(pos != mIndPtr->max()){
|
if(pos != mIndPtr->max()){
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
const size_t mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
||||||
mExpr(mnpos, Getter<NEXT>::template getX<ExtType>( npos ));
|
mExpr(mnpos, getX<NEXT>( npos ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,42 +75,43 @@ namespace MultiArrayTools
|
||||||
//return mExpr.rootSteps(iPtrNum).extend( mOp.rootSteps(iPtrNum) );
|
//return mExpr.rootSteps(iPtrNum).extend( mOp.rootSteps(iPtrNum) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Op, class Index, class Expr, SpaceType STYPE>
|
||||||
|
DExt OpExpr<Op,Index,Expr,STYPE>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
|
{
|
||||||
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
|
}
|
||||||
|
|
||||||
// -> define in range_base.cc
|
template <class Op, class Index, class Expr, SpaceType STYPE>
|
||||||
//std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
DExt OpExpr<Op,Index,Expr,STYPE>::dExtension() const
|
||||||
|
{
|
||||||
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
|
}
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
* MapIndex *
|
* MapIndex *
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
/*
|
|
||||||
template <class MapF, class... Indices>
|
|
||||||
MapIndex<MapF,Indices...>::MapIndex(const MapIndex<MapF,Indices...>& in) :
|
|
||||||
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MapF, class... Indices>
|
|
||||||
MapIndex<MapF,Indices...>& MapIndex<MapF,Indices...>::operator=(const MapIndex<MapF,Indices...>& in)
|
|
||||||
{
|
|
||||||
IndexI::operator=(in);
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
|
||||||
IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,typename Op::value_type>(range, 0)
|
IndexInterface<GenMapIndex<OIType,Op,XSTYPE,Indices...>,typename Op::value_type>(range, 0)
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||||
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element!
|
sfor_mn<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto r = range->template getPtr<i>();
|
||||||
|
std::get<i>(mIPack) = r->beginPtr();
|
||||||
|
*std::get<i>(mIPack) = 0;
|
||||||
|
|
||||||
|
std::get<i>(mBlockSizes) = sfor_p<i,sizeof...(Indices)>
|
||||||
|
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
||||||
|
[&](auto a, auto b) { return a * b; });
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
mOutIndex = std::make_shared<OIType>
|
mOutIndex = std::make_shared<OIType>
|
||||||
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
|
( std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->outRange()->begin() );
|
||||||
}
|
}
|
||||||
|
@ -108,8 +121,16 @@ namespace MultiArrayTools
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::up()
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::up()
|
||||||
{
|
{
|
||||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
||||||
RPackNum<DIR>::pp( mIPack );
|
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
|
sfor_m<DIR+1,0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.last() and i != 0) { si = 0; return true; }
|
||||||
|
else { ++si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +139,16 @@ namespace MultiArrayTools
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::down()
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::down()
|
||||||
{
|
{
|
||||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
||||||
RPackNum<DIR>::mm( mIPack );
|
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
|
sfor_m<DIR+1,0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||||
|
else { --si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +175,15 @@ namespace MultiArrayTools
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator()(const std::shared_ptr<Indices>&... indices)
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator()(const std::shared_ptr<Indices>&... indices)
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
return (*this)(std::make_tuple(indices...));
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
}
|
||||||
|
|
||||||
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
|
||||||
|
{
|
||||||
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
|
||||||
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, IB::mPos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,14 +198,12 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
(*mOutIndex) = pos;
|
(*mOutIndex) = pos;
|
||||||
IB::mPos = mOutIndex->pos();
|
IB::mPos = mOutIndex->pos();
|
||||||
//RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator++()
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator++()
|
||||||
{
|
{
|
||||||
//RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
|
||||||
++(*mOutIndex);
|
++(*mOutIndex);
|
||||||
IB::mPos = mOutIndex->pos();
|
IB::mPos = mOutIndex->pos();
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -178,7 +212,6 @@ namespace MultiArrayTools
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator--()
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator--()
|
||||||
{
|
{
|
||||||
//RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
|
||||||
--(*mOutIndex);
|
--(*mOutIndex);
|
||||||
IB::mPos = mOutIndex->pos();
|
IB::mPos = mOutIndex->pos();
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -187,20 +220,16 @@ namespace MultiArrayTools
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
|
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
//int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
|
||||||
mOutIndex->pp(idxPtrNum);
|
mOutIndex->pp(idxPtrNum);
|
||||||
IB::mPos = mOutIndex->pos();
|
IB::mPos = mOutIndex->pos();
|
||||||
//IB::mPos += tmp;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
|
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
//int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
|
||||||
mOutIndex->mm(idxPtrNum);
|
mOutIndex->mm(idxPtrNum);
|
||||||
IB::mPos = mOutIndex->pos();
|
IB::mPos = mOutIndex->pos();
|
||||||
//IB::mPos -= tmp;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,17 +242,12 @@ namespace MultiArrayTools
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
typename GenMapIndex<OIType,Op,XSTYPE,Indices...>::MetaType GenMapIndex<OIType,Op,XSTYPE,Indices...>::meta() const
|
typename GenMapIndex<OIType,Op,XSTYPE,Indices...>::MetaType GenMapIndex<OIType,Op,XSTYPE,Indices...>::meta() const
|
||||||
{
|
{
|
||||||
//MetaType metaTuple;
|
|
||||||
//RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
|
||||||
//assert(0);
|
|
||||||
return mOutIndex->meta();
|
return mOutIndex->meta();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::at(const MetaType& metaPos)
|
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::at(const MetaType& metaPos)
|
||||||
{
|
{
|
||||||
//RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
|
||||||
//IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
mOutIndex->at(metaPos);
|
mOutIndex->at(metaPos);
|
||||||
IB::mPos = mOutIndex->pos();
|
IB::mPos = mOutIndex->pos();
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -277,40 +301,19 @@ namespace MultiArrayTools
|
||||||
return mBlockSizes[n+1];
|
return mBlockSizes[n+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
|
||||||
std::string GenMapIndex<OIType,Op,XSTYPE,Indices...>::id() const
|
|
||||||
{
|
|
||||||
return std::string("mul") + std::to_string(IB::mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
|
||||||
void GenMapIndex<OIType,Op,XSTYPE,Indices...>::print(size_t offset) const
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
||||||
<< "]" << "(" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
|
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::ifor(size_t step, Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
|
||||||
(step, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
|
|
||||||
( range()->map(), this, step, exs ) ) )
|
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh
|
return RangeHelper::mkFor<0>
|
||||||
(0, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
|
(0, mIPack, mBlockSizes,
|
||||||
( range()->map(), this, step, exs ) );
|
OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
|
||||||
|
( range()->map(), this, step, exs ));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const
|
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const
|
||||||
-> decltype(ifor(step, exs))
|
|
||||||
{
|
{
|
||||||
return ifor(step, exs);
|
return ifor(step, exs);
|
||||||
}
|
}
|
||||||
|
@ -318,7 +321,6 @@ namespace MultiArrayTools
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const
|
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const
|
||||||
-> decltype(ifor(step, exs))
|
|
||||||
{
|
{
|
||||||
return ifor(step, exs);
|
return ifor(step, exs);
|
||||||
}
|
}
|
||||||
|
@ -380,7 +382,9 @@ namespace MultiArrayTools
|
||||||
bool check = false;
|
bool check = false;
|
||||||
for(auto& x: MapRangeFactoryProductMap::mAleadyCreated){
|
for(auto& x: MapRangeFactoryProductMap::mAleadyCreated){
|
||||||
if(x.second.size() == sizeof...(Ranges)){
|
if(x.second.size() == sizeof...(Ranges)){
|
||||||
check = RPackNum<sizeof...(Ranges)-1>::checkIfCreated(ptp, x.second);
|
check = sfor_p<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) { return reinterpret_cast<std::intptr_t>( std::get<i>(ptp).get() ) == x.second[i]; },
|
||||||
|
[&](auto a, auto b) { return a and b; } );
|
||||||
if(check){
|
if(check){
|
||||||
out = x.first;
|
out = x.first;
|
||||||
break;
|
break;
|
||||||
|
@ -389,7 +393,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
if(not check){
|
if(not check){
|
||||||
vector<std::intptr_t> pv(sizeof...(Ranges));
|
vector<std::intptr_t> pv(sizeof...(Ranges));
|
||||||
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
|
sfor_pn<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) { pv[i] = reinterpret_cast<std::intptr_t>( std::get<i>(ptp).get() ); return 0; } );
|
||||||
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 ) );
|
||||||
MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
||||||
|
@ -410,7 +415,7 @@ namespace MultiArrayTools
|
||||||
struct OutRangeMaker<SpaceType::ANY>
|
struct OutRangeMaker<SpaceType::ANY>
|
||||||
{
|
{
|
||||||
template <class MapF, class ORType>
|
template <class MapF, class ORType>
|
||||||
static void mk(std::shared_ptr<ORType>& outRange, MultiArray<size_t,ORType>& mapMult, const MapF& mapf)
|
static void mk(std::shared_ptr<ORType>& outRange, Array<size_t,ORType>& mapMult, const MapF& mapf)
|
||||||
{
|
{
|
||||||
std::map<typename MapF::value_type,size_t> mult;
|
std::map<typename MapF::value_type,size_t> mult;
|
||||||
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
|
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
|
||||||
|
@ -429,7 +434,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
typename ORType::FType orf(outmeta);
|
typename ORType::FType orf(outmeta);
|
||||||
outRange = std::dynamic_pointer_cast<ORType>( orf.create() );
|
outRange = std::dynamic_pointer_cast<ORType>( orf.create() );
|
||||||
mapMult = MultiArray<size_t,ORType>( outRange, outmult );
|
mapMult = Array<size_t,ORType>( outRange, outmult );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -437,7 +442,7 @@ namespace MultiArrayTools
|
||||||
struct OutRangeMaker<SpaceType::NONE>
|
struct OutRangeMaker<SpaceType::NONE>
|
||||||
{
|
{
|
||||||
template <class MapF, class ORType>
|
template <class MapF, class ORType>
|
||||||
static void mk(std::shared_ptr<ORType>& outRange, MultiArray<size_t,ORType>& mapMult, const MapF& mapf)
|
static void mk(std::shared_ptr<ORType>& outRange, Array<size_t,ORType>& mapMult, const MapF& mapf)
|
||||||
{
|
{
|
||||||
static_assert( std::is_same<size_t,typename MapF::value_type>::value,
|
static_assert( std::is_same<size_t,typename MapF::value_type>::value,
|
||||||
"out range value type for NONE must be size_t" );
|
"out range value type for NONE must be size_t" );
|
||||||
|
@ -459,7 +464,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
typename ORType::FType orf(max);
|
typename ORType::FType orf(max);
|
||||||
outRange = std::dynamic_pointer_cast<ORType>( orf.create() );
|
outRange = std::dynamic_pointer_cast<ORType>( orf.create() );
|
||||||
mapMult = MultiArray<size_t,ORType>( outRange, outmult );
|
mapMult = Array<size_t,ORType>( outRange, outmult );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -467,7 +472,7 @@ namespace MultiArrayTools
|
||||||
template <class MA>
|
template <class MA>
|
||||||
void GenMapRange<ORType,Op,XSTYPE,Ranges...>::mkOutRange(const MA& mapf)
|
void GenMapRange<ORType,Op,XSTYPE,Ranges...>::mkOutRange(const MA& mapf)
|
||||||
{
|
{
|
||||||
//FunctionalMultiArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
|
//FunctionalArray<typename MapF::value_type,MapF,Ranges...> fma(mSpace, mMapf);
|
||||||
OutRangeMaker<XSTYPE>::mk(mOutRange,mMapMult,mapf);
|
OutRangeMaker<XSTYPE>::mk(mOutRange,mMapMult,mapf);
|
||||||
auto i = mapf.begin();
|
auto i = mapf.begin();
|
||||||
mMapPos.resize(i.max());
|
mMapPos.resize(i.max());
|
||||||
|
@ -568,7 +573,6 @@ namespace MultiArrayTools
|
||||||
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::size() const
|
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::size() const
|
||||||
{
|
{
|
||||||
return mOutRange->size();
|
return mOutRange->size();
|
||||||
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
|
@ -587,7 +591,7 @@ namespace MultiArrayTools
|
||||||
vector<size_t> GenMapRange<ORType,Op,XSTYPE,Ranges...>::typeNum() const
|
vector<size_t> GenMapRange<ORType,Op,XSTYPE,Ranges...>::typeNum() const
|
||||||
{
|
{
|
||||||
vector<size_t> o;
|
vector<size_t> o;
|
||||||
RPackNum<sizeof...(Ranges)-1>::getTypeNum(o,mSpace);
|
RangeHelper::getTypeNum<sizeof...(Ranges)-1>(o,mSpace);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,13 +601,12 @@ namespace MultiArrayTools
|
||||||
//MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
//MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
||||||
assert(0);
|
assert(0);
|
||||||
return 0;
|
return 0;
|
||||||
//return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,cmetaSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::cmetaSize() const
|
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::cmetaSize() const
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getCMetaSize(mSpace);
|
return RangeHelper::getCMetaSize<0>(mSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
|
@ -611,7 +614,7 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
auto i = begin();
|
auto i = begin();
|
||||||
i = pos;
|
i = pos;
|
||||||
return "[ " + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + " ]";
|
return "[ " + RangeHelper::getStringMeta<0>(i) + " ]";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
|
@ -622,7 +625,12 @@ namespace MultiArrayTools
|
||||||
//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));
|
||||||
RPackNum<sizeof...(Ranges)-1>::fillRangeDataVec(out, mSpace);
|
sfor_pn<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) {
|
||||||
|
vector<char> part = std::get<i>(mSpace)->data();
|
||||||
|
out.insert(out.end(), part.begin(), part.end());
|
||||||
|
return 0;
|
||||||
|
} );
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +666,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||||
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::mapMultiplicity() const
|
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::mapMultiplicity() const
|
||||||
-> const MultiArray<size_t,ORType>&
|
-> const Array<size_t,ORType>&
|
||||||
{
|
{
|
||||||
return mMapMult;
|
return mMapMult;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __map_range_h__
|
#ifndef __cxz_map_range_h__
|
||||||
#define __map_range_h__
|
#define __cxz_map_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
@ -12,30 +12,29 @@
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "ranges/index_base.h"
|
#include "ranges/index_base.h"
|
||||||
|
|
||||||
#include "ranges/rpack_num.h"
|
|
||||||
#include "map_range_factory_product_map.h"
|
#include "map_range_factory_product_map.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
|
|
||||||
#include "xfor/xfor.h"
|
#include "xfor/xfor.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class Func, class... Indices>
|
template <class Func, class... Indices>
|
||||||
auto mkMapOp(const std::shared_ptr<Func>& func,
|
auto mkMapOp(const std::shared_ptr<Func>& func,
|
||||||
const std::shared_ptr<Indices>&... is)
|
const std::shared_ptr<Indices>&... is)
|
||||||
-> decltype(std::make_tuple(FunctionalMultiArray<typename Func::value_type,Func,
|
-> decltype(std::make_tuple(FunctionalArray<typename Func::value_type,Func,
|
||||||
typename Indices::RangeType...>().exec(is...),
|
typename Indices::RangeType...>().exec(is...),
|
||||||
FunctionalMultiArray<typename Func::value_type,Func,
|
FunctionalArray<typename Func::value_type,Func,
|
||||||
typename Indices::RangeType...>()))
|
typename Indices::RangeType...>()))
|
||||||
{
|
{
|
||||||
typedef FunctionalMultiArray<typename Func::value_type,Func,typename Indices::RangeType...> FMA;
|
typedef FunctionalArray<typename Func::value_type,Func,typename Indices::RangeType...> FMA;
|
||||||
if(Func::FISSTATIC){
|
if(Func::FISSTATIC){
|
||||||
FMA fma(is->range()...);
|
FMA fma(is->range()...);
|
||||||
return std::make_tuple(fma.exec(is...),fma);
|
return std::make_tuple(fma.exec(is...),fma);
|
||||||
|
@ -50,13 +49,14 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class Op, class Index, class Expr, SpaceType STYPE = SpaceType::ANY>
|
template <class Op, class Index, class Expr, SpaceType STYPE = SpaceType::ANY>
|
||||||
//template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
|
//template <class MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
|
||||||
class OpExpr
|
class OpExpr : public ExpressionBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//typedef typename Index::OIType OIType;
|
//typedef typename Index::OIType OIType;
|
||||||
//typedef SingleIndex<typename Op::value_type,STYPE> OIType;
|
//typedef SingleIndex<typename Op::value_type,STYPE> OIType;
|
||||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
|
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
|
||||||
|
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpExpr() = default;
|
OpExpr() = default;
|
||||||
|
@ -80,11 +80,20 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
OpExpr(const Op& mapf, const Index* ind, size_t step, Expr ex);
|
OpExpr(const Op& mapf, const Index* ind, size_t step, Expr ex);
|
||||||
|
|
||||||
|
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final;
|
||||||
|
|
||||||
|
template <size_t VS>
|
||||||
|
inline auto vec() const { return *this; }
|
||||||
|
|
||||||
|
inline void operator()(size_t mlast, DExt last) override final;
|
||||||
inline void operator()(size_t mlast, ExtType last);
|
inline void operator()(size_t mlast, ExtType last);
|
||||||
inline void operator()(size_t mlast = 0);
|
inline void operator()(size_t mlast = 0) override final;
|
||||||
|
|
||||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||||
|
|
||||||
|
virtual DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||||
|
virtual DExt dExtension() const override final;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||||
|
@ -106,7 +115,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
||||||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||||
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
static constexpr size_t totalDim() { return (... * Indices::totalDim()); }
|
||||||
static void check_type() { static_assert( std::is_same<typename OIType::MetaType,typename Op::value_type>::value, "inconsitent value types" ); }
|
static void check_type() { static_assert( std::is_same<typename OIType::MetaType,typename Op::value_type>::value, "inconsitent value types" ); }
|
||||||
|
|
||||||
static constexpr SpaceType STYPE = XSTYPE;
|
static constexpr SpaceType STYPE = XSTYPE;
|
||||||
|
@ -149,11 +158,12 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
std::shared_ptr<OIType> outIndex() const;
|
std::shared_ptr<OIType> outIndex() const;
|
||||||
|
|
||||||
// raplace instances (in contrast to its analogon in ContainerIndex
|
// raplace instances (in contrast to its analogon in ConstContainerIndex
|
||||||
// MultiIndices CANNOT be influences be its subindices, so there is
|
// MultiIndices CANNOT be influences be its subindices, so there is
|
||||||
// NO foreign/external controll)
|
// NO foreign/external controll)
|
||||||
// Do NOT share index instances between two or more MapIndex instances
|
// Do NOT share index instances between two or more MapIndex instances
|
||||||
GenMapIndex& operator()(const std::shared_ptr<Indices>&... indices);
|
GenMapIndex& operator()(const std::shared_ptr<Indices>&... indices);
|
||||||
|
GenMapIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& indices);
|
||||||
|
|
||||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||||
|
|
||||||
|
@ -182,23 +192,14 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
size_t getStepSize(size_t n) const;
|
size_t getStepSize(size_t n) const;
|
||||||
|
|
||||||
std::string id() const;
|
|
||||||
void print(size_t offset) const;
|
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto ifor(size_t step, Exprs exs) const
|
auto ifor(size_t step, Exprs exs) const; // first step arg not used!
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
|
||||||
(step, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex,Exprs,XSTYPE>( range()->map(), this, step, exs ) ) );
|
|
||||||
// first step arg not used!
|
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto pifor(size_t step, Exprs exs) const
|
auto pifor(size_t step, Exprs exs) const; // NO MULTITHREADING
|
||||||
-> decltype(ifor(step, exs)); // NO MULTITHREADING
|
|
||||||
|
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto iforh(size_t step, Exprs exs) const
|
auto iforh(size_t step, Exprs exs) const;
|
||||||
-> decltype(ifor(step, exs));
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -251,11 +252,7 @@ namespace MultiArrayTools
|
||||||
typedef RangeBase RB;
|
typedef RangeBase RB;
|
||||||
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
||||||
typedef GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> IndexType;
|
typedef GenMapIndex<typename ORType::IndexType,Op,XSTYPE,typename Ranges::IndexType...> IndexType;
|
||||||
//typedef GenMapRange RangeType;
|
|
||||||
//typedef SingleRange<typename Op::value_type,XSTYPE> ORType;
|
|
||||||
//typedef SingleRangeFactory<typename Op::value_type,XSTYPE> ORFType;
|
|
||||||
typedef typename Op::value_type MetaType;
|
typedef typename Op::value_type MetaType;
|
||||||
//typedef typename RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GenMapRange() = delete;
|
GenMapRange() = delete;
|
||||||
|
@ -280,7 +277,7 @@ namespace MultiArrayTools
|
||||||
Op mMapf;
|
Op mMapf;
|
||||||
//Op mMapf;
|
//Op mMapf;
|
||||||
std::shared_ptr<ORType> mOutRange;
|
std::shared_ptr<ORType> mOutRange;
|
||||||
MultiArray<size_t,ORType> mMapMult;
|
Array<size_t,ORType> mMapMult;
|
||||||
vector<size_t> mMapPos;
|
vector<size_t> mMapPos;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -317,7 +314,7 @@ namespace MultiArrayTools
|
||||||
virtual IndexType begin() const final;
|
virtual IndexType begin() const final;
|
||||||
virtual IndexType end() const final;
|
virtual IndexType end() const final;
|
||||||
|
|
||||||
const MultiArray<size_t,ORType>& mapMultiplicity() const;
|
const Array<size_t,ORType>& mapMultiplicity() const;
|
||||||
ConstSlice<size_t,GenMapRange> explMapMultiplicity() const;
|
ConstSlice<size_t,GenMapRange> explMapMultiplicity() const;
|
||||||
|
|
||||||
vector<size_t> mapPos() const;
|
vector<size_t> mapPos() const;
|
||||||
|
@ -331,8 +328,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
static constexpr bool HASMETACONT = false;
|
static constexpr bool HASMETACONT = false;
|
||||||
static constexpr bool defaultable = false;
|
static constexpr bool defaultable = false;
|
||||||
static constexpr size_t ISSTATIC = SubProp<Op,Ranges...>::ISSTATIC;
|
static constexpr size_t ISSTATIC = Op::ISSTATIC & (... & Ranges::ISSTATIC);
|
||||||
static constexpr size_t SIZE = SubProp<Op,Ranges...>::SIZE;
|
static constexpr size_t SIZE = Op::SIZE * (... * Ranges::SIZE);
|
||||||
};
|
};
|
||||||
|
|
||||||
// for legacy
|
// for legacy
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __map_range_factory_product_map_h__
|
#ifndef __cxz_map_range_factory_product_map_h__
|
||||||
#define __map_range_factory_product_map_h__
|
#define __cxz_map_range_factory_product_map_h__
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
#include "ranges/rbase_def.h"
|
#include "ranges/rbase_def.h"
|
||||||
#include "mbase_def.h"
|
#include "mbase_def.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
class MapRangeFactoryProductMap
|
class MapRangeFactoryProductMap
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,69 +1,75 @@
|
||||||
|
|
||||||
#ifndef __mbase_def_h__
|
#ifndef __cxz_mbase_def_h__
|
||||||
#define __mbase_def_h__
|
#define __cxz_mbase_def_h__
|
||||||
|
|
||||||
#include "ranges/rbase_def.h"
|
#include "ranges/rbase_def.h"
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/***********************
|
/***********************
|
||||||
* Provided Types *
|
* Provided Types *
|
||||||
***********************/
|
***********************/
|
||||||
|
|
||||||
// multi_array.h
|
template <class... Ranges>
|
||||||
template <typename T, class... SRanges>
|
using ContainerRangeFactory = MultiRangeFactory<Ranges...>;
|
||||||
class MultiArrayBase;
|
|
||||||
|
|
||||||
// multi_array.h
|
template <class... Ranges>
|
||||||
template <typename T, class... SRanges>
|
using ContainerRange = MultiRange<Ranges...>;
|
||||||
class MutableMultiArrayBase;
|
|
||||||
|
|
||||||
// multi_array.h
|
// container_index.h
|
||||||
|
template <typename T, class... Indices>
|
||||||
|
class ConstContainerIndex;
|
||||||
|
|
||||||
|
// cxz_array.h
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
class MultiArray;
|
class ArrayBase;
|
||||||
|
|
||||||
|
// cxz_array.h
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
class MutableArrayBase;
|
||||||
|
|
||||||
|
// cxz_array.h
|
||||||
|
template <typename T, class... SRanges>
|
||||||
|
class Array;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class OperationClass>
|
template <typename T, class OperationClass>
|
||||||
class OperationBase;
|
class OperationBase;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
//template <typename T>
|
|
||||||
//class MutableOperationBase;
|
|
||||||
|
|
||||||
// multi_array_operation.h
|
|
||||||
template <typename T, class OperationClass>
|
template <typename T, class OperationClass>
|
||||||
class OperationTemplate;
|
class OperationTemplate;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class OperationRoot;
|
class OperationRoot;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class ParallelOperationRoot;
|
class ParallelOperationRoot;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class OperationValue;
|
class OperationValue;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class ConstOperationRoot;
|
class ConstOperationRoot;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class Op>
|
template <typename T, class Op>
|
||||||
class OperationPointer;
|
class OperationPointer;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
class Operation;
|
class Operation;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class Op, class IndexType>
|
template <typename T, class Op, class IndexType>
|
||||||
class Contraction;
|
class Contraction;
|
||||||
|
|
||||||
// multi_array_operation.h
|
// cxz_operation.h
|
||||||
template <typename T, class Op, class... Indices>
|
template <typename T, class Op, class... Indices>
|
||||||
class SliceContraction;
|
class SliceContraction;
|
||||||
|
|
||||||
|
|
|
@ -1,307 +0,0 @@
|
||||||
|
|
||||||
#include "multi_array.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
Scalar<T> scalar(const T& in)
|
|
||||||
{
|
|
||||||
NullRF nrf;
|
|
||||||
return Scalar<T>( std::dynamic_pointer_cast<NullRange>( nrf.create() ), vector<T>( { in } ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*******************
|
|
||||||
* MultiArray *
|
|
||||||
*******************/
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const typename CRange::Space& space) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(space),
|
|
||||||
mCont(MAB::mRange->size())
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const typename CRange::Space& space,
|
|
||||||
const vector<T>& vec) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(space),
|
|
||||||
mCont(vec)
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
if(mCont.size() > MAB::mRange->size()){
|
|
||||||
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
|
||||||
mCont(MAB::mRange->size())
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const T& val) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
|
||||||
mCont(MAB::mRange->size(), val)
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, const vector<T>& vec) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
|
||||||
mCont(vec)
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
if(mCont.size() > MAB::mRange->size()){
|
|
||||||
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
|
||||||
mCont(std::forward<vector<T>>(vec))
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
if(mCont.size() > MAB::mRange->size()){
|
|
||||||
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class... Ranges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const std::shared_ptr<SRanges>&... ranges, MultiArray<T,Ranges...>&& in) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
|
||||||
mCont( std::move( in.mCont ) )
|
|
||||||
{
|
|
||||||
// maybe some checks here in the future...
|
|
||||||
assert(mCont.size() == MAB::mRange->size());
|
|
||||||
MAB::mInit = true;
|
|
||||||
in.mInit = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>
|
|
||||||
( ama.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
|
|
||||||
mCont( std::move( ama.mCont ) )
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
ama.mInit = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class Range2, class Range3>
|
|
||||||
MultiArray<T,SRanges...>::MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in) :
|
|
||||||
MutableMultiArrayBase<T,SRanges...>(merge(in.range(), in[ in.beginIndex() ].range()))
|
|
||||||
// assert that Range2 has always same extension
|
|
||||||
{
|
|
||||||
MAB::mInit = true;
|
|
||||||
mCont.clear();
|
|
||||||
for(auto i = in.beginIndex(); i != in.endIndex(); ++i){
|
|
||||||
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());
|
|
||||||
}
|
|
||||||
assert(mCont.size() == MAB::mRange->size());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class Range2, class Range3>
|
|
||||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator=(const MultiArray<MultiArray<T,Range2>,Range3> in)
|
|
||||||
{
|
|
||||||
MAB::mRange.reset(new Range(merge(in.range(), in[ in.beginIndex() ].range())));
|
|
||||||
// assert that Range2 has always same extension
|
|
||||||
mCont.clear();
|
|
||||||
for(auto i = in.beginIndex(); i != in.endIndex(); ++i){
|
|
||||||
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());
|
|
||||||
}
|
|
||||||
assert(mCont.size() == MAB::mRange->size());
|
|
||||||
return *this;
|
|
||||||
} */
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
T& MultiArray<T,SRanges...>::operator[](const IndexType& i)
|
|
||||||
{
|
|
||||||
return mCont[ i.pos() ];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
const T& MultiArray<T,SRanges...>::operator[](const IndexType& i) const
|
|
||||||
{
|
|
||||||
return mCont[ i.pos() ];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
T& MultiArray<T,SRanges...>::at(const typename IndexType::MetaType& meta)
|
|
||||||
{
|
|
||||||
return mCont[ MAB::beginIndex().at(meta).pos() ];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
const T& MultiArray<T,SRanges...>::at(const typename IndexType::MetaType& meta) const
|
|
||||||
{
|
|
||||||
return mCont[ MAB::beginIndex().at(meta).pos() ];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
bool MultiArray<T,SRanges...>::isConst() const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
bool MultiArray<T,SRanges...>::isSlice() const
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class... SRanges2>
|
|
||||||
MultiArray<T,SRanges2...> MultiArray<T,SRanges...>::format(const std::shared_ptr<SRanges2>&... nrs)
|
|
||||||
{
|
|
||||||
//MAB::mInit = false;
|
|
||||||
return MultiArray<T,SRanges2...>( nrs... , mCont );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class... SRanges2>
|
|
||||||
MultiArray<T,SRanges2...> MultiArray<T,SRanges...>::format(const std::tuple<std::shared_ptr<SRanges2>...>& nrs)
|
|
||||||
{
|
|
||||||
//MAB::mInit = false;
|
|
||||||
return MultiArray<T,SRanges2...>( nrs , mCont );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class... SRanges2>
|
|
||||||
Slice<T,SRanges2...> MultiArray<T,SRanges...>::slformat(const std::shared_ptr<SRanges2>&... nrs)
|
|
||||||
{
|
|
||||||
return Slice<T,SRanges2...>( nrs..., mCont.data() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
template <class... SRanges2>
|
|
||||||
ConstSlice<T,SRanges2...> MultiArray<T,SRanges...>::slformat(const std::shared_ptr<SRanges2>&... nrs) const
|
|
||||||
{
|
|
||||||
return ConstSlice<T,SRanges2...>( nrs..., mCont.data() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
const T* MultiArray<T,SRanges...>::data() const
|
|
||||||
{
|
|
||||||
return mCont.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
T* MultiArray<T,SRanges...>::data()
|
|
||||||
{
|
|
||||||
return mCont.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > MultiArray<T,SRanges...>::anonymous(bool slice) const
|
|
||||||
{
|
|
||||||
AnonymousRangeFactory arf(MAB::mRange->space());
|
|
||||||
if(slice){
|
|
||||||
return std::make_shared<ConstSlice<T,AnonymousRange> >
|
|
||||||
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
|
||||||
data() );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return std::make_shared<MultiArray<T,AnonymousRange> >
|
|
||||||
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
|
||||||
mCont );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > MultiArray<T,SRanges...>::anonymousMove()
|
|
||||||
{
|
|
||||||
AnonymousRangeFactory arf(MAB::mRange->space());
|
|
||||||
MAB::mInit = false;
|
|
||||||
return std::make_shared<MultiArray<T,AnonymousRange> >
|
|
||||||
( std::dynamic_pointer_cast<AnonymousRange>( arf.create() ),
|
|
||||||
std::move(mCont) );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator=(const T& in)
|
|
||||||
{
|
|
||||||
for(auto& x: mCont){
|
|
||||||
x = in;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator+=(const MultiArray& in)
|
|
||||||
{
|
|
||||||
if(not MAB::mInit){ // not initialized by default constructor !!
|
|
||||||
(*this) = in;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert( PackNum<sizeof...(SRanges)-1>::checkIfSameInstance( MAB::mRange->space(), in.mRange->space() ) );
|
|
||||||
for(size_t i = 0; i != mCont.size(); ++i){
|
|
||||||
mCont[i] += in.mCont[i];
|
|
||||||
}
|
|
||||||
//std::transform(mCont.begin(), mCont.end(), in.mCont.begin(), mCont.begin(), std::plus<T>());
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator-=(const MultiArray& in)
|
|
||||||
{
|
|
||||||
if(not MAB::mInit){ // not initialized by default constructor !!
|
|
||||||
(*this) = in;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert( PackNum<sizeof...(SRanges)-1>::checkIfSameInstance( MAB::mRange->space(), in.mRange->space() ) );
|
|
||||||
for(size_t i = 0; i != mCont.size(); ++i){
|
|
||||||
mCont[i] -= in.mCont[i];
|
|
||||||
}
|
|
||||||
//std::transform(mCont.begin(), mCont.end(), in.mCont.begin(), mCont.begin(), std::minus<T>());
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator*=(const T& in)
|
|
||||||
{
|
|
||||||
for(auto& x: mCont){
|
|
||||||
x *= in;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>& MultiArray<T,SRanges...>::operator/=(const T& in)
|
|
||||||
{
|
|
||||||
for(auto& x: mCont){
|
|
||||||
x /= in;
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
MultiArray<T,SRanges...>::operator T() const
|
|
||||||
{
|
|
||||||
//static_assert( sizeof...(SRanges) == 1, "try to cast non-scalar type into scalar" );
|
|
||||||
// TODO: check that SIZE is statically = 1 !!!
|
|
||||||
return mCont[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
auto MultiArray<T,SRanges...>::cat() const
|
|
||||||
-> decltype(ArrayCatter<T>::cat(*this))
|
|
||||||
{
|
|
||||||
return ArrayCatter<T>::cat(*this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,151 +0,0 @@
|
||||||
// -*- C++ -*-
|
|
||||||
|
|
||||||
#ifndef __multi_array_h__
|
|
||||||
#define __multi_array_h__
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "multi_array_base.h"
|
|
||||||
#include "ranges/anonymous_range.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
struct ArrayCatter;
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct ArrayCatter
|
|
||||||
{
|
|
||||||
template <class... Ranges>
|
|
||||||
static auto cat(const MultiArray<T,Ranges...>& ma)
|
|
||||||
-> MultiArray<T,Ranges...>
|
|
||||||
{
|
|
||||||
return ma;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
|
||||||
class MultiArray : public MutableMultiArrayBase<T,SRanges...>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef ContainerRange<T,SRanges...> CRange;
|
|
||||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
|
||||||
|
|
||||||
using MultiArrayBase<T,SRanges...>::operator[];
|
|
||||||
using MutableMultiArrayBase<T,SRanges...>::operator[];
|
|
||||||
|
|
||||||
DEFAULT_MEMBERS(MultiArray);
|
|
||||||
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 vector<T>& vec);
|
|
||||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, vector<T>&& vec);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
MultiArray(const std::shared_ptr<SRanges>&... ranges, MultiArray<T,Ranges...>&& in); // same effect as format
|
|
||||||
|
|
||||||
MultiArray(const typename CRange::Space& space);
|
|
||||||
MultiArray(const typename CRange::Space& space, const vector<T>& vec);
|
|
||||||
MultiArray(MultiArray<T,AnonymousRange>&& ama, SIZET<SRanges>... sizes);
|
|
||||||
|
|
||||||
// Only if ALL ranges have default extensions:
|
|
||||||
//MultiArray(const vector<T>& vec);
|
|
||||||
//MultiArray(vector<T>&& vec);
|
|
||||||
|
|
||||||
// template <class Range2, class Range3>
|
|
||||||
// MultiArray(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
|
||||||
|
|
||||||
// implement contstructor using FunctionalMultiArray as Input !!!
|
|
||||||
|
|
||||||
//template <class Range2, class Range3>
|
|
||||||
//MultiArray& operator=(const MultiArray<MultiArray<T,Range2>,Range3> in);
|
|
||||||
|
|
||||||
virtual T& operator[](const IndexType& i) final;
|
|
||||||
virtual const T& operator[](const IndexType& i) const final;
|
|
||||||
virtual T& at(const typename IndexType::MetaType& meta) override;
|
|
||||||
virtual const T& at(const typename IndexType::MetaType& meta) const override;
|
|
||||||
|
|
||||||
virtual bool isConst() const override;
|
|
||||||
virtual bool isSlice() const override;
|
|
||||||
|
|
||||||
template <class... SRanges2>
|
|
||||||
MultiArray<T,SRanges2...> format(const std::shared_ptr<SRanges2>&... nrs); // reformat array using 'nr' which in
|
|
||||||
// total must have the same size as mRange
|
|
||||||
|
|
||||||
template <class... SRanges2>
|
|
||||||
MultiArray<T,SRanges2...> format(const std::tuple<std::shared_ptr<SRanges2>...>& nrs);
|
|
||||||
|
|
||||||
template <class... SRanges2>
|
|
||||||
Slice<T,SRanges2...> slformat(const std::shared_ptr<SRanges2>&... nrs);
|
|
||||||
|
|
||||||
template <class... SRanges2>
|
|
||||||
ConstSlice<T,SRanges2...> slformat(const std::shared_ptr<SRanges2>&... nrs) const;
|
|
||||||
|
|
||||||
virtual const T* data() const override;
|
|
||||||
virtual T* data() override;
|
|
||||||
virtual vector<T>& vdata() { return mCont; }
|
|
||||||
virtual const vector<T>& vdata() const { return mCont; }
|
|
||||||
vector<T>&& vmove() { MAB::mInit = false; return std::move(mCont); }
|
|
||||||
|
|
||||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
|
||||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
|
||||||
|
|
||||||
auto cat() const
|
|
||||||
-> decltype(ArrayCatter<T>::cat(*this));
|
|
||||||
|
|
||||||
operator T() const;
|
|
||||||
|
|
||||||
MultiArray& operator=(const T& in);
|
|
||||||
|
|
||||||
MultiArray& operator+=(const MultiArray& in);
|
|
||||||
MultiArray& operator-=(const MultiArray& in);
|
|
||||||
MultiArray& operator*=(const T& in);
|
|
||||||
MultiArray& operator/=(const T& in);
|
|
||||||
|
|
||||||
template <typename U, class... SRanges2>
|
|
||||||
friend class MultiArray;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
vector<T> mCont;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
using Scalar = MultiArray<T,NullRange>;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
Scalar<T> scalar(const T& in);
|
|
||||||
|
|
||||||
template <typename T, class... ERanges>
|
|
||||||
struct ArrayCatter<MultiArray<T,ERanges...> >
|
|
||||||
{
|
|
||||||
template <class... Ranges>
|
|
||||||
static auto cat(const MultiArray<MultiArray<T,ERanges...>,Ranges...>& ma)
|
|
||||||
-> MultiArray<T,Ranges...,ERanges...>
|
|
||||||
{
|
|
||||||
auto sma = *ma.begin();
|
|
||||||
const size_t smas = sma.size();
|
|
||||||
const size_t mas = ma.size();
|
|
||||||
auto cr = ma.range()->cat(sma.range());
|
|
||||||
vector<T> ov;
|
|
||||||
ov.reserve(mas * smas);
|
|
||||||
|
|
||||||
for(auto& x: ma){
|
|
||||||
assert(x.size() == smas);
|
|
||||||
ov.insert(ov.end(), x.vdata().begin(), x.vdata().end());
|
|
||||||
}
|
|
||||||
return MultiArray<T,Ranges...,ERanges...>(cr->space(), std::move(ov));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================= *
|
|
||||||
* --- TEMPLATE CODE --- *
|
|
||||||
* ========================= */
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,14 +0,0 @@
|
||||||
|
|
||||||
#include "ranges/ranges_header.cc.h"
|
|
||||||
|
|
||||||
#include "multi_array_operation.cc.h"
|
|
||||||
#include "functional_multi_array.cc.h"
|
|
||||||
#include "helper_tools.cc.h"
|
|
||||||
#include "map_range.cc.h"
|
|
||||||
#include "multi_array_base.cc.h"
|
|
||||||
#include "multi_array.cc.h"
|
|
||||||
#include "slice.cc.h"
|
|
||||||
#include "dynamic_operation.cc.h"
|
|
||||||
#include "high_level_operation.cc.h"
|
|
||||||
//#include "expressions.cc.h"
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
// -*- C++ -*-
|
|
||||||
|
|
||||||
#ifndef __multi_array_header_h__
|
|
||||||
#define __multi_array_header_h__
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include "multi_array_operation.h"
|
|
||||||
#include "multi_array_base.h"
|
|
||||||
#include "multi_array.h"
|
|
||||||
#include "functional_multi_array.h"
|
|
||||||
#include "helper_tools.h"
|
|
||||||
#include "operation_def.h"
|
|
||||||
#include "map_range.h"
|
|
||||||
#include "dynamic_operation.h"
|
|
||||||
#include "high_level_operation.h"
|
|
||||||
//#include "expressions.h"
|
|
||||||
|
|
||||||
#include "multi_array_header.cc.h"
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
#ifndef __operation_def_h__
|
#ifndef __cxz_operation_def_h__
|
||||||
#define __operation_def_h__
|
#define __cxz_operation_def_h__
|
||||||
|
|
||||||
#include "multi_array_operation.h"
|
#include "cxz_operation.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T, class OperationClass>
|
template <typename T, class OperationClass>
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
|
|
||||||
#ifndef __operation_helper_h__
|
|
||||||
#define __operation_helper_h__
|
|
||||||
|
|
||||||
#include "multi_array_operation.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
|
|
||||||
template <class BaseArray, class... Ranges>
|
|
||||||
class PseudoArray
|
|
||||||
{
|
|
||||||
size_t mThreadNum;
|
|
||||||
Slice<> mSl;
|
|
||||||
mutable ConstOperationRoot<T,Range> mOp;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
template <class ET>
|
|
||||||
const SrcHolder<ConstOperationRoot<T,Range>> operator[](ET pos) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Operation>
|
|
||||||
class SrcHolder
|
|
||||||
{
|
|
||||||
|
|
||||||
TempHolder operator+(SrcHolder in) const;
|
|
||||||
// aso
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Operation>
|
|
||||||
class TempHolder
|
|
||||||
{
|
|
||||||
TempHolder operator+(SrcHolder in) const;
|
|
||||||
TempHolder operator+(TempHolder in) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Operation>
|
|
||||||
class TarHolder
|
|
||||||
{
|
|
||||||
TarHolder& operator=(TempHolder in);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,220 +0,0 @@
|
||||||
// -*- C++ -*-
|
|
||||||
|
|
||||||
#ifndef __pack_num_h__
|
|
||||||
#define __pack_num_h__
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
//#include <type_traits>
|
|
||||||
#include <tuple>
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
#include "base_def.h"
|
|
||||||
#include "xfor/exttype.h"
|
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
|
||||||
{
|
|
||||||
template <bool ISSTATIC>
|
|
||||||
struct Application
|
|
||||||
{
|
|
||||||
template <class OpFunction, typename... Ts>
|
|
||||||
static inline auto apply(std::shared_ptr<OpFunction> f, Ts... as)
|
|
||||||
-> decltype((*f)(as...))
|
|
||||||
{
|
|
||||||
return (*f)(as...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct Application<true>
|
|
||||||
{
|
|
||||||
template <class OpFunction, typename... Ts>
|
|
||||||
static inline auto apply(std::shared_ptr<OpFunction> f, Ts... as)
|
|
||||||
-> decltype(OpFunction::apply(as...))
|
|
||||||
{
|
|
||||||
return OpFunction::apply(as...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
struct PackNum
|
|
||||||
{
|
|
||||||
template <class MA, class ITuple, class... IPtrs>
|
|
||||||
static auto mkElemOperation(const MA& ma, const ITuple& ituple, IPtrs... iptrs)
|
|
||||||
-> decltype(PackNum<N-1>::mkElemOperation(ma, ituple, std::get<N>(ituple), iptrs...))
|
|
||||||
{
|
|
||||||
return PackNum<N-1>::mkElemOperation(ma, ituple, std::get<N>(ituple), iptrs...);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename... T>
|
|
||||||
static void printTuple(std::ostream& out, const std::tuple<T...>& tp)
|
|
||||||
{
|
|
||||||
out << std::get<sizeof...(T)-N-1>(tp) << ", ";
|
|
||||||
PackNum<N-1>::printTuple(out, tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ops>
|
|
||||||
static auto mkSteps(std::intptr_t ii, const std::tuple<Ops...>& otp)
|
|
||||||
-> decltype(PackNum<N-1>::mkSteps(ii, otp).extend( std::get<N>(otp).rootSteps(ii)) )
|
|
||||||
{
|
|
||||||
return PackNum<N-1>::mkSteps(ii, otp).extend( std::get<N>(otp).rootSteps(ii));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RootStepTuple, class IndexClass, class OpClass>
|
|
||||||
static void mkExt(std::array<RootStepTuple,IndexClass::totalDim()>& out,
|
|
||||||
const std::array<std::intptr_t,IndexClass::totalDim()>& siar,
|
|
||||||
const OpClass& second)
|
|
||||||
{
|
|
||||||
std::get<N>(out) = second.rootSteps( std::get<N>(siar) );
|
|
||||||
PackNum<N-1>::mkExt(out, siar, second);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t LAST, class ETuple, class OpTuple, class OpFunction, typename... Args>
|
|
||||||
static inline auto mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, Args... args)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(std::get<N>(ops))>::type NextOpType;
|
|
||||||
static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions");
|
|
||||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
|
||||||
typedef decltype(std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos ))) ArgT;
|
|
||||||
return PackNum<N-1>::template mkOpExpr<NEXT,ETuple,OpTuple,OpFunction,ArgT,Args...>
|
|
||||||
( f, pos, ops, std::get<N>(ops).get(Getter<NEXT>::template getX<ETuple>( pos )), args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class OpTuple, class Expr>
|
|
||||||
static auto mkLoop( const OpTuple& ot, Expr exp )
|
|
||||||
-> decltype(std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) ))
|
|
||||||
{
|
|
||||||
return std::get<N>(ot).loop( PackNum<N-1>::mkLoop(ot,exp) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Op, class... SRanges>
|
|
||||||
static void mkSliceBlocks(std::array<size_t, sizeof...(SRanges)+1>& blocks,
|
|
||||||
const ContainerIndex<T,typename SRanges::IndexType...>& index,
|
|
||||||
const Op& op, size_t total = 1)
|
|
||||||
{
|
|
||||||
const size_t tmp =
|
|
||||||
op.rootSteps(reinterpret_cast<std::intptr_t>
|
|
||||||
( index.template getPtr<N>().get() ) )
|
|
||||||
.val();
|
|
||||||
std::get<N+1>(blocks) = tmp;
|
|
||||||
PackNum<N-1>::template mkSliceBlocks<T,Op,SRanges...>(blocks, index, op, total * tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... SRanges>
|
|
||||||
static bool checkIfSameInstance(const std::tuple<std::shared_ptr<SRanges>...>& rtp1,
|
|
||||||
const std::tuple<std::shared_ptr<SRanges>...>& rtp2)
|
|
||||||
{
|
|
||||||
return std::get<N>(rtp1).get() == std::get<N>(rtp2).get() and PackNum<N-1>::checkIfSameInstance(rtp1,rtp2);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MA, class ITuple, class... Indices>
|
|
||||||
static inline auto mkMapOp(const MA& ma, const ITuple& itp, const std::shared_ptr<Indices>&... inds)
|
|
||||||
-> decltype(PackNum<N-1>::mkMapOp(ma, itp, std::get<N>(itp), inds...))
|
|
||||||
{
|
|
||||||
return PackNum<N-1>::mkMapOp(ma, itp, std::get<N>(itp), inds...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t LAST,class OpTuple, class ETuple>
|
|
||||||
static inline void setOpPos(OpTuple& ot, const ETuple& et)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(std::get<N>(ot))>::type NextOpType;
|
|
||||||
static_assert(LAST >= NextOpType::SIZE, "inconsistent array positions");
|
|
||||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
|
||||||
std::get<N>( ot ).set( Getter<NEXT>::template getX<ETuple>( et ) );
|
|
||||||
PackNum<N-1>::template setOpPos<NEXT,OpTuple,ETuple>(ot, et);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct PackNum<0>
|
|
||||||
{
|
|
||||||
template <class MA, class ITuple, class... IPtrs>
|
|
||||||
static auto mkElemOperation(const MA& ma, const ITuple& ituple, IPtrs... iptrs)
|
|
||||||
-> decltype(ma(iptrs...))
|
|
||||||
{
|
|
||||||
return ma(iptrs...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... T>
|
|
||||||
static void printTuple(std::ostream& out, const std::tuple<T...>& tp)
|
|
||||||
{
|
|
||||||
out << std::get<sizeof...(T)-1>(tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ops>
|
|
||||||
static auto mkSteps(std::intptr_t ii, const std::tuple<Ops...>& otp)
|
|
||||||
-> decltype(std::get<0>(otp).rootSteps(ii))
|
|
||||||
{
|
|
||||||
return std::get<0>(otp).rootSteps(ii);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RootStepTuple, class IndexClass, class OpClass>
|
|
||||||
static void mkExt(std::array<RootStepTuple,IndexClass::totalDim()>& out,
|
|
||||||
const std::array<std::intptr_t,IndexClass::totalDim()>& siar,
|
|
||||||
const OpClass& second)
|
|
||||||
{
|
|
||||||
std::get<0>(out) = second.rootSteps( std::get<0>(siar) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t LAST, class ETuple, class OpTuple, class OpFunction, typename... Args>
|
|
||||||
static inline auto mkOpExpr(std::shared_ptr<OpFunction> f, const ETuple& pos, const OpTuple& ops, const Args&... args)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(std::get<0>(ops))>::type NextOpType;
|
|
||||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
|
||||||
static_assert(NEXT == 0, "inconsistent array positions");
|
|
||||||
typedef decltype(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos ))) ArgT;
|
|
||||||
return Application<OpFunction::FISSTATIC>::template apply<OpFunction,ArgT,Args...>(f, std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
|
|
||||||
//return OpFunction::apply(std::get<0>(ops).get(Getter<0>::template getX<ETuple>( pos )), args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class OpTuple, class Expr>
|
|
||||||
static auto mkLoop( const OpTuple& ot, Expr exp )
|
|
||||||
-> decltype(std::get<0>(ot).loop( exp ))
|
|
||||||
{
|
|
||||||
return std::get<0>(ot).loop( exp );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class Op, class... SRanges>
|
|
||||||
static void mkSliceBlocks(std::array<size_t, sizeof...(SRanges)+1>& blocks,
|
|
||||||
const ContainerIndex<T,typename SRanges::IndexType...>& index,
|
|
||||||
const Op& op, size_t total = 1)
|
|
||||||
{
|
|
||||||
const size_t tmp =
|
|
||||||
op.rootSteps(reinterpret_cast<std::intptr_t>
|
|
||||||
( index.template getPtr<0>().get() ) )
|
|
||||||
.val();
|
|
||||||
std::get<1>(blocks) = tmp;
|
|
||||||
std::get<0>(blocks) = total * tmp; // this is not correct, but not used so far ... !!!
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... SRanges>
|
|
||||||
static bool checkIfSameInstance(const std::tuple<std::shared_ptr<SRanges>...>& rtp1,
|
|
||||||
const std::tuple<std::shared_ptr<SRanges>...>& rtp2)
|
|
||||||
{
|
|
||||||
return std::get<0>(rtp1).get() == std::get<0>(rtp2).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MA, class ITuple, class... Indices>
|
|
||||||
static inline auto mkMapOp(const MA& ma, const ITuple& itp, const std::shared_ptr<Indices>&... inds)
|
|
||||||
-> decltype(ma.exec(std::get<0>(itp), inds...))
|
|
||||||
{
|
|
||||||
return ma.exec(std::get<0>(itp), inds...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t LAST,class OpTuple, class ETuple>
|
|
||||||
static inline void setOpPos(OpTuple& ot, const ETuple& et)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(std::get<0>(ot))>::type NextOpType;
|
|
||||||
static constexpr size_t NEXT = LAST - NextOpType::SIZE;
|
|
||||||
static_assert(NEXT == 0, "inconsistent array positions");
|
|
||||||
std::get<0>( ot ).set( Getter<NEXT>::template getX<ETuple>( et ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __anonymous_range_h__
|
#ifndef __cxz_anonymous_range_h__
|
||||||
#define __anonymous_range_h__
|
#define __cxz_anonymous_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef GenSingleIndex<size_t,SpaceType::ANON,MUI> AnonymousIndex;
|
typedef GenSingleIndex<size_t,SpaceType::ANON,MUI> AnonymousIndex;
|
||||||
|
@ -133,7 +133,7 @@ namespace MultiArrayTools
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
* ========================= */
|
* ========================= */
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
|
@ -171,38 +171,38 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
|
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
|
||||||
}
|
}
|
||||||
|
namespace CNORXZ
|
||||||
namespace MultiArrayHelper
|
|
||||||
{
|
{
|
||||||
using namespace MultiArrayTools;
|
namespace RangeHelper
|
||||||
|
|
||||||
template <>
|
|
||||||
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange>& rp,
|
|
||||||
const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
size_t origpos, size_t size)
|
|
||||||
{
|
{
|
||||||
AnonymousRangeFactory arf;
|
template <>
|
||||||
for(size_t op = origpos; op != origpos + size; ++op){
|
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange>& rp,
|
||||||
//VCHECK(op);
|
const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
arf.append(orig[op]);
|
size_t origpos, size_t size)
|
||||||
|
{
|
||||||
|
AnonymousRangeFactory arf;
|
||||||
|
for(size_t op = origpos; op != origpos + size; ++op){
|
||||||
|
//VCHECK(op);
|
||||||
|
arf.append(orig[op]);
|
||||||
|
}
|
||||||
|
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
||||||
}
|
}
|
||||||
rp = std::dynamic_pointer_cast<AnonymousRange>( arf.create() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
inline void setRangeToVec<AnonymousRange>(vector<std::shared_ptr<RangeBase> >& v,
|
template <>
|
||||||
std::shared_ptr<AnonymousRange> r)
|
inline void setRangeToVec<AnonymousRange>(vector<std::shared_ptr<RangeBase> >& v,
|
||||||
{
|
std::shared_ptr<AnonymousRange> r)
|
||||||
if(not r->isEmpty()){
|
{
|
||||||
for(size_t i = r->anonymousDim(); i != 0; --i){
|
if(not r->isEmpty()){
|
||||||
v.insert(v.begin(), r->sub(i-1));
|
for(size_t i = r->anonymousDim(); i != 0; --i){
|
||||||
|
v.insert(v.begin(), r->sub(i-1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/***********************
|
/***********************
|
||||||
* AnonymousRange *
|
* AnonymousRange *
|
||||||
|
@ -212,8 +212,12 @@ namespace MultiArrayTools
|
||||||
GenSingleRange<size_t,SpaceType::ANON,MUI>::GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
GenSingleRange<size_t,SpaceType::ANON,MUI>::GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
||||||
RangeInterface<AnonymousIndex>()
|
RangeInterface<AnonymousIndex>()
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
|
mOrig.resize(sizeof...(RangeTypes));
|
||||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
|
sfor_pn<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { mOrig[i] = std::get<i>(origs); return 0; } );
|
||||||
|
mSize = sfor_p<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { return std::get<i>(origs)->size(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
if(sizeof...(RangeTypes)){
|
if(sizeof...(RangeTypes)){
|
||||||
mEmpty = false;
|
mEmpty = false;
|
||||||
}
|
}
|
||||||
|
@ -224,8 +228,12 @@ namespace MultiArrayTools
|
||||||
RangeInterface<AnonymousIndex>()
|
RangeInterface<AnonymousIndex>()
|
||||||
{
|
{
|
||||||
auto rst = std::make_tuple(origs...);
|
auto rst = std::make_tuple(origs...);
|
||||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
mOrig.resize(sizeof...(RangeTypes));
|
||||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
sfor_pn<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { mOrig[i] = std::get<i>(rst); return 0; } );
|
||||||
|
mSize = sfor_p<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { return std::get<i>(rst)->size(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
if(sizeof...(RangeTypes)){
|
if(sizeof...(RangeTypes)){
|
||||||
mEmpty = false;
|
mEmpty = false;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +249,7 @@ namespace MultiArrayTools
|
||||||
std::shared_ptr<MultiRange<Ranges...> > GenSingleRange<size_t,SpaceType::ANON,MUI>::scast(SIZET<Ranges>... sizes) const
|
std::shared_ptr<MultiRange<Ranges...> > GenSingleRange<size_t,SpaceType::ANON,MUI>::scast(SIZET<Ranges>... sizes) const
|
||||||
{
|
{
|
||||||
std::tuple<std::shared_ptr<Ranges>...> rtp;
|
std::tuple<std::shared_ptr<Ranges>...> rtp;
|
||||||
RPackNum<sizeof...(Ranges)-1>::resolveRangeType(mOrig, rtp, 0, sizes...);
|
RangeHelper::resolveRangeType<0>(mOrig, rtp, 0, sizes...);
|
||||||
MultiRangeFactory<Ranges...> mrf(rtp);
|
MultiRangeFactory<Ranges...> mrf(rtp);
|
||||||
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,766 +0,0 @@
|
||||||
// -*- C++ -*-
|
|
||||||
|
|
||||||
#ifndef __container_range_h__
|
|
||||||
#define __container_range_h__
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <tuple>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "ranges/range_base.h"
|
|
||||||
#include "ranges/index_base.h"
|
|
||||||
|
|
||||||
#include "rpack_num.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
class ContainerIndex : public IndexInterface<ContainerIndex<T,Indices...>,
|
|
||||||
std::tuple<typename Indices::MetaType...> >,
|
|
||||||
public std::iterator<std::random_access_iterator_tag,T>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef IndexInterface<ContainerIndex<T,Indices...>,
|
|
||||||
std::tuple<typename Indices::MetaType...> > IB;
|
|
||||||
typedef std::tuple<typename Indices::MetaType...> MetaType;
|
|
||||||
typedef std::tuple<std::shared_ptr<Indices>...> IndexPack;
|
|
||||||
typedef ContainerRange<T,typename Indices::RangeType...> RangeType;
|
|
||||||
|
|
||||||
static constexpr IndexType sType() { return IndexType::CONT; }
|
|
||||||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
|
||||||
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
|
||||||
|
|
||||||
static constexpr SpaceType STYPE = SpaceType::ANY;
|
|
||||||
static constexpr bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
|
||||||
|
|
||||||
template <typename X>
|
|
||||||
using CIX = ContainerIndex<X,Indices...>;
|
|
||||||
|
|
||||||
template <typename X>
|
|
||||||
friend class CIX;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
ContainerIndex() = default;
|
|
||||||
|
|
||||||
bool mNonTrivialBlocks = false;
|
|
||||||
bool mExternControl = false;
|
|
||||||
IndexPack mIPack;
|
|
||||||
std::array<size_t,sizeof...(Indices)+1> mBlockSizes;
|
|
||||||
const T* mData = nullptr;
|
|
||||||
size_t mCPos;
|
|
||||||
//const MultiArrayBase<T,typename Indices::RangeType...>* mMa = nullptr;
|
|
||||||
std::intptr_t mObjPtrNum;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ContainerIndex(const ContainerIndex& in) = default;
|
|
||||||
ContainerIndex& operator=(const ContainerIndex& in) = default;
|
|
||||||
|
|
||||||
ContainerIndex(const ContainerIndex& in, bool copy) :
|
|
||||||
IB(in),
|
|
||||||
mNonTrivialBlocks(in.mNonTrivialBlocks),
|
|
||||||
mExternControl(false),
|
|
||||||
mBlockSizes(in.mBlockSizes),
|
|
||||||
mData(in.mData),
|
|
||||||
mCPos(in.mCPos),
|
|
||||||
mObjPtrNum(in.mObjPtrNum)
|
|
||||||
{
|
|
||||||
//if(copy){
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
|
|
||||||
//}
|
|
||||||
//else {
|
|
||||||
//mIPack = in.mIPack;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
ContainerIndex& copy(const ContainerIndex& in)
|
|
||||||
{
|
|
||||||
IB::operator=(in);
|
|
||||||
mNonTrivialBlocks = in.mNonTrivialBlocks;
|
|
||||||
mExternControl = false;
|
|
||||||
mBlockSizes = in.mBlockSizes;
|
|
||||||
mData = in.mData;
|
|
||||||
mCPos = in.mCPos;
|
|
||||||
mObjPtrNum = in.mObjPtrNum;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copyIndex(mIPack, in);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename X>
|
|
||||||
ContainerIndex& operator=(const ContainerIndex<X,Indices...>& in);
|
|
||||||
|
|
||||||
template <class MRange>
|
|
||||||
ContainerIndex(const std::shared_ptr<MRange>& range,
|
|
||||||
std::intptr_t objPtrNum);
|
|
||||||
|
|
||||||
template <class MRange>
|
|
||||||
ContainerIndex(const std::shared_ptr<MRange>& range,
|
|
||||||
std::intptr_t objPtrNum,
|
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSizes);
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
auto get() const -> decltype( *std::get<N>( mIPack ) )&;
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
auto getPtr() const -> decltype( std::get<N>( mIPack ) )&;
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
|
||||||
|
|
||||||
const IndexPack& pack() const { return mIPack; }
|
|
||||||
|
|
||||||
ContainerIndex& sync(); // recalculate 'IB::mPos' when externalControl == true
|
|
||||||
ContainerIndex& operator()(const std::shared_ptr<Indices>&... inds); // control via external indices
|
|
||||||
ContainerIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& inds);
|
|
||||||
ContainerIndex& operator()(); // -> sync; just to shorten the code
|
|
||||||
|
|
||||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
|
||||||
|
|
||||||
IndexType type() const;
|
|
||||||
|
|
||||||
ContainerIndex& operator++();
|
|
||||||
ContainerIndex& operator--();
|
|
||||||
|
|
||||||
ContainerIndex& operator=(size_t pos);
|
|
||||||
|
|
||||||
int pp(std::intptr_t idxPtrNum);
|
|
||||||
int mm(std::intptr_t idxPtrNum);
|
|
||||||
|
|
||||||
std::string stringMeta() const;
|
|
||||||
MetaType meta() const;
|
|
||||||
ContainerIndex& at(const MetaType& metaPos);
|
|
||||||
|
|
||||||
size_t dim() const;
|
|
||||||
bool first() const;
|
|
||||||
bool last() const;
|
|
||||||
bool sliceMode() const;
|
|
||||||
|
|
||||||
std::shared_ptr<RangeType> range();
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
auto getPtr() -> decltype( std::get<N>( mIPack ) )&;
|
|
||||||
|
|
||||||
size_t getStepSize(size_t n);
|
|
||||||
|
|
||||||
std::string id() const;
|
|
||||||
void print(size_t offset);
|
|
||||||
|
|
||||||
template <class Exprs>
|
|
||||||
auto ifor(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
|
||||||
|
|
||||||
template <class Exprs>
|
|
||||||
auto iforh(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
|
||||||
|
|
||||||
template <class Exprs>
|
|
||||||
auto pifor(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs));
|
|
||||||
|
|
||||||
std::intptr_t container() const;
|
|
||||||
ContainerIndex& format(const std::array<size_t,sizeof...(Indices)+1>& blocks);
|
|
||||||
|
|
||||||
// Iterator Stuff
|
|
||||||
|
|
||||||
ContainerIndex& setData(const T* data);
|
|
||||||
|
|
||||||
const T& operator*() const;
|
|
||||||
const T* operator->() const;
|
|
||||||
//T& operator*();
|
|
||||||
//T* operator->();
|
|
||||||
|
|
||||||
ContainerIndex operator++(int);
|
|
||||||
ContainerIndex operator--(int);
|
|
||||||
ContainerIndex& operator+=(int diff);
|
|
||||||
ContainerIndex& operator-=(int diff);
|
|
||||||
ContainerIndex operator+(int num) const;
|
|
||||||
ContainerIndex operator-(int num) const;
|
|
||||||
|
|
||||||
int operator-(const ContainerIndex& it) const;
|
|
||||||
const T& operator[](int num) const;
|
|
||||||
|
|
||||||
bool operator<(const ContainerIndex& it) const;
|
|
||||||
bool operator>(const ContainerIndex& it) const;
|
|
||||||
bool operator<=(const ContainerIndex& it) const;
|
|
||||||
bool operator>=(const ContainerIndex& it) const;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
class ContainerRangeFactory : public RangeFactoryBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef ContainerRange<T,Ranges...> oType;
|
|
||||||
|
|
||||||
ContainerRangeFactory();
|
|
||||||
ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
|
||||||
ContainerRangeFactory(const typename ContainerRange<T,Ranges...>::SpaceType& space);
|
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> create() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
};*/
|
|
||||||
/*
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
class ContainerRange : public RangeInterface<ContainerIndex<T,typename Ranges::IndexType...> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef RangeBase RB;
|
|
||||||
typedef std::tuple<std::shared_ptr<Ranges>...> SpaceType;
|
|
||||||
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ContainerRange() = default;
|
|
||||||
ContainerRange(const ContainerRange& in) = delete;
|
|
||||||
ContainerRange& operator=(const ContainerRange& in) = delete;
|
|
||||||
|
|
||||||
ContainerRange(const std::shared_ptr<Ranges>&... rs);
|
|
||||||
ContainerRange(const SpaceType& space);
|
|
||||||
|
|
||||||
SpaceType mSpace;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const size_t sdim = sizeof...(Ranges);
|
|
||||||
|
|
||||||
virtual size_t dim() const override;
|
|
||||||
virtual size_t size() const override;
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
auto get() const -> decltype( *std::get<N>( mSpace ) )&;
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
auto getPtr() const -> decltype( std::get<N>( mSpace ) )&;
|
|
||||||
|
|
||||||
const SpaceType& space() const;
|
|
||||||
|
|
||||||
virtual IndexType begin() const override;
|
|
||||||
virtual IndexType end() const override;
|
|
||||||
|
|
||||||
friend ContainerRangeFactory<T,Ranges...>;
|
|
||||||
|
|
||||||
static constexpr bool defaultable = false;
|
|
||||||
static constexpr size_t ISSTATIC = SubProp<Ranges...>::ISSTATIC;
|
|
||||||
static constexpr size_t SIZE = SubProp<Ranges...>::SIZE;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
//template <typename T, class... Ranges>
|
|
||||||
//using ContainerRange = MultiRange<Ranges...>;
|
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
|
||||||
|
|
||||||
/* ========================= *
|
|
||||||
* --- TEMPLATE CODE --- *
|
|
||||||
* ========================= */
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
using namespace MultiArrayHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************
|
|
||||||
* ContainerIndex *
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <class MRange>
|
|
||||||
ContainerIndex<T,Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range,
|
|
||||||
std::intptr_t objPtrNum) :
|
|
||||||
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
|
||||||
mObjPtrNum(objPtrNum)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
|
||||||
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <class MRange>
|
|
||||||
ContainerIndex<T,Indices...>::ContainerIndex(const std::shared_ptr<MRange>& range,
|
|
||||||
std::intptr_t objPtrNum,
|
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSizes) :
|
|
||||||
IndexInterface<ContainerIndex<T,Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0),
|
|
||||||
mObjPtrNum(objPtrNum)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
|
||||||
mBlockSizes = blockSizes;
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
mNonTrivialBlocks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <typename X>
|
|
||||||
ContainerIndex<T,Indices...>&
|
|
||||||
ContainerIndex<T,Indices...>::operator=(const ContainerIndex<X,Indices...>& in)
|
|
||||||
{
|
|
||||||
mIPack = in.mIPack;
|
|
||||||
return (*this)();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::sync()
|
|
||||||
{
|
|
||||||
if(mExternControl){
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
//VCHECK(id());
|
|
||||||
//VCHECK(sizeof...(Indices));
|
|
||||||
//assert(IB::mPos < IB::max());
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <size_t N>
|
|
||||||
auto ContainerIndex<T,Indices...>::get() const -> decltype( *std::get<N>( mIPack ) )&
|
|
||||||
{
|
|
||||||
return *std::get<N>( mIPack );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <size_t N>
|
|
||||||
auto ContainerIndex<T,Indices...>::getPtr() const -> decltype( std::get<N>( mIPack ) )&
|
|
||||||
{
|
|
||||||
return std::get<N>( mIPack );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::shared_ptr<Indices>&... inds)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, inds...);
|
|
||||||
mExternControl = true;
|
|
||||||
return sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& inds)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, inds);
|
|
||||||
mExternControl = true;
|
|
||||||
return sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator()()
|
|
||||||
{
|
|
||||||
return sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
IndexType ContainerIndex<T,Indices...>::type() const { return IndexType::CONT; }
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator++()
|
|
||||||
{
|
|
||||||
if(mExternControl){
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
}
|
|
||||||
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
|
||||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
++IB::mPos;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator--()
|
|
||||||
{
|
|
||||||
if(mExternControl){
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
}
|
|
||||||
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
|
||||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
--IB::mPos;
|
|
||||||
return *this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator=(size_t pos)
|
|
||||||
{
|
|
||||||
IB::mPos = pos;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
|
||||||
mCPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
int ContainerIndex<T,Indices...>::pp(std::intptr_t idxPtrNum)
|
|
||||||
{
|
|
||||||
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
|
||||||
IB::mPos += tmp;
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
int ContainerIndex<T,Indices...>::mm(std::intptr_t idxPtrNum)
|
|
||||||
{
|
|
||||||
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
|
||||||
IB::mPos -= tmp;
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
std::string ContainerIndex<T,Indices...>::stringMeta() const
|
|
||||||
{
|
|
||||||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr )->stringMeta(IB::mPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
typename ContainerIndex<T,Indices...>::MetaType ContainerIndex<T,Indices...>::meta() const
|
|
||||||
{
|
|
||||||
MetaType metaTuple;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
|
||||||
return metaTuple;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::at(const MetaType& metaPos)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack, mBlockSizes);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
size_t ContainerIndex<T,Indices...>::dim() const
|
|
||||||
{
|
|
||||||
return sizeof...(Indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::first() const
|
|
||||||
{
|
|
||||||
return IB::pos() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::last() const
|
|
||||||
{
|
|
||||||
return IB::pos() == IB::mMax - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::sliceMode() const
|
|
||||||
{
|
|
||||||
return mNonTrivialBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
std::shared_ptr<typename ContainerIndex<T,Indices...>::RangeType>
|
|
||||||
ContainerIndex<T,Indices...>::range()
|
|
||||||
{
|
|
||||||
return std::dynamic_pointer_cast<RangeType>( IB::mRangePtr );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <size_t N>
|
|
||||||
auto ContainerIndex<T,Indices...>::getPtr() -> decltype( std::get<N>( mIPack ) )&
|
|
||||||
{
|
|
||||||
return std::get<N>( mIPack );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
size_t ContainerIndex<T,Indices...>::getStepSize(size_t n)
|
|
||||||
{
|
|
||||||
if(n >= sizeof...(Indices)){
|
|
||||||
assert(0);
|
|
||||||
// throw !!
|
|
||||||
}
|
|
||||||
return mBlockSizes[n+1];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
std::string ContainerIndex<T,Indices...>::id() const
|
|
||||||
{
|
|
||||||
return std::string("con") + std::to_string(IB::mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
void ContainerIndex<T,Indices...>::print(size_t offset)
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this) << "]"
|
|
||||||
<< "(" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <class Exprs>
|
|
||||||
auto ContainerIndex<T,Indices...>::ifor(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
|
||||||
{
|
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <class Exprs>
|
|
||||||
auto ContainerIndex<T,Indices...>::iforh(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
|
||||||
{
|
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
template <class Exprs>
|
|
||||||
auto ContainerIndex<T,Indices...>::pifor(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs))
|
|
||||||
{
|
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
std::intptr_t ContainerIndex<T,Indices...>::container() const
|
|
||||||
{
|
|
||||||
return mObjPtrNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::
|
|
||||||
format(const std::array<size_t,sizeof...(Indices)+1>& blocks)
|
|
||||||
{
|
|
||||||
mBlockSizes = blocks;
|
|
||||||
mNonTrivialBlocks = true;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::setData(const T* data)
|
|
||||||
{
|
|
||||||
mData = data;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
const T& ContainerIndex<T,Indices...>::operator*() const
|
|
||||||
{
|
|
||||||
//return mMa[*this];
|
|
||||||
return mData[mCPos];
|
|
||||||
//return mData[IB::mPos];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
const T* ContainerIndex<T,Indices...>::operator->() const
|
|
||||||
{
|
|
||||||
//return &mMa[*this];
|
|
||||||
return &mData[mCPos];
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
T& ContainerIndex<T,Indices...>::operator*()
|
|
||||||
{
|
|
||||||
//return mMa[*this];
|
|
||||||
return mData[IB::mPos];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
T* ContainerIndex<T,Indices...>::operator->()
|
|
||||||
{
|
|
||||||
//return &mMa[*this];
|
|
||||||
return &mData[IB::mPos];
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...> ContainerIndex<T,Indices...>::operator++(int)
|
|
||||||
{
|
|
||||||
auto tmp = *this;
|
|
||||||
++(*this);
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...> ContainerIndex<T,Indices...>::operator--(int)
|
|
||||||
{
|
|
||||||
auto tmp = *this;
|
|
||||||
--(*this);
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator+=(int diff)
|
|
||||||
{
|
|
||||||
if(diff < 0){
|
|
||||||
for(int i = 0; i != diff; ++i){
|
|
||||||
(*this)--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for(int i = 0; i != diff; ++i){
|
|
||||||
(*this)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...>& ContainerIndex<T,Indices...>::operator-=(int diff)
|
|
||||||
{
|
|
||||||
if(diff < 0){
|
|
||||||
for(int i = 0; i != diff; ++i){
|
|
||||||
(*this)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for(int i = 0; i != diff; ++i){
|
|
||||||
(*this)--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...> ContainerIndex<T,Indices...>::operator+(int num) const
|
|
||||||
{
|
|
||||||
auto tmp = *this;
|
|
||||||
return tmp += num;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
ContainerIndex<T,Indices...> ContainerIndex<T,Indices...>::operator-(int num) const
|
|
||||||
{
|
|
||||||
auto tmp = *this;
|
|
||||||
return tmp -= num;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
int ContainerIndex<T,Indices...>::operator-(const ContainerIndex<T,Indices...>& it) const
|
|
||||||
{
|
|
||||||
return static_cast<int>( IB::mPos ) - static_cast<int>( it.pos() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
const T& ContainerIndex<T,Indices...>::operator[](int num) const
|
|
||||||
{
|
|
||||||
return mData[IB::mPos + num];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::operator<(const ContainerIndex<T,Indices...>& it) const
|
|
||||||
{
|
|
||||||
return IB::mPos < it.pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::operator>(const ContainerIndex<T,Indices...>& it) const
|
|
||||||
{
|
|
||||||
return IB::mPos > it.pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::operator<=(const ContainerIndex<T,Indices...>& it) const
|
|
||||||
{
|
|
||||||
return IB::mPos <= it.pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
bool ContainerIndex<T,Indices...>::operator>=(const ContainerIndex<T,Indices...>& it) const
|
|
||||||
{
|
|
||||||
return IB::mPos >= it.pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************
|
|
||||||
* ContainerRangeFactory *
|
|
||||||
*****************************/
|
|
||||||
/*
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
ContainerRangeFactory<T,Ranges...>::ContainerRangeFactory(const std::shared_ptr<Ranges>&... rs)
|
|
||||||
{
|
|
||||||
mProd = std::shared_ptr<ContainerRange<T,Ranges...> >( new ContainerRange<T,Ranges...>( rs... ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
ContainerRangeFactory<T,Ranges...>::
|
|
||||||
ContainerRangeFactory(const typename ContainerRange<T,Ranges...>::SpaceType& space)
|
|
||||||
{
|
|
||||||
mProd = std::shared_ptr<ContainerRange<T,Ranges...> >( new ContainerRange<T,Ranges...>( space ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
std::shared_ptr<RangeBase> ContainerRangeFactory<T,Ranges...>::create()
|
|
||||||
{
|
|
||||||
setSelf();
|
|
||||||
return mProd;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/**********************
|
|
||||||
* ContainerRange *
|
|
||||||
**********************/
|
|
||||||
/*
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
ContainerRange<T,Ranges...>::ContainerRange(const std::shared_ptr<Ranges>&... rs) :
|
|
||||||
mSpace( std::make_tuple( rs... ) ) {}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
ContainerRange<T,Ranges...>::ContainerRange(const SpaceType& space) : mSpace( space ) {}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
size_t ContainerRange<T,Ranges...>::dim() const
|
|
||||||
{
|
|
||||||
return sizeof...(Ranges);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
size_t ContainerRange<T,Ranges...>::size() const
|
|
||||||
{
|
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
template <size_t N>
|
|
||||||
auto ContainerRange<T,Ranges...>::get() const -> decltype( *std::get<N>( mSpace ) )&
|
|
||||||
{
|
|
||||||
return *std::get<N>( mSpace );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
template <size_t N>
|
|
||||||
auto ContainerRange<T,Ranges...>::getPtr() const -> decltype( std::get<N>( mSpace ) )&
|
|
||||||
{
|
|
||||||
return std::get<N>( mSpace );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
const typename ContainerRange<T,Ranges...>::SpaceType& ContainerRange<T,Ranges...>::space() const
|
|
||||||
{
|
|
||||||
return mSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
typename ContainerRange<T,Ranges...>::IndexType ContainerRange<T,Ranges...>::begin() const
|
|
||||||
{
|
|
||||||
ContainerIndex<T,typename Ranges::IndexType...>
|
|
||||||
i( std::dynamic_pointer_cast<ContainerRange<T,Ranges...> >
|
|
||||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
||||||
i = 0;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
typename ContainerRange<T,Ranges...>::IndexType ContainerRange<T,Ranges...>::end() const
|
|
||||||
{
|
|
||||||
ContainerIndex<T,typename Ranges::IndexType...>
|
|
||||||
i( std::dynamic_pointer_cast<ContainerRange<T,Ranges...> >
|
|
||||||
( std::shared_ptr<RangeBase>( RB::mThis ) ) );
|
|
||||||
i = size();
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
} // end namespace MultiArrayTools
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
#ifndef __dynamic_meta_h__
|
#ifndef __cxz_dynamic_meta_h__
|
||||||
#define __dynamic_meta_h__
|
#define __cxz_dynamic_meta_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef std::pair<const char*,size_t> DynamicMetaElem;
|
typedef std::pair<const char*,size_t> DynamicMetaElem;
|
||||||
|
@ -66,6 +66,6 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
|
|
||||||
#include "ranges/dynamic_range.h"
|
#include "ranges/dynamic_range.h"
|
||||||
//#include "ranges/dynamic_meta.h"
|
|
||||||
|
|
||||||
//#include "rpack_num.h"
|
namespace CNORXZ
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,8 +140,12 @@ namespace MultiArrayTools
|
||||||
DynamicRange::DynamicRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
DynamicRange::DynamicRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
||||||
RangeInterface<DynamicIndex>()
|
RangeInterface<DynamicIndex>()
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
|
mOrig.resize(sizeof...(RangeTypes));
|
||||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
|
sfor_pn<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { mOrig[i] = std::get<i>(origs); return 0; } );
|
||||||
|
mSize = sfor_p<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { return std::get<i>(origs)->size(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
if(sizeof...(RangeTypes)){
|
if(sizeof...(RangeTypes)){
|
||||||
mEmpty = false;
|
mEmpty = false;
|
||||||
}
|
}
|
||||||
|
@ -156,8 +157,12 @@ namespace MultiArrayTools
|
||||||
RangeInterface<DynamicIndex>()
|
RangeInterface<DynamicIndex>()
|
||||||
{
|
{
|
||||||
auto rst = std::make_tuple(origs...);
|
auto rst = std::make_tuple(origs...);
|
||||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
mOrig.resize(sizeof...(RangeTypes));
|
||||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
sfor_pn<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { mOrig[i] = std::get<i>(rst); return 0; } );
|
||||||
|
mSize = sfor_p<0,sizeof...(RangeTypes)>
|
||||||
|
( [&](auto i) { return std::get<i>(rst)->size(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
if(sizeof...(RangeTypes)){
|
if(sizeof...(RangeTypes)){
|
||||||
mEmpty = false;
|
mEmpty = false;
|
||||||
}
|
}
|
||||||
|
@ -175,60 +180,59 @@ namespace MultiArrayTools
|
||||||
std::shared_ptr<MultiRange<Ranges...> > DynamicRange::scast(SIZET<Ranges>... sizes) const
|
std::shared_ptr<MultiRange<Ranges...> > DynamicRange::scast(SIZET<Ranges>... sizes) const
|
||||||
{
|
{
|
||||||
std::tuple<std::shared_ptr<Ranges>...> rtp;
|
std::tuple<std::shared_ptr<Ranges>...> rtp;
|
||||||
RPackNum<sizeof...(Ranges)-1>::resolveRangeType(mOrig, rtp, 0, sizes...);
|
RangeHelper::resolveRangeType<0>(mOrig, rtp, 0, sizes...);
|
||||||
MultiRangeFactory<Ranges...> mrf(rtp);
|
MultiRangeFactory<Ranges...> mrf(rtp);
|
||||||
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
return std::dynamic_pointer_cast<MultiRange<Ranges...> >( mrf.create() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace RangeHelper
|
||||||
{
|
{
|
||||||
using namespace MultiArrayTools;
|
template <>
|
||||||
}
|
inline void resolveSetRange<DynamicRange>(std::shared_ptr<DynamicRange>& rp,
|
||||||
|
const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
template <>
|
size_t origpos, size_t size)
|
||||||
inline void resolveSetRange<DynamicRange>(std::shared_ptr<DynamicRange>& rp,
|
{
|
||||||
const vector<std::shared_ptr<RangeBase> >& orig,
|
DynamicRangeFactory arf;
|
||||||
size_t origpos, size_t size)
|
for(size_t op = origpos; op != origpos + size; ++op){
|
||||||
{
|
//VCHECK(op);
|
||||||
DynamicRangeFactory arf;
|
arf.append(orig[op]);
|
||||||
for(size_t op = origpos; op != origpos + size; ++op){
|
}
|
||||||
//VCHECK(op);
|
rp = std::dynamic_pointer_cast<DynamicRange>( arf.create() );
|
||||||
arf.append(orig[op]);
|
|
||||||
}
|
}
|
||||||
rp = std::dynamic_pointer_cast<DynamicRange>( arf.create() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
|
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
|
||||||
std::shared_ptr<DynamicRange> r)
|
std::shared_ptr<DynamicRange> r)
|
||||||
{
|
{
|
||||||
if(not r->isEmpty()){
|
if(not r->isEmpty()){
|
||||||
for(size_t i = r->dim(); i != 0; --i){
|
for(size_t i = r->dim(); i != 0; --i){
|
||||||
v.insert(v.begin(), r->sub(i-1));
|
v.insert(v.begin(), r->sub(i-1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j)
|
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j)
|
||||||
{
|
{
|
||||||
size_t ss = 0;
|
size_t ss = 0;
|
||||||
size_t sx = 1;
|
size_t sx = 1;
|
||||||
for(size_t k = ii.dim(); k != 0; --k){
|
for(size_t k = ii.dim(); k != 0; --k){
|
||||||
const size_t i = k-1;
|
const size_t i = k-1;
|
||||||
const auto& ni = ii.get(i);
|
const auto& ni = ii.get(i);
|
||||||
const size_t max = ni.max();
|
const size_t max = ni.max();
|
||||||
const size_t tmp = ni.getStepSizeComp(j);
|
const size_t tmp = ni.getStepSizeComp(j);
|
||||||
ss += tmp * ii.getStepSize(i);
|
ss += tmp * ii.getStepSize(i);
|
||||||
sx *= max;
|
sx *= max;
|
||||||
}
|
}
|
||||||
return ss;
|
return ss;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __dynamic_range_h__
|
#ifndef __cxz_dynamic_range_h__
|
||||||
#define __dynamic_range_h__
|
#define __cxz_dynamic_range_h__
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -11,19 +11,17 @@
|
||||||
|
|
||||||
#include "xfor/xfor.h"
|
#include "xfor/xfor.h"
|
||||||
|
|
||||||
//#include "ranges/rpheader.h"
|
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
#include "ranges/dynamic_meta.h"
|
#include "ranges/dynamic_meta.h"
|
||||||
|
|
||||||
#include "index_wrapper.h"
|
#include "index_wrapper.h"
|
||||||
#include "rpack_num.h"
|
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DynamicIndex : public IndexInterface<DynamicIndex,vector<char>>
|
class DynamicIndex : public IndexInterface<DynamicIndex,vector<char>>
|
||||||
|
@ -111,9 +109,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
size_t getStepSize(size_t n) const;
|
size_t getStepSize(size_t n) const;
|
||||||
|
|
||||||
std::string id() const;
|
|
||||||
void print(size_t offset);
|
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
DynamicExpression ifor(size_t step, Expr ex) const;
|
DynamicExpression ifor(size_t step, Expr ex) const;
|
||||||
|
|
||||||
|
@ -228,28 +223,26 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace RangeHelper
|
||||||
{
|
{
|
||||||
using namespace MultiArrayTools;
|
|
||||||
|
template <>
|
||||||
|
inline void resolveSetRange<DynamicRange>(std::shared_ptr<DynamicRange>& rp,
|
||||||
|
const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
size_t origpos, size_t size);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
|
||||||
|
std::shared_ptr<DynamicRange> r);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
|
||||||
inline void resolveSetRange<DynamicRange>(std::shared_ptr<DynamicRange>& rp,
|
|
||||||
const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
size_t origpos, size_t size);
|
|
||||||
|
|
||||||
template <>
|
|
||||||
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
|
|
||||||
std::shared_ptr<DynamicRange> r);
|
|
||||||
|
|
||||||
template <>
|
|
||||||
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#include "dynamic_range.cc.h"
|
//#include "dynamic_range.cc.h"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __index_base_h__
|
#ifndef __cxz_index_base_h__
|
||||||
#define __index_base_h__
|
#define __cxz_index_base_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include "xfor/xfor.h"
|
#include "xfor/xfor.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class I, typename MetaType>
|
template <class I, typename MetaType>
|
||||||
|
@ -57,15 +57,11 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
operator size_t() const;
|
operator size_t() const;
|
||||||
|
|
||||||
std::string id() const { return THIS().id(); }
|
|
||||||
|
|
||||||
std::string stringMeta() const { return THIS().stringMeta(); }
|
std::string stringMeta() const { return THIS().stringMeta(); }
|
||||||
MetaType meta() const { return THIS().meta(); }
|
MetaType meta() const { return THIS().meta(); }
|
||||||
MetaType metaPtr() const { return THIS().metaPtr(); }
|
MetaType metaPtr() const { return THIS().metaPtr(); }
|
||||||
I& at(const MetaType& meta) { return THIS().at(meta); }
|
I& at(const MetaType& meta) { return THIS().at(meta); }
|
||||||
|
|
||||||
void print(size_t offset = 0) const { THIS().print(offset); }
|
|
||||||
|
|
||||||
// CHECK / IMPLEMENT !!!!!!
|
// CHECK / IMPLEMENT !!!!!!
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto ifor(size_t step, const Expr ex) const
|
auto ifor(size_t step, const Expr ex) const
|
||||||
|
@ -93,7 +89,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
std::shared_ptr<RangeBase> mRangePtr;
|
std::shared_ptr<RangeBase> mRangePtr;
|
||||||
size_t mPos = 0;
|
size_t mPos = 0;
|
||||||
size_t mId;
|
|
||||||
size_t mMax = 0;
|
size_t mMax = 0;
|
||||||
|
|
||||||
std::intptr_t mPtrNum;
|
std::intptr_t mPtrNum;
|
||||||
|
@ -111,14 +106,14 @@ namespace MultiArrayTools
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
* ========================= */
|
* ========================= */
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/**********************
|
/**********************
|
||||||
* IndexInterface *
|
* IndexInterface *
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
template <class I, typename MetaType>
|
template <class I, typename MetaType>
|
||||||
IndexInterface<I,MetaType>::IndexInterface() : mId(indexId())
|
IndexInterface<I,MetaType>::IndexInterface()
|
||||||
{
|
{
|
||||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +123,6 @@ namespace MultiArrayTools
|
||||||
mPos(in.mPos),
|
mPos(in.mPos),
|
||||||
mMax(in.mMax)
|
mMax(in.mMax)
|
||||||
{
|
{
|
||||||
mId = indexId();
|
|
||||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +131,6 @@ namespace MultiArrayTools
|
||||||
mPos(in.mPos),
|
mPos(in.mPos),
|
||||||
mMax(in.mMax)
|
mMax(in.mMax)
|
||||||
{
|
{
|
||||||
mId = indexId();
|
|
||||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +158,6 @@ namespace MultiArrayTools
|
||||||
mPos(pos),
|
mPos(pos),
|
||||||
mMax(mRangePtr->size())
|
mMax(mRangePtr->size())
|
||||||
{
|
{
|
||||||
mId = indexId();
|
|
||||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
#ifndef __index_type_h__
|
#ifndef __cxz_index_type_h__
|
||||||
#define __index_type_h__
|
#define __cxz_index_type_h__
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
enum class IndexType{
|
enum class IndexType{
|
||||||
SINGLE = 0,
|
SINGLE = 0,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
#include "index_wrapper.h"
|
#include "index_wrapper.h"
|
||||||
#include "rpack_num.h"
|
#include "range_helper.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
|
@ -117,9 +117,9 @@ namespace MultiArrayTools
|
||||||
template <class Index>
|
template <class Index>
|
||||||
size_t IndexWrapper<Index>::getStepSizeComp(std::intptr_t j) const
|
size_t IndexWrapper<Index>::getStepSizeComp(std::intptr_t j) const
|
||||||
{
|
{
|
||||||
size_t out = MultiArrayHelper::getStepSize(*mI, j);
|
size_t out = RangeHelper::getStepSize(*mI, j);
|
||||||
if(out == 0){
|
if(out == 0){
|
||||||
out = MultiArrayHelper::getStepSize(*mCI, j);
|
out = RangeHelper::getStepSize(*mCI, j);
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -153,14 +153,7 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
return std::make_shared<IndexWrapper>( std::make_shared<Index>( *mI ) );
|
return std::make_shared<IndexWrapper>( std::make_shared<Index>( *mI ) );
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
template <class Index>
|
|
||||||
RegIndInfo IndexWrapper<Index>::regN() const
|
|
||||||
{
|
|
||||||
RegIndInfo out;
|
|
||||||
return out.set(mI);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
std::shared_ptr<Index> IndexWrapper<Index>::getIndex() const
|
std::shared_ptr<Index> IndexWrapper<Index>::getIndex() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
|
|
||||||
#ifndef __index_wrapper_h__
|
#ifndef __cxz_index_wrapper_h__
|
||||||
#define __index_wrapper_h__
|
#define __cxz_index_wrapper_h__
|
||||||
|
|
||||||
#include "ranges/rbase_def.h"
|
#include "ranges/rbase_def.h"
|
||||||
#include "xfor/xfor.h"
|
#include "xfor/xfor.h"
|
||||||
#include "hl_reg_ind.h"
|
#include "ranges/rheader.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
class IndexWrapperBase
|
class IndexWrapperBase
|
||||||
|
@ -50,13 +50,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
virtual std::shared_ptr<IndexWrapperBase> duplicate() const = 0;
|
virtual std::shared_ptr<IndexWrapperBase> duplicate() const = 0;
|
||||||
|
|
||||||
//virtual RegIndInfo regN() const = 0;
|
|
||||||
//virtual DynamicMetaT meta() const = 0;
|
|
||||||
//virtual const DynamicMetaT* metaPtr() const = 0;
|
|
||||||
//virtual AbstractIW& at(const U& metaPos) = 0;
|
|
||||||
//virtual size_t posAt(const U& metaPos) const = 0;
|
|
||||||
|
|
||||||
//virtual bool isMeta(const U& metaPos) const = 0;
|
|
||||||
inline IndexWrapperBase& at(const std::string smeta)
|
inline IndexWrapperBase& at(const std::string smeta)
|
||||||
{
|
{
|
||||||
// ignore spaces, " and ' (string identifiers)
|
// ignore spaces, " and ' (string identifiers)
|
||||||
|
@ -150,7 +143,6 @@ namespace MultiArrayTools
|
||||||
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override final;
|
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override final;
|
||||||
|
|
||||||
virtual std::shared_ptr<IndexWrapperBase> duplicate() const override final;
|
virtual std::shared_ptr<IndexWrapperBase> duplicate() const override final;
|
||||||
//virtual RegIndInfo regN() const override final;
|
|
||||||
|
|
||||||
std::shared_ptr<Index> getIndex() const;
|
std::shared_ptr<Index> getIndex() const;
|
||||||
virtual std::shared_ptr<ClassicIndex> reduced() const override final;
|
virtual std::shared_ptr<ClassicIndex> reduced() const override final;
|
||||||
|
|
|
@ -1,27 +1,28 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __multi_range_h__
|
#ifndef __cxz_multi_range_h__
|
||||||
#define __multi_range_h__
|
#define __cxz_multi_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
//#include "base_def.h"
|
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "ranges/index_base.h"
|
#include "ranges/index_base.h"
|
||||||
|
|
||||||
#include "ranges/rpack_num.h"
|
#include "ranges/range_helper.h"
|
||||||
#include "ranges/multi_range_factory_product_map.h"
|
#include "ranges/multi_range_factory_product_map.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
#include "statics/static_for.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
|
@ -39,7 +40,7 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
static constexpr IndexType sType() { return IndexType::MULTI; }
|
static constexpr IndexType sType() { return IndexType::MULTI; }
|
||||||
static constexpr size_t sDim() { return sizeof...(Indices); }
|
static constexpr size_t sDim() { return sizeof...(Indices); }
|
||||||
static constexpr size_t totalDim() { return mkTotalDim<Indices...>(); }
|
static constexpr size_t totalDim() { return (... * Indices::totalDim()); }
|
||||||
|
|
||||||
static constexpr SpaceType STYPE = SpaceType::ANY;
|
static constexpr SpaceType STYPE = SpaceType::ANY;
|
||||||
static constexpr bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
static constexpr bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
||||||
|
@ -57,10 +58,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
// NO DEFAULT HERE !!!
|
// NO DEFAULT HERE !!!
|
||||||
// ( have to assign sub-indices (ptr!) correctly )
|
// ( have to assign sub-indices (ptr!) correctly )
|
||||||
//MultiIndex(const MultiIndex& in);
|
|
||||||
//MultiIndex& operator=(const MultiIndex& in);
|
|
||||||
template <typename T>
|
|
||||||
MultiIndex& operator=(ContainerIndex<T,Indices...>& ci);
|
|
||||||
|
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
MultiIndex(const std::shared_ptr<MRange>& range);
|
MultiIndex(const std::shared_ptr<MRange>& range);
|
||||||
|
@ -80,7 +77,7 @@ namespace MultiArrayTools
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
size_t getBlockSize() const { return std::get<N>(mBlockSizes); }
|
||||||
|
|
||||||
// raplace instances (in contrast to its analogon in ContainerIndex
|
// raplace instances (in contrast to its analogon in ConstContainerIndex
|
||||||
// MultiIndices CANNOT be influences be its subindices, so there is
|
// MultiIndices CANNOT be influences be its subindices, so there is
|
||||||
// NO foreign/external controll)
|
// NO foreign/external controll)
|
||||||
// Do NOT share index instances between two or more MultiIndex instances
|
// Do NOT share index instances between two or more MultiIndex instances
|
||||||
|
@ -113,21 +110,14 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
size_t getStepSize(size_t n);
|
size_t getStepSize(size_t n);
|
||||||
|
|
||||||
std::string id() const;
|
template <class Exprs>
|
||||||
void print(size_t offset);
|
auto ifor(size_t step, Exprs exs) const;
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto ifor(size_t step, Exprs exs) const
|
auto iforh(size_t step, Exprs exs) const;
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs));
|
|
||||||
|
|
||||||
template <class Exprs>
|
|
||||||
auto iforh(size_t step, Exprs exs) const
|
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs));
|
|
||||||
|
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto pifor(size_t step, Exprs exs) const
|
auto pifor(size_t step, Exprs exs) const;
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs));
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,9 +136,6 @@ namespace MultiArrayTools
|
||||||
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
||||||
MultiRangeFactory(const typename MultiRange<Ranges...>::Space& space);
|
MultiRangeFactory(const typename MultiRange<Ranges...>::Space& space);
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
MultiRangeFactory(const std::shared_ptr<ContainerRange<T,Ranges...> >& cr);
|
|
||||||
|
|
||||||
virtual std::shared_ptr<RangeBase> create() override;
|
virtual std::shared_ptr<RangeBase> create() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -171,7 +158,6 @@ namespace MultiArrayTools
|
||||||
typedef std::tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
typedef std::tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
||||||
typedef MultiRange RangeType;
|
typedef MultiRange RangeType;
|
||||||
typedef MultiRangeFactory<Ranges...> FType;
|
typedef MultiRangeFactory<Ranges...> FType;
|
||||||
//typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MultiRange() = delete;
|
MultiRange() = delete;
|
||||||
|
@ -222,8 +208,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
static constexpr bool HASMETACONT = false;
|
static constexpr bool HASMETACONT = false;
|
||||||
static constexpr bool defaultable = false;
|
static constexpr bool defaultable = false;
|
||||||
static constexpr size_t ISSTATIC = SubProp<Ranges...>::ISSTATIC;
|
static constexpr size_t ISSTATIC = (... & Ranges::ISSTATIC);
|
||||||
static constexpr size_t SIZE = SubProp<Ranges...>::SIZE;
|
static constexpr size_t SIZE = (... * Ranges::SIZE);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -232,12 +218,12 @@ namespace MultiArrayTools
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
* ========================= */
|
* ========================= */
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -> define in range_base.cc
|
// -> define in range_base.cc
|
||||||
|
@ -246,43 +232,28 @@ namespace MultiArrayTools
|
||||||
/******************
|
/******************
|
||||||
* MultiIndex *
|
* MultiIndex *
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
/*
|
|
||||||
template <class... Indices>
|
|
||||||
MultiIndex<Indices...>::MultiIndex(const MultiIndex<Indices...>& in) :
|
|
||||||
IndexInterface<std::tuple<typename Indices::MetaType...> >(in)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(const MultiIndex<Indices...>& in)
|
|
||||||
{
|
|
||||||
IndexI::operator=(in);
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copy(mIPack, in);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
template <class... Indices>
|
|
||||||
template <typename T>
|
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(ContainerIndex<T,Indices...>& ci)
|
|
||||||
{
|
|
||||||
RPackNum<sizeof...(Indices)-1>::copyInst(mIPack, ci);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class MRange>
|
template <class MRange>
|
||||||
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
||||||
IndexInterface<MultiIndex<Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
IndexInterface<MultiIndex<Indices...>,std::tuple<typename Indices::MetaType...> >(range, 0)
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::construct(mIPack, *range);
|
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
|
||||||
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
std::get<sizeof...(Indices)>(mBlockSizes) = 1;
|
||||||
RPackNum<sizeof...(Indices)-1>::initBlockSizes(mBlockSizes, mIPack); // has one more element!
|
sfor_mn<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto r = range->template getPtr<i>();
|
||||||
|
std::get<i>(mIPack) = r->beginPtr();
|
||||||
|
*std::get<i>(mIPack) = 0;
|
||||||
|
|
||||||
|
std::get<i>(mBlockSizes) = sfor_p<i,sizeof...(Indices)>
|
||||||
|
( [&](auto j) { return std::get<j>(mIPack)->max(); } ,
|
||||||
|
[&](auto a, auto b) { return a * b; });
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
|
@ -290,8 +261,16 @@ namespace MultiArrayTools
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
||||||
{
|
{
|
||||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
||||||
RPackNum<DIR>::pp( mIPack );
|
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
|
sfor_m<DIR+1,0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.last() and i != 0) { si = 0; return true; }
|
||||||
|
else { ++si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,8 +279,16 @@ namespace MultiArrayTools
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
||||||
{
|
{
|
||||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
||||||
RPackNum<DIR>::mm( mIPack );
|
( [&](auto i) { return std::get<i>(mIPack)->max(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
|
sfor_m<DIR+1,0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||||
|
else { --si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,16 +309,15 @@ namespace MultiArrayTools
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
return (*this)(std::make_tuple(indices...));
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices);
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
( [&](auto i) { std::get<i>(mIPack) = std::get<i>(indices); return 0; } );
|
||||||
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, IB::mPos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,14 +331,20 @@ namespace MultiArrayTools
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
|
||||||
{
|
{
|
||||||
IB::mPos = pos;
|
IB::mPos = pos;
|
||||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator++()
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.last() and i != 0) { si = 0; return true; }
|
||||||
|
else { ++si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
++IB::mPos;
|
++IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -360,15 +352,22 @@ namespace MultiArrayTools
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
MultiIndex<Indices...>& MultiIndex<Indices...>::operator--()
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) {
|
||||||
|
auto& si = *std::get<i>( mIPack );
|
||||||
|
if(si.first() and i != 0) { si = si.max()-1; return true; }
|
||||||
|
else { --si; return false; }
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
--IB::mPos;
|
--IB::mPos;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
int MultiIndex<Indices...>::pp(std::intptr_t idxPtrNum)
|
int MultiIndex<Indices...>::pp(std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
const int tmp = RangeHelper::ppx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||||
IB::mPos += tmp;
|
IB::mPos += tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -376,7 +375,7 @@ namespace MultiArrayTools
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
int MultiIndex<Indices...>::mm(std::intptr_t idxPtrNum)
|
int MultiIndex<Indices...>::mm(std::intptr_t idxPtrNum)
|
||||||
{
|
{
|
||||||
int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
const int tmp = RangeHelper::mmx<sizeof...(Indices)-1>(mIPack, mBlockSizes, idxPtrNum);
|
||||||
IB::mPos -= tmp;
|
IB::mPos -= tmp;
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -391,15 +390,19 @@ namespace MultiArrayTools
|
||||||
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
|
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
|
||||||
{
|
{
|
||||||
MetaType metaTuple;
|
MetaType metaTuple;
|
||||||
RPackNum<sizeof...(Indices)-1>::getMetaPos(metaTuple, mIPack);
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i) { std::get<i>(metaTuple) = std::get<i>(mIPack)->meta(); return 0; } );
|
||||||
return metaTuple;
|
return metaTuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
|
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
|
||||||
{
|
{
|
||||||
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
sfor_pn<0,sizeof...(Indices)>
|
||||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
( [&](auto i) { std::get<i>(mIPack)->at( std::get<i>(metaPos) ); return 0; } );
|
||||||
|
IB::mPos = sfor_m<sizeof...(Indices),0>
|
||||||
|
( [&](auto i) { return std::get<i>(mIPack); },
|
||||||
|
[&](auto a, auto b) {return a->pos() + b*a->max();}, 0 );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,47 +447,26 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
return mBlockSizes[n+1];
|
return mBlockSizes[n+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
std::string MultiIndex<Indices...>::id() const
|
|
||||||
{
|
|
||||||
return std::string("mul") + std::to_string(IB::mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
void MultiIndex<Indices...>::print(size_t offset)
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
||||||
<< "]" << "(" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
||||||
RPackNum<sizeof...(Indices)-1>::printIndex(mIPack, offset+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto MultiIndex<Indices...>::ifor(size_t step, Exprs exs) const
|
auto MultiIndex<Indices...>::ifor(size_t step, Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs))
|
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkFor(step, mIPack, mBlockSizes, exs);
|
return RangeHelper::mkFor<0>(step, mIPack, mBlockSizes, exs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto MultiIndex<Indices...>::iforh(size_t step, Exprs exs) const
|
auto MultiIndex<Indices...>::iforh(size_t step, Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs))
|
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkForh(step, mIPack, mBlockSizes, exs);
|
return RangeHelper::mkForh<0>(step, mIPack, mBlockSizes, exs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
template <class Exprs>
|
template <class Exprs>
|
||||||
auto MultiIndex<Indices...>::pifor(size_t step, Exprs exs) const
|
auto MultiIndex<Indices...>::pifor(size_t step, Exprs exs) const
|
||||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs))
|
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs);
|
return RangeHelper::mkPFor<0>(step, mIPack, mBlockSizes, exs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
|
@ -503,13 +485,6 @@ namespace MultiArrayTools
|
||||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( st ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
template <typename T>
|
|
||||||
MultiRangeFactory<Ranges...>::MultiRangeFactory(const std::shared_ptr<ContainerRange<T,Ranges...> >& cr)
|
|
||||||
{
|
|
||||||
mProd = std::shared_ptr< MultiRange<Ranges...> >( new MultiRange<Ranges...>( cr->space() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
||||||
{
|
{
|
||||||
|
@ -525,7 +500,9 @@ namespace MultiArrayTools
|
||||||
bool check = false;
|
bool check = false;
|
||||||
for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){
|
for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){
|
||||||
if(x.second.size() == sizeof...(Ranges)){
|
if(x.second.size() == sizeof...(Ranges)){
|
||||||
check = RPackNum<sizeof...(Ranges)-1>::checkIfCreated(ptp, x.second);
|
check = sfor_p<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) { return reinterpret_cast<std::intptr_t>( std::get<i>(ptp).get() ) == x.second[i]; },
|
||||||
|
[&](auto a, auto b) { return a and b; } );
|
||||||
if(check){
|
if(check){
|
||||||
out = x.first;
|
out = x.first;
|
||||||
break;
|
break;
|
||||||
|
@ -534,7 +511,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
if(not check){
|
if(not check){
|
||||||
vector<std::intptr_t> pv(sizeof...(Ranges));
|
vector<std::intptr_t> pv(sizeof...(Ranges));
|
||||||
RPackNum<sizeof...(Ranges)-1>::RangesToVec(ptp, pv);
|
sfor_pn<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) { pv[i] = reinterpret_cast<std::intptr_t>( std::get<i>(ptp).get() ); return 0; } );
|
||||||
MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
MultiRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
||||||
out = mProd;
|
out = mProd;
|
||||||
}
|
}
|
||||||
|
@ -561,7 +539,7 @@ namespace MultiArrayTools
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
size_t MultiRange<Ranges...>::getMeta(const MetaType& metaPos) const
|
size_t MultiRange<Ranges...>::getMeta(const MetaType& metaPos) const
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getMeta(mSpace,metaPos);
|
return RangeHelper::getMeta<sizeof...(Ranges)-1>(mSpace,metaPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -574,7 +552,10 @@ namespace MultiArrayTools
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
std::shared_ptr<RangeBase> MultiRange<Indices...>::sub(size_t num) const
|
std::shared_ptr<RangeBase> MultiRange<Indices...>::sub(size_t num) const
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Indices)-1>::getSub(mSpace, num);
|
assert(num < sizeof...(Indices));
|
||||||
|
return sforx_p<0,sizeof...(Indices)>
|
||||||
|
( [&](auto i) { return std::dynamic_pointer_cast<RangeBase>(std::get<i>(mSpace)); },
|
||||||
|
[&](auto i) { return num != i;} );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -586,7 +567,9 @@ namespace MultiArrayTools
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
size_t MultiRange<Ranges...>::size() const
|
size_t MultiRange<Ranges...>::size() const
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
return sfor_p<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) { return std::get<i>(mSpace)->size(); },
|
||||||
|
[&](auto a, auto b) { return a * b; } );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -605,7 +588,7 @@ namespace MultiArrayTools
|
||||||
vector<size_t> MultiRange<Ranges...>::typeNum() const
|
vector<size_t> MultiRange<Ranges...>::typeNum() const
|
||||||
{
|
{
|
||||||
vector<size_t> o;
|
vector<size_t> o;
|
||||||
RPackNum<sizeof...(Ranges)-1>::getTypeNum(o,mSpace);
|
RangeHelper::getTypeNum<sizeof...(Ranges)-1>(o,mSpace);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,13 +597,13 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
const size_t off = cmetaSize();
|
const size_t off = cmetaSize();
|
||||||
MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,off);
|
return RangeHelper::getCMeta<sizeof...(Ranges)-1>(xtarget,pos,mSpace,off);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
size_t MultiRange<Ranges...>::cmetaSize() const
|
size_t MultiRange<Ranges...>::cmetaSize() const
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Ranges)-1>::getCMetaSize(mSpace);
|
return RangeHelper::getCMetaSize<0>(mSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -628,7 +611,7 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
auto i = begin();
|
auto i = begin();
|
||||||
i = pos;
|
i = pos;
|
||||||
return "[" + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + "]";
|
return "[" + RangeHelper::getStringMeta<0>(i) + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -639,7 +622,12 @@ namespace MultiArrayTools
|
||||||
//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));
|
||||||
RPackNum<sizeof...(Ranges)-1>::fillRangeDataVec(out, mSpace);
|
sfor_pn<0,sizeof...(Ranges)>
|
||||||
|
( [&](auto i) {
|
||||||
|
vector<char> part = std::get<i>(mSpace)->data();
|
||||||
|
out.insert(out.end(), part.begin(), part.end());
|
||||||
|
return 0;
|
||||||
|
} );
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
#ifndef __multi_range_factory_product_map_h__
|
#ifndef __cxz_multi_range_factory_product_map_h__
|
||||||
#define __multi_range_factory_product_map_h__
|
#define __cxz_multi_range_factory_product_map_h__
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "ranges/rbase_def.h"
|
#include "ranges/rbase_def.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
class MultiRangeFactoryProductMap
|
class MultiRangeFactoryProductMap
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __range_base_h__
|
#ifndef __cxz_range_base_h__
|
||||||
#define __range_base_h__
|
#define __cxz_range_base_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -9,12 +9,12 @@
|
||||||
|
|
||||||
#include "rbase_def.h"
|
#include "rbase_def.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
class RangeBase;
|
class RangeBase;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
size_t indexId();
|
size_t indexId();
|
||||||
|
@ -116,6 +116,8 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
virtual Index begin() const = 0;
|
virtual Index begin() const = 0;
|
||||||
virtual Index end() const = 0;
|
virtual Index end() const = 0;
|
||||||
|
std::shared_ptr<Index> beginPtr() const { return std::make_shared<Index>(this->begin()); }
|
||||||
|
std::shared_ptr<Index> endPtr() const { return std::make_shared<Index>(this->end()); }
|
||||||
virtual std::shared_ptr<IndexWrapperBase> aindex() const override final
|
virtual std::shared_ptr<IndexWrapperBase> aindex() const override final
|
||||||
{ return mkIndexWrapper(this->begin()); }
|
{ return mkIndexWrapper(this->begin()); }
|
||||||
//{ auto i = std::make_shared<Index>(this->begin()); return std::make_shared<IndexWrapper<Index>>(i); } //!!!
|
//{ auto i = std::make_shared<Index>(this->begin()); return std::make_shared<IndexWrapper<Index>>(i); } //!!!
|
||||||
|
|
285
src/include/ranges/range_helper.h
Normal file
285
src/include/ranges/range_helper.h
Normal file
|
@ -0,0 +1,285 @@
|
||||||
|
|
||||||
|
#ifndef __cxz_range_helper_h__
|
||||||
|
#define __cxz_range_helper_h__
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
namespace RangeHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
template <size_t I, class... Indices>
|
||||||
|
int ppx(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
auto& siPtr = std::get<I>(ip);
|
||||||
|
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
|
if constexpr(I != 0){
|
||||||
|
return ppx<I-1>(ip, bs, idxPtrNum);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<0>(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const int tmp = siPtr->pp(idxPtrNum);
|
||||||
|
if constexpr(I != 0){
|
||||||
|
if(siPtr->pos() == siPtr->max()){
|
||||||
|
(*siPtr) = 0;
|
||||||
|
return ppx<I-1>(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmp * std::get<I+1>(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I, class... Indices>
|
||||||
|
int mmx(std::tuple<std::shared_ptr<Indices>...>& ip,
|
||||||
|
std::array<size_t,sizeof...(Indices)+1>& bs,
|
||||||
|
std::intptr_t idxPtrNum)
|
||||||
|
{
|
||||||
|
auto& siPtr = std::get<I>(ip);
|
||||||
|
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
||||||
|
if constexpr(I != 0){
|
||||||
|
return mmx<I-1>(ip, bs, idxPtrNum);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<0>(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const int tmp = siPtr->mm(idxPtrNum);
|
||||||
|
if constexpr(I != 0){
|
||||||
|
if(siPtr->pos() == siPtr->max()){
|
||||||
|
(*siPtr) = siPtr->max() - 1;
|
||||||
|
return mmx<I-1>(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmp * std::get<I+1>(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class... Indices>
|
||||||
|
inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
||||||
|
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
||||||
|
{
|
||||||
|
if constexpr(N != 0){
|
||||||
|
return makePos<N-1>(iPtrTup, blockSize) +
|
||||||
|
std::get<N>(iPtrTup)->pos() * std::get<N+1>(blockSize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<0>(iPtrTup)->pos() * std::get<1>(blockSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
size_t origpos, size_t size)
|
||||||
|
{
|
||||||
|
assert(size == 1);
|
||||||
|
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Range>
|
||||||
|
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
||||||
|
std::shared_ptr<Range> r)
|
||||||
|
{
|
||||||
|
v.insert(v.begin(), r);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class IndexPack>
|
||||||
|
void setIndexPack(IndexPack& iPack, size_t pos)
|
||||||
|
{
|
||||||
|
auto& i = *std::get<N>(iPack).get();
|
||||||
|
const size_t ownPos = pos % i.max();
|
||||||
|
i = ownPos;
|
||||||
|
if constexpr(N != 0){
|
||||||
|
setIndexPack<N-1>(iPack, (pos - ownPos) / i.max() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class... Ranges>
|
||||||
|
inline size_t getMeta(const std::tuple<std::shared_ptr<Ranges>...>& space,
|
||||||
|
const std::tuple<typename Ranges::IndexType::MetaType...>& meta)
|
||||||
|
{
|
||||||
|
if constexpr(N != 0){
|
||||||
|
return getMeta<N-1>(space,meta) * std::get<N>(space)->size() +
|
||||||
|
std::get<N>(space)->getMeta(std::get<N>(meta));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<0>(space)->getMeta(std::get<0>(meta));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class... Ranges>
|
||||||
|
inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
auto& r = *std::get<N>(stp);
|
||||||
|
auto tn = r.typeNum();
|
||||||
|
res.insert(res.begin(), tn.begin(), tn.end());
|
||||||
|
if constexpr(N != 0){
|
||||||
|
getTypeNum<N-1>(res, stp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
{
|
||||||
|
constexpr size_t S = std::tuple_size<IndexPack>::value;
|
||||||
|
if constexpr(N < S-1){
|
||||||
|
return std::get<N>(ipack)
|
||||||
|
->ifor( step*std::get<N+1>(ba), mkFor<N+1>(step, ipack, ba, exs) );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<N>(ipack)->ifor( step*std::get<N+1>(ba), exs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
{
|
||||||
|
constexpr size_t S = std::tuple_size<IndexPack>::value;
|
||||||
|
if constexpr(N < S-1){
|
||||||
|
return std::get<N>(ipack)
|
||||||
|
->iforh( step*std::get<N+1>(ba), mkForh<N+1>(step, ipack, ba, exs) );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<N>(ipack)->iforh( step*std::get<N+1>(ba), exs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class IndexPack, class BlockArray, class Exprs>
|
||||||
|
auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
||||||
|
{
|
||||||
|
constexpr size_t S = std::tuple_size<IndexPack>::value;
|
||||||
|
if constexpr(N < S-1){
|
||||||
|
return std::get<N>(ipack)
|
||||||
|
->pifor( step*std::get<N+1>(ba), mkFor<N+1>(step, ipack, ba, exs) );
|
||||||
|
// mkFor is correct here, because we want to multithread only the FIRST index!!
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return std::get<N>(ipack)->pifor( step*std::get<N+1>(ba), exs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class RangeTuple, typename... SIZET>
|
||||||
|
inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
|
||||||
|
{
|
||||||
|
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||||
|
::CNORXZ::RangeHelper::resolveSetRange(std::get<N>(rtp), orig, off, size);
|
||||||
|
if constexpr(N < tps-1){
|
||||||
|
resolveRangeType<N+1>(orig, rtp, off+size, sizes...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class RangeTuple>
|
||||||
|
inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
||||||
|
RangeTuple& rtp, size_t off, size_t size)
|
||||||
|
{
|
||||||
|
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
||||||
|
::CNORXZ::RangeHelper::resolveSetRange(std::get<N>(rtp), orig, off, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class MetaType, class... Ranges>
|
||||||
|
inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
||||||
|
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
||||||
|
{
|
||||||
|
//constexpr size_t NN = sizeof...(Ranges);
|
||||||
|
auto& r = *std::get<N>(stp);
|
||||||
|
const size_t ownPos = pos % r.size();
|
||||||
|
const size_t s = r.cmetaSize();
|
||||||
|
off -= s;
|
||||||
|
r.cmeta(reinterpret_cast<char*>(&std::get<N>(*xtarget)), ownPos);
|
||||||
|
if constexpr(N != 0){
|
||||||
|
return s + getCMeta<N-1>(xtarget, (pos - ownPos) / r.size(), stp, off);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(off == 0);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class... Ranges>
|
||||||
|
inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
auto& r = *std::get<N>(stp);
|
||||||
|
if constexpr(N < sizeof...(Ranges)-1){
|
||||||
|
return r.cmetaSize() + getCMetaSize<N+1>(stp);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return r.cmetaSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class MIndex>
|
||||||
|
inline std::string getStringMeta(const MIndex& mi)
|
||||||
|
{
|
||||||
|
if constexpr(N < MIndex::sDim()-1){
|
||||||
|
return mi.template getPtr<N>()->stringMeta() + "," + getStringMeta<N+1>(mi);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return mi.template getPtr<N>()->stringMeta();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
||||||
|
|
||||||
|
template <size_t N, class Index>
|
||||||
|
inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
||||||
|
{
|
||||||
|
const auto& ni = ii.template get<N>();
|
||||||
|
const size_t max = ni.max();
|
||||||
|
const size_t tmp = getStepSize(ni, j);
|
||||||
|
ss += tmp * ii.template getBlockSize<N+1>();
|
||||||
|
sx *= max;
|
||||||
|
if constexpr(N != 0){
|
||||||
|
getStepSizeX<N-1>(ii, j, ss, sx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
||||||
|
{
|
||||||
|
constexpr IndexType IT = Index::sType();
|
||||||
|
if constexpr(IT == IndexType::SINGLE){
|
||||||
|
const std::intptr_t ip = reinterpret_cast<std::intptr_t>(&ii);
|
||||||
|
return ip == j ? 1 : 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
size_t ss = 0;
|
||||||
|
size_t sx = 1;
|
||||||
|
constexpr size_t DIM = Index::sDim();
|
||||||
|
getStepSizeX<DIM-1>(ii, j, ss, sx);
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <size_t N, size_t SIZE, class Range, class... Ranges>
|
||||||
|
inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
|
||||||
|
{
|
||||||
|
if constexpr(N != 0){
|
||||||
|
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE and compareSpaceTypes<N-1,SIZE,Ranges...>(rbvec);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rbvec[SIZE-N-1]->spaceType() == Range::STYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t N, class... Ranges>
|
||||||
|
inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
||||||
|
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
||||||
|
{
|
||||||
|
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
|
||||||
|
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
|
||||||
|
if constexpr(N != 0){
|
||||||
|
setSpace<N-1>(rbvec, stp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace RangeHelper
|
||||||
|
} // namespace CNORXZ
|
||||||
|
|
||||||
|
#endif
|
|
@ -4,13 +4,13 @@
|
||||||
//#else
|
//#else
|
||||||
|
|
||||||
#ifndef include_range_type
|
#ifndef include_range_type
|
||||||
#ifdef __ranges_header__
|
#ifdef __cxz_ranges_header__
|
||||||
// assert, that this is only used within range_types/header.h
|
// assert, that this is only used within range_types/header.h
|
||||||
|
|
||||||
#ifndef __range_type_classic_def__
|
#ifndef __cxz_range_type_classic_def__
|
||||||
#define __range_type_classic_def__
|
#define __cxz_range_type_classic_def__
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
typedef GenSingleIndex<size_t,SpaceType::NONE,MUI> ClassicIndex;
|
typedef GenSingleIndex<size_t,SpaceType::NONE,MUI> ClassicIndex;
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef __range_type_classic_def__
|
#endif // #ifndef __cxz_range_type_classic_def__
|
||||||
|
|
||||||
#endif // #ifdef __ranges_header__
|
#endif // #ifdef __cxz_ranges_header__
|
||||||
|
|
||||||
#endif // #ifdef include_range_type
|
#endif // #ifdef include_range_type
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
|
|
||||||
#ifdef include_range_type
|
#ifdef include_range_type
|
||||||
#define __incl_this__
|
#define __cxz_incl_this__
|
||||||
#endif
|
#endif
|
||||||
#ifdef __single_range_h__
|
#ifdef __cxz_single_range_h__
|
||||||
// singel_range is template which is specialized here
|
// singel_range is template which is specialized here
|
||||||
// therefore it must be defined before...
|
// therefore it must be defined before...
|
||||||
#define __incl_this__
|
#define __cxz_incl_this__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __incl_this__
|
#ifdef __cxz_incl_this__
|
||||||
|
|
||||||
|
|
||||||
#define __ranges_header__
|
#define __cxz_ranges_header__
|
||||||
//#ifndef __ranges_header__
|
//#ifndef __cxz_ranges_header__
|
||||||
//#define __ranges_header__
|
//#define __cxz_ranges_header__
|
||||||
|
|
||||||
#include "null_range.h"
|
#include "null_range.h"
|
||||||
#include "spin_range.h"
|
#include "spin_range.h"
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
include_range_type(NUL,-2)
|
include_range_type(NUL,-2)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef __ranges_header__
|
#ifdef __cxz_ranges_header__
|
||||||
// assert, that this is only used within range_types/header.h
|
// assert, that this is only used within range_types/header.h
|
||||||
|
|
||||||
#ifndef __range_type_null_def__
|
#ifndef __cxz_range_type_null_def__
|
||||||
#define __range_type_null_def__
|
#define __cxz_range_type_null_def__
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
typedef GenSingleIndex<size_t,SpaceType::NUL,0> NullIndex;
|
typedef GenSingleIndex<size_t,SpaceType::NUL,0> NullIndex;
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef __range_type_null_def__
|
#endif // #ifndef __cxz_range_type_null_def__
|
||||||
|
|
||||||
#endif // #ifdef __ranges_header__
|
#endif // #ifdef __cxz_ranges_header__
|
||||||
|
|
||||||
#endif // #ifdef include_range_type
|
#endif // #ifdef include_range_type
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
include_range_type(PSPACE,3) // Periodic 1dim space
|
include_range_type(PSPACE,3) // Periodic 1dim space
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef __ranges_header__
|
#ifdef __cxz_ranges_header__
|
||||||
|
|
||||||
#ifndef __range_type_space_def__
|
#ifndef __cxz_range_type_space_def__
|
||||||
#define __range_type_space_def__
|
#define __cxz_range_type_space_def__
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
// Periodic 1dim space
|
// Periodic 1dim space
|
||||||
typedef GenSingleIndex<int,SpaceType::PSPACE,MUI> XSpaceIndex;
|
typedef GenSingleIndex<int,SpaceType::PSPACE,MUI> XSpaceIndex;
|
||||||
|
@ -128,8 +128,8 @@ namespace MultiArrayTools
|
||||||
using MSpaceRF = decltype(CreateNDimSpaceRange<N>::template mkf<SpaceRange>());
|
using MSpaceRF = decltype(CreateNDimSpaceRange<N>::template mkf<SpaceRange>());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef __range_type_space_def__
|
#endif // #ifndef __cxz_range_type_space_def__
|
||||||
|
|
||||||
#endif // #ifdef __ranges_header__
|
#endif // #ifdef __cxz_ranges_header__
|
||||||
|
|
||||||
#endif // #ifdef include_range_type
|
#endif // #ifdef include_range_type
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
include_range_type(SPIN,2)
|
include_range_type(SPIN,2)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef __ranges_header__
|
#ifdef __cxz_ranges_header__
|
||||||
// assert, that this is only used within range_types/header.h
|
// assert, that this is only used within range_types/header.h
|
||||||
|
|
||||||
#ifndef __range_type_spin_def__
|
#ifndef __cxz_range_type_spin_def__
|
||||||
#define __range_type_spin_def__
|
#define __cxz_range_type_spin_def__
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
typedef GenSingleIndex<size_t,SpaceType::SPIN,4> SpinIndex;
|
typedef GenSingleIndex<size_t,SpaceType::SPIN,4> SpinIndex;
|
||||||
|
|
||||||
|
@ -82,8 +82,8 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // #ifndef __range_type_spin_def__
|
#endif // #ifndef __cxz_range_type_spin_def__
|
||||||
|
|
||||||
#endif // #ifdef __ranges_header__
|
#endif // #ifdef __cxz_ranges_header__
|
||||||
|
|
||||||
#endif // #ifdef include_range_type
|
#endif // #ifdef include_range_type
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "rpack_num.cc.h"
|
|
||||||
#include "ranges/dynamic_range.cc.h"
|
#include "ranges/dynamic_range.cc.h"
|
||||||
#include "ranges/index_wrapper.cc.h"
|
#include "ranges/index_wrapper.cc.h"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __ranges_base_def_h__
|
#ifndef __cxz_ranges_base_def_h__
|
||||||
#define __ranges_base_def_h__
|
#define __cxz_ranges_base_def_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
#define MUI static_cast<size_t>(-1)
|
#define MUI static_cast<size_t>(-1)
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class R>
|
template <class R>
|
||||||
|
@ -80,28 +80,9 @@ namespace MultiArrayTools
|
||||||
template <class... Indices>
|
template <class... Indices>
|
||||||
class MultiIndex;
|
class MultiIndex;
|
||||||
|
|
||||||
// container_range.h
|
|
||||||
//template <typename T, class... Ranges>
|
|
||||||
//class ContainerRangeFactory;
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
using ContainerRangeFactory = MultiRangeFactory<Ranges...>;
|
|
||||||
|
|
||||||
// container_range.h
|
|
||||||
//template <typename T, class... Ranges>
|
|
||||||
//class ContainerRange;
|
|
||||||
template <typename T, class... Ranges>
|
|
||||||
using ContainerRange = MultiRange<Ranges...>;
|
|
||||||
|
|
||||||
// container_range.h
|
|
||||||
template <typename T, class... Indices>
|
|
||||||
class ContainerIndex;
|
|
||||||
|
|
||||||
// anonymous_range.h
|
// anonymous_range.h
|
||||||
class AnonymousRangeFactory;
|
class AnonymousRangeFactory;
|
||||||
|
|
||||||
// anonymous_range.h
|
|
||||||
//class AnonymousRange;
|
|
||||||
|
|
||||||
// dynamic_range.h
|
// dynamic_range.h
|
||||||
class IndexWrapperBase;
|
class IndexWrapperBase;
|
||||||
|
|
||||||
|
@ -110,15 +91,12 @@ namespace MultiArrayTools
|
||||||
class IndexWrapper;
|
class IndexWrapper;
|
||||||
|
|
||||||
// dynamic_range.h
|
// dynamic_range.h
|
||||||
//template <class EC>
|
|
||||||
class DynamicIndex;
|
class DynamicIndex;
|
||||||
|
|
||||||
// dynamic_range.h
|
// dynamic_range.h
|
||||||
//template <class EC>
|
|
||||||
class DynamicRangeFactory;
|
class DynamicRangeFactory;
|
||||||
|
|
||||||
// dynamic_range.h
|
// dynamic_range.h
|
||||||
//template <class EC>
|
|
||||||
class DynamicRange;
|
class DynamicRange;
|
||||||
|
|
||||||
// value_range.h
|
// value_range.h
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __reg_ind_num_h__
|
#ifndef __cxz_reg_ind_num_h__
|
||||||
#define __reg_ind_num_h__
|
#define __cxz_reg_ind_num_h__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
//#ifndef __rheader_h__
|
//#ifndef __cxz_rheader_h__
|
||||||
//#define __rheader_h__
|
//#define __cxz_rheader_h__
|
||||||
|
|
||||||
#include "dynamic_range.h"
|
#include "dynamic_range.h"
|
||||||
#include "rpheader.h"
|
#include "rpheader.h"
|
||||||
|
|
|
@ -1,745 +0,0 @@
|
||||||
|
|
||||||
#include "rpack_num.h"
|
|
||||||
namespace MultiArrayHelper
|
|
||||||
{
|
|
||||||
using namespace MultiArrayTools;
|
|
||||||
|
|
||||||
template <class Index1>
|
|
||||||
size_t mkTotalDim()
|
|
||||||
{
|
|
||||||
return Index1::totalDim();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index1, class Index2, class... Indices>
|
|
||||||
size_t mkTotalDim()
|
|
||||||
{
|
|
||||||
return Index1::totalDim() * mkTotalDim<Index2,Indices...>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <class Range>
|
|
||||||
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
size_t origpos, size_t size)
|
|
||||||
{
|
|
||||||
assert(size == 1);
|
|
||||||
rp = std::dynamic_pointer_cast<Range>( orig[origpos] ); // catch bad cast here!!
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Range>
|
|
||||||
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
|
||||||
std::shared_ptr<Range> r)
|
|
||||||
{
|
|
||||||
v.insert(v.begin(), r);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
void RPackNum<N>::initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
|
||||||
{
|
|
||||||
std::get<N>(bs) = RPackNum<sizeof...(Indices)-N>::blockSize(ip);
|
|
||||||
RPackNum<N-1>::initBlockSizes(bs, ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
inline void RPackNum<N>::pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
|
||||||
{
|
|
||||||
auto& si = *std::get<N>(ip);
|
|
||||||
if(si.last()){
|
|
||||||
si = 0;
|
|
||||||
RPackNum<N-1>::pp(ip);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
++si;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
inline int RPackNum<N>::pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum)
|
|
||||||
{
|
|
||||||
auto& siPtr = std::get<N>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return RPackNum<N-1>::pp(ip, bs, idxPtrNum);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int tmp = siPtr->pp(idxPtrNum);
|
|
||||||
if(siPtr->pos() == siPtr->max()){
|
|
||||||
(*siPtr) = 0;
|
|
||||||
return RPackNum<N-1>::pp(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return tmp * std::get<N+1>(bs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
inline void RPackNum<N>::mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
|
||||||
{
|
|
||||||
auto& si = *std::get<N>(ip);
|
|
||||||
if(si.first()){
|
|
||||||
si = si.max() - 1;
|
|
||||||
RPackNum<N-1>::mm(ip);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
--si;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// !!!!
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
inline int RPackNum<N>::mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum)
|
|
||||||
{
|
|
||||||
auto& siPtr = std::get<N>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return std::get<N>(bs) + RPackNum<N-1>::mm(ip, bs, idxPtrNum);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(siPtr->first()){
|
|
||||||
(*siPtr) = siPtr->max() - 1;
|
|
||||||
return RPackNum<N-1>::mm(ip, bs, idxPtrNum) - siPtr->max() + 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return siPtr->mm(idxPtrNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class RangeTuple>
|
|
||||||
size_t RPackNum<N>::getSize(const RangeTuple& rt)
|
|
||||||
{
|
|
||||||
return std::get<N>(rt)->size() * RPackNum<N-1>::getSize(rt);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexPack, class MetaType>
|
|
||||||
void RPackNum<N>::getMetaPos(MetaType& target,
|
|
||||||
const IndexPack& source)
|
|
||||||
{
|
|
||||||
std::get<N>(target) = std::get<N>(source)->meta();
|
|
||||||
RPackNum<N-1>::getMetaPos(target, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexPack, typename MetaType>
|
|
||||||
void RPackNum<N>::setMeta(IndexPack& target, const MetaType& source)
|
|
||||||
{
|
|
||||||
std::get<N>(target)->at( std::get<N>(source) );
|
|
||||||
RPackNum<N-1>::setMeta(target, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class SpaceClass>
|
|
||||||
inline std::shared_ptr<RangeBase> RPackNum<N>::getSub(const SpaceClass& space, size_t num)
|
|
||||||
{
|
|
||||||
if(num == N){
|
|
||||||
return std::get<N>(space);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return RPackNum<N-1>::getSub(space, num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexPack>
|
|
||||||
void RPackNum<N>::setIndexPack(IndexPack& iPack, size_t pos)
|
|
||||||
{
|
|
||||||
auto& i = *std::get<N>(iPack).get();
|
|
||||||
const size_t ownPos = pos % i.max();
|
|
||||||
i = ownPos;
|
|
||||||
RPackNum<N-1>::setIndexPack(iPack, (pos - ownPos) / i.max() );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class MRange, class... Indices>
|
|
||||||
void RPackNum<N>::construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const MRange& range)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(range.template get<N>())>::type SubRangeType;
|
|
||||||
typedef typename SubRangeType::IndexType SubIndexType;
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<N>(ip).get())>::type TypeFromIndexPack;
|
|
||||||
|
|
||||||
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
|
||||||
"inconsistent types");
|
|
||||||
|
|
||||||
std::get<N>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<N>() ) );
|
|
||||||
*std::get<N>(ip) = 0;
|
|
||||||
RPackNum<N-1>::construct(ip, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
void RPackNum<N>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind)
|
|
||||||
{
|
|
||||||
std::get<N>(ip) = ind.template getPtr<N>() ;
|
|
||||||
RPackNum<N-1>::copyInst(ip, ind);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
void RPackNum<N>::copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<N>(ip))>::type SubType;
|
|
||||||
std::get<N>(ip) = std::make_shared<SubType>( ind.template get<N>() ) ;
|
|
||||||
RPackNum<N-1>::copyIndex(ip, ind);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
|
||||||
{
|
|
||||||
//const auto& idx = *std::get<N>(iPtrTup);
|
|
||||||
return std::get<N>(iPtrTup)->pos() + RPackNum<N-1>::makePos(iPtrTup) * std::get<N>(iPtrTup)->max();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
inline size_t RPackNum<N>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
|
||||||
{
|
|
||||||
return RPackNum<N-1>::makePos(iPtrTup, blockSize) + std::get<N>(iPtrTup)->pos() * std::get<N+1>(blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class Pack, class IndexType, class... Indices>
|
|
||||||
void RPackNum<N>::swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind,
|
|
||||||
const std::shared_ptr<Indices>&... ninds)
|
|
||||||
{
|
|
||||||
std::get<std::tuple_size<Pack>::value-N-1>(ipack) = nind;
|
|
||||||
RPackNum<N-1>::swapIndices(ipack, ninds...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class Pack, class... Indices>
|
|
||||||
void RPackNum<N>::swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
|
||||||
{
|
|
||||||
std::get<N>(ipack) = std::get<N>(ninds);
|
|
||||||
RPackNum<N-1>::swapIndices(ipack, ninds);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
size_t RPackNum<N>::blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
|
||||||
{
|
|
||||||
return std::get<sizeof...(Indices)-N>(pack)->max() * RPackNum<N-1>::blockSize(pack);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<N>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::shared_ptr<RangeBase> >& v)
|
|
||||||
{
|
|
||||||
setRangeToVec(v, std::get<N>(rst));
|
|
||||||
RPackNum<N-1>::RangesToVec(rst, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<N>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::intptr_t>& v)
|
|
||||||
{
|
|
||||||
v[N] = reinterpret_cast<std::intptr_t>( std::get<N>(rst).get() );
|
|
||||||
RPackNum<N-1>::RangesToVec(rst, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Indices>
|
|
||||||
void RPackNum<N>::printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
|
||||||
{
|
|
||||||
std::get<N>(ip)->print(offset);
|
|
||||||
RPackNum<N-1>::printIndex(ip, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class Range, class... Ranges>
|
|
||||||
void RPackNum<N>::checkDefaultable()
|
|
||||||
{
|
|
||||||
static_assert( Range::defaultable, "not defaultable" );
|
|
||||||
RPackNum<N-1>::template checkDefaultable<Ranges...>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
auto RPackNum<N>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
|
||||||
->ifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->ifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
auto RPackNum<N>::mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
|
||||||
->iforh( 0, RPackNum<N-1>::mkForh(step, ipack, ba, exs) ) )
|
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->iforh( step*std::get<NN+1>(ba), RPackNum<N-1>::mkForh(step, ipack, ba, exs) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
auto RPackNum<N>::mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
|
||||||
->pifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) )
|
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-N-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->pifor( step*std::get<NN+1>(ba), RPackNum<N-1>::mkFor(step, ipack, ba, exs) );
|
|
||||||
// mkFor is correct here, because we want to multithread only the FIRST index!!
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class Index>
|
|
||||||
inline void RPackNum<N>::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
|
||||||
{
|
|
||||||
//constexpr size_t DIM = Index::sDim();
|
|
||||||
const auto& ni = ii.template get<N>();
|
|
||||||
const size_t max = ni.max();
|
|
||||||
const size_t tmp = getStepSize(ni, j);
|
|
||||||
//ss += tmp * sx;
|
|
||||||
ss += tmp * ii.template getBlockSize<N+1>();
|
|
||||||
sx *= max;
|
|
||||||
RPackNum<N-1>::getStepSizeX(ii, j, ss, sx);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class RangeTuple, typename... SIZET>
|
|
||||||
inline void RPackNum<N>::resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes)
|
|
||||||
{
|
|
||||||
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
|
||||||
resolveSetRange(std::get<tps-N-1>(rtp), orig, off, size);
|
|
||||||
RPackNum<N-1>::resolveRangeType(orig, rtp, off+size, sizes...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline bool RPackNum<N>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
|
||||||
const vector<std::intptr_t>& a)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<std::intptr_t>( std::get<N>(p).get() ) == a[N] and
|
|
||||||
RPackNum<N-1>::checkIfCreated(p,a);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class MIndex>
|
|
||||||
inline std::string RPackNum<N>::getStringMeta(const MIndex& mi)
|
|
||||||
{
|
|
||||||
return RPackNum<N-1>::getStringMeta(mi) + "," + mi.template getPtr<N>()->stringMeta();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<N>::fillRangeDataVec(vector<char>& out,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& tp)
|
|
||||||
{
|
|
||||||
vector<char> part = std::get<sizeof...(Ranges)-N-1>(tp)->data();
|
|
||||||
out.insert(out.end(), part.begin(), part.end());
|
|
||||||
RPackNum<N-1>::fillRangeDataVec(out, tp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <size_t SIZE, class Range, class... Ranges>
|
|
||||||
inline bool RPackNum<N>::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);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<N>::setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
|
||||||
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<N>( stp ))>::type RType;
|
|
||||||
std::get<N>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[N] );
|
|
||||||
RPackNum<N-1>::setSpace(rbvec, stp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class MetaType, class... Ranges>
|
|
||||||
inline size_t RPackNum<N>::getCMeta(MetaType* xtarget, size_t pos,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
|
||||||
{
|
|
||||||
//constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<N>(stp);
|
|
||||||
const size_t ownPos = pos % r.size();
|
|
||||||
const size_t s = r.cmetaSize();
|
|
||||||
off -= s;
|
|
||||||
r.cmeta(reinterpret_cast<char*>(&std::get<N>(*xtarget)), ownPos);
|
|
||||||
return s + RPackNum<N-1>::getCMeta(xtarget, (pos - ownPos) / r.size(), stp, off);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline size_t RPackNum<N>::getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
|
||||||
{
|
|
||||||
constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<NN-N-1>(stp);
|
|
||||||
return r.cmetaSize() + RPackNum<N-1>::getCMetaSize(stp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<N>::getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
|
||||||
{
|
|
||||||
auto& r = *std::get<N>(stp);
|
|
||||||
auto tn = r.typeNum();
|
|
||||||
res.insert(res.begin(), tn.begin(), tn.end());
|
|
||||||
RPackNum<N-1>::getTypeNum(res, stp);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
template <class... Ranges>
|
|
||||||
inline size_t RPackNum<N>::getMeta(const std::tuple<std::shared_ptr<Ranges>...>& space,
|
|
||||||
const std::tuple<typename Ranges::IndexType::MetaType...>& meta)
|
|
||||||
{
|
|
||||||
return RPackNum<N-1>::getMeta(space,meta) * std::get<N>(space)->size() +
|
|
||||||
std::get<N>(space)->getMeta(std::get<N>(meta));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
void RPackNum<0>::initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::tuple<std::shared_ptr<Indices>...>& ip)
|
|
||||||
{
|
|
||||||
std::get<0>(bs) = RPackNum<sizeof...(Indices)>::blockSize(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
inline void RPackNum<0>::pp(std::tuple<std::shared_ptr<Indices>...>& ip)
|
|
||||||
{
|
|
||||||
auto& si = *std::get<0>(ip);
|
|
||||||
++si;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
inline int RPackNum<0>::pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum)
|
|
||||||
{
|
|
||||||
auto& siPtr = std::get<0>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return std::get<0>(bs);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int tmp = siPtr->pp(idxPtrNum);
|
|
||||||
return tmp * std::get<1>(bs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
inline void RPackNum<0>::mm(std::tuple<std::shared_ptr<Indices>...>& ip)
|
|
||||||
{
|
|
||||||
auto& si = *std::get<0>(ip);
|
|
||||||
--si;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
inline int RPackNum<0>::mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum)
|
|
||||||
{
|
|
||||||
auto& siPtr = std::get<0>(ip);
|
|
||||||
if(reinterpret_cast<std::intptr_t>(siPtr.get()) == idxPtrNum){
|
|
||||||
return std::get<0>(bs);
|
|
||||||
//return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return siPtr->mm(idxPtrNum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RangeTuple>
|
|
||||||
size_t RPackNum<0>::getSize(const RangeTuple& rt)
|
|
||||||
{
|
|
||||||
return std::get<0>(rt)->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class MetaType>
|
|
||||||
void RPackNum<0>::getMetaPos(MetaType& target,
|
|
||||||
const IndexPack& source)
|
|
||||||
{
|
|
||||||
std::get<0>(target) = std::get<0>(source)->meta();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, typename MetaType>
|
|
||||||
void RPackNum<0>::setMeta(IndexPack& target, const MetaType& source)
|
|
||||||
{
|
|
||||||
std::get<0>(target)->at( std::get<0>( source ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class SpaceClass>
|
|
||||||
inline std::shared_ptr<RangeBase> RPackNum<0>::getSub(const SpaceClass& space, size_t num)
|
|
||||||
{
|
|
||||||
if(num == 0){
|
|
||||||
return std::get<0>(space);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assert(0);
|
|
||||||
return std::shared_ptr<RangeBase>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack>
|
|
||||||
void RPackNum<0>::setIndexPack(IndexPack& iPack, size_t pos)
|
|
||||||
{
|
|
||||||
auto& i = *std::get<0>(iPack);
|
|
||||||
const size_t ownPos = pos % i.max();
|
|
||||||
i = ownPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MRange, class... Indices>
|
|
||||||
void RPackNum<0>::construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const MRange& range)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(range.template get<0>())>::type SubRangeType;
|
|
||||||
typedef typename SubRangeType::IndexType SubIndexType;
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<0>(ip).get())>::type TypeFromIndexPack;
|
|
||||||
|
|
||||||
static_assert(std::is_same<SubIndexType,TypeFromIndexPack>::value,
|
|
||||||
"inconsistent types");
|
|
||||||
|
|
||||||
std::get<0>(ip) = std::shared_ptr<SubIndexType>( new SubIndexType( range.template getPtr<0>() ) );
|
|
||||||
*std::get<0>(ip) = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
void RPackNum<0>::copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind)
|
|
||||||
{
|
|
||||||
std::get<0>(ip) = ind.template getPtr<0>();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
void RPackNum<0>::copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<0>(ip))>::type SubType;
|
|
||||||
std::get<0>(ip) = std::make_shared<SubType>( ind.template get<0>() ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup)
|
|
||||||
{
|
|
||||||
return std::get<0>(iPtrTup)->pos();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
inline size_t RPackNum<0>::makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSize)
|
|
||||||
{
|
|
||||||
return std::get<0>(iPtrTup)->pos() * std::get<1>(blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class IndexType>
|
|
||||||
void RPackNum<0>::swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind)
|
|
||||||
{
|
|
||||||
std::get<std::tuple_size<Pack>::value-1>(ipack) = nind;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Pack, class... Indices>
|
|
||||||
void RPackNum<0>::swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds)
|
|
||||||
{
|
|
||||||
std::get<0>(ipack) = std::get<0>(ninds);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
size_t RPackNum<0>::blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<0>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::intptr_t>& v)
|
|
||||||
{
|
|
||||||
v[0] = reinterpret_cast<std::intptr_t>( std::get<0>(rst).get() );;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<0>::RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::shared_ptr<RangeBase> >& v)
|
|
||||||
{
|
|
||||||
setRangeToVec(v, std::get<0>(rst));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
void RPackNum<0>::printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset)
|
|
||||||
{
|
|
||||||
std::get<0>(ip)->print(offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Range>
|
|
||||||
void RPackNum<0>::checkDefaultable()
|
|
||||||
{
|
|
||||||
static_assert( Range::defaultable, "not defaultable" );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
auto RPackNum<0>::mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
|
||||||
->ifor(0,exs) )
|
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->ifor( step*std::get<NN+1>(ba), exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
auto RPackNum<0>::mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
|
||||||
->iforh(0,exs) )
|
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->iforh( step*std::get<NN+1>(ba), exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
auto RPackNum<0>::mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
|
||||||
->pifor(0,exs) )
|
|
||||||
{
|
|
||||||
constexpr size_t NN = std::tuple_size<IndexPack>::value-1;
|
|
||||||
return std::get<NN>(ipack)
|
|
||||||
->pifor( step*std::get<NN+1>(ba), exs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
inline void RPackNum<0>::getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx)
|
|
||||||
{
|
|
||||||
//constexpr size_t DIM = Index::sDim();
|
|
||||||
const auto& ni = ii.template get<0>();
|
|
||||||
const size_t max = ni.max();
|
|
||||||
const size_t tmp = getStepSize(ni, j);
|
|
||||||
//ss += tmp * sx;
|
|
||||||
ss += tmp * ii.template getBlockSize<1>();
|
|
||||||
sx *= max;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class RangeTuple, typename... SIZET>
|
|
||||||
inline void RPackNum<0>::resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
RangeTuple& rtp, size_t off, size_t size)
|
|
||||||
{
|
|
||||||
constexpr size_t tps = std::tuple_size<RangeTuple>::value;
|
|
||||||
resolveSetRange(std::get<tps-1>(rtp), orig, off, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline bool RPackNum<0>::checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
|
||||||
const vector<std::intptr_t>& a)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<std::intptr_t>( std::get<0>(p).get() ) == a[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MIndex>
|
|
||||||
inline std::string RPackNum<0>::getStringMeta(const MIndex& mi)
|
|
||||||
{
|
|
||||||
return mi.template getPtr<0>()->stringMeta();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<0>::fillRangeDataVec(vector<char>& out,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& tp)
|
|
||||||
{
|
|
||||||
vector<char> part = std::get<sizeof...(Ranges)-1>(tp)->data();
|
|
||||||
out.insert(out.end(), part.begin(), part.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t SIZE, class Range>
|
|
||||||
inline bool RPackNum<0>::compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec)
|
|
||||||
{
|
|
||||||
return rbvec[SIZE-1]->spaceType() == Range::STYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<0>::setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
|
||||||
std::tuple<std::shared_ptr<Ranges>...>& stp)
|
|
||||||
{
|
|
||||||
typedef typename std::remove_reference<decltype(*std::get<0>( stp ))>::type RType;
|
|
||||||
std::get<0>( stp ) = std::dynamic_pointer_cast<RType>( rbvec[0] );
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class MetaType, class... Ranges>
|
|
||||||
inline size_t RPackNum<0>::getCMeta(MetaType* xtarget, size_t pos,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off)
|
|
||||||
{
|
|
||||||
//constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<0>(stp);
|
|
||||||
const size_t ownPos = pos % r.size();
|
|
||||||
const size_t s = r.cmetaSize();
|
|
||||||
off -= s;
|
|
||||||
assert(off == 0);
|
|
||||||
r.cmeta(reinterpret_cast<char*>(&std::get<0>(*xtarget)), ownPos);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline size_t RPackNum<0>::getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
|
||||||
{
|
|
||||||
constexpr size_t NN = sizeof...(Ranges);
|
|
||||||
auto& r = *std::get<NN-1>(stp);
|
|
||||||
return r.cmetaSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline void RPackNum<0>::getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp)
|
|
||||||
{
|
|
||||||
auto& r = *std::get<0>(stp);
|
|
||||||
auto tn = r.typeNum();
|
|
||||||
res.insert(res.begin(), tn.begin(), tn.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
inline size_t RPackNum<0>::getMeta(const std::tuple<std::shared_ptr<Ranges>...>& space,
|
|
||||||
const std::tuple<typename Ranges::IndexType::MetaType...>& meta)
|
|
||||||
{
|
|
||||||
return std::get<0>(space)->getMeta(std::get<0>(meta));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template <IndexType IT>
|
|
||||||
template <class Index>
|
|
||||||
inline size_t SSG<IT>::getStepSize(const Index& ii, std::intptr_t j)
|
|
||||||
{
|
|
||||||
size_t ss = 0;
|
|
||||||
size_t sx = 1;
|
|
||||||
constexpr size_t DIM = Index::sDim();
|
|
||||||
RPackNum<DIM-1>::getStepSizeX(ii, j, ss, sx);
|
|
||||||
return ss;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
inline size_t SSG<IndexType::SINGLE>::getStepSize(const Index& ii, std::intptr_t j)
|
|
||||||
{
|
|
||||||
const std::intptr_t ip = reinterpret_cast<std::intptr_t>(&ii);
|
|
||||||
return ip == j ? 1 : 0;
|
|
||||||
//return ii.ptrNum() == j ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
inline size_t getStepSize(const Index& ii, std::intptr_t j)
|
|
||||||
{
|
|
||||||
constexpr IndexType IT = Index::sType();
|
|
||||||
return SSG<IT>::getStepSize(ii, j);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
|
|
@ -1,346 +0,0 @@
|
||||||
|
|
||||||
#ifndef __rpack_num_h__
|
|
||||||
#define __rpack_num_h__
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
#include <cassert>
|
|
||||||
#include "ranges/rbase_def.h"
|
|
||||||
#include "ranges/index_base.h"
|
|
||||||
#include "ranges/x_to_string.h"
|
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
|
||||||
{
|
|
||||||
using namespace MultiArrayTools;
|
|
||||||
|
|
||||||
|
|
||||||
template <class Index1>
|
|
||||||
size_t mkTotalDim();
|
|
||||||
|
|
||||||
template <class Index1, class Index2, class... Indices>
|
|
||||||
size_t mkTotalDim();
|
|
||||||
|
|
||||||
|
|
||||||
template <class RangeType, class... Ranges>
|
|
||||||
struct SubProp
|
|
||||||
{
|
|
||||||
static constexpr size_t ISSTATIC = RangeType::ISSTATIC & SubProp<Ranges...>::ISSTATIC;
|
|
||||||
static constexpr size_t SIZE = RangeType::SIZE * SubProp<Ranges...>::SIZE;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct SubProp<None>
|
|
||||||
{
|
|
||||||
static constexpr size_t ISSTATIC = 1;
|
|
||||||
static constexpr size_t SIZE = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
|
||||||
|
|
||||||
|
|
||||||
template <class Range>
|
|
||||||
inline void resolveSetRange(std::shared_ptr<Range>& rp, const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
size_t origpos, size_t size);
|
|
||||||
|
|
||||||
template <class Range>
|
|
||||||
inline void setRangeToVec(vector<std::shared_ptr<RangeBase> >& v,
|
|
||||||
std::shared_ptr<Range> r);
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
struct RPackNum
|
|
||||||
{
|
|
||||||
template <class... Indices>
|
|
||||||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::tuple<std::shared_ptr<Indices>...>& ip);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip);
|
|
||||||
|
|
||||||
// !!!!
|
|
||||||
template <class... Indices>
|
|
||||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum);
|
|
||||||
|
|
||||||
template <class RangeTuple>
|
|
||||||
static size_t getSize(const RangeTuple& rt);
|
|
||||||
|
|
||||||
template <class IndexPack, class MetaType>
|
|
||||||
static void getMetaPos(MetaType& target,
|
|
||||||
const IndexPack& source);
|
|
||||||
|
|
||||||
template <class IndexPack, typename MetaType>
|
|
||||||
static void setMeta(IndexPack& target, const MetaType& source);
|
|
||||||
|
|
||||||
template <class SpaceClass>
|
|
||||||
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
|
|
||||||
|
|
||||||
template <class IndexPack>
|
|
||||||
static void setIndexPack(IndexPack& iPack, size_t pos);
|
|
||||||
|
|
||||||
template <class MRange, class... Indices>
|
|
||||||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const MRange& range);
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind);
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSize);
|
|
||||||
|
|
||||||
template <class Pack, class IndexType, class... Indices>
|
|
||||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind,
|
|
||||||
const std::shared_ptr<Indices>&... ninds);
|
|
||||||
|
|
||||||
template <class Pack, class... Indices>
|
|
||||||
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack);
|
|
||||||
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::shared_ptr<RangeBase> >& v);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::intptr_t>& v);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset);
|
|
||||||
|
|
||||||
template <class Range, class... Ranges>
|
|
||||||
static void checkDefaultable();
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
|
||||||
->ifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) );
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
|
||||||
->iforh( 0, RPackNum<N-1>::mkForh(step, ipack, ba, exs) ) );
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-N-1>(ipack)
|
|
||||||
->pifor( 0, RPackNum<N-1>::mkFor(step, ipack, ba, exs) ) );
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx);
|
|
||||||
|
|
||||||
template <class RangeTuple, typename... SIZET>
|
|
||||||
static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
RangeTuple& rtp, size_t off, size_t size, SIZET... sizes);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
|
||||||
const vector<std::intptr_t>& a);
|
|
||||||
|
|
||||||
template <class MIndex>
|
|
||||||
static inline std::string getStringMeta(const MIndex& mi);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void fillRangeDataVec(vector<char>& out,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& tp);
|
|
||||||
|
|
||||||
template <size_t SIZE, class Range, class... Ranges>
|
|
||||||
static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
|
||||||
std::tuple<std::shared_ptr<Ranges>...>& stp);
|
|
||||||
|
|
||||||
template <class MetaType, class... Ranges>
|
|
||||||
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline size_t getMeta(const std::tuple<std::shared_ptr<Ranges>...>& space,
|
|
||||||
const std::tuple<typename Ranges::IndexType::MetaType...>& meta);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct RPackNum<0>
|
|
||||||
{
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static void initBlockSizes(std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::tuple<std::shared_ptr<Indices>...>& ip);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline void pp(std::tuple<std::shared_ptr<Indices>...>& ip);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline int pp(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline void mm(std::tuple<std::shared_ptr<Indices>...>& ip);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline int mm(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
std::array<size_t,sizeof...(Indices)+1>& bs,
|
|
||||||
std::intptr_t idxPtrNum);
|
|
||||||
|
|
||||||
template <class RangeTuple>
|
|
||||||
static size_t getSize(const RangeTuple& rt);
|
|
||||||
|
|
||||||
template <class IndexPack, class MetaType>
|
|
||||||
static void getMetaPos(MetaType& target,
|
|
||||||
const IndexPack& source);
|
|
||||||
|
|
||||||
template <class IndexPack, typename MetaType>
|
|
||||||
static void setMeta(IndexPack& target, const MetaType& source);
|
|
||||||
|
|
||||||
template <class SpaceClass>
|
|
||||||
inline static std::shared_ptr<RangeBase> getSub(const SpaceClass& space, size_t num);
|
|
||||||
|
|
||||||
template <class IndexPack>
|
|
||||||
static void setIndexPack(IndexPack& iPack, size_t pos);
|
|
||||||
|
|
||||||
template <class MRange, class... Indices>
|
|
||||||
static void construct(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const MRange& range);
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
static void copyInst(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind);
|
|
||||||
|
|
||||||
template <class IndexType, class... Indices>
|
|
||||||
static void copyIndex(std::tuple<std::shared_ptr<Indices>...>& ip,
|
|
||||||
const IndexType& ind);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static inline size_t makePos(const std::tuple<std::shared_ptr<Indices>...>& iPtrTup,
|
|
||||||
const std::array<size_t,sizeof...(Indices)+1>& blockSize);
|
|
||||||
|
|
||||||
template <class Pack, class IndexType>
|
|
||||||
static void swapIndices(Pack& ipack, const std::shared_ptr<IndexType>& nind);
|
|
||||||
|
|
||||||
template <class Pack, class... Indices>
|
|
||||||
static void swapIndices(Pack& ipack, const std::tuple<std::shared_ptr<Indices>...>& ninds);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static size_t blockSize(const std::tuple<std::shared_ptr<Indices>...>& pack);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::intptr_t>& v);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void RangesToVec(const std::tuple<std::shared_ptr<Ranges>...>& rst,
|
|
||||||
vector<std::shared_ptr<RangeBase> >& v);
|
|
||||||
|
|
||||||
template <class... Indices>
|
|
||||||
static void printIndex(const std::tuple<std::shared_ptr<Indices>...>& ip, size_t offset);
|
|
||||||
|
|
||||||
template <class Range>
|
|
||||||
static void checkDefaultable();
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
static auto mkFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
|
||||||
->ifor(0,exs) );
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
static auto mkForh(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
|
||||||
->iforh(0,exs) );
|
|
||||||
|
|
||||||
template <class IndexPack, class BlockArray, class Exprs>
|
|
||||||
static auto mkPFor(size_t step, const IndexPack& ipack, const BlockArray& ba, Exprs exs)
|
|
||||||
-> decltype(std::get<std::tuple_size<IndexPack>::value-1>(ipack)
|
|
||||||
->pifor(0,exs) );
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
static inline void getStepSizeX(const Index& ii, std::intptr_t j, size_t& ss, size_t& sx);
|
|
||||||
|
|
||||||
template <class RangeTuple, typename... SIZET>
|
|
||||||
static inline void resolveRangeType(const vector<std::shared_ptr<RangeBase> >& orig,
|
|
||||||
RangeTuple& rtp, size_t off, size_t size);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline bool checkIfCreated(const std::tuple<std::shared_ptr<Ranges>...>& p,
|
|
||||||
const vector<std::intptr_t>& a);
|
|
||||||
|
|
||||||
template <class MIndex>
|
|
||||||
static inline std::string getStringMeta(const MIndex& mi);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void fillRangeDataVec(vector<char>& out,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& tp);
|
|
||||||
|
|
||||||
template <size_t SIZE, class Range>
|
|
||||||
static inline bool compareSpaceTypes(const vector<std::shared_ptr<RangeBase> >& rbvec);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void setSpace(const vector<std::shared_ptr<RangeBase> >& rbvec,
|
|
||||||
std::tuple<std::shared_ptr<Ranges>...>& stp);
|
|
||||||
|
|
||||||
template <class MetaType, class... Ranges>
|
|
||||||
static inline size_t getCMeta(MetaType* xtarget, size_t pos,
|
|
||||||
const std::tuple<std::shared_ptr<Ranges>...>& stp, size_t off);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline size_t getCMetaSize(const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline void getTypeNum(vector<size_t>& res, const std::tuple<std::shared_ptr<Ranges>...>& stp);
|
|
||||||
|
|
||||||
template <class... Ranges>
|
|
||||||
static inline size_t getMeta(const std::tuple<std::shared_ptr<Ranges>...>& space,
|
|
||||||
const std::tuple<typename Ranges::IndexType::MetaType...>& meta);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <IndexType IT>
|
|
||||||
struct SSG
|
|
||||||
{
|
|
||||||
template <class Index>
|
|
||||||
static inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct SSG<IndexType::SINGLE>
|
|
||||||
{
|
|
||||||
template <class Index>
|
|
||||||
static inline size_t getStepSize(const Index& ii, std::intptr_t j);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
|
||||||
|
|
||||||
//#include "rpack_num.cc.h"
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,10 +1,9 @@
|
||||||
|
|
||||||
//#ifndef __rpheader_h__
|
//#ifndef __cxz_rpheader_h__
|
||||||
//#define __rpheader_h__
|
//#define __cxz_rpheader_h__
|
||||||
|
|
||||||
#include "single_range.h"
|
#include "single_range.h"
|
||||||
#include "multi_range.h"
|
#include "multi_range.h"
|
||||||
#include "container_range.h"
|
|
||||||
#include "subrange.h"
|
#include "subrange.h"
|
||||||
//#include "anonymous_range.h"
|
//#include "anonymous_range.h"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// -*- C++ -*-
|
// -*- C++ -*-
|
||||||
|
|
||||||
#ifndef __single_range_h__
|
#ifndef __cxz_single_range_h__
|
||||||
#define __single_range_h__
|
#define __cxz_single_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -9,22 +9,18 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
//#include "ranges/rpack_num.h"
|
|
||||||
#include "ranges/index_base.h"
|
#include "ranges/index_base.h"
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
|
|
||||||
#include "xfor/for_type.h"
|
#include "xfor/for_type.h"
|
||||||
//#include "xfor/xfor.h"
|
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
|
||||||
namespace MultiArrayTools
|
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,9 +74,6 @@ namespace MultiArrayTools
|
||||||
void getPtr();
|
void getPtr();
|
||||||
|
|
||||||
size_t getStepSize(size_t n);
|
size_t getStepSize(size_t n);
|
||||||
|
|
||||||
std::string id() const;
|
|
||||||
void print(size_t offset);
|
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto ifor(size_t step, Expr ex) const
|
auto ifor(size_t step, Expr ex) const
|
||||||
|
@ -334,7 +327,7 @@ namespace MultiArrayTools
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
* ========================= */
|
* ========================= */
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/******************
|
/******************
|
||||||
* GenSingleIndex *
|
* GenSingleIndex *
|
||||||
|
@ -492,23 +485,6 @@ namespace MultiArrayTools
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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, size_t S>
|
|
||||||
void GenSingleIndex<U,TYPE,S>::print(size_t offset)
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
||||||
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U, SpaceType TYPE, size_t S>
|
template <typename U, SpaceType TYPE, size_t S>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
|
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __subrange_h__
|
#ifndef __cxz_subrange_h__
|
||||||
#define __subrange_h__
|
#define __cxz_subrange_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -8,7 +8,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
//#include "ranges/rpack_num.h"
|
|
||||||
#include "ranges/index_base.h"
|
#include "ranges/index_base.h"
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
|
@ -16,11 +15,11 @@
|
||||||
|
|
||||||
#include "xfor/for_type.h"
|
#include "xfor/for_type.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
|
@ -71,9 +70,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
size_t getStepSize(size_t n);
|
size_t getStepSize(size_t n);
|
||||||
|
|
||||||
std::string id() const;
|
|
||||||
void print(size_t offset);
|
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto ifor(size_t step, Expr ex) const
|
auto ifor(size_t step, Expr ex) const
|
||||||
-> For<SubIndex<Index>,SubExpr<Index,Expr>>;
|
-> For<SubIndex<Index>,SubExpr<Index,Expr>>;
|
||||||
|
@ -158,9 +154,9 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
|
@ -302,23 +298,6 @@ namespace MultiArrayTools
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
std::string SubIndex<Index>::id() const
|
|
||||||
{
|
|
||||||
return std::string("sub") + std::to_string(IB::mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
|
||||||
void SubIndex<Index>::print(size_t offset)
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
||||||
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Index>
|
template <class Index>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto SubIndex<Index>::ifor(size_t step, Expr ex) const
|
auto SubIndex<Index>::ifor(size_t step, Expr ex) const
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __ma_type_map_h__
|
#ifndef __cxz_type_map_h__
|
||||||
#define __ma_type_map_h__
|
#define __cxz_type_map_h__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __value_range_h__
|
#ifndef __cxz_value_range_h__
|
||||||
#define __value_range_h__
|
#define __cxz_value_range_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -17,12 +17,12 @@
|
||||||
|
|
||||||
#include "xfor/for_type.h"
|
#include "xfor/for_type.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
|
@ -69,9 +69,6 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
size_t getStepSize(size_t n);
|
size_t getStepSize(size_t n);
|
||||||
|
|
||||||
std::string id() const;
|
|
||||||
void print(size_t offset);
|
|
||||||
|
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto ifor(size_t step, Expr ex) const
|
auto ifor(size_t step, Expr ex) const
|
||||||
-> For<ValueIndex<U>,Expr>;
|
-> For<ValueIndex<U>,Expr>;
|
||||||
|
@ -141,13 +138,13 @@ namespace MultiArrayTools
|
||||||
ValueRange() = default;
|
ValueRange() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
* ========================= */
|
* ========================= */
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/*****************
|
/*****************
|
||||||
* ValueIndex *
|
* ValueIndex *
|
||||||
|
@ -275,23 +272,6 @@ namespace MultiArrayTools
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U>
|
|
||||||
std::string ValueIndex<U>::id() const
|
|
||||||
{
|
|
||||||
return std::string("val") + std::to_string(IB::mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U>
|
|
||||||
void ValueIndex<U>::print(size_t offset)
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
||||||
<< "](" << IB::mRangePtr << "): " << meta() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
template <class Expr>
|
template <class Expr>
|
||||||
auto ValueIndex<U>::ifor(size_t step, Expr ex) const
|
auto ValueIndex<U>::ifor(size_t step, Expr ex) const
|
||||||
|
@ -430,6 +410,6 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __x_to_string_h__
|
#ifndef __cxz_x_to_string_h__
|
||||||
#define __x_to_string_h__
|
#define __cxz_x_to_string_h__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
#include "ranges/dynamic_meta.h"
|
#include "ranges/dynamic_meta.h"
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::string xToString(const T& x);
|
inline std::string xToString(const T& x);
|
||||||
|
@ -22,7 +22,7 @@ namespace MultiArrayHelper
|
||||||
template <>
|
template <>
|
||||||
inline std::string xToString<std::string>(const std::string& x);
|
inline std::string xToString<std::string>(const std::string& x);
|
||||||
|
|
||||||
using MultiArrayTools::DynamicMetaT;
|
using CNORXZ::DynamicMetaT;
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x);
|
inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#include "slice.h"
|
#include "slice.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
|
@ -17,7 +17,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstSlice<T,SRanges...>::ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
ConstSlice<T,SRanges...>::ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
||||||
const T* data) :
|
const T* data) :
|
||||||
MultiArrayBase<T,SRanges...>(ranges),
|
ArrayBase<T,SRanges...>(ranges),
|
||||||
mData(data)
|
mData(data)
|
||||||
{
|
{
|
||||||
MAB::mInit = true;
|
MAB::mInit = true;
|
||||||
|
@ -25,15 +25,15 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstSlice<T,SRanges...>::ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data) :
|
ConstSlice<T,SRanges...>::ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data) :
|
||||||
MultiArrayBase<T,SRanges...>(ranges...),
|
ArrayBase<T,SRanges...>(ranges...),
|
||||||
mData(data)
|
mData(data)
|
||||||
{
|
{
|
||||||
MAB::mInit = true;
|
MAB::mInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
ConstSlice<T,SRanges...>::ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) :
|
ConstSlice<T,SRanges...>::ConstSlice(const ArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) :
|
||||||
MultiArrayBase<T,SRanges...>
|
ArrayBase<T,SRanges...>
|
||||||
( ma.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
|
( ma.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
|
||||||
mData( ma.data() )
|
mData( ma.data() )
|
||||||
{
|
{
|
||||||
|
@ -87,7 +87,7 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > ConstSlice<T,SRanges...>::anonymous(bool slice) const
|
std::shared_ptr<ArrayBase<T,AnonymousRange> > ConstSlice<T,SRanges...>::anonymous(bool slice) const
|
||||||
{
|
{
|
||||||
assert(slice);
|
assert(slice);
|
||||||
assert(not MAB::mProtoI->sliceMode()); // only originally ordered slices!
|
assert(not MAB::mProtoI->sliceMode()); // only originally ordered slices!
|
||||||
|
@ -118,13 +118,13 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
Slice<T,SRanges...>::Slice(const std::shared_ptr<SRanges>&... ranges, T* data) :
|
Slice<T,SRanges...>::Slice(const std::shared_ptr<SRanges>&... ranges, T* data) :
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
MutableArrayBase<T,SRanges...>(ranges...),
|
||||||
mData(data) {}
|
mData(data) {}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
Slice<T,SRanges...>::Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
Slice<T,SRanges...>::Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
||||||
T* data) :
|
T* data) :
|
||||||
MutableMultiArrayBase<T,SRanges...>(ranges),
|
MutableArrayBase<T,SRanges...>(ranges),
|
||||||
mData(data)
|
mData(data)
|
||||||
{
|
{
|
||||||
MAB::mInit = true;
|
MAB::mInit = true;
|
||||||
|
@ -208,14 +208,14 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymous(bool slice) const
|
std::shared_ptr<ArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymous(bool slice) const
|
||||||
{
|
{
|
||||||
assert(0); // think about carefully!!!!
|
assert(0); // think about carefully!!!!
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
std::shared_ptr<MultiArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymousMove()
|
std::shared_ptr<ArrayBase<T,AnonymousRange> > Slice<T,SRanges...>::anonymousMove()
|
||||||
{
|
{
|
||||||
assert(0); // think about carefully!!!!
|
assert(0); // think about carefully!!!!
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -243,8 +243,12 @@ namespace MultiArrayTools
|
||||||
SliceDef<T,SRanges...>& SliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
|
SliceDef<T,SRanges...>& SliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
|
||||||
{
|
{
|
||||||
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
||||||
PackNum<sizeof...(SRanges)-1>::
|
sfor_pn<0,sizeof...(SRanges)>
|
||||||
template mkSliceBlocks<T,OperationRoot<T,ORanges...>,SRanges...>(blocks, mIndex, op);
|
( [&](auto i) {
|
||||||
|
std::get<i+1>(blocks) =
|
||||||
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
||||||
|
( mIndex.template getPtr<i>().get())).val();
|
||||||
|
return 0; } );
|
||||||
mSl.format(blocks);
|
mSl.format(blocks);
|
||||||
mSl.mData = op.data();
|
mSl.mData = op.data();
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -264,8 +268,12 @@ namespace MultiArrayTools
|
||||||
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const ConstOperationRoot<T,ORanges...>& op)
|
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const ConstOperationRoot<T,ORanges...>& op)
|
||||||
{
|
{
|
||||||
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
||||||
PackNum<sizeof...(SRanges)-1>::
|
sfor_pn<0,sizeof...(SRanges)>
|
||||||
template mkSliceBlocks<T,ConstOperationRoot<T,ORanges...>,SRanges...>(blocks, mIndex, op);
|
( [&](auto i) {
|
||||||
|
std::get<i+1>(blocks) =
|
||||||
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
||||||
|
( mIndex.template getPtr<i>().get())).val();
|
||||||
|
return 0; } );
|
||||||
mSl.format(blocks);
|
mSl.format(blocks);
|
||||||
mSl.mData = op.data();
|
mSl.mData = op.data();
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -276,13 +284,17 @@ namespace MultiArrayTools
|
||||||
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
|
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
|
||||||
{
|
{
|
||||||
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
||||||
PackNum<sizeof...(SRanges)-1>::
|
sfor_pn<0,sizeof...(SRanges)>
|
||||||
template mkSliceBlocks<T,OperationRoot<T,ORanges...>,SRanges...>(blocks, mIndex, op);
|
( [&](auto i) {
|
||||||
|
std::get<i+1>(blocks) =
|
||||||
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
||||||
|
( mIndex.template getPtr<i>().get())).val();
|
||||||
|
return 0; } );
|
||||||
mSl.format(blocks);
|
mSl.format(blocks);
|
||||||
mSl.mData = op.data();
|
mSl.mData = op.data();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
|
|
||||||
#ifndef __slice_h__
|
#ifndef __cxz_slice_h__
|
||||||
#define __slice_h__
|
#define __cxz_slice_h__
|
||||||
|
|
||||||
#include "multi_array_base.h"
|
#include "cxz_array_base.h"
|
||||||
#include "multi_array_operation.h"
|
#include "cxz_operation.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
class ConstSlice : public MultiArrayBase<T,SRanges...>
|
class ConstSlice : public ArrayBase<T,SRanges...>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef ContainerRange<T,SRanges...> CRange;
|
typedef ContainerRange<SRanges...> CRange;
|
||||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
typedef ArrayBase<T,SRanges...> MAB;
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||||
|
|
||||||
using MultiArrayBase<T,SRanges...>::operator();
|
using ArrayBase<T,SRanges...>::operator();
|
||||||
using MultiArrayBase<T,SRanges...>::operator[];
|
using ArrayBase<T,SRanges...>::operator[];
|
||||||
|
|
||||||
DEFAULT_MEMBERS(ConstSlice);
|
DEFAULT_MEMBERS(ConstSlice);
|
||||||
|
|
||||||
ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
||||||
const T* data = nullptr);
|
const T* data = nullptr);
|
||||||
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
|
ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data = nullptr);
|
||||||
ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes);
|
ConstSlice(const ArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes);
|
||||||
|
|
||||||
virtual const T& operator[](const IType& i) const final;
|
virtual const T& operator[](const IType& i) const final;
|
||||||
virtual const T& at(const typename IType::MetaType& meta) const override;
|
virtual const T& at(const typename IType::MetaType& meta) const override;
|
||||||
|
@ -36,7 +36,7 @@ namespace MultiArrayTools
|
||||||
virtual auto begin() const -> IType override;
|
virtual auto begin() const -> IType override;
|
||||||
virtual auto end() const -> IType override;
|
virtual auto end() const -> IType override;
|
||||||
|
|
||||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||||
|
|
||||||
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||||
-> ConstSliceDef<T,SRanges...>;
|
-> ConstSliceDef<T,SRanges...>;
|
||||||
|
@ -51,18 +51,18 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
|
|
||||||
template <typename T, class... SRanges>
|
template <typename T, class... SRanges>
|
||||||
class Slice : public MutableMultiArrayBase<T,SRanges...>
|
class Slice : public MutableArrayBase<T,SRanges...>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef ContainerRange<T,SRanges...> CRange;
|
typedef ContainerRange<SRanges...> CRange;
|
||||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
typedef ArrayBase<T,SRanges...> MAB;
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||||
|
|
||||||
using MultiArrayBase<T,SRanges...>::operator();
|
using ArrayBase<T,SRanges...>::operator();
|
||||||
using MutableMultiArrayBase<T,SRanges...>::operator();
|
using MutableArrayBase<T,SRanges...>::operator();
|
||||||
using MultiArrayBase<T,SRanges...>::operator[];
|
using ArrayBase<T,SRanges...>::operator[];
|
||||||
using MutableMultiArrayBase<T,SRanges...>::operator[];
|
using MutableArrayBase<T,SRanges...>::operator[];
|
||||||
|
|
||||||
DEFAULT_MEMBERS(Slice);
|
DEFAULT_MEMBERS(Slice);
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ namespace MultiArrayTools
|
||||||
virtual auto begin() const -> IType override;
|
virtual auto begin() const -> IType override;
|
||||||
virtual auto end() const -> IType override;
|
virtual auto end() const -> IType override;
|
||||||
|
|
||||||
virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
//virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||||
|
|
||||||
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||||
-> SliceDef<T,SRanges...>;
|
-> SliceDef<T,SRanges...>;
|
||||||
|
@ -104,17 +104,20 @@ namespace MultiArrayTools
|
||||||
class SliceDef
|
class SliceDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||||
|
|
||||||
template <class Op>
|
template <class Op>
|
||||||
static Slice<T,SRanges...> mkSlice( const typename Slice<T,SRanges...>::IndexType& ind,
|
static Slice<T,SRanges...> mkSlice( const typename Slice<T,SRanges...>::IndexType& ind,
|
||||||
const Op& op )
|
const Op& op )
|
||||||
{
|
{
|
||||||
Slice<T,SRanges...> out(ind->range()->space(), &*ind);
|
Slice<T,SRanges...> out(ind->range()->space(), &*ind);
|
||||||
std::array<size_t,sizeof...(SRanges)+1> ff;
|
std::array<size_t,sizeof...(SRanges)+1> ff;
|
||||||
for(size_t i = 0; i != sizeof...(SRanges)+1; ++i){
|
sfor_pn<0,sizeof...(SRanges)>
|
||||||
PackNum<sizeof...(SRanges)-1>::mkSliceBlocks(ff, ind, op);
|
( [&](auto i) {
|
||||||
}
|
std::get<i+1>(ff) =
|
||||||
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
||||||
|
( ind.template getPtr<i>().get())).val();
|
||||||
|
return 0; } );
|
||||||
out.format(ff);
|
out.format(ff);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +140,7 @@ namespace MultiArrayTools
|
||||||
class ConstSliceDef
|
class ConstSliceDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||||
|
|
||||||
template <class Op>
|
template <class Op>
|
||||||
static ConstSlice<T,SRanges...> mkSlice( const typename ConstSlice<T,SRanges...>::IndexType& ind,
|
static ConstSlice<T,SRanges...> mkSlice( const typename ConstSlice<T,SRanges...>::IndexType& ind,
|
||||||
|
@ -145,9 +148,12 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
ConstSlice<T,SRanges...> out(ind->range()->space(), &*ind);
|
ConstSlice<T,SRanges...> out(ind->range()->space(), &*ind);
|
||||||
std::array<size_t,sizeof...(SRanges)+1> ff;
|
std::array<size_t,sizeof...(SRanges)+1> ff;
|
||||||
for(size_t i = 0; i != sizeof...(SRanges)+1; ++i){
|
sfor_pn<0,sizeof...(SRanges)>
|
||||||
PackNum<sizeof...(SRanges)-1>::mkSliceBlocks(ff, ind, op);
|
( [&](auto i) {
|
||||||
}
|
std::get<i+1>(ff) =
|
||||||
|
op.rootSteps(reinterpret_cast<std::intptr_t>
|
||||||
|
( ind.template getPtr<i>().get())).val();
|
||||||
|
return 0; } );
|
||||||
out.format(ff);
|
out.format(ff);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +188,7 @@ namespace MultiArrayTools
|
||||||
return SliceDef<T,Ranges...>::mkSlice(ind, op);
|
return SliceDef<T,Ranges...>::mkSlice(ind, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
|
|
173
src/include/statics/static_for.h
Normal file
173
src/include/statics/static_for.h
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
|
||||||
|
#ifndef __cxz_static_for_h__
|
||||||
|
#define __cxz_static_for_h__
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
template <size_t BEG, size_t END, int OFF, typename Incr, typename F>
|
||||||
|
inline auto sfor(Incr incr, F f)
|
||||||
|
{
|
||||||
|
constexpr auto idx = std::integral_constant<size_t, BEG>{};
|
||||||
|
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||||
|
|
||||||
|
const bool cond = f(idxm);
|
||||||
|
if constexpr(incr(idx) != END){
|
||||||
|
if(cond){
|
||||||
|
sfor<incr(idx),END,OFF>(incr,f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cond;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Cond>
|
||||||
|
inline auto sforx(Incr incr, F f, Cond cond)
|
||||||
|
{
|
||||||
|
constexpr auto idx = std::integral_constant<size_t, BEG>{};
|
||||||
|
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||||
|
|
||||||
|
if constexpr(incr(idx) != END){
|
||||||
|
if(cond(idx)){
|
||||||
|
return sforx<incr(idx),END,OFF>(incr,f,cond);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return f(idxm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return f(idxm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Conc>
|
||||||
|
inline auto sfor(Incr incr, F f, Conc conc)
|
||||||
|
{
|
||||||
|
constexpr auto idx = std::integral_constant<size_t, BEG>{};
|
||||||
|
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||||
|
//static_assert(abs(idx.value - END) >= abs(incr(idx) - END),
|
||||||
|
// "this turns out to be a static endless loop");
|
||||||
|
auto tmp = f(idxm);
|
||||||
|
if constexpr(incr(idx) == END){
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return conc(tmp, sfor<incr(idx),END,OFF>(incr,f,conc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Conc, typename Arg>
|
||||||
|
inline auto sfor(Incr incr, F f, Conc conc, const Arg& arg)
|
||||||
|
{
|
||||||
|
constexpr auto idx = std::integral_constant<size_t, BEG>{};
|
||||||
|
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||||
|
//static_assert(abs(idx.value - END) >= abs(incr(idx) - END),
|
||||||
|
// "this turns out to be a static endless loop");
|
||||||
|
auto tmp = f(idxm);
|
||||||
|
if constexpr(incr(idx) == END){
|
||||||
|
return conc(tmp, arg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return conc(tmp, sfor<incr(idx),END,OFF>(incr,f,conc,arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, int OFF, typename Incr, typename F, typename Create, typename... Args>
|
||||||
|
inline auto unpack(Incr incr, F f, Create create, const Args&... args)
|
||||||
|
{
|
||||||
|
constexpr auto idx = std::integral_constant<size_t, BEG>{};
|
||||||
|
constexpr auto idxm = std::integral_constant<size_t, BEG+OFF>{};
|
||||||
|
//static_assert(abs(idx.value - END) >= abs(incr(idx) - END),
|
||||||
|
// "this turns out to be a static endless loop");
|
||||||
|
if constexpr(BEG == END){
|
||||||
|
return create(args...);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto tmp = f(idxm);
|
||||||
|
return unpack<incr(idx),END,OFF>(incr, f, create, args..., tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MA_INC [&](auto i) constexpr { return i+1; }
|
||||||
|
#define MA_DEC [&](auto i) constexpr { return i-1; }
|
||||||
|
#define MA_ZCONC [&](auto a, auto b) { return 0; }
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
template <size_t BEG, size_t END, typename F>
|
||||||
|
inline auto sfor_p(F f)
|
||||||
|
{
|
||||||
|
return sfor<BEG,END,0>(MA_INC,f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F>
|
||||||
|
inline auto sfor_m(F f)
|
||||||
|
{
|
||||||
|
return sfor<BEG,END,-1>(MA_DEC,f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Cond>
|
||||||
|
inline auto sforx_p(F f, Cond cond)
|
||||||
|
{
|
||||||
|
return sforx<BEG,END,0>(MA_INC,f,cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Cond>
|
||||||
|
inline auto sforx_m(F f, Cond cond)
|
||||||
|
{
|
||||||
|
return sforx<BEG,END,-1>(MA_DEC,f,cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Conc>
|
||||||
|
inline auto sfor_p(F f, Conc conc)
|
||||||
|
{
|
||||||
|
return sfor<BEG,END,0>(MA_INC,f,conc);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F>
|
||||||
|
inline auto sfor_pn(F f)
|
||||||
|
{
|
||||||
|
return sfor_p<BEG,END>(f,MA_ZCONC);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Conc>
|
||||||
|
inline auto sfor_m(F f, Conc conc)
|
||||||
|
{
|
||||||
|
return sfor<BEG,END,-1>(MA_DEC,f,conc);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F>
|
||||||
|
inline auto sfor_mn(F f)
|
||||||
|
{
|
||||||
|
return sfor_m<BEG,END>(f,MA_ZCONC);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Conc, typename Arg>
|
||||||
|
inline auto sfor_p(F f, Conc conc, const Arg& arg)
|
||||||
|
{
|
||||||
|
return sfor<BEG,END,0>(MA_INC,f,conc,arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Arg>
|
||||||
|
inline auto sfor_pn(F f, const Arg& arg)
|
||||||
|
{
|
||||||
|
return sfor_p<BEG,END>(f,MA_ZCONC,arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Conc, typename Arg>
|
||||||
|
inline auto sfor_m(F f, Conc conc, const Arg& arg)
|
||||||
|
{
|
||||||
|
return sfor<BEG,END,-1>(MA_DEC,f,conc,arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t BEG, size_t END, typename F, typename Arg>
|
||||||
|
inline auto sfor_mn(F f, const Arg& arg)
|
||||||
|
{
|
||||||
|
return sfor_m<BEG,END>(f,MA_ZCONC,arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
26
src/include/statics/traits.h
Normal file
26
src/include/statics/traits.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
#include "base_def.h"
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct IsArray
|
||||||
|
{
|
||||||
|
static constexpr bool VALUE = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define add_array_trait(name) template <typename... X> struct IsArray<##name<X...>> { \
|
||||||
|
static constexpr bool VALUE = true; \
|
||||||
|
}
|
||||||
|
|
||||||
|
add_array_trait(ArrayBase);
|
||||||
|
add_array_trait(MutableArrayBase);
|
||||||
|
add_array_trait(Array);
|
||||||
|
add_array_trait(FunctionalArray);
|
||||||
|
add_array_trait(Slice);
|
||||||
|
add_array_trait(ConstSlice);
|
||||||
|
|
||||||
|
#undef add_array_trait
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __type_operations_h__
|
#ifndef __cxz_type_operations_h__
|
||||||
#define __type_operations_h__
|
#define __cxz_type_operations_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -9,16 +9,18 @@
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "mbase_def.h"
|
#include "mbase_def.h"
|
||||||
|
|
||||||
#include "pack_num.h"
|
#include "statics/static_for.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
#include <cmath>
|
||||||
|
|
||||||
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MultiArray
|
// Array
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class operate
|
class operate
|
||||||
|
@ -28,10 +30,13 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
operate(const std::shared_ptr<typename Ranges::IndexType>&... inds) : ituple(inds...) {}
|
operate(const std::shared_ptr<typename Ranges::IndexType>&... inds) : ituple(inds...) {}
|
||||||
|
|
||||||
inline auto apply(const MultiArray<T,Ranges...>& ma)
|
inline auto apply(const Array<T,Ranges...>& ma)
|
||||||
-> OperationRoot<T,Ranges...>
|
-> OperationRoot<T,Ranges...>
|
||||||
{
|
{
|
||||||
return PackNum<sizeof...(Ranges)-1>::mkElemOperation(ma, ituple);
|
return unpack<0,sizeof...(Ranges),0>
|
||||||
|
( [&](auto i) constexpr { return i+1; },
|
||||||
|
[&](auto i){ return std::get<i>(ituple); },
|
||||||
|
[&](auto... args) { return ma(args...); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -41,9 +46,9 @@ namespace MultiArrayTools
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class OperationClass, typename T, class... Ranges>
|
template <class OperationClass, typename T, class... Ranges>
|
||||||
class OperationTemplate<MultiArray<T,Ranges...>,OperationClass> : public OperationBase<MultiArray<T,Ranges...>,OperationClass>
|
class OperationTemplate<Array<T,Ranges...>,OperationClass> : public OperationBase<Array<T,Ranges...>,OperationClass>
|
||||||
{
|
{
|
||||||
typedef OperationBase<MultiArray<T,Ranges...>,OperationClass> OB;
|
typedef OperationBase<Array<T,Ranges...>,OperationClass> OB;
|
||||||
|
|
||||||
auto operator()(const std::shared_ptr<typename Ranges::IndexType>&... indices)
|
auto operator()(const std::shared_ptr<typename Ranges::IndexType>&... indices)
|
||||||
-> Operation<OperationRoot<T,Ranges...>,operate<T,Ranges...>,OperationClass>
|
-> Operation<OperationRoot<T,Ranges...>,operate<T,Ranges...>,OperationClass>
|
||||||
|
@ -470,7 +475,49 @@ namespace MultiArrayTools
|
||||||
xsdiv<4>( o._x, a._x );
|
xsdiv<4>( o._x, a._x );
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
inline double xpow(const double& b, const double& e)
|
||||||
|
{
|
||||||
|
return pow(b,e);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline v256 pow(const v256& b, const v256& e)
|
||||||
|
{
|
||||||
|
v256 out;
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
out._x[i] = xpow(b._x[i],e._x[i]);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double xexp(const double& a)
|
||||||
|
{
|
||||||
|
return exp(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline v256 exp(const v256& a)
|
||||||
|
{
|
||||||
|
v256 out;
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
out._x[i] = xexp(a._x[i]);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline double xsqrt(const double& a)
|
||||||
|
{
|
||||||
|
return sqrt(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline v256 sqrt(const v256& a)
|
||||||
|
{
|
||||||
|
v256 out;
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
out._x[i] = xsqrt(a._x[i]);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CNORXZ
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,48 +1,96 @@
|
||||||
|
|
||||||
#ifndef __exttype_h__
|
#ifndef __cxz_exttype_h__
|
||||||
#define __exttype_h__
|
#define __cxz_exttype_h__
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
|
|
||||||
template <size_t I>
|
|
||||||
struct Getter
|
|
||||||
{
|
|
||||||
template <class ExtType>
|
|
||||||
static inline size_t get(const ExtType& et)
|
|
||||||
{
|
|
||||||
return Getter<I-1>::get(et.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
static inline auto getX(const ExtType& et)
|
|
||||||
-> decltype(Getter<I-1>::getX(et.next()))
|
|
||||||
{
|
|
||||||
return Getter<I-1>::getX(et.next());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct Getter<0>
|
|
||||||
{
|
|
||||||
template <class ExtType>
|
|
||||||
static inline size_t get(const ExtType& et)
|
|
||||||
{
|
|
||||||
return et.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
static inline auto getX(const ExtType& et)
|
|
||||||
-> ExtType
|
|
||||||
{
|
|
||||||
return et;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct None;
|
struct None;
|
||||||
|
|
||||||
|
class ExtBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExtBase() = default;
|
||||||
|
ExtBase(const ExtBase& in) = default;
|
||||||
|
ExtBase(ExtBase&& in) = default;
|
||||||
|
ExtBase& operator=(const ExtBase& in) = default;
|
||||||
|
ExtBase& operator=(ExtBase&& in) = default;
|
||||||
|
|
||||||
|
virtual size_t size() const = 0;
|
||||||
|
virtual const size_t& val() const = 0;
|
||||||
|
//virtual size_t rootSteps() const = 0;
|
||||||
|
virtual bool operator==(const ExtBase& in) const = 0;
|
||||||
|
virtual bool operator==(size_t in) const = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0;
|
||||||
|
virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0;
|
||||||
|
virtual void zero() = 0;
|
||||||
|
|
||||||
|
virtual std::shared_ptr<ExtBase> deepCopy() const = 0;
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
const ExtType& expl() const;
|
||||||
|
|
||||||
|
virtual std::string stype() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::shared_ptr<ExtBase> DExt;
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
class ExtT : public ExtBase
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
ExtType mExt;
|
||||||
|
public:
|
||||||
|
static constexpr size_t SIZE = ExtType::SIZE;
|
||||||
|
static constexpr size_t NUM = ExtType::NUM;
|
||||||
|
|
||||||
|
ExtT() = default;
|
||||||
|
ExtT(const ExtT& in) = default;
|
||||||
|
ExtT(ExtT&& in) = default;
|
||||||
|
ExtT& operator=(const ExtT& in) = default;
|
||||||
|
ExtT& operator=(ExtT&& in) = default;
|
||||||
|
|
||||||
|
ExtT(const ExtType& in) : mExt(in) {}
|
||||||
|
|
||||||
|
virtual std::shared_ptr<ExtBase> deepCopy() const override final { return std::make_shared<ExtT<ExtType>>(mExt); }
|
||||||
|
|
||||||
|
virtual size_t size() const override final { return sizeof(ExtType)/sizeof(size_t); }
|
||||||
|
//virtual size_t size() const override final { return ExtType::MExtSize(); }
|
||||||
|
//virtual size_t rootSteps() const override final;
|
||||||
|
const ExtType& ext() const { return mExt; }
|
||||||
|
virtual const size_t& val() const override final { return mExt.val(); }
|
||||||
|
virtual void zero() override final { mExt.zero(); }
|
||||||
|
|
||||||
|
virtual bool operator==(const ExtBase& in) const override final
|
||||||
|
{ return mExt == dynamic_cast<const ExtT<ExtType>&>(in).mExt; }
|
||||||
|
|
||||||
|
virtual bool operator==(size_t in) const override final
|
||||||
|
{ return mExt == in; }
|
||||||
|
|
||||||
|
virtual DExt operator+(const ExtBase& in) const override final
|
||||||
|
{ return std::make_shared<ExtT<ExtType>>( mExt + dynamic_cast<const ExtT<ExtType>&>(in).mExt ); }
|
||||||
|
virtual DExt operator*(size_t in) const override final
|
||||||
|
{ return std::make_shared<ExtT<ExtType>>( mExt * in ); }
|
||||||
|
|
||||||
|
virtual std::string stype() const override final { return std::string("T[") + mExt.stype() + "]"; }
|
||||||
|
};
|
||||||
|
//class DExtT;
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
DExt mkDExt(const ExtT<ExtType>& in)
|
||||||
|
{
|
||||||
|
return std::make_shared<ExtT<ExtType>>(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
ExtT<ExtType> mkExtT(const ExtType& in)
|
||||||
|
{
|
||||||
|
return ExtT<ExtType>(in);
|
||||||
|
}
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
class MExt
|
class MExt
|
||||||
{
|
{
|
||||||
|
@ -82,10 +130,18 @@ namespace MultiArrayHelper
|
||||||
inline const X& next() const;
|
inline const X& next() const;
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
inline auto nn() const
|
inline auto nn() const;
|
||||||
-> decltype(Getter<N>::getX(*this))
|
|
||||||
{ return Getter<N>::getX(*this); }
|
inline bool operator==(const MExt& in) const
|
||||||
|
{
|
||||||
|
return mExt == in.mExt and mNext == in.mNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(size_t in) const
|
||||||
|
{
|
||||||
|
return mExt == in and mNext == in;
|
||||||
|
}
|
||||||
|
|
||||||
inline MExt operator+(const MExt& in) const;
|
inline MExt operator+(const MExt& in) const;
|
||||||
inline MExt operator+(const None& in) const;
|
inline MExt operator+(const None& in) const;
|
||||||
inline MExt operator*(size_t in) const;
|
inline MExt operator*(size_t in) const;
|
||||||
|
@ -110,7 +166,17 @@ namespace MultiArrayHelper
|
||||||
None(const Y& y) {}
|
None(const Y& y) {}
|
||||||
|
|
||||||
static constexpr size_t SIZE = 0;
|
static constexpr size_t SIZE = 0;
|
||||||
|
|
||||||
|
inline bool operator==(const None& in) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(size_t in) const
|
||||||
|
{
|
||||||
|
return true; // CHECK!!!
|
||||||
|
}
|
||||||
|
|
||||||
inline None operator+(const None& in) const { return None(); }
|
inline None operator+(const None& in) const { return None(); }
|
||||||
inline None operator*(size_t in) const { return None(); }
|
inline None operator*(size_t in) const { return None(); }
|
||||||
|
|
||||||
|
@ -157,16 +223,24 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
template <class Y>
|
template <class Y>
|
||||||
inline MExt(const MExt<Y>& y);
|
inline MExt(const MExt<Y>& y);
|
||||||
|
|
||||||
|
inline bool operator==(const MExt& in) const
|
||||||
|
{
|
||||||
|
return mExt == in.mExt;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator==(size_t in) const
|
||||||
|
{
|
||||||
|
return mExt == in;
|
||||||
|
}
|
||||||
|
|
||||||
inline const size_t& val() const;
|
inline const size_t& val() const;
|
||||||
inline None next() const { return None(); }
|
inline None next() const { return None(); }
|
||||||
|
|
||||||
inline void zero();
|
inline void zero();
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
inline auto nn() const
|
inline auto nn() const;
|
||||||
-> decltype(Getter<N>::getX(*this))
|
|
||||||
{ return Getter<N>::getX(*this); }
|
|
||||||
|
|
||||||
inline MExt operator+(const MExt& in) const;
|
inline MExt operator+(const MExt& in) const;
|
||||||
inline MExt operator+(const None& in) const;
|
inline MExt operator+(const None& in) const;
|
||||||
|
@ -180,15 +254,134 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
class DExtTX
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
mutable DExt mDExt;
|
||||||
|
X mNext;
|
||||||
|
|
||||||
|
template <class Y>
|
||||||
|
friend class DExtTX;
|
||||||
|
public:
|
||||||
|
static constexpr size_t NUM = X::SIZE;
|
||||||
|
static constexpr size_t SIZE = NUM + 1;
|
||||||
|
|
||||||
|
DExtTX() { mDExt = std::make_shared<ExtT<None>>(); }
|
||||||
|
DExtTX(const DExtTX& in) : mNext(in.mNext)
|
||||||
|
{ mDExt = in.mDExt->deepCopy(); }
|
||||||
|
DExtTX(DExtTX&& in) : mNext(in.mNext)
|
||||||
|
{ mDExt = in.mDExt->deepCopy(); }
|
||||||
|
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
|
||||||
|
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
|
||||||
|
explicit DExtTX(const DExt& in) : mDExt(in) {}
|
||||||
|
/*
|
||||||
|
template <class Y>
|
||||||
|
DExtTX& operator=(const Y& y) { mDExt = std::make_shared<ExtT<Y>>(y); return *this; }
|
||||||
|
|
||||||
|
template <class Y>
|
||||||
|
DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {}
|
||||||
|
*/
|
||||||
|
bool operator==(const DExtTX& in) const
|
||||||
|
{ return *mDExt == *in.mDExt and mNext == in.mNext; }
|
||||||
|
|
||||||
|
bool operator==(size_t in) const
|
||||||
|
{ return *mDExt == in and mNext == in; }
|
||||||
|
|
||||||
|
template <class Y>
|
||||||
|
DExtTX(const DExtTX<Y>& in) : mDExt(in.mDExt), mNext(in.mNext) {}
|
||||||
|
|
||||||
|
DExtTX(const DExt& y, const X& x) : mDExt(y->deepCopy()),
|
||||||
|
mNext(x) {}
|
||||||
|
|
||||||
|
virtual size_t size() const { return mDExt->size(); }
|
||||||
|
inline const DExt& get() const { return mDExt; }
|
||||||
|
|
||||||
|
inline DExtTX<None> reduce() const { return DExtTX<None>(mDExt,None(0)); }
|
||||||
|
|
||||||
|
inline DExtTX operator+(const DExtTX& in) const
|
||||||
|
{ if (not mDExt) return in; else return DExtTX( (*mDExt) + (*in.mDExt), mNext + in.mNext ); }
|
||||||
|
inline DExtTX operator*(size_t in) const
|
||||||
|
{ if (not mDExt) return *this; else return DExtTX((*mDExt) * in, mNext * in); }
|
||||||
|
|
||||||
|
template <class ExtType>
|
||||||
|
inline const ExtType& expl() const
|
||||||
|
{ if(mDExt == nullptr) mDExt = std::make_shared<ExtT<ExtType>>(); assert(mDExt != nullptr); return mDExt->expl<ExtType>(); }
|
||||||
|
|
||||||
|
template <class Y>
|
||||||
|
inline auto extend(const Y& y) const -> DExtTX<decltype(mNext.extend(y))>
|
||||||
|
{ return DExtTX<decltype(mNext.extend(y))>(mDExt, mNext.extend(y)); }
|
||||||
|
|
||||||
|
inline const size_t& val() const { return mDExt->val(); }
|
||||||
|
inline const X& next() const { return mNext; }
|
||||||
|
|
||||||
|
inline void zero() { mDExt->zero(); }
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
inline auto nn() const;
|
||||||
|
|
||||||
|
std::string stype() const { return std::string("D[") + mDExt->stype() + "," + mNext.stype() + "]"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef DExtTX<None> DExtT;
|
||||||
|
|
||||||
|
inline MExt<None> mkExt(size_t s) { return MExt<None>(s); }
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
template <size_t I, class X>
|
||||||
|
auto getX(const MExt<X>& et)
|
||||||
|
{
|
||||||
|
if constexpr(I == 0){
|
||||||
|
return et;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getX<I-1>(et.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I, class X>
|
||||||
|
auto getX(const DExtTX<X>& et)
|
||||||
|
{
|
||||||
|
if constexpr(I == 0){
|
||||||
|
return et;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getX<I-1>(et.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
auto getX(const None& et)
|
||||||
|
{
|
||||||
|
static_assert(I == 0);
|
||||||
|
return et;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I, class X>
|
||||||
|
size_t get(const MExt<X>& et)
|
||||||
|
{
|
||||||
|
return getX<I>(et).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I, class X>
|
||||||
|
size_t get(const DExtTX<X>& et)
|
||||||
|
{
|
||||||
|
return getX<I>(et).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t I>
|
||||||
|
size_t get(const None& et)
|
||||||
|
{
|
||||||
|
return getX<I>(et).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace CNORXZInternal
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
* ========================= */
|
* ========================= */
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
|
@ -233,6 +426,13 @@ namespace MultiArrayHelper
|
||||||
mNext.zero();
|
mNext.zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
template <size_t N>
|
||||||
|
inline auto MExt<X>::nn() const
|
||||||
|
{
|
||||||
|
return getX<N>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
template <class X>
|
template <class X>
|
||||||
inline MExt<X> MExt<X>::operator+(const MExt<X>& in) const
|
inline MExt<X> MExt<X>::operator+(const MExt<X>& in) const
|
||||||
{
|
{
|
||||||
|
@ -282,6 +482,12 @@ namespace MultiArrayHelper
|
||||||
mExt = 0u;
|
mExt = 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
inline auto MExt<None>::nn() const
|
||||||
|
{
|
||||||
|
return getX<N>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
inline const size_t& MExt<None>::val() const
|
inline const size_t& MExt<None>::val() const
|
||||||
{
|
{
|
||||||
return mExt;
|
return mExt;
|
||||||
|
@ -304,8 +510,14 @@ namespace MultiArrayHelper
|
||||||
return MExt<None>(mExt * in);
|
return MExt<None>(mExt * in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class X>
|
||||||
|
template <size_t N>
|
||||||
|
inline auto DExtTX<X>::nn() const
|
||||||
|
{
|
||||||
|
return getX<N>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
} // end namespace CNORXZInternal
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
#ifndef __for_type_h__
|
#ifndef __cxz_for_type_h__
|
||||||
#define __for_type_h__
|
#define __cxz_for_type_h__
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class ForType {
|
enum class ForType {
|
||||||
|
@ -10,11 +10,14 @@ namespace MultiArrayHelper
|
||||||
HIDDEN = 1
|
HIDDEN = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT = ForType::DEFAULT>
|
template <class IndexClass, class Expr, ForType FT = ForType::DEFAULT, size_t DIV = 1>
|
||||||
class For;
|
class For;
|
||||||
|
|
||||||
|
template <class IndexClass, class Expr, size_t DIV = 1>
|
||||||
|
class PFor;
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
} // end namespace CNORXZInternal
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
#ifndef __for_utils_h__
|
#ifndef __cxz_for_utils_h__
|
||||||
#define __for_utils_h__
|
#define __cxz_for_utils_h__
|
||||||
|
|
||||||
//#include "ranges/rheader.h"
|
//#include "ranges/rheader.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
namespace {
|
namespace {
|
||||||
template <class Op>
|
template <class Op>
|
||||||
|
@ -34,6 +34,6 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace MultiArrayHelper
|
} // end namespace CNORXZInternal
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __ma_iloop_h__
|
#ifndef __cxz_iloop_h__
|
||||||
#define __ma_iloop_h__
|
#define __cxz_iloop_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#include "xfor.h"
|
#include "xfor.h"
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct NN
|
struct NN
|
||||||
|
@ -116,6 +116,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//static constexpr size_t SIZE = NN<LTpSize-1>::lsize(std::declval<LTp>());
|
//static constexpr size_t SIZE = NN<LTpSize-1>::lsize(std::declval<LTp>());
|
||||||
|
static constexpr size_t NHLAYER = 10; // some large value
|
||||||
static constexpr size_t SIZE = NN<LTpSize-1>::template LSIZE<LTp>();
|
static constexpr size_t SIZE = NN<LTpSize-1>::template LSIZE<LTp>();
|
||||||
static constexpr bool CONT = false;
|
static constexpr bool CONT = false;
|
||||||
typedef decltype(NN<LTpSize-1>::rootSteps(mLTp)) ExtType;
|
typedef decltype(NN<LTpSize-1>::rootSteps(mLTp)) ExtType;
|
||||||
|
@ -248,6 +249,8 @@ namespace MultiArrayHelper
|
||||||
static constexpr size_t VarTpSize = LType::VarTpSize;
|
static constexpr size_t VarTpSize = LType::VarTpSize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static constexpr size_t NHLAYER = 10; // some large value
|
||||||
static constexpr size_t SIZE = LType::SIZE;
|
static constexpr size_t SIZE = LType::SIZE;
|
||||||
static constexpr bool CONT = LType::CONT;
|
static constexpr bool CONT = LType::CONT;
|
||||||
typedef typename LType::ExtType ExtType;
|
typedef typename LType::ExtType ExtType;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
#ifndef __xfor_h__
|
#ifndef __cxz_xfor_h__
|
||||||
#define __xfor_h__
|
#define __cxz_xfor_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -15,155 +15,15 @@
|
||||||
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
|
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
|
||||||
<< " in " << __func__ << ": " << #a << " = " << a << std::endl;
|
<< " in " << __func__ << ": " << #a << " = " << a << std::endl;
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
using namespace MultiArrayTools;
|
using namespace CNORXZ;
|
||||||
// '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 !!!!!)
|
||||||
|
|
||||||
//typedef std::pair<size_t const*,size_t> DExt;
|
//typedef std::pair<size_t const*,size_t> DExt;
|
||||||
|
|
||||||
class ExtBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ExtBase() = default;
|
|
||||||
ExtBase(const ExtBase& in) = default;
|
|
||||||
ExtBase(ExtBase&& in) = default;
|
|
||||||
ExtBase& operator=(const ExtBase& in) = default;
|
|
||||||
ExtBase& operator=(ExtBase&& in) = default;
|
|
||||||
|
|
||||||
virtual size_t size() const = 0;
|
|
||||||
virtual const size_t& val() const = 0;
|
|
||||||
//virtual size_t rootSteps() const = 0;
|
|
||||||
virtual std::shared_ptr<ExtBase> operator+(const ExtBase& in) const = 0;
|
|
||||||
virtual std::shared_ptr<ExtBase> operator*(size_t in) const = 0;
|
|
||||||
virtual void zero() = 0;
|
|
||||||
|
|
||||||
virtual std::shared_ptr<ExtBase> deepCopy() const = 0;
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
const ExtType& expl() const;
|
|
||||||
|
|
||||||
virtual std::string stype() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::shared_ptr<ExtBase> DExt;
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
class ExtT : public ExtBase
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
ExtType mExt;
|
|
||||||
public:
|
|
||||||
static constexpr size_t SIZE = ExtType::SIZE;
|
|
||||||
static constexpr size_t NUM = ExtType::NUM;
|
|
||||||
|
|
||||||
ExtT() = default;
|
|
||||||
ExtT(const ExtT& in) = default;
|
|
||||||
ExtT(ExtT&& in) = default;
|
|
||||||
ExtT& operator=(const ExtT& in) = default;
|
|
||||||
ExtT& operator=(ExtT&& in) = default;
|
|
||||||
|
|
||||||
ExtT(const ExtType& in) : mExt(in) {}
|
|
||||||
|
|
||||||
virtual std::shared_ptr<ExtBase> deepCopy() const override final { return std::make_shared<ExtT<ExtType>>(mExt); }
|
|
||||||
|
|
||||||
virtual size_t size() const override final { return sizeof(ExtType)/sizeof(size_t); }
|
|
||||||
//virtual size_t size() const override final { return ExtType::MExtSize(); }
|
|
||||||
//virtual size_t rootSteps() const override final;
|
|
||||||
const ExtType& ext() const { return mExt; }
|
|
||||||
virtual const size_t& val() const override final { return mExt.val(); }
|
|
||||||
virtual void zero() override final { mExt.zero(); }
|
|
||||||
|
|
||||||
virtual DExt operator+(const ExtBase& in) const override final
|
|
||||||
{ return std::make_shared<ExtT<ExtType>>( mExt + dynamic_cast<const ExtT<ExtType>&>(in).mExt ); }
|
|
||||||
virtual DExt operator*(size_t in) const override final
|
|
||||||
{ return std::make_shared<ExtT<ExtType>>( mExt * in ); }
|
|
||||||
|
|
||||||
virtual std::string stype() const override final { return std::string("T[") + mExt.stype() + "]"; }
|
|
||||||
};
|
|
||||||
//class DExtT;
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
DExt mkDExt(const ExtT<ExtType>& in)
|
|
||||||
{
|
|
||||||
return std::make_shared<ExtT<ExtType>>(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
ExtT<ExtType> mkExtT(const ExtType& in)
|
|
||||||
{
|
|
||||||
return ExtT<ExtType>(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class X>
|
|
||||||
class DExtTX
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
mutable DExt mDExt = nullptr;
|
|
||||||
X mNext;
|
|
||||||
|
|
||||||
template <class Y>
|
|
||||||
friend class DExtTX;
|
|
||||||
public:
|
|
||||||
static constexpr size_t NUM = X::SIZE;
|
|
||||||
static constexpr size_t SIZE = NUM + 1;
|
|
||||||
|
|
||||||
DExtTX() { mDExt = std::make_shared<ExtT<None>>(); }
|
|
||||||
DExtTX(const DExtTX& in) : mNext(in.mNext)
|
|
||||||
{ mDExt = in.mDExt->deepCopy(); }
|
|
||||||
DExtTX(DExtTX&& in) : mNext(in.mNext)
|
|
||||||
{ mDExt = in.mDExt->deepCopy(); }
|
|
||||||
DExtTX& operator=(const DExtTX& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
|
|
||||||
DExtTX& operator=(DExtTX&& in) { mNext = in.mNext; mDExt = in.mDExt->deepCopy(); return *this; }
|
|
||||||
explicit DExtTX(const DExt& in) : mDExt(in) {}
|
|
||||||
/*
|
|
||||||
template <class Y>
|
|
||||||
DExtTX& operator=(const Y& y) { mDExt = std::make_shared<ExtT<Y>>(y); return *this; }
|
|
||||||
|
|
||||||
template <class Y>
|
|
||||||
DExtTX(const Y& y) : mDExt(std::make_shared<ExtT<Y>>(y)) {}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <class Y>
|
|
||||||
DExtTX(const DExtTX<Y>& in) : mDExt(in.mDExt), mNext(in.mNext) {}
|
|
||||||
|
|
||||||
DExtTX(const DExt& y, const X& x) : mDExt(y->deepCopy()),
|
|
||||||
mNext(x) {}
|
|
||||||
|
|
||||||
virtual size_t size() const { return mDExt->size(); }
|
|
||||||
inline const DExt& get() const { return mDExt; }
|
|
||||||
|
|
||||||
inline DExtTX<None> reduce() const { return DExtTX<None>(mDExt,None(0)); }
|
|
||||||
|
|
||||||
inline DExtTX operator+(const DExtTX& in) const
|
|
||||||
{ if (not mDExt) return in; else return DExtTX( (*mDExt) + (*in.mDExt), mNext + in.mNext ); }
|
|
||||||
inline DExtTX operator*(size_t in) const
|
|
||||||
{ if (not mDExt) return *this; else return DExtTX((*mDExt) * in, mNext * in); }
|
|
||||||
|
|
||||||
template <class ExtType>
|
|
||||||
inline const ExtType& expl() const
|
|
||||||
{ if(mDExt == nullptr) mDExt = std::make_shared<ExtT<ExtType>>(); assert(mDExt != nullptr); return mDExt->expl<ExtType>(); }
|
|
||||||
|
|
||||||
template <class Y>
|
|
||||||
inline auto extend(const Y& y) const -> DExtTX<decltype(mNext.extend(y))>
|
|
||||||
{ return DExtTX<decltype(mNext.extend(y))>(mDExt, mNext.extend(y)); }
|
|
||||||
|
|
||||||
inline const size_t& val() const { return mDExt->val(); }
|
|
||||||
inline const X& next() const { return mNext; }
|
|
||||||
|
|
||||||
inline void zero() { mDExt->zero(); }
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
inline auto nn() const -> decltype(Getter<N>::getX(*this))
|
|
||||||
{ return Getter<N>::getX(*this); }
|
|
||||||
|
|
||||||
std::string stype() const { return std::string("D[") + mDExt->stype() + "," + mNext.stype() + "]"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef DExtTX<None> DExtT;
|
|
||||||
|
|
||||||
inline MExt<None> mkExt(size_t s) { return MExt<None>(s); }
|
|
||||||
|
|
||||||
class ExpressionBase
|
class ExpressionBase
|
||||||
{
|
{
|
||||||
|
@ -175,6 +35,9 @@ namespace MultiArrayHelper
|
||||||
ExpressionBase& operator=(const ExpressionBase& in) = default;
|
ExpressionBase& operator=(const ExpressionBase& in) = default;
|
||||||
ExpressionBase& operator=(ExpressionBase&& in) = default;
|
ExpressionBase& operator=(ExpressionBase&& in) = default;
|
||||||
|
|
||||||
|
//virtual size_t divResid() const { return 1; }
|
||||||
|
virtual std::intptr_t vI() const { return 0; }
|
||||||
|
|
||||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const = 0;
|
virtual std::shared_ptr<ExpressionBase> deepCopy() const = 0;
|
||||||
|
|
||||||
virtual void operator()(size_t mlast, DExt last) = 0;
|
virtual void operator()(size_t mlast, DExt last) = 0;
|
||||||
|
@ -217,20 +80,20 @@ namespace MultiArrayHelper
|
||||||
template <size_t ISSTATIC>
|
template <size_t ISSTATIC>
|
||||||
struct ForBound
|
struct ForBound
|
||||||
{
|
{
|
||||||
template <size_t BOUND>
|
template <size_t BOUND, size_t DIV = 1>
|
||||||
static inline size_t bound(size_t bound)
|
static inline size_t bound(size_t bound)
|
||||||
{
|
{
|
||||||
return bound;
|
return bound / DIV;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct ForBound<1>
|
struct ForBound<1>
|
||||||
{
|
{
|
||||||
template <size_t BOUND>
|
template <size_t BOUND, size_t DIV = 1>
|
||||||
static constexpr size_t bound(size_t bound)
|
static constexpr size_t bound(size_t bound)
|
||||||
{
|
{
|
||||||
return BOUND;
|
return BOUND / DIV;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -256,6 +119,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static constexpr size_t SIZE = Expr::SIZE;
|
static constexpr size_t SIZE = Expr::SIZE;
|
||||||
|
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||||
|
|
||||||
SingleExpression(const SingleExpression& in) = default;
|
SingleExpression(const SingleExpression& in) = default;
|
||||||
SingleExpression& operator=(const SingleExpression& in) = default;
|
SingleExpression& operator=(const SingleExpression& in) = default;
|
||||||
|
@ -273,6 +137,9 @@ namespace MultiArrayHelper
|
||||||
return std::make_shared<SingleExpression<IndexClass,Expr>>(*this);
|
return std::make_shared<SingleExpression<IndexClass,Expr>>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t VS>
|
||||||
|
inline auto vec() const { return *this; }
|
||||||
|
|
||||||
inline void operator()(size_t mlast, DExt last) override final;
|
inline void operator()(size_t mlast, DExt last) override final;
|
||||||
inline void operator()(size_t mlast, ExtType last);
|
inline void operator()(size_t mlast, ExtType last);
|
||||||
inline void operator()(size_t mlast = 0) override final;
|
inline void operator()(size_t mlast = 0) override final;
|
||||||
|
@ -308,6 +175,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static constexpr size_t SIZE = Expr::SIZE + 1;
|
static constexpr size_t SIZE = Expr::SIZE + 1;
|
||||||
|
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||||
|
|
||||||
SubExpr(const SubExpr& in) = default;
|
SubExpr(const SubExpr& in) = default;
|
||||||
SubExpr& operator=(const SubExpr& in) = default;
|
SubExpr& operator=(const SubExpr& in) = default;
|
||||||
|
@ -326,6 +194,9 @@ namespace MultiArrayHelper
|
||||||
return std::make_shared<SubExpr<IndexClass,Expr>>(*this);
|
return std::make_shared<SubExpr<IndexClass,Expr>>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t VS>
|
||||||
|
inline auto vec() const { return *this; }
|
||||||
|
|
||||||
inline void operator()(size_t mlast, DExt last) override final;
|
inline void operator()(size_t mlast, DExt last) override final;
|
||||||
inline void operator()(size_t mlast, ExtType last) ;
|
inline void operator()(size_t mlast, ExtType last) ;
|
||||||
inline void operator()(size_t mlast = 0) override final;
|
inline void operator()(size_t mlast = 0) override final;
|
||||||
|
@ -337,15 +208,95 @@ namespace MultiArrayHelper
|
||||||
auto extension() const -> ExtType;
|
auto extension() const -> ExtType;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <size_t LAYER, bool ISV>
|
||||||
class PFor;
|
struct MkVFor
|
||||||
|
{
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <size_t DIV, class IndexClass, class Expr>
|
||||||
|
using ptype = PFor<IndexClass,Expr,1>;
|
||||||
|
|
||||||
|
template <size_t DIV, class IndexClass, class Expr, ForType FT>
|
||||||
|
using type = For<IndexClass,Expr,FT,1>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct MkVFor<1,true>
|
||||||
|
{
|
||||||
|
template <size_t DIV, class IndexClass, class Expr>
|
||||||
|
using ptype = PFor<IndexClass,Expr,DIV>;
|
||||||
|
|
||||||
|
template <size_t DIV, class IndexClass, class Expr, ForType FT>
|
||||||
|
using type = For<IndexClass,Expr,FT,DIV>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <size_t LAYER>
|
||||||
|
struct MkVExpr
|
||||||
|
{
|
||||||
|
template <size_t VS, class Expr>
|
||||||
|
static auto mk(const Expr& e)
|
||||||
|
{
|
||||||
|
return e.template vec<VS>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Expr>
|
||||||
|
static inline size_t divResid(const Expr& e)
|
||||||
|
{
|
||||||
|
return e.divResid();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct MkVExpr<1>
|
||||||
|
{
|
||||||
|
template <size_t VS, class Expr>
|
||||||
|
static auto mk(const Expr& e)
|
||||||
|
{
|
||||||
|
return e; // terminate
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class Expr>
|
||||||
|
static inline size_t divResid(const Expr& e)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <ForType FT, size_t LAYER>
|
||||||
|
struct NHLayer
|
||||||
|
{
|
||||||
|
template <class Expr>
|
||||||
|
static constexpr size_t get()
|
||||||
|
{
|
||||||
|
return Expr::NHLAYER + 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <size_t LAYER>
|
||||||
|
struct NHLayer<ForType::HIDDEN,LAYER>
|
||||||
|
{
|
||||||
|
template <class Expr>
|
||||||
|
static constexpr size_t get()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct NHLayer<ForType::DEFAULT,1>
|
||||||
|
{
|
||||||
|
template <class Expr>
|
||||||
|
static constexpr size_t get()
|
||||||
|
{
|
||||||
|
return Expr::LAYER;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
class For : public ExpressionBase
|
class For : public ExpressionBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
For() = default;
|
For() = default;
|
||||||
|
|
||||||
|
typedef typename IndexClass::RangeType RangeType;
|
||||||
const IndexClass* mIndPtr;
|
const IndexClass* mIndPtr;
|
||||||
size_t mSPos;
|
size_t mSPos;
|
||||||
size_t mMax;
|
size_t mMax;
|
||||||
|
@ -359,10 +310,12 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef ExpressionBase EB;
|
typedef ExpressionBase EB;
|
||||||
|
|
||||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static constexpr size_t SIZE = Expr::SIZE;
|
static constexpr size_t SIZE = Expr::SIZE;
|
||||||
|
static constexpr size_t MAX = RangeType::SIZE / DIV;
|
||||||
|
static constexpr size_t NHLAYER = (FT == ForType::HIDDEN) ? 0 : Expr::NHLAYER + 1;
|
||||||
|
|
||||||
For(const For& in) = default;
|
For(const For& in) = default;
|
||||||
For& operator=(const For& in) = default;
|
For& operator=(const For& in) = default;
|
||||||
For(For&& in) = default;
|
For(For&& in) = default;
|
||||||
|
@ -376,14 +329,35 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||||
{
|
{
|
||||||
return std::make_shared<For<IndexClass,Expr,FT>>(*this);
|
return std::make_shared<For<IndexClass,Expr,FT,DIV>>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//virtual size_t divResid() const override final { return mMax % DIV + MkVExpr<LAYER>::divResid(mExpr); }
|
||||||
|
|
||||||
|
virtual std::intptr_t vI() const override final
|
||||||
|
{
|
||||||
|
if(mStep == 1 and NHLAYER == 1 and mMax % DIV == 0){
|
||||||
|
//if(mStep == 1 and mMax % DIV == 0){
|
||||||
|
//VCHECK(LAYER);
|
||||||
|
//VCHECK(NHLAYER);
|
||||||
|
return reinterpret_cast<std::intptr_t>(mIndPtr);
|
||||||
|
}
|
||||||
|
return mExpr.vI();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t VS>
|
||||||
|
auto vec() const
|
||||||
|
{
|
||||||
|
typedef typename MkVFor<NHLAYER,RangeType::SIZE % DIV == 0 or RangeType::SIZE == static_cast<size_t>(-1)>::
|
||||||
|
template type<VS,IndexClass,decltype(MkVExpr<NHLAYER>::template mk<VS>(mExpr)),FT> oType;
|
||||||
|
return oType(mIndPtr,mStep,MkVExpr<NHLAYER>::template mk<VS>(mExpr));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator()(size_t mlast, DExt last) override final;
|
inline void operator()(size_t mlast, DExt last) override final;
|
||||||
inline void operator()(size_t mlast, ExtType last) ;
|
inline void operator()(size_t mlast, ExtType last) ;
|
||||||
inline void operator()(size_t mlast = 0) override final;
|
inline void operator()(size_t mlast = 0) override final;
|
||||||
|
|
||||||
PFor<IndexClass,Expr> parallel() const;
|
PFor<IndexClass,Expr,DIV> parallel() const;
|
||||||
|
|
||||||
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||||
DExt dExtension() const override final;
|
DExt dExtension() const override final;
|
||||||
|
@ -393,12 +367,14 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
|
||||||
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
class PFor : public ExpressionBase
|
class PFor : public ExpressionBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
PFor() = default;
|
PFor() = default;
|
||||||
|
|
||||||
|
typedef typename IndexClass::RangeType RangeType;
|
||||||
const IndexClass* mIndPtr;
|
const IndexClass* mIndPtr;
|
||||||
size_t mSPos;
|
size_t mSPos;
|
||||||
size_t mMax;
|
size_t mMax;
|
||||||
|
@ -415,18 +391,40 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static constexpr size_t SIZE = Expr::SIZE;
|
static constexpr size_t SIZE = Expr::SIZE;
|
||||||
|
static constexpr size_t MAX = RangeType::SIZE / DIV;
|
||||||
|
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||||
|
|
||||||
PFor(const PFor& in) = default;
|
PFor(const PFor& in) = default;
|
||||||
PFor& operator=(const PFor& in) = default;
|
PFor& operator=(const PFor& in) = default;
|
||||||
PFor(PFor&& in) = default;
|
PFor(PFor&& in) = default;
|
||||||
PFor& operator=(PFor&& in) = default;
|
PFor& operator=(PFor&& in) = default;
|
||||||
|
|
||||||
PFor(const std::shared_ptr<IndexClass>& indPtr,
|
PFor(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
size_t step, Expr expr);
|
size_t step, Expr expr);
|
||||||
|
|
||||||
PFor(const IndexClass* indPtr,
|
PFor(const IndexClass* indPtr,
|
||||||
size_t step, Expr expr);
|
size_t step, Expr expr);
|
||||||
|
|
||||||
|
//virtual size_t divResid() const override final { return mMax % DIV + MkVExpr<LAYER>::divResid(mExpr); }
|
||||||
|
virtual std::intptr_t vI() const override final
|
||||||
|
{
|
||||||
|
if(mStep == 1 and NHLAYER == 1 and mMax % DIV == 0){
|
||||||
|
//if(mStep == 1 and mMax % DIV == 0){
|
||||||
|
//VCHECK(LAYER);
|
||||||
|
//VCHECK(LAYER);
|
||||||
|
return reinterpret_cast<std::intptr_t>(mIndPtr);
|
||||||
|
}
|
||||||
|
return mExpr.vI();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t VS>
|
||||||
|
auto vec() const
|
||||||
|
{
|
||||||
|
typedef typename MkVFor<NHLAYER,RangeType::SIZE % DIV == 0 or RangeType::SIZE == static_cast<size_t>(-1)>::
|
||||||
|
template ptype<VS,IndexClass,decltype(MkVExpr<NHLAYER>::template mk<VS>(mExpr))> oType;
|
||||||
|
return oType(mIndPtr,mStep,MkVExpr<NHLAYER>::template mk<VS>(mExpr));
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||||
{
|
{
|
||||||
return std::make_shared<PFor<IndexClass,Expr>>(*this);
|
return std::make_shared<PFor<IndexClass,Expr>>(*this);
|
||||||
|
@ -462,6 +460,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
static constexpr size_t LAYER = 0;
|
static constexpr size_t LAYER = 0;
|
||||||
static constexpr size_t SIZE = 0;
|
static constexpr size_t SIZE = 0;
|
||||||
|
static constexpr size_t NHLAYER = 0;
|
||||||
|
|
||||||
DynamicExpression(const DynamicExpression& in) :
|
DynamicExpression(const DynamicExpression& in) :
|
||||||
mThreadId(omp_get_thread_num()),
|
mThreadId(omp_get_thread_num()),
|
||||||
|
@ -504,6 +503,9 @@ namespace MultiArrayHelper
|
||||||
return std::make_shared<DynamicExpression>(*this);
|
return std::make_shared<DynamicExpression>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <size_t VS>
|
||||||
|
inline auto vec() const { return *this; }
|
||||||
|
|
||||||
inline void operator()(size_t mlast, DExt last) override final;
|
inline void operator()(size_t mlast, DExt last) override final;
|
||||||
inline void operator()(size_t mlast, DExtT last) { (*this)(mlast,last.get()); }
|
inline void operator()(size_t mlast, DExtT last) { (*this)(mlast,last.get()); }
|
||||||
inline void operator()(size_t mlast = 0) override final;
|
inline void operator()(size_t mlast = 0) override final;
|
||||||
|
@ -534,6 +536,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||||
static constexpr size_t SIZE = Expr::SIZE;
|
static constexpr size_t SIZE = Expr::SIZE;
|
||||||
|
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||||
|
|
||||||
ExpressionHolder(const ExpressionHolder& in) = default;
|
ExpressionHolder(const ExpressionHolder& in) = default;
|
||||||
ExpressionHolder(ExpressionHolder&& in) = default;
|
ExpressionHolder(ExpressionHolder&& in) = default;
|
||||||
|
@ -559,7 +562,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace MultiArrayHelper
|
} // namespace CNORXZInternal
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
* --- TEMPLATE CODE --- *
|
* --- TEMPLATE CODE --- *
|
||||||
|
@ -567,7 +570,7 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace MultiArrayHelper
|
namespace CNORXZInternal
|
||||||
{
|
{
|
||||||
template <class ExtType>
|
template <class ExtType>
|
||||||
const ExtType& ExtBase::expl() const
|
const ExtType& ExtBase::expl() const
|
||||||
|
@ -579,50 +582,54 @@ namespace MultiArrayHelper
|
||||||
* F o r *
|
* F o r *
|
||||||
*****************/
|
*****************/
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
For<IndexClass,Expr,FT>::For(const std::shared_ptr<IndexClass>& indPtr,
|
For<IndexClass,Expr,FT,DIV>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
size_t step, Expr expr) :
|
size_t step, Expr expr) :
|
||||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||||
{
|
{
|
||||||
|
assert(mMax % DIV == 0);
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
For<IndexClass,Expr,FT>::For(const IndexClass* indPtr,
|
For<IndexClass,Expr,FT,DIV>::For(const IndexClass* indPtr,
|
||||||
size_t step, Expr expr) :
|
size_t step, Expr expr) :
|
||||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||||
{
|
{
|
||||||
|
//VCHECK(mMax);
|
||||||
|
//VCHECK(DIV);
|
||||||
|
//assert(mMax % DIV == 0);
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast, DExt last)
|
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast, DExt last)
|
||||||
{
|
{
|
||||||
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||||
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast,
|
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast,
|
||||||
ExtType last)
|
ExtType last)
|
||||||
{
|
{
|
||||||
typedef typename IndexClass::RangeType RangeType;
|
typedef typename IndexClass::RangeType RangeType;
|
||||||
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE>(mMax); ++pos){
|
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax); ++pos){
|
||||||
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
|
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
mExpr(mnpos, npos);
|
mExpr(mnpos, npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast)
|
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast)
|
||||||
{
|
{
|
||||||
typedef typename IndexClass::RangeType RangeType;
|
typedef typename IndexClass::RangeType RangeType;
|
||||||
ExtType last = rootSteps();
|
ExtType last = rootSteps();
|
||||||
last.zero();
|
last.zero();
|
||||||
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE>(mMax); ++pos){
|
for(size_t pos = 0u; pos != ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax); ++pos){
|
||||||
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
|
const size_t mnpos = PosForward<FT>::valuex(mlast, mStep, pos);
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
mExpr(mnpos, npos);
|
mExpr(mnpos, npos);
|
||||||
|
@ -630,22 +637,22 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
auto For<IndexClass,Expr,FT>::rootSteps(std::intptr_t iPtrNum) const
|
auto For<IndexClass,Expr,FT,DIV>::rootSteps(std::intptr_t iPtrNum) const
|
||||||
-> ExtType
|
-> ExtType
|
||||||
{
|
{
|
||||||
return mExpr.rootSteps(iPtrNum);
|
return mExpr.rootSteps(iPtrNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
auto For<IndexClass,Expr,FT>::extension() const
|
auto For<IndexClass,Expr,FT,DIV>::extension() const
|
||||||
-> ExtType
|
-> ExtType
|
||||||
{
|
{
|
||||||
return mExt;
|
return mExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
DExt For<IndexClass,Expr,FT>::dRootSteps(std::intptr_t iPtrNum) const
|
DExt For<IndexClass,Expr,FT,DIV>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
//mRootSteps = rootSteps(iPtrNum);
|
//mRootSteps = rootSteps(iPtrNum);
|
||||||
|
@ -653,52 +660,54 @@ namespace MultiArrayHelper
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
DExt For<IndexClass,Expr,FT>::dExtension() const
|
DExt For<IndexClass,Expr,FT,DIV>::dExtension() const
|
||||||
{
|
{
|
||||||
return std::make_shared<ExtT<ExtType>>(mExt);
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr, ForType FT>
|
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||||
PFor<IndexClass,Expr> For<IndexClass,Expr,FT>::parallel() const
|
PFor<IndexClass,Expr,DIV> For<IndexClass,Expr,FT,DIV>::parallel() const
|
||||||
{
|
{
|
||||||
static_assert(FT == ForType::DEFAULT, "hidden for not parallelizable");
|
static_assert(FT == ForType::DEFAULT, "hidden for not parallelizable");
|
||||||
return PFor<IndexClass,Expr>(mIndPtr, mStep, mExpr);
|
return PFor<IndexClass,Expr,DIV>(mIndPtr, mStep, mExpr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
* P F o r *
|
* P F o r *
|
||||||
******************/
|
******************/
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
PFor<IndexClass,Expr>::PFor(const std::shared_ptr<IndexClass>& indPtr,
|
PFor<IndexClass,Expr,DIV>::PFor(const std::shared_ptr<IndexClass>& indPtr,
|
||||||
size_t step, Expr expr) :
|
size_t step, Expr expr) :
|
||||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||||
{
|
{
|
||||||
|
//assert(mMax % DIV == 0);
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
PFor<IndexClass,Expr>::PFor(const IndexClass* indPtr,
|
PFor<IndexClass,Expr,DIV>::PFor(const IndexClass* indPtr,
|
||||||
size_t step, Expr expr) :
|
size_t step, Expr expr) :
|
||||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||||
{
|
{
|
||||||
|
assert(mMax % DIV == 0);
|
||||||
assert(mIndPtr != nullptr);
|
assert(mIndPtr != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
inline void PFor<IndexClass,Expr>::operator()(size_t mlast, DExt last)
|
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast, DExt last)
|
||||||
{
|
{
|
||||||
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||||
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
inline void PFor<IndexClass,Expr>::operator()(size_t mlast,
|
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast,
|
||||||
ExtType last)
|
ExtType last)
|
||||||
{
|
{
|
||||||
CHECK;
|
CHECK;
|
||||||
|
@ -710,7 +719,7 @@ namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
auto expr = mExpr;
|
auto expr = mExpr;
|
||||||
#pragma omp for nowait
|
#pragma omp for nowait
|
||||||
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE>(mMax)); pos++){
|
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax)); pos++){
|
||||||
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
||||||
npos = last + mExt*static_cast<size_t>(pos);
|
npos = last + mExt*static_cast<size_t>(pos);
|
||||||
expr(mnpos, npos);
|
expr(mnpos, npos);
|
||||||
|
@ -718,11 +727,10 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
inline void PFor<IndexClass,Expr>::operator()(size_t mlast)
|
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast)
|
||||||
{
|
{
|
||||||
CHECK;
|
CHECK;
|
||||||
typedef typename IndexClass::RangeType RangeType;
|
|
||||||
ExtType last = rootSteps();
|
ExtType last = rootSteps();
|
||||||
last.zero();
|
last.zero();
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -733,7 +741,7 @@ namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
auto expr = mExpr;
|
auto expr = mExpr;
|
||||||
#pragma omp for nowait
|
#pragma omp for nowait
|
||||||
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE>(mMax)); pos++){
|
for(pos = 0; pos < static_cast<int>(ForBound<RangeType::ISSTATIC>::template bound<RangeType::SIZE,DIV>(mMax)); pos++){
|
||||||
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
mnpos = PosForward<ForType::DEFAULT>::valuex(mlast, mStep, pos);
|
||||||
npos = last + mExt*static_cast<size_t>(pos);
|
npos = last + mExt*static_cast<size_t>(pos);
|
||||||
expr(mnpos, npos);
|
expr(mnpos, npos);
|
||||||
|
@ -742,22 +750,22 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
auto PFor<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
|
auto PFor<IndexClass,Expr,DIV>::rootSteps(std::intptr_t iPtrNum) const
|
||||||
-> ExtType
|
-> ExtType
|
||||||
{
|
{
|
||||||
return mExpr.rootSteps(iPtrNum);
|
return mExpr.rootSteps(iPtrNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
auto PFor<IndexClass,Expr>::extension() const
|
auto PFor<IndexClass,Expr,DIV>::extension() const
|
||||||
-> ExtType
|
-> ExtType
|
||||||
{
|
{
|
||||||
return mExt;
|
return mExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
DExt PFor<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
DExt PFor<IndexClass,Expr,DIV>::dRootSteps(std::intptr_t iPtrNum) const
|
||||||
{
|
{
|
||||||
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||||
//mRootSteps = rootSteps(iPtrNum);
|
//mRootSteps = rootSteps(iPtrNum);
|
||||||
|
@ -765,8 +773,8 @@ namespace MultiArrayHelper
|
||||||
// sizeof(ExtType)/sizeof(size_t));
|
// sizeof(ExtType)/sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr, size_t DIV>
|
||||||
DExt PFor<IndexClass,Expr>::dExtension() const
|
DExt PFor<IndexClass,Expr,DIV>::dExtension() const
|
||||||
{
|
{
|
||||||
return std::make_shared<ExtT<ExtType>>(mExt);
|
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||||
|
@ -901,7 +909,7 @@ namespace MultiArrayHelper
|
||||||
const size_t pos = (*mSubSet)[last.val()];
|
const size_t pos = (*mSubSet)[last.val()];
|
||||||
const size_t mnpos = mlast;
|
const size_t mnpos = mlast;
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
mExpr(mnpos, getX<1>( npos ));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class IndexClass, class Expr>
|
template <class IndexClass, class Expr>
|
||||||
|
@ -912,7 +920,7 @@ namespace MultiArrayHelper
|
||||||
const size_t pos = (*mSubSet)[last.val()];
|
const size_t pos = (*mSubSet)[last.val()];
|
||||||
const size_t mnpos = mlast;
|
const size_t mnpos = mlast;
|
||||||
const ExtType npos = last + mExt*pos;
|
const ExtType npos = last + mExt*pos;
|
||||||
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
mExpr(mnpos, getX<1>( npos ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1027,6 +1035,6 @@ namespace MultiArrayHelper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace MultiArrayHelper
|
} // namespace CNORXZInternal
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh
|
execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ )
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ )
|
||||||
|
|
||||||
set(libmultiarray_a_SOURCES
|
set(libcnorxz_a_SOURCES
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc
|
${CMAKE_SOURCE_DIR}/src/lib/ranges/range_base.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/anonymous_range.cc
|
${CMAKE_SOURCE_DIR}/src/lib/ranges/anonymous_range.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/dynamic_meta.cc
|
${CMAKE_SOURCE_DIR}/src/lib/ranges/dynamic_meta.cc
|
||||||
|
@ -10,40 +10,66 @@ set(libmultiarray_a_SOURCES
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/type_map.cc
|
${CMAKE_SOURCE_DIR}/src/lib/ranges/type_map.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/ranges/multi_range_factory_product_map.cc
|
${CMAKE_SOURCE_DIR}/src/lib/ranges/multi_range_factory_product_map.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/map_range_factory_product_map.cc
|
${CMAKE_SOURCE_DIR}/src/lib/map_range_factory_product_map.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(libhlcnorxz_a_SOURCES
|
||||||
${CMAKE_SOURCE_DIR}/src/lib/high_level_operation.cc
|
${CMAKE_SOURCE_DIR}/src/lib/high_level_operation.cc
|
||||||
)
|
)
|
||||||
|
#message(WARNING ${libhlcnorxz_a_SOURCES})
|
||||||
|
|
||||||
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")
|
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")
|
||||||
foreach(ccfile ${cc_files})
|
foreach(ccfile ${cc_files})
|
||||||
set(libmultiarray_a_SOURCES ${libmultiarray_a_SOURCES}
|
set(libcnorxz_a_SOURCES ${libcnorxz_a_SOURCES}
|
||||||
${ccfile})
|
${ccfile})
|
||||||
endforeach(ccfile)
|
endforeach(ccfile)
|
||||||
|
|
||||||
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc")
|
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc")
|
||||||
foreach(ccfile ${cc_files})
|
foreach(ccfile ${cc_files})
|
||||||
set(libmultiarray_a_SOURCES ${libmultiarray_a_SOURCES}
|
set(libhlcnorxz_a_SOURCES ${libhlcnorxz_a_SOURCES}
|
||||||
${ccfile})
|
${ccfile})
|
||||||
endforeach(ccfile)
|
endforeach(ccfile)
|
||||||
|
|
||||||
add_library(multiarray_obj OBJECT
|
add_library(cnorxz_obj OBJECT
|
||||||
${libmultiarray_a_SOURCES}
|
${libcnorxz_a_SOURCES}
|
||||||
)
|
)
|
||||||
set_target_properties(multiarray_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
add_library(hlcnorxz_obj OBJECT
|
||||||
|
${libhlcnorxz_a_SOURCES}
|
||||||
add_library(multiarray SHARED
|
|
||||||
$<TARGET_OBJECTS:multiarray_obj>
|
|
||||||
)
|
)
|
||||||
set_target_properties(multiarray PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
add_library(multiarray_static
|
add_library(cnorxz SHARED
|
||||||
$<TARGET_OBJECTS:multiarray_obj>
|
$<TARGET_OBJECTS:cnorxz_obj>
|
||||||
)
|
)
|
||||||
set_target_properties(multiarray_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
set_target_properties(cnorxz PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
install(TARGETS multiarray
|
add_library(cnorxz_static
|
||||||
|
$<TARGET_OBJECTS:cnorxz_obj>
|
||||||
|
)
|
||||||
|
set_target_properties(cnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
|
add_library(hlcnorxz SHARED
|
||||||
|
$<TARGET_OBJECTS:hlcnorxz_obj>
|
||||||
|
)
|
||||||
|
set_target_properties(hlcnorxz PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
|
add_library(hlcnorxz_static
|
||||||
|
$<TARGET_OBJECTS:hlcnorxz_obj>
|
||||||
|
)
|
||||||
|
set_target_properties(hlcnorxz_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
|
|
||||||
|
install(TARGETS cnorxz
|
||||||
ARCHIVE DESTINATION ${INSTALL_PATH}/lib
|
ARCHIVE DESTINATION ${INSTALL_PATH}/lib
|
||||||
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
||||||
|
|
||||||
install(TARGETS multiarray_static
|
install(TARGETS cnorxz_static
|
||||||
|
ARCHIVE DESTINATION ${INSTALL_PATH}/lib
|
||||||
|
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
||||||
|
|
||||||
|
install(TARGETS hlcnorxz
|
||||||
|
ARCHIVE DESTINATION ${INSTALL_PATH}/lib
|
||||||
|
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
||||||
|
|
||||||
|
install(TARGETS hlcnorxz_static
|
||||||
ARCHIVE DESTINATION ${INSTALL_PATH}/lib
|
ARCHIVE DESTINATION ${INSTALL_PATH}/lib
|
||||||
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
#include "multi_array_header.h"
|
#include "cnorxz.h"
|
||||||
#include "high_level_operation.h"
|
#include "hl_cnorxz.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::shared_ptr<DynamicIndex> mkSubSpaceX(const std::shared_ptr<DynamicIndex>& di,
|
std::shared_ptr<DynamicIndex> mkSubSpaceX(const std::shared_ptr<DynamicIndex>& di,
|
||||||
size_t max)
|
size_t max)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#include "map_range_factory_product_map.h"
|
#include "map_range_factory_product_map.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MapRangeFactoryProductMap::mAleadyCreated;
|
std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MapRangeFactoryProductMap::mAleadyCreated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ for x in $(cat ../include/extensions/math.h) ; do
|
||||||
fff=${xx%\)}
|
fff=${xx%\)}
|
||||||
file=hl_ops/${fff}.cc
|
file=hl_ops/${fff}.cc
|
||||||
test -f ${file} && rm -f ${file}
|
test -f ${file} && rm -f ${file}
|
||||||
echo "#include \"multi_array_header.h\"" >> ${file}
|
echo "#include \"cnorxz.h\"" >> ${file}
|
||||||
echo "#include \"high_level_operation.h\"" >> ${file}
|
echo "#include \"hl_cnorxz.h\"" >> ${file}
|
||||||
echo "" >> ${file}
|
echo "" >> ${file}
|
||||||
echo "namespace MultiArrayTools" >> ${file}
|
echo "namespace CNORXZ" >> ${file}
|
||||||
echo "{" >> ${file}
|
echo "{" >> ${file}
|
||||||
echo " template class HighLevelOp<OpCD,x_${fff}<double>,1>;" >> ${file}
|
echo " template class HighLevelOp<OpCD,x_${fff}<double>,1>;" >> ${file}
|
||||||
echo " template class HighLevelOp<OpD,x_${fff}<double>,1>;" >> ${file}
|
echo " template class HighLevelOp<OpD,x_${fff}<double>,1>;" >> ${file}
|
||||||
|
@ -24,10 +24,10 @@ done
|
||||||
for fff in plus minus multiplies divides ; do
|
for fff in plus minus multiplies divides ; do
|
||||||
file=hl_ops/${fff}.cc
|
file=hl_ops/${fff}.cc
|
||||||
test -f ${file} && rm -f ${file}
|
test -f ${file} && rm -f ${file}
|
||||||
echo "#include \"multi_array_header.h\"" >> ${file}
|
echo "#include \"cnorxz.h\"" >> ${file}
|
||||||
echo "#include \"high_level_operation.h\"" >> ${file}
|
echo "#include \"hl_cnorxz.h\"" >> ${file}
|
||||||
echo "" >> ${file}
|
echo "" >> ${file}
|
||||||
echo "namespace MultiArrayTools" >> ${file}
|
echo "namespace CNORXZ" >> ${file}
|
||||||
echo "{" >> ${file}
|
echo "{" >> ${file}
|
||||||
echo " template class HighLevelOp<OpCD,${fff}x<double,double>,2>;" >> ${file}
|
echo " template class HighLevelOp<OpCD,${fff}x<double,double>,2>;" >> ${file}
|
||||||
echo " template class HighLevelOp<OpD,${fff}x<double,double>,2>;" >> ${file}
|
echo " template class HighLevelOp<OpD,${fff}x<double,double>,2>;" >> ${file}
|
||||||
|
@ -37,10 +37,10 @@ done
|
||||||
for fff in negate ; do
|
for fff in negate ; do
|
||||||
file=hl_ops/${fff}.cc
|
file=hl_ops/${fff}.cc
|
||||||
test -f ${file} && rm -f ${file}
|
test -f ${file} && rm -f ${file}
|
||||||
echo "#include \"multi_array_header.h\"" >> ${file}
|
echo "#include \"cnorxz.h\"" >> ${file}
|
||||||
echo "#include \"high_level_operation.h\"" >> ${file}
|
echo "#include \"hl_cnorxz.h\"" >> ${file}
|
||||||
echo "" >> ${file}
|
echo "" >> ${file}
|
||||||
echo "namespace MultiArrayTools" >> ${file}
|
echo "namespace CNORXZ" >> ${file}
|
||||||
echo "{" >> ${file}
|
echo "{" >> ${file}
|
||||||
echo " template class HighLevelOp<OpCD,${fff}<double>,1>;" >> ${file}
|
echo " template class HighLevelOp<OpCD,${fff}<double>,1>;" >> ${file}
|
||||||
echo " template class HighLevelOp<OpD,${fff}<double>,1>;" >> ${file}
|
echo " template class HighLevelOp<OpD,${fff}<double>,1>;" >> ${file}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
#include "ranges/anonymous_range.h"
|
#include "ranges/anonymous_range.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
#include "ma_assert.h"
|
#include "cxz_assert.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/******************************
|
/******************************
|
||||||
* AnonymousRangeFactory *
|
* AnonymousRangeFactory *
|
||||||
|
@ -294,4 +294,4 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "ranges/dynamic_meta.h"
|
#include "ranges/dynamic_meta.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
|
@ -45,4 +45,4 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace CNORXZ
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
#include "ranges/dynamic_range.h"
|
#include "ranges/dynamic_range.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
#include "ma_assert.h"
|
#include "cxz_assert.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using namespace MultiArrayHelper;
|
using namespace CNORXZInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,23 +303,6 @@ namespace MultiArrayTools
|
||||||
return mIVec[n].second;
|
return mIVec[n].second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string DynamicIndex::id() const
|
|
||||||
{
|
|
||||||
return std::string("dyn") + std::to_string(IB::mId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DynamicIndex::print(size_t offset)
|
|
||||||
{
|
|
||||||
if(offset == 0){
|
|
||||||
std::cout << " === " << std::endl;
|
|
||||||
}
|
|
||||||
for(size_t j = 0; j != offset; ++j) { std::cout << "\t"; }
|
|
||||||
std::cout << id() << "[" << reinterpret_cast<std::intptr_t>(this)
|
|
||||||
<< "](" << IB::mRangePtr << "): " /*<< meta().first*/ << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
* DynamicRange *
|
* DynamicRange *
|
||||||
|
@ -501,5 +484,5 @@ namespace MultiArrayTools
|
||||||
return mOrig;
|
return mOrig;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "ranges/multi_range_factory_product_map.h"
|
#include "ranges/multi_range_factory_product_map.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MultiRangeFactoryProductMap::mAleadyCreated;
|
std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MultiRangeFactoryProductMap::mAleadyCreated;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@
|
||||||
|
|
||||||
#include "ranges/range_base.h"
|
#include "ranges/range_base.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
#include "ranges/range_helper.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
|
|
||||||
//using namespace MultiArrayHelpers;
|
//using namespace CNORXZInternals;
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
using STP = std::tuple<std::shared_ptr<Ranges>...>;
|
using STP = std::tuple<std::shared_ptr<Ranges>...>;
|
||||||
|
@ -23,8 +24,7 @@ namespace MultiArrayTools
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
inline bool compareSpaceTypes(const RVEC& rvec)
|
inline bool compareSpaceTypes(const RVEC& rvec)
|
||||||
{
|
{
|
||||||
return RPackNum<sizeof...(Ranges)-1>::
|
return RangeHelper::compareSpaceTypes<sizeof...(Ranges)-1,sizeof...(Ranges),Ranges...>(rvec);
|
||||||
template compareSpaceTypes<sizeof...(Ranges),Ranges...>(rvec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ranges>
|
template <class... Ranges>
|
||||||
|
@ -32,7 +32,7 @@ namespace MultiArrayTools
|
||||||
{
|
{
|
||||||
if(compareSpaceTypes<Ranges...>(rvec)) {
|
if(compareSpaceTypes<Ranges...>(rvec)) {
|
||||||
STP<Ranges...> stp;
|
STP<Ranges...> stp;
|
||||||
RPackNum<sizeof...(Ranges)-1>::setSpace(rvec, stp);
|
RangeHelper::setSpace<sizeof...(Ranges)-1>(rvec, stp);
|
||||||
fptr = std::make_shared<MultiRangeFactory<Ranges...> >(stp);
|
fptr = std::make_shared<MultiRangeFactory<Ranges...> >(stp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -215,4 +215,4 @@ namespace MultiArrayTools
|
||||||
return reinterpret_cast<std::intptr_t>(this);
|
return reinterpret_cast<std::intptr_t>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace MultiArrayTools
|
} // end namespace CNORXZ
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
/********************
|
/********************
|
||||||
* GenSingleRange *
|
* GenSingleRange *
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::shared_ptr<NullRF> mkNUL(const char* dp, size_t size)
|
std::shared_ptr<NullRF> mkNUL(const char* dp, size_t size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::shared_ptr<PSpaceRF> mkPSPACE(const char* dp, size_t size)
|
std::shared_ptr<PSpaceRF> mkPSPACE(const char* dp, size_t size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "ranges/x_to_string.h"
|
#include "ranges/x_to_string.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::shared_ptr<SpinRF> mkSPIN(const char* dp, size_t size)
|
std::shared_ptr<SpinRF> mkSPIN(const char* dp, size_t size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "ranges/type_map.h"
|
#include "ranges/type_map.h"
|
||||||
#include "ranges/ranges_header.cc.h"
|
#include "ranges/ranges_header.cc.h"
|
||||||
|
|
||||||
namespace MultiArrayTools
|
namespace CNORXZ
|
||||||
{
|
{
|
||||||
#define XCOMMAX() ,
|
#define XCOMMAX() ,
|
||||||
#define include_type(t,n) template struct TypeMap<n>; \
|
#define include_type(t,n) template struct TypeMap<n>; \
|
||||||
|
|
7
src/name_map.txt
Normal file
7
src/name_map.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
:: Rename MultiArray library in CNORXZ (Containers with Native Operation Routines by XZ (chizeta))
|
||||||
|
MultiArrayTools -> CNORXZ
|
||||||
|
MultiArray -> Array
|
||||||
|
multi_array_*.{cc,h} -> cxz_*.{cc,h}
|
||||||
|
*ma* -> *cxz*
|
||||||
|
libmultiarray -> libcnorxz
|
||||||
|
...!!!
|
|
@ -1,41 +1,41 @@
|
||||||
|
|
||||||
#add_executable(iutest /ranges/index_unit_test.cc ${INDEX_CC_FILES})
|
#add_executable(iutest /ranges/index_unit_test.cc ${INDEX_CC_FILES})
|
||||||
add_executable(iutest ranges/index_unit_test.cc)
|
add_executable(iutest ranges/index_unit_test.cc)
|
||||||
add_dependencies(iutest multiarray)
|
add_dependencies(iutest cnorxz)
|
||||||
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(iutest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
|
||||||
add_test(NAME iutest COMMAND iutest)
|
add_test(NAME iutest COMMAND iutest)
|
||||||
|
|
||||||
add_executable(autest ranges/anonymous_unit_test.cc)
|
add_executable(autest ranges/anonymous_unit_test.cc)
|
||||||
add_dependencies(autest multiarray)
|
add_dependencies(autest cnorxz)
|
||||||
target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(autest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
|
||||||
add_test(NAME autest COMMAND autest)
|
add_test(NAME autest COMMAND autest)
|
||||||
|
|
||||||
#add_executable(mautest src/tests/ma_unit_test.cc ${MA_CC_FILES})
|
#add_executable(mautest src/tests/array_unit_test.cc ${MA_CC_FILES})
|
||||||
add_executable(mautest ma_unit_test.cc)
|
add_executable(mautest array_unit_test.cc)
|
||||||
add_dependencies(mautest multiarray)
|
add_dependencies(mautest cnorxz)
|
||||||
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(mautest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
|
||||||
add_test(NAME mautest COMMAND mautest)
|
add_test(NAME mautest COMMAND mautest)
|
||||||
|
|
||||||
add_executable(oputest op_unit_test.cc)
|
add_executable(oputest op_unit_test.cc)
|
||||||
add_dependencies(oputest multiarray)
|
add_dependencies(oputest cnorxz)
|
||||||
target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(oputest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
|
||||||
add_test(NAME oputest COMMAND oputest)
|
add_test(NAME oputest COMMAND oputest)
|
||||||
|
|
||||||
add_executable(op2utest op2_unit_test.cc)
|
add_executable(op2utest op2_unit_test.cc)
|
||||||
add_dependencies(op2utest multiarray)
|
add_dependencies(op2utest cnorxz)
|
||||||
target_link_libraries(op2utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(op2utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
|
||||||
add_test(NAME op2utest COMMAND op2utest)
|
add_test(NAME op2utest COMMAND op2utest)
|
||||||
|
|
||||||
add_executable(op3utest op3_unit_test.cc)
|
add_executable(op3utest op3_unit_test.cc)
|
||||||
add_dependencies(op3utest multiarray)
|
add_dependencies(op3utest cnorxz)
|
||||||
target_link_libraries(op3utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(op3utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz)
|
||||||
add_test(NAME op3utest COMMAND op3utest)
|
add_test(NAME op3utest COMMAND op3utest)
|
||||||
|
|
||||||
add_executable(op4utest op4_unit_test.cc)
|
add_executable(op4utest op4_unit_test.cc)
|
||||||
add_dependencies(op4utest multiarray)
|
add_dependencies(op4utest cnorxz hlcnorxz)
|
||||||
target_link_libraries(op4utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} multiarray)
|
target_link_libraries(op4utest ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} cnorxz hlcnorxz)
|
||||||
add_test(NAME op4utest COMMAND op4utest)
|
add_test(NAME op4utest COMMAND op4utest)
|
||||||
|
|
||||||
add_executable(opptest op_perf_test.cc)
|
add_executable(opptest op_perf_test.cc)
|
||||||
add_dependencies(opptest multiarray)
|
add_dependencies(opptest cnorxz)
|
||||||
target_link_libraries(opptest multiarray)
|
target_link_libraries(opptest cnorxz)
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "multi_array_header.h"
|
#include "cnorxz.h"
|
||||||
|
|
||||||
namespace MAT = MultiArrayTools;
|
namespace MAT = CNORXZ;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -98,12 +98,12 @@ namespace {
|
||||||
|
|
||||||
TEST_F(MATest_1Dim, SimpleCall)
|
TEST_F(MATest_1Dim, SimpleCall)
|
||||||
{
|
{
|
||||||
MultiArray<double,MATest_1Dim::SRange> ma(srptr, vv);
|
Array<double,MATest_1Dim::SRange> ma(srptr, vv);
|
||||||
EXPECT_EQ( ma.size(), 5u);
|
EXPECT_EQ( ma.size(), 5u);
|
||||||
EXPECT_EQ( ma.isConst(), false);
|
EXPECT_EQ( ma.isConst(), false);
|
||||||
EXPECT_EQ( ma.isSlice(), false);
|
EXPECT_EQ( ma.isSlice(), false);
|
||||||
|
|
||||||
auto i = ma.beginIndex();
|
auto i = ma.cbegin();
|
||||||
EXPECT_EQ( ma[ i.at('x') ], 3.141);
|
EXPECT_EQ( ma[ i.at('x') ], 3.141);
|
||||||
EXPECT_EQ( ma[ i.at('y') ], 2.718);
|
EXPECT_EQ( ma[ i.at('y') ], 2.718);
|
||||||
EXPECT_EQ( ma[ i.at('l') ], 1.618);
|
EXPECT_EQ( ma[ i.at('l') ], 1.618);
|
||||||
|
@ -115,7 +115,7 @@ namespace {
|
||||||
TEST_F(MATest_1Dim, ForLoop)
|
TEST_F(MATest_1Dim, ForLoop)
|
||||||
{
|
{
|
||||||
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 ) );
|
Array<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){
|
||||||
|
|
||||||
|
@ -142,12 +142,12 @@ namespace {
|
||||||
swapFactory<SRF>( rfbptr, { 'a', 'c', 'e', 'g', 'i' } );
|
swapFactory<SRF>( rfbptr, { 'a', 'c', 'e', 'g', 'i' } );
|
||||||
std::shared_ptr<SRange> sr2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
std::shared_ptr<SRange> sr2 = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||||||
|
|
||||||
MultiArray<double,MATest_1Dim::SRange> ma(srptr, vv);
|
Array<double,MATest_1Dim::SRange> ma(srptr, vv);
|
||||||
auto i = ma.beginIndex();
|
auto i = ma.cbegin();
|
||||||
EXPECT_EQ( ma[ i.at('x') ], 3.141);
|
EXPECT_EQ( ma[ i.at('x') ], 3.141);
|
||||||
|
|
||||||
auto ma2 = ma.format( sr2 );
|
auto ma2 = ma.format( sr2 );
|
||||||
auto j = ma2.beginIndex();
|
auto j = ma2.cbegin();
|
||||||
|
|
||||||
EXPECT_EQ( ma[ j.at('a') ], 3.141);
|
EXPECT_EQ( ma[ j.at('a') ], 3.141);
|
||||||
EXPECT_EQ( ma[ j.at('c') ], 2.718);
|
EXPECT_EQ( ma[ j.at('c') ], 2.718);
|
||||||
|
@ -158,11 +158,11 @@ namespace {
|
||||||
|
|
||||||
TEST_F(MATest_MDim, SimpleCall)
|
TEST_F(MATest_MDim, SimpleCall)
|
||||||
{
|
{
|
||||||
MultiArray<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
Array<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
||||||
EXPECT_EQ( ma.size(), 24u );
|
EXPECT_EQ( ma.size(), 24u );
|
||||||
EXPECT_EQ( ma.range()->dim(), 2u );
|
EXPECT_EQ( ma.range()->dim(), 2u );
|
||||||
|
|
||||||
auto i = ma.beginIndex();
|
auto i = ma.cbegin();
|
||||||
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '1' ) ) ], 2.917);
|
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '1' ) ) ], 2.917);
|
||||||
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '2' ) ) ], 9.436);
|
EXPECT_EQ( ma[ i.at( mkt( mkt('x', 'a'), '2' ) ) ], 9.436);
|
||||||
|
|
||||||
|
@ -175,10 +175,10 @@ namespace {
|
||||||
|
|
||||||
TEST_F(MATest_MDim, ReFormat)
|
TEST_F(MATest_MDim, ReFormat)
|
||||||
{
|
{
|
||||||
MultiArray<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
Array<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
||||||
|
|
||||||
auto ma2 = ma.format( sr4ptr );
|
auto ma2 = ma.format( sr4ptr );
|
||||||
auto i = ma2.beginIndex();
|
auto i = ma2.cbegin();
|
||||||
EXPECT_EQ( ma2.at('A') , 2.917 );
|
EXPECT_EQ( ma2.at('A') , 2.917 );
|
||||||
EXPECT_EQ( ma2[ i.at('G') ], 4.892 );
|
EXPECT_EQ( ma2[ i.at('G') ], 4.892 );
|
||||||
EXPECT_EQ( ma2.at('J') , 4.790 );
|
EXPECT_EQ( ma2.at('J') , 4.790 );
|
||||||
|
@ -188,7 +188,7 @@ namespace {
|
||||||
|
|
||||||
TEST_F(MATest_MDim, SliceTest1)
|
TEST_F(MATest_MDim, SliceTest1)
|
||||||
{
|
{
|
||||||
MultiArray<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
Array<double,MATest_MDim::MRange,MATest_MDim::SRange> ma(mrptr, sr3ptr, vv);
|
||||||
Slice<double,MATest_MDim::SRange> sl(sr3ptr);
|
Slice<double,MATest_MDim::SRange> sl(sr3ptr);
|
||||||
|
|
||||||
auto i = MAT::getIndex(sr3ptr);
|
auto i = MAT::getIndex(sr3ptr);
|
|
@ -119,7 +119,7 @@ namespace
|
||||||
|
|
||||||
TEST_F(MapTest, Exec1)
|
TEST_F(MapTest, Exec1)
|
||||||
{
|
{
|
||||||
MultiArray<double,SRange,SRange> ma1(sr1ptr,sr2ptr,v1);
|
Array<double,SRange,SRange> ma1(sr1ptr,sr2ptr,v1);
|
||||||
|
|
||||||
|
|
||||||
auto ii1 = getIndex( rptr<0>( ma1 ) );
|
auto ii1 = getIndex( rptr<0>( ma1 ) );
|
||||||
|
@ -127,8 +127,8 @@ namespace
|
||||||
|
|
||||||
auto mr = mkMapR( mkMapOp(std::make_shared<plus<size_t>>(),ii1,ii2) , sr1ptr, sr2ptr );
|
auto mr = mkMapR( mkMapOp(std::make_shared<plus<size_t>>(),ii1,ii2) , sr1ptr, sr2ptr );
|
||||||
//auto mr = mkMapR(std::make_shared<plus<size_t>>(),sr1ptr,sr2ptr);
|
//auto mr = mkMapR(std::make_shared<plus<size_t>>(),sr1ptr,sr2ptr);
|
||||||
MultiArray<double,MpRange> res(mr);
|
Array<double,MpRange> res(mr);
|
||||||
MultiArray<double,MpRange> res2(mr);
|
Array<double,MpRange> res2(mr);
|
||||||
auto jj = getIndex( mr );
|
auto jj = getIndex( mr );
|
||||||
(*jj)(ii1,ii2);
|
(*jj)(ii1,ii2);
|
||||||
///auto jj = mkMapI( std::make_shared<plus<size_t> >(), ii1, ii1 );
|
///auto jj = mkMapI( std::make_shared<plus<size_t> >(), ii1, ii1 );
|
||||||
|
@ -137,8 +137,8 @@ namespace
|
||||||
auto mult = mr->explMapMultiplicity();
|
auto mult = mr->explMapMultiplicity();
|
||||||
res2(jj) += ma1(ii1,ii2) / staticcast<double>( mult(jj) );
|
res2(jj) += ma1(ii1,ii2) / staticcast<double>( mult(jj) );
|
||||||
|
|
||||||
MultiArray<double,TRange> form = res.format(mpr1ptr->outRange());
|
Array<double,TRange> form = res.format(mpr1ptr->outRange());
|
||||||
MultiArray<double,TRange> form2 = res2.format(mpr1ptr->outRange());
|
Array<double,TRange> form2 = res2.format(mpr1ptr->outRange());
|
||||||
|
|
||||||
EXPECT_EQ( jj->range()->outRange()->size(), static_cast<size_t>( 10 ) );
|
EXPECT_EQ( jj->range()->outRange()->size(), static_cast<size_t>( 10 ) );
|
||||||
EXPECT_EQ( jj->range()->mapMultiplicity().at(9), static_cast<size_t>( 3 ) );
|
EXPECT_EQ( jj->range()->mapMultiplicity().at(9), static_cast<size_t>( 3 ) );
|
||||||
|
@ -169,7 +169,7 @@ namespace
|
||||||
|
|
||||||
TEST_F(MetaOp_Test, SimpleCall)
|
TEST_F(MetaOp_Test, SimpleCall)
|
||||||
{
|
{
|
||||||
FunctionalMultiArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
|
FunctionalArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
|
||||||
|
|
||||||
auto i = fma.begin();
|
auto i = fma.begin();
|
||||||
|
|
||||||
|
@ -178,8 +178,8 @@ namespace
|
||||||
|
|
||||||
TEST_F(MetaOp_Test, Operation)
|
TEST_F(MetaOp_Test, Operation)
|
||||||
{
|
{
|
||||||
FunctionalMultiArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
|
FunctionalArray<double,Pow<double>,SR,SR> fma(sr1ptr, sr2ptr);
|
||||||
MultiArray<double,SR> res( sr1ptr );
|
Array<double,SR> res( sr1ptr );
|
||||||
|
|
||||||
auto i1 = MAT::getIndex(sr1ptr);
|
auto i1 = MAT::getIndex(sr1ptr);
|
||||||
auto i2 = MAT::getIndex(sr2ptr);
|
auto i2 = MAT::getIndex(sr2ptr);
|
||||||
|
@ -203,14 +203,14 @@ namespace
|
||||||
|
|
||||||
TEST_F(OpTest_Sub, Exec)
|
TEST_F(OpTest_Sub, Exec)
|
||||||
{
|
{
|
||||||
MultiArray<double,SRange,SRange,SRange> ma1(sr1ptr, sr2ptr, sr3ptr, v1);
|
Array<double,SRange,SRange,SRange> ma1(sr1ptr, sr2ptr, sr3ptr, v1);
|
||||||
MultiArray<double,SRange,SRange> ma2(sr3ptr, sr2ptr, v2);
|
Array<double,SRange,SRange> ma2(sr3ptr, sr2ptr, v2);
|
||||||
|
|
||||||
SubRangeFactory<SRange> subf(sr2ptr, 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.);
|
Array<double,SRange,SRange> res(sr3ptr,sr1ptr,0.);
|
||||||
MultiArray<double,SRange,SubRange<SRange>,SRange> res2(sr3ptr,subptr,sr1ptr,0.);
|
Array<double,SRange,SubRange<SRange>,SRange> res2(sr3ptr,subptr,sr1ptr,0.);
|
||||||
|
|
||||||
auto i1 = MAT::getIndex( sr1ptr );
|
auto i1 = MAT::getIndex( sr1ptr );
|
||||||
auto i2 = MAT::getIndex( sr2ptr );
|
auto i2 = MAT::getIndex( sr2ptr );
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue