Compare commits
66 commits
fddceea1e3
...
21bd120032
Author | SHA1 | Date | |
---|---|---|---|
![]() |
21bd120032 | ||
![]() |
8f6094233a | ||
![]() |
388531c37f | ||
![]() |
7aa4b18d15 | ||
![]() |
8b64d2c0d5 | ||
![]() |
b5ec02c7c5 | ||
![]() |
3c6f9ea025 | ||
![]() |
7a24e328e7 | ||
![]() |
3975edea20 | ||
![]() |
c5e6003fc9 | ||
![]() |
e3d4c34962 | ||
![]() |
bba1c6944a | ||
![]() |
a841782115 | ||
![]() |
8bde2d7250 | ||
![]() |
bf4633054d | ||
![]() |
33b52c1a70 | ||
![]() |
bf7853c1b5 | ||
![]() |
e80c71aa62 | ||
![]() |
312074c486 | ||
![]() |
24ea3c2c30 | ||
![]() |
9946a8d416 | ||
![]() |
d5e02ba9d2 | ||
![]() |
ffb8e71dbd | ||
![]() |
c282cf683d | ||
![]() |
7cd0c3104f | ||
![]() |
6991742206 | ||
![]() |
49f2c41a95 | ||
![]() |
f1b44cfd5c | ||
![]() |
c26fb133ae | ||
![]() |
53362be499 | ||
![]() |
01703dec28 | ||
![]() |
63df6bbdef | ||
![]() |
98138114f7 | ||
![]() |
1d882d55c4 | ||
![]() |
34e69cd805 | ||
![]() |
c5b9e84486 | ||
![]() |
6dc926f234 | ||
![]() |
12c79b595f | ||
![]() |
893b2360bc | ||
![]() |
29f4ddc0cd | ||
![]() |
43e8486354 | ||
![]() |
482a7a7b4e | ||
![]() |
13488b9839 | ||
![]() |
7fee5aa45d | ||
![]() |
acda91d792 | ||
![]() |
44f6149a23 | ||
![]() |
9d85f8df46 | ||
![]() |
fe22b1ad80 | ||
![]() |
1f663e0b76 | ||
![]() |
64c5c2b4f3 | ||
![]() |
48084b2a5e | ||
![]() |
cf1850923f | ||
![]() |
70c850be2f | ||
![]() |
469a7b4848 | ||
![]() |
c608239ced | ||
![]() |
867c20959a | ||
![]() |
269ff69ec3 | ||
![]() |
3bacc6c1c4 | ||
![]() |
15664781f7 | ||
![]() |
64d10867dd | ||
![]() |
db92197048 | ||
![]() |
68ae7d8428 | ||
![]() |
29b1502e60 | ||
![]() |
fdb1bb6833 | ||
![]() |
6ecbe5ff27 | ||
![]() |
ec430efcc6 |
112 changed files with 4390 additions and 5132 deletions
CMakeLists.txtREADME.md
src
include
access.cc.haccess.hallocator.harith.cc.harith.hbase_def.hbasic_types.hcnorxz.cc.hcnorxz.hcontainer_index.cc.hcontainer_index.hconversions.hcxz_array.cc.hcxz_array.hcxz_array_base.cc.hcxz_array_base.hcxz_assert.hcxz_operation.cc.hcxz_operation.hdynamic_operation.cc.hdynamic_operation.h
extensions
functional_array.cc.hfunctional_array.hfunctional_multi_array.cc.hfunctional_multi_array.hhelper_tools.cc.hhelper_tools.hhigh_level_operation.cc.hhigh_level_operation.hhl_cnorxz.hhl_reg_ind.hmap_range.cc.hmap_range.hmap_range_factory_product_map.hmbase_def.hmulti_array.cc.hmulti_array.hmulti_array_header.cc.hmulti_array_header.hop_expressions.cc.hop_expressions.hoperation_def.hoperation_helper.hpack_num.hranges
anonymous_range.hcontainer_range.hdynamic_meta.hdynamic_range.cc.hdynamic_range.hindex_base.hindex_type.hindex_wrapper.cc.hindex_wrapper.hmulti_range.hmulti_range_factory_product_map.hrange_base.hrange_helper.h
slice.cc.hslice.hrange_types
ranges_header.cc.hrbase_def.hreg_ind_num.hrheader.hrpack_num.cc.hrpack_num.hrpheader.hsingle_range.hsubrange.htype_map.hvalue_range.hx_to_string.hstatics
type_operations.hxfor
lib
|
@ -10,7 +10,7 @@ else()
|
|||
message(WARNING "compiler ${CMAKE_CXX_COMPILER_ID} officially not supported")
|
||||
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 -O0 -march=native -faligned-new -funroll-loops -fopenmp")
|
||||
|
||||
|
|
66
README.md
66
README.md
|
@ -1,15 +1,15 @@
|
|||
# Multi Array Container Library
|
||||
# Container with Native Operation Routines by XZ (CNORXZ)
|
||||
|
||||
## Description
|
||||
|
||||
This library provides a framework for handling multi dimensional containers. This includes the basic container class template `MultiArrayBase` and their derivates, the Range class templates on which the containers are defined, as well as some operation class templates, which allow comfortable calling of operations on the containers.
|
||||
This library provides a framework for handling multi dimensional containers. This includes the basic container class template `ArrayBase` and their derivates, the Range class templates on which the containers are defined, as well as some operation class templates, which allow comfortable calling of operations on the containers.
|
||||
|
||||
## Build instructions
|
||||
|
||||
The library can be installed by the following procedure (`gtest` required):
|
||||
|
||||
```bash
|
||||
git clone git@rqcd.ur.de:czimmermann/multi_array.git <SOURCE_DIR>
|
||||
git clone git@git.f3l.de:chizeta/cnorxz.git <SOURCE_DIR>
|
||||
cd <BUILD_DIR>
|
||||
cmake -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> <SOURCE_DIR>
|
||||
make install
|
||||
|
@ -17,18 +17,18 @@ make install
|
|||
|
||||
## Usage and Examples
|
||||
|
||||
To use the features of the libraries one has to include `multi_array_header.h` and link against the `libmultiarray.so`.
|
||||
The tools of the library are accessible within the namespace `MultiArrayTools`.
|
||||
To use the features of the libraries one has to include `cnorxz.h` and link against the `libcnorxz.so`.
|
||||
The tools of the library are accessible within the namespace `CONORXZ`.
|
||||
|
||||
### Some Terms
|
||||
|
||||
* Ranges: A set of meta data which is mapped onto the linear position. Every container is supposed to be defined on at least one Range. In the simplest case a Range space "containes" the numbers [0,...,rangesize]. Ranges have to be created via the corresponding factory and only exist within a shared pointer. They cannot be copied. The reason is, that every operation performed on the containers, has to identify common sets of ranges, on which the containers are defined. Every range inherits the `RangeBase` class.
|
||||
|
||||
* Indices: They can be thought of as iterators of the range space. In the special case of the `ContainerIndex` it is also an iterator over the corresponding container. The index type must be known at compile time (static polymorphism). Indices on a range can be obtained by `getIndex( range )`. For Container Indices call the `begin()` function of a `MultiArray`. Indices are crucial for defining operations.
|
||||
* Indices: They can be thought of as iterators of the range space. In the special case of the `ContainerIndex` it is also an iterator over the corresponding container. The index type must be known at compile time (static polymorphism). Indices on a range can be obtained by `getIndex( range )`. For Container Indices call the `begin()` function of a `Array`. Indices are crucial for defining operations.
|
||||
|
||||
* `MultiArray<T,Ranges...>`: Contains data of type `T` and is defined on `Ranges...`.
|
||||
* `[Const]Slice<T,Ranges...>`: Views data of type `T` and acts as a MultiArray defined on `Ranges...`.
|
||||
* `FunctionalMultiArray`: Additional template argument indicating the funtion. The value at some position is then defined by the function value obtained from the meta data of the indices/ranges.
|
||||
* `Array<T,Ranges...>`: Contains data of type `T` and is defined on `Ranges...`.
|
||||
* `[Const]Slice<T,Ranges...>`: Views data of type `T` and acts as an Array defined on `Ranges...`.
|
||||
* `FunctionalArray`: Additional template argument indicating the funtion. The value at some position is then defined by the function value obtained from the meta data of the indices/ranges.
|
||||
|
||||
On each of these types one can perform an operation by calling `operator(...)` where within the braces the corresponding indices have to be specified (see example below).
|
||||
|
||||
|
@ -36,16 +36,16 @@ On each of these types one can perform an operation by calling `operator(...)` w
|
|||
|
||||
```c++
|
||||
|
||||
#include "multi_array_header.h"
|
||||
#include "cnorxz.h"
|
||||
|
||||
namespace mat = MultiArrayTools;
|
||||
namespace cnx = CNORXZ;
|
||||
|
||||
typedef mat::SingleRange<double,mat::SpaceType::ANY> DRange;
|
||||
typedef mat::SingleRangeFactory<double,mat::SpaceType::ANY> DRangeF;
|
||||
typedef mat::SingleRange<std::string,mat::SpaceType::ANY> SRange;
|
||||
typedef mat::SingleRangeFactory<std::string,mat::SpaceType::ANY> SRangeF;
|
||||
typedef mat::SingleRange<size_t,mat::SpaceType::NONE> CRange; // also provided as 'ClassicR'
|
||||
typedef mat::SingleRangeFactory<size_t,mat::SpaceType::NONE> CRangeF;
|
||||
typedef cnx::SingleRange<double,cnx::SpaceType::ANY> DRange;
|
||||
typedef cnx::SingleRangeFactory<double,cnx::SpaceType::ANY> DRangeF;
|
||||
typedef cnx::SingleRange<std::string,cnx::SpaceType::ANY> SRange;
|
||||
typedef cnx::SingleRangeFactory<std::string,cnx::SpaceType::ANY> SRangeF;
|
||||
typedef cnx::SingleRange<size_t,cnx::SpaceType::NONE> CRange; // also provided as 'ClassicR'
|
||||
typedef cnx::SingleRangeFactory<size_t,cnx::SpaceType::NONE> CRangeF;
|
||||
|
||||
/*create ranges*/
|
||||
std::vector<double> meta1({...});
|
||||
|
@ -57,13 +57,13 @@ DRangeF drf2(meta2);
|
|||
SRangeF srf(meta3);
|
||||
CRangeF crf(10); // specialized in this case; only size needed.
|
||||
|
||||
auto dr1 = mat::createExplicit( drf1 );
|
||||
auto dr2 = mat::createExplicit( drf2 );
|
||||
auto sr = mat::createExplicit( srf );
|
||||
auto cr = mat::createExplicit( crf );
|
||||
auto dr1 = cnx::createExplicit( drf1 );
|
||||
auto dr2 = cnx::createExplicit( drf2 );
|
||||
auto sr = cnx::createExplicit( srf );
|
||||
auto cr = cnx::createExplicit( crf );
|
||||
|
||||
mat::MultiArray<double,DRange,DRange,SRange,CRange> ma_a(dr1,dr2,sr,cr,0);
|
||||
mat::MultiArray<double,SRange,SRange> ma_b(sr,sr,0);
|
||||
cnx::Array<double,DRange,DRange,SRange,CRange> ma_a(dr1,dr2,sr,cr,0);
|
||||
cnx::Array<double,SRange,SRange> ma_b(sr,sr,0);
|
||||
|
||||
/* assign some values... */
|
||||
double val = 1.;
|
||||
|
@ -75,16 +75,16 @@ for(auto& x: ma_b){
|
|||
x = val /= 2.;
|
||||
}
|
||||
|
||||
mat::FunctionalMultiArray<double,plus<double>,DRange,DRange> fma(dr1,dr2);
|
||||
mat::MultiArray<double,DRange,DRange> res1(dr1,dr2);
|
||||
mat::MultiArray<double,DRange,DRange> res2(dr1,dr2);
|
||||
cnx::FunctionalArray<double,plus<double>,DRange,DRange> fma(dr1,dr2);
|
||||
cnx::Array<double,DRange,DRange> res1(dr1,dr2);
|
||||
cnx::Array<double,DRange,DRange> res2(dr1,dr2);
|
||||
|
||||
/* get indices... */
|
||||
auto i1 = mat::getIndex( dr1 );
|
||||
auto i2 = mat::getIndex( dr2 );
|
||||
auto i3 = mat::getIndex( sr );
|
||||
auto i4 = mat::getIndex( sr );
|
||||
auto i5 = mat::getIndex( cr );
|
||||
auto i1 = cnx::getIndex( dr1 );
|
||||
auto i2 = cnx::getIndex( dr2 );
|
||||
auto i3 = cnx::getIndex( sr );
|
||||
auto i4 = cnx::getIndex( sr );
|
||||
auto i5 = cnx::getIndex( cr );
|
||||
|
||||
i3->at(<metaString>);
|
||||
i5->at(<metaNum>);
|
||||
|
@ -107,7 +107,7 @@ Multithreading can be enabled by the operation class member function `par()`, wh
|
|||
/* Enable multithreading for the loop over i1 */
|
||||
res1(i1,i2).par() = (ma_a(i1,i2,i4,i5) + ma_b(i4,i3)).c(i4);
|
||||
```
|
||||
Caution: If you want to multithread operations over functional multi arrays, you have to make sure by yourself that involved functors are either static or const (const member variables).
|
||||
Caution: If you want to multithread operations over functional arrays, you have to make sure by yourself that involved functors are either static or const (const member variables).
|
||||
|
||||
# Planned features
|
||||
|
||||
|
@ -115,6 +115,6 @@ Basically the structure of the operation routines allows in some cases (at least
|
|||
|
||||
# Known Issues
|
||||
|
||||
I didn't care that much about error handling because of missing time. There it might happen that you declare a `MultiArray` or `Slice` and an operation on it yields a segfault because it was forgotten to instancate the underlying container. Of course, there should be some mechanism, that catches such things, but due to the afore mentioned lack of time, it has not been implemented in every case. If you encounter such problems, pleas tell me, but be aware, that I won't fix it very soon.
|
||||
I didn't care that much about error handling because of missing time. There it might happen that you declare a `Array` or `Slice` and an operation on it yields a segfault because it was forgotten to instancate the underlying container. Of course, there should be some mechanism, that catches such things, but due to the afore mentioned lack of time, it has not been implemented in every case. If you encounter such problems, pleas tell me, but be aware, that I won't fix it very soon.
|
||||
|
||||
There are unit tests, which cover the all crucial parts of this library, but probably not every special case. Hence, there is no warranty, that, if you do something fancy I didn't consider, everything works fine.
|
41
src/include/access.cc.h
Normal file
41
src/include/access.cc.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
|
||||
#include "access.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
/************************
|
||||
* AccessTemplate *
|
||||
************************/
|
||||
|
||||
template <class AccessClass>
|
||||
auto AccessTemplate<AccessClass>::get(size_t pos)
|
||||
{
|
||||
return THIS().get(pos);
|
||||
}
|
||||
|
||||
template <class AccessClass>
|
||||
auto AccessTemplate<AccessClass>::get(size_t pos) const
|
||||
{
|
||||
return THIS().get(pos);
|
||||
}
|
||||
|
||||
template <class AccessClass>
|
||||
auto AccessTemplate<AccessClass>::oget(size_t pos) const
|
||||
{
|
||||
return THIS().oget(pos);
|
||||
}
|
||||
|
||||
template <class AccessClass>
|
||||
template <class F, typename Op, class ExtType>
|
||||
void AccessTemplate<AccessClass>::exec(size_t pos, const Op& op, ExtType e) const
|
||||
{
|
||||
return THIS().template exec<F>(pos,op,e);
|
||||
}
|
||||
|
||||
|
||||
} // namespace CNORXZ
|
173
src/include/access.h
Normal file
173
src/include/access.h
Normal file
|
@ -0,0 +1,173 @@
|
|||
|
||||
#ifndef __cxz_access_h__
|
||||
#define __cxz_access_h__
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
struct VType
|
||||
{
|
||||
typedef T type;
|
||||
static constexpr size_t MULT = sizeof(type)/sizeof(T);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VType<double>
|
||||
{
|
||||
typedef v256 type;
|
||||
static constexpr size_t MULT = sizeof(type)/sizeof(double);
|
||||
};
|
||||
|
||||
template <template <typename...> class F,typename... Ts>
|
||||
inline auto mkVFuncPtr(const std::shared_ptr<F<Ts...>>& f)
|
||||
{
|
||||
return std::shared_ptr<F<typename VType<Ts>::type...>>();
|
||||
// empty, implement corresponding constructors...!!!
|
||||
}
|
||||
|
||||
template <template <typename...> class F,typename... Ts>
|
||||
inline auto mkVFunc(const F<Ts...>& f)
|
||||
{
|
||||
return F<typename VType<Ts>::type...>();
|
||||
// empty, implement corresponding constructors...!!!
|
||||
}
|
||||
|
||||
|
||||
template <class F>
|
||||
using VFunc = decltype(mkVFunc(std::declval<F>()));
|
||||
|
||||
//template <class F>
|
||||
//using VFunc = F;
|
||||
|
||||
template <typename T, class F, class... Indices>
|
||||
class OpAccess
|
||||
{
|
||||
private:
|
||||
std::tuple<std::shared_ptr<Indices>...> mInds;
|
||||
|
||||
public:
|
||||
static constexpr bool ISSTATIC = false;
|
||||
|
||||
template <typename Op, class ExtType>
|
||||
inline void operator()(T*& t, size_t pos, const Op& op, ExtType e)
|
||||
{
|
||||
F::selfApply(t[pos](mInds), op.get(e)); // s.th. like that
|
||||
// TODO for classes related to the r.h.s.:
|
||||
// forward get(e) to elements returned by get(e) until basic types are reached
|
||||
// (also same for rootSteps etc...) !!!!
|
||||
// introduce traits !!!!
|
||||
// !!!!
|
||||
}
|
||||
};
|
||||
|
||||
// static polymorphism
|
||||
template <class AccessClass>
|
||||
class AccessTemplate
|
||||
{
|
||||
public:
|
||||
typedef AccessClass AC;
|
||||
|
||||
AccessTemplate(const AccessTemplate& in) = default;
|
||||
AccessTemplate(AccessTemplate&& in) = default;
|
||||
AccessTemplate& operator=(const AccessTemplate& in) = default;
|
||||
AccessTemplate& operator=(AccessTemplate&& in) = default;
|
||||
|
||||
AccessClass& THIS() { return static_cast<AccessClass&>(*this); }
|
||||
const AccessClass& THIS() const { return static_cast<const AccessClass&>(*this); }
|
||||
|
||||
inline auto get(size_t pos);
|
||||
inline auto get(size_t pos) const;
|
||||
inline auto oget(size_t pos) const;
|
||||
|
||||
template <class F, typename Op, class ExtType>
|
||||
inline void exec(size_t pos, const Op& op, ExtType e) const;
|
||||
|
||||
protected:
|
||||
AccessTemplate() = default;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class PointerAccess : public AccessTemplate<PointerAccess<T>>
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef T in_type;
|
||||
|
||||
static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type);
|
||||
|
||||
friend class AccessTemplate<PointerAccess<T>>;
|
||||
private:
|
||||
PointerAccess() = default;
|
||||
|
||||
T* mPtr = nullptr;
|
||||
T* mOrigPtr = nullptr;
|
||||
|
||||
public:
|
||||
PointerAccess(T* ptr, T* origPtr) : mPtr(ptr), mOrigPtr(origPtr) {}
|
||||
|
||||
PointerAccess(const PointerAccess& in) = default;
|
||||
PointerAccess(PointerAccess&& in) = default;
|
||||
PointerAccess& operator=(const PointerAccess& in) = default;
|
||||
PointerAccess& operator=(PointerAccess&& in) = default;
|
||||
|
||||
T* get(size_t pos) { return mPtr+pos; }
|
||||
T* get(size_t pos) const { return mPtr+pos; }
|
||||
PointerAccess<T>& set(size_t pos) { mPtr = mOrigPtr + pos; return *this; }
|
||||
T* oget(size_t pos) const { return mOrigPtr+pos; }
|
||||
|
||||
template <class F, typename Op, class ExtType>
|
||||
inline void exec(size_t pos, const Op& op, ExtType e) const
|
||||
{
|
||||
F::selfApply(*get(pos),op.get(e));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class VPointerAccess : public AccessTemplate<VPointerAccess<T>>
|
||||
{
|
||||
public:
|
||||
typedef typename VType<T>::type value_type;
|
||||
typedef T in_type;
|
||||
|
||||
static constexpr size_t VSIZE = sizeof(value_type) / sizeof(in_type);
|
||||
|
||||
friend class AccessTemplate<VPointerAccess<T>>;
|
||||
private:
|
||||
VPointerAccess() = default;
|
||||
|
||||
T* mPtr = nullptr;
|
||||
T* mOrigPtr = nullptr;
|
||||
|
||||
public:
|
||||
VPointerAccess(T* ptr, T* origPtr) : mPtr(ptr), mOrigPtr(origPtr) {}
|
||||
|
||||
VPointerAccess(const PointerAccess<T>& in) : mPtr(in.get(0)), mOrigPtr(in.oget(0)) {}
|
||||
|
||||
VPointerAccess(const VPointerAccess& in) = default;
|
||||
VPointerAccess(VPointerAccess&& in) = default;
|
||||
VPointerAccess& operator=(const VPointerAccess& in) = default;
|
||||
VPointerAccess& operator=(VPointerAccess&& in) = default;
|
||||
|
||||
value_type* get(size_t pos) { return reinterpret_cast<value_type*>(mPtr+pos); }
|
||||
value_type* get(size_t pos) const { return reinterpret_cast<value_type*>(mPtr+pos); }
|
||||
VPointerAccess<T>& set(size_t pos) { mPtr = mOrigPtr + pos; return *this; }
|
||||
value_type* oget(size_t pos) const { return reinterpret_cast<value_type*>(mOrigPtr+pos); }
|
||||
|
||||
template <class F, typename Op, class ExtType>
|
||||
inline void exec(size_t pos, const Op& op, ExtType e) const
|
||||
{
|
||||
F::selfApply(*get(pos),op.template vget<value_type>(e));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __ma_allocator__
|
||||
#define __ma_allocator__
|
||||
#ifndef __cxz_allocator__
|
||||
#define __cxz_allocator__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
@ -12,7 +12,7 @@
|
|||
#define MIB_SIZE 1024*1024 // 1MiB
|
||||
#define WARN_SIZE MIB_SIZE*100 // 100 MiB
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
|
@ -65,12 +65,12 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
|
||||
} // namespace MultiArrayHelper
|
||||
} // namespace CNORXZInternal
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T>
|
||||
using vector = std::vector<T,MultiArrayHelper::Allocator<T>>;
|
||||
using vector = std::vector<T,CNORXZInternal::Allocator<T>>;
|
||||
|
||||
template <typename T>
|
||||
inline std::vector<T> toStdVec(const vector<T>& v)
|
||||
|
@ -84,6 +84,6 @@ namespace MultiArrayTools
|
|||
return vector<T>(v.begin(), v.end());
|
||||
}
|
||||
|
||||
} // namespace MultiArrayTools
|
||||
} // namespace CNORXZ
|
||||
|
||||
#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__
|
||||
#define __arith_h__
|
||||
#ifndef __cxz_arith_h__
|
||||
#define __cxz_arith_h__
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <size_t N>
|
||||
struct ArgPack
|
||||
{
|
||||
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>
|
||||
//template <typename T, class F, typename... As>
|
||||
template <class F>
|
||||
struct StaticFunctionBase
|
||||
{
|
||||
static constexpr bool FISSTATIC = true;
|
||||
typedef T value_type;
|
||||
|
||||
template <class... Ops>
|
||||
static auto mk(const Ops&... ops)
|
||||
-> Operation<T,F,Ops...>
|
||||
{
|
||||
return Operation<T,F,Ops...>(ops...);
|
||||
}
|
||||
typedef F function;
|
||||
//typedef typename F::value_type value_type;
|
||||
|
||||
static inline T apply(const std::tuple<As...>& arg)
|
||||
{
|
||||
return ArgPack<sizeof...(As)-1>::template mk<F,std::tuple<As...> >(arg);
|
||||
}
|
||||
template <class... Ops>
|
||||
static auto mk(const Ops&... ops);
|
||||
|
||||
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)
|
||||
template <typename T>
|
||||
struct identity : public StaticFunctionBase<T, identity<T>, T>
|
||||
struct identity : public StaticFunctionBase<identity<T>>
|
||||
{
|
||||
//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)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline T selfApply(T& a1, const T& a2)
|
||||
{
|
||||
return a1 = a2;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
|
@ -89,12 +58,13 @@ namespace MultiArrayTools
|
|||
using dividesv = decltype(std::declval<T>()/std::declval<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;
|
||||
using StaticFunctionBase<plusv<T,U>, plusx<T,U>, T, U>::apply;
|
||||
|
||||
static inline plusv<T,U> apply(T a1, U a2)
|
||||
using StaticFunctionBase<plusx<T,U>>::apply;
|
||||
typedef plusv<T,U> value_type;
|
||||
|
||||
static inline value_type apply(T a1, U a2)
|
||||
{
|
||||
return a1 + a2;
|
||||
}
|
||||
|
@ -106,36 +76,39 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
@ -143,11 +116,12 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct negate : public StaticFunctionBase<T, negate<T>, T>
|
||||
struct negate : public StaticFunctionBase<negate<T>>
|
||||
{
|
||||
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)
|
||||
{
|
||||
return -a;
|
||||
|
@ -167,60 +141,6 @@ namespace MultiArrayTools
|
|||
template <typename 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)
|
||||
template <typename R, typename... Args>
|
||||
class function
|
||||
|
@ -241,16 +161,28 @@ namespace MultiArrayTools
|
|||
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)
|
||||
{
|
||||
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>
|
||||
#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;\
|
||||
typedef T value_type; \
|
||||
static inline T apply(T a){\
|
||||
return fff(a); } };
|
||||
|
||||
|
@ -265,35 +197,17 @@ namespace MultiArrayTools
|
|||
template <typename T>
|
||||
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 <>
|
||||
struct x_ipow<0>
|
||||
{
|
||||
static constexpr bool FISSTATIC = true;
|
||||
} // end namespace CNORXZInternal
|
||||
|
||||
#include "arith.cc.h"
|
||||
|
||||
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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __base_def_h__
|
||||
#define __base_def_h__
|
||||
#ifndef __cxz_base_def_h__
|
||||
#define __cxz_base_def_h__
|
||||
|
||||
#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
|
17
src/include/cnorxz.cc.h
Normal file
17
src/include/cnorxz.cc.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
#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 "access.cc.h"
|
||||
#include "op_expressions.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
|
306
src/include/container_index.h
Normal file
306
src/include/container_index.h
Normal file
|
@ -0,0 +1,306 @@
|
|||
// -*- 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:
|
||||
|
||||
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__
|
||||
#define __ma_conversions_h__
|
||||
#ifndef __cxz_conversions_h__
|
||||
#define __cxz_conversions_h__
|
||||
|
||||
#include "multi_array.h"
|
||||
#include "cxz_array.h"
|
||||
#include "slice.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
namespace ConversionSizes
|
||||
|
@ -94,7 +94,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename C, typename T, class... Ranges>
|
||||
auto tcast(MultiArray<T,Ranges...>& ma)
|
||||
auto tcast(Array<T,Ranges...>& ma)
|
||||
-> decltype(rangeTpToSlice
|
||||
( rtcast<C,T>( ma.range()->space() ),
|
||||
reinterpret_cast<C*>( ma.data() ) ))
|
||||
|
@ -107,7 +107,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename C, typename T, class... Ranges>
|
||||
auto tcast(const MultiArray<T,Ranges...>& ma)
|
||||
auto tcast(const Array<T,Ranges...>& ma)
|
||||
-> decltype(rangeTpToSlice
|
||||
( rtcast<C,T>( ma.range()->space() ),
|
||||
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>
|
||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(const MultiArrayBase& in) :
|
||||
ArrayBase<T,SRanges...>::ArrayBase(const ArrayBase& in) :
|
||||
mInit(in.mInit),
|
||||
mRange(in.mRange)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ namespace MultiArrayTools
|
|||
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
MultiArrayBase<T,SRanges...>::MultiArrayBase(MultiArrayBase&& in) :
|
||||
ArrayBase<T,SRanges...>::ArrayBase(ArrayBase&& in) :
|
||||
mInit(in.mInit),
|
||||
mRange(in.mRange)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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;
|
||||
mRange = in.mRange;
|
||||
|
@ -41,7 +41,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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;
|
||||
mRange = in.mRange;
|
||||
|
@ -52,24 +52,24 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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...);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
|
||||
ContainerRangeFactory<SRanges...> crf(ranges...);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
||||
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
||||
}
|
||||
|
||||
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);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<T,SRanges...> >( crf.create() );
|
||||
ContainerRangeFactory<SRanges...> crf(space);
|
||||
mRange = std::dynamic_pointer_cast<ContainerRange<SRanges...> >( crf.create() );
|
||||
mProtoI = std::make_shared<IndexType>( mRange, reinterpret_cast<std::intptr_t>(this) );
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
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);
|
||||
ii = i;
|
||||
|
@ -77,7 +77,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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);
|
||||
ii(is);
|
||||
|
@ -85,70 +85,62 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
size_t MultiArrayBase<T,SRanges...>::size() const
|
||||
size_t ArrayBase<T,SRanges...>::size() const
|
||||
{
|
||||
return mRange->size();
|
||||
}
|
||||
|
||||
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;
|
||||
return i.setData(data());
|
||||
}
|
||||
|
||||
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 = 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());
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
typename MultiArrayBase<T,SRanges...>::IndexType
|
||||
MultiArrayBase<T,SRanges...>::endIndex() 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
|
||||
const std::shared_ptr<typename ArrayBase<T,SRanges...>::CRange>&
|
||||
ArrayBase<T,SRanges...>::range() const
|
||||
{
|
||||
return mRange;
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::isConst() const
|
||||
bool ArrayBase<T,SRanges...>::isConst() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, class... 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...);
|
||||
}
|
||||
|
||||
template <typename T, class... 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);
|
||||
}
|
||||
|
@ -156,7 +148,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
template <class... 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),
|
||||
"number of mapped ranges must be equal to number of original ranges");
|
||||
|
@ -164,14 +156,14 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
bool MultiArrayBase<T,SRanges...>::isInit() const
|
||||
bool ArrayBase<T,SRanges...>::isInit() const
|
||||
{
|
||||
return mInit;
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
template <size_t N>
|
||||
auto MultiArrayBase<T,SRanges...>::getRangePtr() const
|
||||
auto ArrayBase<T,SRanges...>::getRangePtr() const
|
||||
-> decltype(mRange->template getPtr<N>())
|
||||
{
|
||||
return mRange->template getPtr<N>();
|
||||
|
@ -179,35 +171,20 @@ namespace MultiArrayTools
|
|||
|
||||
|
||||
/******************************
|
||||
* MutableMultiArrayBase *
|
||||
* MutableArrayBase *
|
||||
******************************/
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
MutableMultiArrayBase<T,SRanges...>::MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges) :
|
||||
MultiArrayBase<T,SRanges...>(ranges...) {}
|
||||
MutableArrayBase<T,SRanges...>::MutableArrayBase(const std::shared_ptr<SRanges>&... ranges) :
|
||||
ArrayBase<T,SRanges...>(ranges...) {}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
MutableMultiArrayBase<T,SRanges...>::MutableMultiArrayBase(const typename CRange::Space& space) :
|
||||
MultiArrayBase<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());
|
||||
}
|
||||
*/
|
||||
MutableArrayBase<T,SRanges...>::MutableArrayBase(const typename CRange::Space& space) :
|
||||
ArrayBase<T,SRanges...>(space) {}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
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);
|
||||
ii = i;
|
||||
|
@ -215,44 +192,60 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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);
|
||||
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>
|
||||
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;
|
||||
}
|
||||
|
||||
template <typename T, class... 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...);
|
||||
}
|
||||
|
||||
template <typename T, class... 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);
|
||||
}
|
||||
|
||||
template <typename T, class... 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...);
|
||||
}
|
||||
|
||||
template <typename T, class... 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);
|
||||
}
|
||||
|
@ -260,7 +253,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
template <class... 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),
|
||||
"number of mapped ranges must be equal to number of original ranges");
|
||||
|
@ -270,12 +263,12 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
template <class... 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),
|
||||
"number of mapped ranges must be equal to number of original ranges");
|
||||
return ConstOperationRoot<T,MappedRanges...>(*this, inds...);
|
||||
}
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
} // end namespace CNORXZ
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
|
||||
#ifndef __multi_array_base_h__
|
||||
#define __multi_array_base_h__
|
||||
#ifndef __cxz_array_base_h__
|
||||
#define __cxz_array_base_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
||||
#include "base_def.h"
|
||||
|
@ -13,7 +12,7 @@
|
|||
|
||||
#include "ranges/rheader.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <class IndexType>
|
||||
|
@ -51,38 +50,39 @@ namespace MultiArrayTools
|
|||
|
||||
// Explicitely specify subranges in template argument !!!
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArrayBase
|
||||
class ArrayBase
|
||||
{
|
||||
public:
|
||||
|
||||
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;
|
||||
|
||||
protected:
|
||||
bool mInit = false;
|
||||
std::shared_ptr<CRange> mRange;
|
||||
std::shared_ptr<IndexType> mProtoI;
|
||||
std::shared_ptr<CIndexType> mProtoI;
|
||||
|
||||
public:
|
||||
|
||||
//DEFAULT_MEMBERS(MultiArrayBase);
|
||||
MultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||
MultiArrayBase(const typename CRange::Space& space);
|
||||
//DEFAULT_MEMBERS(ArrayBase);
|
||||
ArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||
ArrayBase(const typename CRange::Space& space);
|
||||
|
||||
MultiArrayBase() = default;
|
||||
MultiArrayBase(const MultiArrayBase& in);
|
||||
MultiArrayBase(MultiArrayBase&& in);
|
||||
MultiArrayBase& operator=(const MultiArrayBase& in);
|
||||
MultiArrayBase& operator=(MultiArrayBase&& in);
|
||||
ArrayBase() = default;
|
||||
ArrayBase(const ArrayBase& in);
|
||||
ArrayBase(ArrayBase&& in);
|
||||
ArrayBase& operator=(const ArrayBase& in);
|
||||
ArrayBase& operator=(ArrayBase&& in);
|
||||
|
||||
virtual ~MultiArrayBase() = default;
|
||||
virtual ~ArrayBase() = default;
|
||||
|
||||
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;
|
||||
|
||||
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* data() const = 0;
|
||||
|
@ -90,20 +90,19 @@ namespace MultiArrayTools
|
|||
virtual size_t size() const;
|
||||
virtual bool isSlice() const = 0;
|
||||
|
||||
virtual IndexType begin() const;
|
||||
virtual IndexType end() const;
|
||||
virtual CIndexType begin() 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 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...>
|
||||
op(const std::shared_ptr<IndexType>& ind) const;
|
||||
op(const std::shared_ptr<CIndexType>& ind) const;
|
||||
|
||||
virtual ConstOperationRoot<T,SRanges...>
|
||||
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const;
|
||||
|
@ -121,48 +120,49 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
class MutableMultiArrayBase : public MultiArrayBase<T,SRanges...>
|
||||
class MutableArrayBase : public ArrayBase<T,SRanges...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ContainerRange<T,SRanges...> CRange;
|
||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef ArrayBase<T,SRanges...> MAB;
|
||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IndexType;
|
||||
typedef ConstContainerIndex<T,typename SRanges::IndexType...> CIndexType;
|
||||
|
||||
using MultiArrayBase<T,SRanges...>::operator[];
|
||||
using MultiArrayBase<T,SRanges...>::at;
|
||||
using MultiArrayBase<T,SRanges...>::data;
|
||||
using MultiArrayBase<T,SRanges...>::begin;
|
||||
using MultiArrayBase<T,SRanges...>::end;
|
||||
using ArrayBase<T,SRanges...>::operator[];
|
||||
using ArrayBase<T,SRanges...>::at;
|
||||
using ArrayBase<T,SRanges...>::data;
|
||||
using ArrayBase<T,SRanges...>::begin;
|
||||
using ArrayBase<T,SRanges...>::end;
|
||||
using ArrayBase<T,SRanges...>::cbegin;
|
||||
using ArrayBase<T,SRanges...>::cend;
|
||||
|
||||
DEFAULT_MEMBERS(MutableMultiArrayBase);
|
||||
MutableMultiArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||
MutableMultiArrayBase(const typename CRange::Space& space);
|
||||
DEFAULT_MEMBERS(MutableArrayBase);
|
||||
MutableArrayBase(const std::shared_ptr<SRanges>&... ranges);
|
||||
MutableArrayBase(const typename CRange::Space& space);
|
||||
|
||||
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);
|
||||
|
||||
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* data() = 0;
|
||||
|
||||
//virtual IndexType begin();
|
||||
//virtual IndexType end();
|
||||
virtual IndexType begin();
|
||||
virtual IndexType end();
|
||||
|
||||
virtual bool isConst() const override;
|
||||
|
||||
//virtual std::shared_ptr<MultiArrayBase<T,AnonymousRange> > anonymousMove() = 0;
|
||||
|
||||
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...>
|
||||
operator()(const std::shared_ptr<typename SRanges::IndexType>&... inds) const override;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -177,7 +177,7 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
} // end namespace CNORXZ
|
||||
|
||||
/* ========================= *
|
||||
* --- TEMPLATE CODE --- *
|
File diff suppressed because it is too large
Load diff
|
@ -1,30 +1,34 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __multi_array_operation_h__
|
||||
#define __multi_array_operation_h__
|
||||
#ifndef __cxz_operation_h__
|
||||
#define __cxz_operation_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
#include "base_def.h"
|
||||
#include "mbase_def.h"
|
||||
|
||||
#include "ranges/rheader.h"
|
||||
#include "pack_num.h"
|
||||
|
||||
#include "arith.h"
|
||||
|
||||
#include "xfor/xfor.h"
|
||||
#include "type_operations.h"
|
||||
#include "op_expressions.h"
|
||||
#include "access.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
#include "statics/static_for.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
template <typename T, class OperationClass>
|
||||
|
@ -48,43 +52,30 @@ namespace MultiArrayTools
|
|||
auto operator/(const OperationBase<U,Second>& in) const;
|
||||
|
||||
template <class IndexType>
|
||||
auto c(const std::shared_ptr<IndexType>& ind) const
|
||||
-> Contraction<T,OperationClass,IndexType>;
|
||||
auto c(const std::shared_ptr<IndexType>& ind) const;
|
||||
|
||||
template <class... Indices>
|
||||
auto sl(const std::shared_ptr<Indices>&... inds) const
|
||||
-> ConstSlice<T,typename Indices::RangeType...>;
|
||||
auto sl(const std::shared_ptr<Indices>&... inds) const;
|
||||
|
||||
template <class... Indices>
|
||||
auto slc(const std::shared_ptr<Indices>&... inds) const
|
||||
-> SliceContraction<T,OperationClass,Indices...>;
|
||||
auto p(const std::shared_ptr<Indices>&... inds) const;
|
||||
|
||||
template <class... Indices>
|
||||
auto p(const std::shared_ptr<Indices>&... inds) const
|
||||
-> ConstOperationRoot<T,typename Indices::RangeType...>;
|
||||
|
||||
template <class... Indices>
|
||||
auto to(const std::shared_ptr<Indices>&... inds) const
|
||||
-> MultiArray<T,typename Indices::RangeType...>;
|
||||
auto to(const std::shared_ptr<Indices>&... inds) const;
|
||||
|
||||
template <class... Indices>
|
||||
auto addto(const std::shared_ptr<Indices>&... inds) const
|
||||
-> MultiArray<T,typename Indices::RangeType...>;
|
||||
auto addto(const std::shared_ptr<Indices>&... inds) const;
|
||||
|
||||
template <class... Indices>
|
||||
auto pto(const std::shared_ptr<Indices>&... inds) const
|
||||
-> MultiArray<T,typename Indices::RangeType...>;
|
||||
auto pto(const std::shared_ptr<Indices>&... inds) const;
|
||||
|
||||
template <class... Indices>
|
||||
auto paddto(const std::shared_ptr<Indices>&... inds) const
|
||||
-> MultiArray<T,typename Indices::RangeType...>;
|
||||
auto paddto(const std::shared_ptr<Indices>&... inds) const;
|
||||
|
||||
template <typename R, class... Args> // Args = Operation Classes
|
||||
auto a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll, const Args&... args) const
|
||||
-> Operation<R,function<R,T,typename Args::value_type...>,OperationClass, Args...>;
|
||||
auto a(const std::shared_ptr<function<R,T,typename Args::value_type...>>& ll, const Args&... args) const;
|
||||
|
||||
auto ptr() const
|
||||
-> OperationPointer<T,OperationClass>;
|
||||
auto ptr() const;
|
||||
|
||||
private:
|
||||
friend OperationClass;
|
||||
|
@ -101,97 +92,6 @@ namespace MultiArrayTools
|
|||
friend OperationClass;
|
||||
};
|
||||
|
||||
template <class Op>
|
||||
size_t sumRootNum()
|
||||
{
|
||||
return typename Op::rootNum();
|
||||
}
|
||||
|
||||
template <class Op1, class Op2, class... Ops>
|
||||
size_t sumRootNum()
|
||||
{
|
||||
return typename Op1::rootNum() + sumRootNum<Op2,Ops...>();
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
struct RootSumN
|
||||
{
|
||||
template <class Op1, class... Ops>
|
||||
struct rs
|
||||
{
|
||||
static constexpr size_t SIZE = Op1::SIZE + RootSumN<N-1>::template rs<Ops...>::SIZE;
|
||||
};
|
||||
|
||||
template <class... Exprs>
|
||||
static inline auto rootSteps(const std::tuple<Exprs...>& etp, std::intptr_t i)
|
||||
{
|
||||
return RootSumN<N-1>::rootSteps(etp,i).extend( std::get<N>(etp).rootSteps(i) );
|
||||
}
|
||||
|
||||
template <class ExtType, class... Exprs>
|
||||
static inline void exec( size_t start, ExtType last, std::tuple<Exprs...>& etp)
|
||||
{
|
||||
std::get<sizeof...(Exprs)-N-1>(etp)(start,last);
|
||||
RootSumN<N-1>::exec(start,last.next(),etp);
|
||||
}
|
||||
|
||||
template <class ExtType, class... Exprs>
|
||||
static inline size_t get( ExtType last, const std::tuple<Exprs...>& etp)
|
||||
{
|
||||
std::get<sizeof...(Exprs)-N-1>(etp).get(last);
|
||||
return RootSumN<N-1>::get(last.next(),etp);
|
||||
}
|
||||
|
||||
template <class ExtType, class... Exprs>
|
||||
static inline void set( ExtType last, std::tuple<Exprs...>& etp)
|
||||
{
|
||||
std::get<sizeof...(Exprs)-N-1>(etp).set(last);
|
||||
RootSumN<N-1>::set(last.next(),etp);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RootSumN<0>
|
||||
{
|
||||
template <class Op1>
|
||||
struct rs
|
||||
{
|
||||
static constexpr size_t SIZE = Op1::SIZE;
|
||||
};
|
||||
|
||||
template <class... Exprs>
|
||||
static inline auto rootSteps(const std::tuple<Exprs...>& etp, std::intptr_t i)
|
||||
{
|
||||
return std::get<0>(etp).rootSteps(i);
|
||||
}
|
||||
|
||||
template <class ExtType, class... Exprs>
|
||||
static inline void exec( size_t start, ExtType last, std::tuple<Exprs...>& etp)
|
||||
{
|
||||
std::get<sizeof...(Exprs)-1>(etp)(start,last);
|
||||
}
|
||||
|
||||
template <class ExtType, class... Exprs>
|
||||
static inline size_t get( ExtType last, const std::tuple<Exprs...>& etp)
|
||||
{
|
||||
std::get<sizeof...(Exprs)-1>(etp).get(last);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class ExtType, class... Exprs>
|
||||
static inline void set( ExtType last, std::tuple<Exprs...>& etp)
|
||||
{
|
||||
std::get<sizeof...(Exprs)-1>(etp).set(last);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class... Ops>
|
||||
struct RootSum
|
||||
{
|
||||
static constexpr size_t SIZE = RootSumN<sizeof...(Ops)-1>::template rs<Ops...>::SIZE;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct SelfIdentity
|
||||
|
@ -202,60 +102,36 @@ namespace MultiArrayTools
|
|||
}
|
||||
};
|
||||
|
||||
enum class OpIndexAff {
|
||||
EXTERN = 0,
|
||||
TARGET = 1
|
||||
};
|
||||
|
||||
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
|
||||
class AssignmentExpr2 : public ExpressionBase
|
||||
|
||||
template <class... Ops>
|
||||
struct OperationTuple
|
||||
{
|
||||
private:
|
||||
AssignmentExpr2() = default;
|
||||
|
||||
Target mTar;
|
||||
OpClass mSec;
|
||||
T* mDataPtr;
|
||||
|
||||
public:
|
||||
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE;
|
||||
typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType;
|
||||
|
||||
AssignmentExpr2(T* dataPtr, const Target& tar, const OpClass& sec);
|
||||
AssignmentExpr2(const AssignmentExpr2& in) = default;
|
||||
AssignmentExpr2(AssignmentExpr2&& in) = default;
|
||||
AssignmentExpr2& operator=(const AssignmentExpr2& in) = default;
|
||||
AssignmentExpr2& operator=(AssignmentExpr2&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<AssignmentExpr2<T,Target,OpClass,OIA>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
|
||||
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||
inline DExt dExtension() const override final;
|
||||
OperationTuple(const Ops&... ops) : mOps(ops...) {}
|
||||
std::tuple<Ops...> mOps;
|
||||
auto rootSteps(std::intptr_t iPtrNum) const;
|
||||
};
|
||||
|
||||
template <class... Ops>
|
||||
auto OperationTuple<Ops...>::rootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return sfor_p<0,sizeof...(Ops)>
|
||||
( [&](auto i){ return std::get<i>(mOps).rootSteps(iPtrNum); },
|
||||
[&](auto f, auto next) { return f.extend(next); } );
|
||||
}
|
||||
|
||||
template <typename T, class... Ops>
|
||||
class MOp
|
||||
{
|
||||
private:
|
||||
MOp() = default;
|
||||
std::tuple<Ops...> mOps;
|
||||
|
||||
OperationTuple<Ops...> mOps;
|
||||
|
||||
public:
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t SIZE = RootSum<Ops...>::SIZE;
|
||||
typedef decltype(RootSumN<sizeof...(Ops)-1>::rootSteps(mOps,0) ) ExtType;
|
||||
|
||||
static constexpr size_t NHLAYER = 0;
|
||||
static constexpr size_t SIZE = (... + Ops::SIZE);
|
||||
typedef decltype(mOps.rootSteps(0)) ExtType;
|
||||
|
||||
MOp(const Ops&... exprs);
|
||||
|
||||
MOp(const MOp& in) = default;
|
||||
|
@ -264,12 +140,15 @@ namespace MultiArrayTools
|
|||
MOp& operator=(MOp&& in) = default;
|
||||
|
||||
inline size_t get(ExtType last) const;
|
||||
|
||||
template <typename V>
|
||||
inline size_t vget(ExtType last) const { return get(last); }
|
||||
|
||||
inline MOp& set(ExtType last);
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
|
||||
template <class Expr>
|
||||
auto loop(Expr exp) const
|
||||
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp));
|
||||
auto loop(Expr exp) const;
|
||||
|
||||
T* data() const { assert(0); return nullptr; }
|
||||
|
||||
|
@ -288,6 +167,7 @@ namespace MultiArrayTools
|
|||
public:
|
||||
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t NHLAYER = 0;
|
||||
static constexpr size_t SIZE = OpClass::SIZE + NextExpr::SIZE;
|
||||
typedef decltype(mSec.rootSteps(0).extend( mNExpr.rootSteps(0) ) ) ExtType;
|
||||
|
||||
|
@ -304,6 +184,10 @@ namespace MultiArrayTools
|
|||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void get(ExtType last);
|
||||
|
||||
template <typename V>
|
||||
inline void vget(ExtType last) { get(last); }
|
||||
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
|
||||
|
@ -325,48 +209,6 @@ namespace MultiArrayTools
|
|||
return MOp<T,Ops...>(exprs...);
|
||||
}
|
||||
|
||||
//template <typename T, class OpClass>
|
||||
template <typename T, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
|
||||
class AddExpr : public ExpressionBase
|
||||
{
|
||||
private:
|
||||
AddExpr() = default;
|
||||
|
||||
Target mTar;
|
||||
OpClass mSec;
|
||||
T* mDataPtr;
|
||||
|
||||
public:
|
||||
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE;
|
||||
typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType;
|
||||
// static constexpr size_t LAYER = 0;
|
||||
//static constexpr size_t SIZE = OpClass::SIZE;
|
||||
//typedef decltype(mSec.rootSteps()) ExtType;
|
||||
|
||||
//AddExpr(T* dataPtr, const OpClass& sec);
|
||||
AddExpr(T* dataPtr, const Target& tar, const OpClass& sec);
|
||||
AddExpr(const AddExpr& in) = default;
|
||||
AddExpr(AddExpr&& in) = default;
|
||||
AddExpr& operator=(const AddExpr& in) = default;
|
||||
AddExpr& operator=(AddExpr&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<AddExpr<T,Target,OpClass,OIA>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
|
||||
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||
inline DExt dExtension() const override final;
|
||||
};
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
class ConstOperationRoot : public OperationTemplate<T,ConstOperationRoot<T,Ranges...> >
|
||||
{
|
||||
|
@ -374,16 +216,17 @@ namespace MultiArrayTools
|
|||
|
||||
typedef T value_type;
|
||||
typedef OperationBase<T,ConstOperationRoot<T,Ranges...> > OT;
|
||||
typedef ContainerRange<T,Ranges...> CRange;
|
||||
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef ConstContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
|
||||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool CONT = true;
|
||||
static constexpr bool VABLE = true;
|
||||
|
||||
ConstOperationRoot(const MultiArrayBase<T,Ranges...>& ma,
|
||||
ConstOperationRoot(const ArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
ConstOperationRoot(std::shared_ptr<MultiArrayBase<T,Ranges...> > maptr,
|
||||
ConstOperationRoot(std::shared_ptr<ArrayBase<T,Ranges...> > maptr,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
ConstOperationRoot(const T* data, const IndexType& ind);
|
||||
|
@ -391,6 +234,9 @@ namespace MultiArrayTools
|
|||
template <class ET>
|
||||
inline const T& get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline const V& vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline ConstOperationRoot& set(ET pos);
|
||||
|
||||
|
@ -406,7 +252,7 @@ namespace MultiArrayTools
|
|||
const T* mDataPtr;
|
||||
const T* mOrigDataPtr;
|
||||
IndexType mIndex;
|
||||
std::shared_ptr<MultiArrayBase<T,Ranges...> > mMaPtr; // never remove this ptr, otherwise we lose temporary container instances!
|
||||
std::shared_ptr<ArrayBase<T,Ranges...> > mMaPtr; // never remove this ptr, otherwise we lose temporary container instances!
|
||||
};
|
||||
|
||||
template <typename T, class Op>
|
||||
|
@ -424,12 +270,16 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr size_t SIZE = Op::SIZE;
|
||||
static constexpr bool CONT = false;
|
||||
static constexpr bool VABLE = false;
|
||||
|
||||
StaticCast(const Op& op);
|
||||
|
||||
template <class ET>
|
||||
inline T get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline V vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline StaticCast& set(ET pos);
|
||||
|
||||
|
@ -459,12 +309,16 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool CONT = false;
|
||||
static constexpr bool VABLE = false;
|
||||
|
||||
MetaOperationRoot(const std::shared_ptr<IndexType>& ind);
|
||||
|
||||
template <class ET>
|
||||
inline value_type get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline V vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline MetaOperationRoot& set(ET pos);
|
||||
|
||||
|
@ -486,50 +340,52 @@ namespace MultiArrayTools
|
|||
|
||||
typedef T value_type;
|
||||
typedef OperationBase<T,OperationRoot<T,Ranges...> > OT;
|
||||
typedef ContainerRange<T,Ranges...> CRange;
|
||||
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef ConstContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
|
||||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool CONT = true;
|
||||
static constexpr bool VABLE = true;
|
||||
|
||||
private:
|
||||
|
||||
T* mDataPtr;
|
||||
T* mOrigDataPtr;
|
||||
PointerAccess<T> mDataAcc;
|
||||
IndexType mIndex;
|
||||
|
||||
public:
|
||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
OperationRoot(MutableArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
OperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
OperationRoot(MutableArrayBase<T,Ranges...>& ma,
|
||||
const std::tuple<std::shared_ptr<typename Ranges::IndexType>...>& indices);
|
||||
|
||||
OperationRoot(T* data, const IndexType& ind);
|
||||
|
||||
template <class OpClass>
|
||||
auto assign(const OpClass& in) const
|
||||
-> decltype(mIndex.ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
template <class Func, class Access, class OpClass>
|
||||
auto asx(const OpClass& in) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto assignExpr(const OpClass& in) const
|
||||
-> decltype(in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>(mOrigDataPtr,*this,in)));
|
||||
template <class Func, class Access, class OpClass>
|
||||
auto asxExpr(const OpClass& in) const;
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const
|
||||
-> decltype(i->ifor(1,in.loop(AssignmentExpr2<T,OperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
template <class Func, class Access, class OpClass, class Index>
|
||||
auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto plus(const OpClass& in) const
|
||||
-> decltype(mIndex.ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
auto assign(const OpClass& in) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto assignExpr(const OpClass& in) const;
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto plus(const OpClass& in) const;
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const
|
||||
-> decltype(i->ifor(1,in.loop(AddExpr<T,OperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const;
|
||||
|
||||
template <class OpClass>
|
||||
OperationRoot& operator=(const OpClass& in);
|
||||
|
@ -539,11 +395,14 @@ namespace MultiArrayTools
|
|||
|
||||
OperationRoot& operator=(const OperationRoot& in);
|
||||
|
||||
ParallelOperationRoot<T,Ranges...> par();
|
||||
auto par() { return *this; }
|
||||
|
||||
template <class ET>
|
||||
inline T& get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline V& vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline OperationRoot& set(ET pos);
|
||||
|
||||
|
@ -559,7 +418,7 @@ namespace MultiArrayTools
|
|||
-> Slice<T,typename Indices::RangeType...>;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
template <typename T, class... Ranges>
|
||||
class ParallelOperationRoot : public OperationTemplate<T,ParallelOperationRoot<T,Ranges...> >
|
||||
{
|
||||
|
@ -567,43 +426,49 @@ namespace MultiArrayTools
|
|||
|
||||
typedef T value_type;
|
||||
typedef OperationBase<T,ParallelOperationRoot<T,Ranges...> > OT;
|
||||
typedef ContainerRange<T,Ranges...> CRange;
|
||||
typedef ContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
typedef ContainerRange<Ranges...> CRange;
|
||||
typedef ConstContainerIndex<T,typename Ranges::IndexType...> IndexType;
|
||||
|
||||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool CONT = true;
|
||||
static constexpr bool VABLE = true;
|
||||
|
||||
private:
|
||||
|
||||
T* mDataPtr;
|
||||
T* mOrigDataPtr;
|
||||
PointerAccess<T> mDataAcc;
|
||||
IndexType mIndex;
|
||||
|
||||
public:
|
||||
ParallelOperationRoot(MutableMultiArrayBase<T,Ranges...>& ma,
|
||||
ParallelOperationRoot(MutableArrayBase<T,Ranges...>& ma,
|
||||
const std::shared_ptr<typename Ranges::IndexType>&... indices);
|
||||
|
||||
ParallelOperationRoot(T* data, const IndexType& ind);
|
||||
|
||||
template <class OpClass>
|
||||
auto assign(const OpClass& in)
|
||||
-> decltype(mIndex.pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
template <class Func, class OpClass>
|
||||
auto asx(const OpClass& in) const;
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const
|
||||
-> decltype(i->pifor(1,in.loop(AssignmentExpr2<T,ParallelOperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
template <class Func, class OpClass>
|
||||
auto asxExpr(const OpClass& in) const;
|
||||
|
||||
template <class Func, class OpClass, class Index>
|
||||
auto asx(const OpClass& in, const std::shared_ptr<Index>& i) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto assign(const OpClass& in) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto plus(const OpClass& in)
|
||||
-> decltype(mIndex.pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass,OpIndexAff::TARGET>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
auto assignExpr(const OpClass& in) const;
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto assign(const OpClass& in, const std::shared_ptr<Index>& i) const;
|
||||
|
||||
template <class OpClass>
|
||||
auto plus(const OpClass& in) const;
|
||||
|
||||
template <class OpClass, class Index>
|
||||
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const
|
||||
-> decltype(i->pifor(1,in.loop(AddExpr<T,ParallelOperationRoot<T,Ranges...>,OpClass>
|
||||
(mOrigDataPtr,*this,in))));
|
||||
auto plus(const OpClass& in, const std::shared_ptr<Index>& i) const;
|
||||
|
||||
template <class OpClass>
|
||||
ParallelOperationRoot& operator=(const OpClass& in);
|
||||
|
@ -615,6 +480,9 @@ namespace MultiArrayTools
|
|||
|
||||
template <class ET>
|
||||
inline T& get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline V& vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline ParallelOperationRoot& set(ET pos);
|
||||
|
@ -627,24 +495,28 @@ namespace MultiArrayTools
|
|||
T* data() const;
|
||||
|
||||
};
|
||||
|
||||
*/
|
||||
template <typename T>
|
||||
class OperationValue : public OperationTemplate<T,OperationValue<T> >
|
||||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef OperationBase<T,OperationValue<T> > OT;
|
||||
typedef ContainerRange<T,NullRange> CRange;
|
||||
typedef ContainerIndex<T,NullIndex> IndexType;
|
||||
typedef ContainerRange<NullRange> CRange;
|
||||
typedef ConstContainerIndex<T,NullIndex> IndexType;
|
||||
|
||||
static constexpr size_t SIZE = 0;
|
||||
static constexpr bool CONT = true;
|
||||
static constexpr bool VABLE = false;
|
||||
|
||||
OperationValue(const T& val);
|
||||
|
||||
template <class ET>
|
||||
inline const T& get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline V vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline OperationValue& set(ET pos);
|
||||
|
||||
|
@ -661,7 +533,6 @@ namespace MultiArrayTools
|
|||
class OperationPointer : public OperationTemplate<const T*,OperationPointer<T,Op>>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
typedef OperationTemplate<const T*,OperationPointer<T,Op>> OT;
|
||||
|
||||
|
@ -694,7 +565,7 @@ namespace MultiArrayTools
|
|||
|
||||
T const** data() const { assert(0); return nullptr; }
|
||||
};
|
||||
|
||||
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
class Operation : public OperationTemplate<T,Operation<T,OpFunction,Ops...> >
|
||||
{
|
||||
|
@ -704,69 +575,51 @@ namespace MultiArrayTools
|
|||
typedef OperationBase<T,Operation<T,OpFunction,Ops...> > OT;
|
||||
typedef OpFunction F;
|
||||
|
||||
static constexpr size_t SIZE = RootSum<Ops...>::SIZE;
|
||||
static constexpr size_t SIZE = (... + Ops::SIZE);
|
||||
static constexpr bool FISSTATIC = OpFunction::FISSTATIC;
|
||||
static constexpr bool CONT = false;
|
||||
static constexpr bool VABLE =
|
||||
(... and (Ops::VABLE and std::is_same<T,typename Ops::value_type>::value));
|
||||
|
||||
private:
|
||||
std::tuple<Ops...> mOps;
|
||||
OperationTuple<Ops...> mOps;
|
||||
std::shared_ptr<OpFunction> mF; // only if non-static
|
||||
typedef decltype(mOps.rootSteps(0)) ExtType;
|
||||
|
||||
public:
|
||||
typedef decltype(PackNum<sizeof...(Ops)-1>::template mkSteps<Ops...>(0, mOps)) ETuple;
|
||||
|
||||
Operation(const Ops&... ops);
|
||||
Operation(std::shared_ptr<OpFunction> ff, const Ops&... ops);
|
||||
|
||||
|
||||
template <class ET>
|
||||
inline auto get(ET pos) const;
|
||||
|
||||
template <typename V, class ET>
|
||||
inline auto vget(ET pos) const;
|
||||
|
||||
template <class ET>
|
||||
inline Operation& set(ET pos);
|
||||
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
|
||||
-> decltype(PackNum<sizeof...(Ops)-1>::mkSteps(iPtrNum, mOps));
|
||||
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const
|
||||
-> ExtType; // nullptr for simple usage with decltype
|
||||
|
||||
template <class Expr>
|
||||
auto loop(Expr exp) const
|
||||
-> decltype(PackNum<sizeof...(Ops)-1>::mkLoop( mOps, exp));
|
||||
auto loop(Expr exp) const;
|
||||
|
||||
T* data() const { assert(0); return nullptr; }
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
template <bool FISSTATIC>
|
||||
struct OpMaker
|
||||
{
|
||||
template <class OpFunction, class... Ops>
|
||||
static inline auto mkOperation(const std::shared_ptr<OpFunction>& f, const Ops&... ops)
|
||||
-> Operation<typename OpFunction::value_type,OpFunction,Ops...>
|
||||
{
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(f,ops...);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct OpMaker<true>
|
||||
{
|
||||
template <class OpFunction, class... Ops>
|
||||
static inline auto mkOperation(const std::shared_ptr<OpFunction>& f, const Ops&... ops)
|
||||
-> Operation<typename OpFunction::value_type,OpFunction,Ops...>
|
||||
{
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(ops...);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class OpFunction, class... Ops>
|
||||
auto mkOperation(const std::shared_ptr<OpFunction>& f, const Ops&... ops)
|
||||
-> Operation<typename OpFunction::value_type,OpFunction,Ops...>
|
||||
{
|
||||
return OpMaker<OpFunction::FISSTATIC>::mkOperation(f, ops...);
|
||||
if constexpr(OpFunction::FISSTATIC){
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(ops...);
|
||||
}
|
||||
else {
|
||||
return Operation<typename OpFunction::value_type,OpFunction,Ops...>(f,ops...);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T, class Op, class IndexType>
|
||||
class Contraction : public OperationTemplate<T,Contraction<T,Op,IndexType> >
|
||||
|
@ -778,6 +631,7 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr size_t SIZE = Op::SIZE;
|
||||
static constexpr bool CONT = Op::CONT;
|
||||
static constexpr bool VABLE = Op::VABLE;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -793,6 +647,10 @@ namespace MultiArrayTools
|
|||
inline auto get(ET pos) const
|
||||
-> decltype(mOp.template get<ET>(pos));
|
||||
|
||||
template <typename V, class ET>
|
||||
inline auto vget(ET pos) const
|
||||
-> decltype(mOp.template vget<V,ET>(pos));
|
||||
|
||||
template <class ET>
|
||||
inline Contraction& set(ET pos);
|
||||
|
||||
|
@ -806,43 +664,49 @@ namespace MultiArrayTools
|
|||
-> decltype(mInd->iforh(1,mOp.loop(exp)));
|
||||
};
|
||||
|
||||
template <typename T, class Op, class... Indices>
|
||||
// class SliceContraction : public OperationTemplate
|
||||
//<MultiArray<T,typename Indices::RangeType...>,
|
||||
//SliceContraction<MultiArray<T,typename Indices::RangeType...>,Op,Indices...> >
|
||||
class SliceContraction : public OperationTemplate<T,SliceContraction<T,Op,Indices...> >
|
||||
// for SliceArray
|
||||
/*
|
||||
template <typename T, class Op>
|
||||
class HyperOperation : public OperationTemplate<T,HyperOperation<T,Op> >
|
||||
{
|
||||
public:
|
||||
typedef MultiArray<T,typename Indices::RangeType...> value_type;
|
||||
typedef OperationTemplate<T,SliceContraction<T,Op,Indices...> > OT;
|
||||
|
||||
typedef Op value_type;
|
||||
typedef OperationTemplate<T,HyperOperation<T,Op> > OT;
|
||||
|
||||
static constexpr size_t SIZE = Op::SIZE;
|
||||
static constexpr bool CONT = false;
|
||||
static constexpr bool VABLE = false;
|
||||
|
||||
private:
|
||||
|
||||
mutable Op mOp;
|
||||
mutable std::shared_ptr<MultiArray<T,typename Indices::RangeType...> > mCont;
|
||||
mutable OperationRoot<T,typename Indices::RangeType...> mTarOp;
|
||||
|
||||
Op mOp; // proto
|
||||
|
||||
public:
|
||||
typedef decltype(mOp.rootSteps(0)) ETuple;
|
||||
|
||||
SliceContraction(const Op& op, std::shared_ptr<Indices>... ind);
|
||||
//typedef decltype(mOp.rootSteps(0)) ETuple;
|
||||
|
||||
template <class ET>
|
||||
inline const value_type& get(ET pos) const;
|
||||
// include ALL indices (external/internal!!!)
|
||||
inline auto get(ET pos) const
|
||||
-> decltype(mOp.template get<ET>(pos));
|
||||
|
||||
template <typename V, class ET>
|
||||
inline auto vget(ET pos) const
|
||||
-> decltype(mOp.template vget<V,ET>(pos));
|
||||
|
||||
template <class ET>
|
||||
inline SliceContraction& set(ET pos);
|
||||
inline HyperOperation& set(ET pos);
|
||||
|
||||
T* data() const { assert(0); return nullptr; }
|
||||
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const // nullptr for simple usage with decltype
|
||||
-> decltype(mOp.rootSteps(iPtrNum));
|
||||
|
||||
template <class Expr>
|
||||
auto loop(Expr exp) const -> decltype(mOp.loop(exp)); // no loop
|
||||
|
||||
};
|
||||
auto loop(Expr exp) const
|
||||
-> decltype(mInd->iforh(1,mOp.loop(exp)));
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
#include "dynamic_operation.h"
|
||||
#include "helper_tools.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T, class Operation>
|
||||
T DynamicOperation<T,Operation>::get(const DExtT& pos) const
|
||||
|
@ -45,7 +45,7 @@ namespace MultiArrayTools
|
|||
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(const DynamicOuterOp& in) :
|
||||
mThreadId(omp_get_thread_num()), mOp(in.mOp),
|
||||
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),
|
||||
mL((mThreadId != in.mThreadId) ?
|
||||
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||
|
@ -60,7 +60,7 @@ namespace MultiArrayTools
|
|||
DynamicOuterOp<T,Operation,Ranges...>::DynamicOuterOp(DynamicOuterOp&& in) :
|
||||
mThreadId(omp_get_thread_num()), mOp(in.mOp),
|
||||
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),
|
||||
mL((mThreadId != in.mThreadId) ?
|
||||
mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||
|
@ -79,7 +79,7 @@ namespace MultiArrayTools
|
|||
mOp = in.mOp;
|
||||
mIndices = in.mIndices;
|
||||
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);
|
||||
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||
std::make_tuple(mMa),
|
||||
|
@ -103,7 +103,7 @@ namespace MultiArrayTools
|
|||
mOp = in.mOp;
|
||||
mIndices = in.mIndices;
|
||||
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);
|
||||
mL = mkILoop(std::make_tuple(*mProto.mOp,mOp), mIndices,
|
||||
std::make_tuple(mMa),
|
||||
|
@ -124,7 +124,7 @@ namespace MultiArrayTools
|
|||
const std::shared_ptr<typename Ranges::IndexType>&... inds)
|
||||
: mThreadId(omp_get_thread_num()), 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...)),
|
||||
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(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()),
|
||||
//mDyn(dyn),
|
||||
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...)),
|
||||
mL(std::make_tuple(*mProto.mOp,mOp), std::make_tuple(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);
|
||||
}
|
||||
|
||||
} // namespace MultiArrayTools
|
||||
} // namespace CNORXZ
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
#ifndef __dynamic_operation_h__
|
||||
#define __dynamic_operation_h__
|
||||
#ifndef __cxz_dynamic_operation_h__
|
||||
#define __cxz_dynamic_operation_h__
|
||||
|
||||
#include "base_def.h"
|
||||
#include "multi_array_operation.h"
|
||||
#include "cxz_operation.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
|
@ -17,6 +17,7 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool CONT = true;
|
||||
static constexpr bool VABLE = false;
|
||||
|
||||
DynamicOperationBase() = default;
|
||||
DynamicOperationBase(const DynamicOperationBase& in) = default;
|
||||
|
@ -76,13 +77,13 @@ namespace MultiArrayTools
|
|||
Operation mOp;
|
||||
//OperationRoot<T,Ranges...> mProto;
|
||||
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;
|
||||
|
||||
|
||||
typedef ILoop<std::tuple<OperationRoot<T,Ranges...>,Operation>,
|
||||
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;
|
||||
|
||||
|
||||
|
@ -125,6 +126,7 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr size_t SIZE = 1;
|
||||
static constexpr bool CONT = true;
|
||||
static constexpr bool VABLE = false;
|
||||
|
||||
DynamicO() = default;
|
||||
DynamicO(const DynamicO& in) : mOp(in.mOp ? in.mOp->deepCopy() : nullptr) {}
|
||||
|
@ -144,6 +146,11 @@ namespace MultiArrayTools
|
|||
|
||||
template <class X>
|
||||
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>
|
||||
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); }
|
||||
|
@ -197,6 +204,6 @@ namespace MultiArrayTools
|
|||
|
||||
};
|
||||
*/
|
||||
} // namespace MultiArrayTools
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,29 +2,5 @@
|
|||
#ifdef regFunc1
|
||||
|
||||
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
|
||||
|
|
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"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename... T>
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -21,8 +22,7 @@ namespace MultiArrayTools
|
|||
auto getIndex()
|
||||
-> std::shared_ptr<typename RangeType::IndexType>
|
||||
{
|
||||
static_assert( RangeType::defaultable,
|
||||
/*typeid(typename RangeType).name() + */" is not defaultable" );
|
||||
static_assert( RangeType::defaultable, "Range not defaultable" );
|
||||
static auto f = RangeType::factory();
|
||||
static auto r = std::dynamic_pointer_cast<RangeType>( f.create() );
|
||||
return std::make_shared<typename RangeType::IndexType>(r);
|
||||
|
@ -237,7 +237,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <class MArray>
|
||||
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());
|
||||
if(slice){
|
||||
|
@ -246,7 +246,7 @@ namespace MultiArrayTools
|
|||
ma.data() );
|
||||
}
|
||||
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() ),
|
||||
ma.vdata() );
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <class MArray>
|
||||
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());
|
||||
if(slice){
|
||||
|
@ -263,7 +263,7 @@ namespace MultiArrayTools
|
|||
ma.data() );
|
||||
}
|
||||
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() ),
|
||||
ma.vdata() );
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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>
|
||||
{
|
||||
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
||||
|
@ -307,7 +307,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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>
|
||||
{
|
||||
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
||||
|
@ -320,8 +320,8 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T, class Range1, class... RangeTypes>
|
||||
auto dynToAnonMove(MultiArray<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
||||
-> MultiArray<T,Range1,RangeTypes...,AnonymousRange>
|
||||
auto dynToAnonMove(Array<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
||||
-> Array<T,Range1,RangeTypes...,AnonymousRange>
|
||||
{
|
||||
constexpr size_t LAST = sizeof...(RangeTypes)+1;
|
||||
AnonymousRangeFactory arf(rptr<LAST>(ma)->orig());
|
||||
|
@ -333,7 +333,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
auto anonToDynView(const MultiArrayBase<T,AnonymousRange>& ma)
|
||||
auto anonToDynView(const ArrayBase<T,AnonymousRange>& ma)
|
||||
-> ConstSlice<T,DynamicRange>
|
||||
{
|
||||
DynamicRangeFactory drf(rptr<0>(ma)->orig());
|
||||
|
@ -342,7 +342,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
auto anonToDynView(MutableMultiArrayBase<T,AnonymousRange>& ma)
|
||||
auto anonToDynView(MutableArrayBase<T,AnonymousRange>& ma)
|
||||
-> Slice<T,DynamicRange>
|
||||
{
|
||||
DynamicRangeFactory drf(rptr<0>(ma)->orig());
|
||||
|
@ -351,8 +351,8 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
auto dynToAnonMove(MultiArray<T,DynamicRange>&& ma)
|
||||
-> MultiArray<T,AnonymousRange>
|
||||
auto dynToAnonMove(Array<T,DynamicRange>&& ma)
|
||||
-> Array<T,AnonymousRange>
|
||||
{
|
||||
AnonymousRangeFactory arf(rptr<0>(ma)->orig());
|
||||
auto mNSpace = std::make_tuple( createExplicit( arf ) );
|
||||
|
@ -376,23 +376,23 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Ranges>
|
||||
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>
|
||||
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>
|
||||
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__
|
||||
#define __helper_tools_h__
|
||||
#ifndef __cxz_helper_tools_h__
|
||||
#define __cxz_helper_tools_h__
|
||||
|
||||
#include "base_def.h"
|
||||
#include "slice.h"
|
||||
#include <ostream>
|
||||
#include "pack_num.h"
|
||||
#include "map_range.h"
|
||||
#include <functional>
|
||||
#include "xfor/iloop.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <typename... T>
|
||||
|
@ -120,35 +119,35 @@ namespace MultiArrayTools
|
|||
|
||||
template <class MArray>
|
||||
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>
|
||||
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>
|
||||
auto anonToDynView(const MultiArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
||||
auto anonToDynView(const ArrayBase<T,Range1,RangeTypes...,AnonymousRange>& ma)
|
||||
-> ConstSlice<T,Range1,RangeTypes...,DynamicRange>;
|
||||
|
||||
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>;
|
||||
|
||||
template <typename T, class Range1, class... RangeTypes>
|
||||
auto dynToAnonMove(MultiArray<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
||||
-> MultiArray<T,Range1,RangeTypes...,AnonymousRange>;
|
||||
auto dynToAnonMove(Array<T,Range1,RangeTypes...,DynamicRange>&& ma)
|
||||
-> Array<T,Range1,RangeTypes...,AnonymousRange>;
|
||||
|
||||
template <typename T>
|
||||
auto anonToDynView(const MultiArrayBase<T,AnonymousRange>& ma)
|
||||
auto anonToDynView(const ArrayBase<T,AnonymousRange>& ma)
|
||||
-> ConstSlice<T,DynamicRange>;
|
||||
|
||||
template <typename T>
|
||||
auto anonToDynView(MutableMultiArrayBase<T,AnonymousRange>& ma)
|
||||
auto anonToDynView(MutableArrayBase<T,AnonymousRange>& ma)
|
||||
-> Slice<T,DynamicRange>;
|
||||
|
||||
template <typename T>
|
||||
auto dynToAnonMove(MultiArray<T,DynamicRange>&& ma)
|
||||
-> MultiArray<T,AnonymousRange>;
|
||||
auto dynToAnonMove(Array<T,DynamicRange>&& ma)
|
||||
-> Array<T,AnonymousRange>;
|
||||
|
||||
template <class Range>
|
||||
auto metaSlice(const std::shared_ptr<Range>& r)
|
||||
|
@ -160,30 +159,30 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... Ranges>
|
||||
auto mkArray(const std::shared_ptr<Ranges>&... rs)
|
||||
-> MultiArray<T,Ranges...>;
|
||||
-> Array<T,Ranges...>;
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
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>
|
||||
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>
|
||||
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<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>
|
||||
auto mkPILoop(const CF& cf)
|
||||
-> MultiArrayHelper::PILoop<CF>
|
||||
-> CNORXZInternal::PILoop<CF>
|
||||
{
|
||||
return MultiArrayHelper::PILoop<CF>(cf);
|
||||
return CNORXZInternal::PILoop<CF>(cf);
|
||||
}
|
||||
|
||||
template <class IndexType>
|
||||
|
@ -215,11 +214,11 @@ namespace MultiArrayTools
|
|||
|
||||
template <class Index>
|
||||
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> >
|
||||
().exec(i))
|
||||
{
|
||||
FunctionalMultiArray<typename Index::MetaType,
|
||||
FunctionalArray<typename Index::MetaType,
|
||||
identity<typename Index::MetaType>,
|
||||
typename Index::RangeType> fma(i->range());
|
||||
return fma.exec(i);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "high_level_operation.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <typename T, class Op>
|
||||
|
@ -114,82 +114,53 @@ namespace MultiArrayTools
|
|||
|
||||
namespace
|
||||
{
|
||||
template <size_t N>
|
||||
template <size_t N, class... Indices>
|
||||
struct Create
|
||||
{
|
||||
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)
|
||||
{
|
||||
static_assert(N > 0, "N > 0 failed");
|
||||
auto& inn = std::get<N>(in);
|
||||
if(not inn->root()){
|
||||
auto dop = inn->create(inds...);
|
||||
auto op = *dop.op.data()->mOp;
|
||||
typedef decltype(op) OP;
|
||||
res.appendOuter(dop);
|
||||
assert(dop.op.init());
|
||||
Create<N-1>::template cx<Indices...>::template ccx<ROP,OpF,OP,OPs...>::template cccx<M>
|
||||
(res, in, inds..., op, ops..., dop, dops...);
|
||||
}
|
||||
else {
|
||||
auto op = inn->get();
|
||||
auto vop = inn->vget();
|
||||
typedef typename std::remove_reference<decltype(*op)>::type OP;
|
||||
typedef typename std::remove_reference<decltype(*vop)>::type VOP;
|
||||
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)
|
||||
{
|
||||
//static_assert(N > 0, "N > 0 failed");
|
||||
auto& inn = std::get<N>(in);
|
||||
if(not inn->root()){
|
||||
auto dop = inn->create(inds...);
|
||||
auto op = *dop.op.data()->mOp;
|
||||
res.appendOuter(dop);
|
||||
assert(dop.op.init());
|
||||
if constexpr(N > 0){
|
||||
typedef decltype(op) OP;
|
||||
Create<N-1,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...);
|
||||
res.appendOuterM(dop.op,dops.op...);
|
||||
}
|
||||
}
|
||||
else {
|
||||
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){
|
||||
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...);
|
||||
}
|
||||
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...);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
else {
|
||||
if(op != nullptr){
|
||||
res.op = mkDynOutOp(mkFOp<OpF>(*op,ops...), inds...);
|
||||
}
|
||||
|
@ -197,11 +168,12 @@ namespace MultiArrayTools
|
|||
res.op = mkDynOutOp(mkFOp<OpF>(*vop,ops...), inds...);
|
||||
}
|
||||
res.appendOuterM(dops.op...);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class ROP, class OpF, size_t N>
|
||||
|
@ -234,7 +206,7 @@ namespace MultiArrayTools
|
|||
-> typename B::template RetT<Inds...>
|
||||
{
|
||||
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...);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
#ifndef __high_level_operation_h__
|
||||
#define __high_level_operation_h__
|
||||
#ifndef __cxz_high_level_operation_h__
|
||||
#define __cxz_high_level_operation_h__
|
||||
|
||||
#include "base_def.h"
|
||||
#include "ranges/rheader.h"
|
||||
#include "dynamic_operation.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
typedef ClassicRange CR;
|
||||
|
@ -54,7 +54,10 @@ namespace MultiArrayTools
|
|||
#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
|
||||
|
||||
#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_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) \
|
||||
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 VOP* vget() override final;
|
||||
|
@ -121,7 +127,10 @@ namespace MultiArrayTools
|
|||
|
||||
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 VOP* vget() override final;
|
||||
|
@ -158,7 +167,10 @@ namespace MultiArrayTools
|
|||
virtual ROP* get() 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_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 <type_traits>
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
/**************
|
||||
|
@ -27,6 +27,18 @@ namespace MultiArrayTools
|
|||
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>
|
||||
inline void OpExpr<Op,Index,Expr,STYPE>::operator()(size_t mlast,
|
||||
ExtType last)
|
||||
|
@ -37,7 +49,7 @@ namespace MultiArrayTools
|
|||
if(pos != mIndPtr->max()){
|
||||
const ExtType npos = last + mExt*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()){
|
||||
const ExtType npos = last + mExt*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) );
|
||||
}
|
||||
|
||||
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
|
||||
//std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
||||
|
||||
template <class Op, class Index, class Expr, SpaceType STYPE>
|
||||
DExt OpExpr<Op,Index,Expr,STYPE>::dExtension() const
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||
}
|
||||
|
||||
/******************
|
||||
* 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 MRange>
|
||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>::GenMapIndex(const std::shared_ptr<MRange>& range) :
|
||||
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;
|
||||
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>
|
||||
( 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()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::pp( mIPack );
|
||||
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](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;
|
||||
}
|
||||
|
||||
|
@ -118,8 +139,16 @@ namespace MultiArrayTools
|
|||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::down()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::mm( mIPack );
|
||||
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](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;
|
||||
}
|
||||
|
||||
|
@ -146,8 +175,15 @@ namespace MultiArrayTools
|
|||
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)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
||||
return (*this)(std::make_tuple(indices...));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -162,14 +198,12 @@ namespace MultiArrayTools
|
|||
{
|
||||
(*mOutIndex) = pos;
|
||||
IB::mPos = mOutIndex->pos();
|
||||
//RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator++()
|
||||
{
|
||||
//RPackNum<sizeof...(Indices)-1>::pp( mIPack );
|
||||
++(*mOutIndex);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
return *this;
|
||||
|
@ -178,7 +212,6 @@ namespace MultiArrayTools
|
|||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
GenMapIndex<OIType,Op,XSTYPE,Indices...>& GenMapIndex<OIType,Op,XSTYPE,Indices...>::operator--()
|
||||
{
|
||||
//RPackNum<sizeof...(Indices)-1>::mm( mIPack );
|
||||
--(*mOutIndex);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
return *this;
|
||||
|
@ -187,20 +220,16 @@ namespace MultiArrayTools
|
|||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::pp(std::intptr_t idxPtrNum)
|
||||
{
|
||||
//int tmp = RPackNum<sizeof...(Indices)-1>::pp(mIPack, mBlockSizes, idxPtrNum);
|
||||
mOutIndex->pp(idxPtrNum);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
//IB::mPos += tmp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
int GenMapIndex<OIType,Op,XSTYPE,Indices...>::mm(std::intptr_t idxPtrNum)
|
||||
{
|
||||
//int tmp = RPackNum<sizeof...(Indices)-1>::mm(mIPack, mBlockSizes, idxPtrNum);
|
||||
mOutIndex->mm(idxPtrNum);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
//IB::mPos -= tmp;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -213,17 +242,12 @@ namespace MultiArrayTools
|
|||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
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();
|
||||
}
|
||||
|
||||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
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);
|
||||
IB::mPos = mOutIndex->pos();
|
||||
return *this;
|
||||
|
@ -277,40 +301,19 @@ namespace MultiArrayTools
|
|||
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 Exprs>
|
||||
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
|
||||
(0, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex<OIType,Op,XSTYPE,Indices...>,Exprs,XSTYPE>
|
||||
( range()->map(), this, step, exs ) );
|
||||
return RangeHelper::mkFor<0>
|
||||
(0, mIPack, mBlockSizes,
|
||||
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 Exprs>
|
||||
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::pifor(size_t step, Exprs exs) const
|
||||
-> decltype(ifor(step, exs))
|
||||
{
|
||||
return ifor(step, exs);
|
||||
}
|
||||
|
@ -318,7 +321,6 @@ namespace MultiArrayTools
|
|||
template <class OIType, class Op, SpaceType XSTYPE, class... Indices>
|
||||
template <class Exprs>
|
||||
auto GenMapIndex<OIType,Op,XSTYPE,Indices...>::iforh(size_t step, Exprs exs) const
|
||||
-> decltype(ifor(step, exs))
|
||||
{
|
||||
return ifor(step, exs);
|
||||
}
|
||||
|
@ -380,7 +382,9 @@ namespace MultiArrayTools
|
|||
bool check = false;
|
||||
for(auto& x: MapRangeFactoryProductMap::mAleadyCreated){
|
||||
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){
|
||||
out = x.first;
|
||||
break;
|
||||
|
@ -389,7 +393,8 @@ namespace MultiArrayTools
|
|||
}
|
||||
if(not check){
|
||||
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>
|
||||
( &std::dynamic_pointer_cast<oType>( mProd )->mMapf ) );
|
||||
MapRangeFactoryProductMap::mAleadyCreated[mProd] = pv;
|
||||
|
@ -410,7 +415,7 @@ namespace MultiArrayTools
|
|||
struct OutRangeMaker<SpaceType::ANY>
|
||||
{
|
||||
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;
|
||||
for(auto ii = mapf.begin(); ii.max() != ii.pos(); ++ii) {
|
||||
|
@ -429,7 +434,7 @@ namespace MultiArrayTools
|
|||
|
||||
typename ORType::FType orf(outmeta);
|
||||
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>
|
||||
{
|
||||
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,
|
||||
"out range value type for NONE must be size_t" );
|
||||
|
@ -459,7 +464,7 @@ namespace MultiArrayTools
|
|||
|
||||
typename ORType::FType orf(max);
|
||||
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>
|
||||
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);
|
||||
auto i = mapf.begin();
|
||||
mMapPos.resize(i.max());
|
||||
|
@ -568,7 +573,6 @@ namespace MultiArrayTools
|
|||
size_t GenMapRange<ORType,Op,XSTYPE,Ranges...>::size() const
|
||||
{
|
||||
return mOutRange->size();
|
||||
//return RPackNum<sizeof...(Ranges)-1>::getSize(mSpace);
|
||||
}
|
||||
|
||||
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> o;
|
||||
RPackNum<sizeof...(Ranges)-1>::getTypeNum(o,mSpace);
|
||||
RangeHelper::getTypeNum<sizeof...(Ranges)-1>(o,mSpace);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
@ -597,13 +601,12 @@ namespace MultiArrayTools
|
|||
//MetaType* xtarget = reinterpret_cast<MetaType*>(target);
|
||||
assert(0);
|
||||
return 0;
|
||||
//return RPackNum<sizeof...(Ranges)-1>::getCMeta(xtarget,pos,mSpace,cmetaSize());
|
||||
}
|
||||
|
||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||
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>
|
||||
|
@ -611,7 +614,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
auto i = begin();
|
||||
i = pos;
|
||||
return "[ " + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + " ]";
|
||||
return "[ " + RangeHelper::getStringMeta<0>(i) + " ]";
|
||||
}
|
||||
|
||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||
|
@ -622,7 +625,12 @@ namespace MultiArrayTools
|
|||
//out.reserve(h.metaSize + sizeof(DataHeader));
|
||||
char* hcp = reinterpret_cast<char*>(&h);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -658,7 +666,7 @@ namespace MultiArrayTools
|
|||
|
||||
template <class ORType, class Op, SpaceType XSTYPE, class... Ranges>
|
||||
auto GenMapRange<ORType,Op,XSTYPE,Ranges...>::mapMultiplicity() const
|
||||
-> const MultiArray<size_t,ORType>&
|
||||
-> const Array<size_t,ORType>&
|
||||
{
|
||||
return mMapMult;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __map_range_h__
|
||||
#define __map_range_h__
|
||||
#ifndef __cxz_map_range_h__
|
||||
#define __cxz_map_range_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
|
@ -12,30 +12,29 @@
|
|||
#include "ranges/range_base.h"
|
||||
#include "ranges/index_base.h"
|
||||
|
||||
#include "ranges/rpack_num.h"
|
||||
#include "map_range_factory_product_map.h"
|
||||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
|
||||
#include "xfor/xfor.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
|
||||
template <class Func, class... Indices>
|
||||
auto mkMapOp(const std::shared_ptr<Func>& func,
|
||||
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...),
|
||||
FunctionalMultiArray<typename Func::value_type,Func,
|
||||
FunctionalArray<typename Func::value_type,Func,
|
||||
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){
|
||||
FMA fma(is->range()...);
|
||||
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 MapF, class IndexPack, class Expr, SpaceType STYPE = SpaceType::ANY>
|
||||
class OpExpr
|
||||
class OpExpr : public ExpressionBase
|
||||
{
|
||||
public:
|
||||
//typedef typename Index::OIType OIType;
|
||||
//typedef SingleIndex<typename Op::value_type,STYPE> OIType;
|
||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||
static constexpr size_t SIZE = Expr::SIZE + Op::SIZE;
|
||||
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||
|
||||
private:
|
||||
OpExpr() = default;
|
||||
|
@ -80,11 +80,20 @@ namespace MultiArrayTools
|
|||
|
||||
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 = 0);
|
||||
inline void operator()(size_t mlast = 0) override final;
|
||||
|
||||
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>
|
||||
|
@ -106,7 +115,7 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr IndexType sType() { return IndexType::SINGLE; }
|
||||
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 constexpr SpaceType STYPE = XSTYPE;
|
||||
|
@ -149,11 +158,12 @@ namespace MultiArrayTools
|
|||
|
||||
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
|
||||
// NO foreign/external controll)
|
||||
// Do NOT share index instances between two or more MapIndex instances
|
||||
GenMapIndex& operator()(const std::shared_ptr<Indices>&... indices);
|
||||
GenMapIndex& operator()(const std::tuple<std::shared_ptr<Indices>...>& indices);
|
||||
|
||||
// ==== >>>>> STATIC POLYMORPHISM <<<<< ====
|
||||
|
||||
|
@ -182,23 +192,14 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n) const;
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto ifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkForh
|
||||
(step, mIPack, mBlockSizes, OpExpr<Op,GenMapIndex,Exprs,XSTYPE>( range()->map(), this, step, exs ) ) );
|
||||
// first step arg not used!
|
||||
auto ifor(size_t step, Exprs exs) const; // first step arg not used!
|
||||
|
||||
template <class Exprs>
|
||||
auto pifor(size_t step, Exprs exs) const
|
||||
-> decltype(ifor(step, exs)); // NO MULTITHREADING
|
||||
|
||||
auto pifor(size_t step, Exprs exs) const; // NO MULTITHREADING
|
||||
|
||||
template <class Exprs>
|
||||
auto iforh(size_t step, Exprs exs) const
|
||||
-> decltype(ifor(step, exs));
|
||||
auto iforh(size_t step, Exprs exs) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -251,11 +252,7 @@ namespace MultiArrayTools
|
|||
typedef RangeBase RB;
|
||||
typedef std::tuple<std::shared_ptr<Ranges>...> Space;
|
||||
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 RangeInterface<MapIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
||||
|
||||
protected:
|
||||
GenMapRange() = delete;
|
||||
|
@ -280,7 +277,7 @@ namespace MultiArrayTools
|
|||
Op mMapf;
|
||||
//Op mMapf;
|
||||
std::shared_ptr<ORType> mOutRange;
|
||||
MultiArray<size_t,ORType> mMapMult;
|
||||
Array<size_t,ORType> mMapMult;
|
||||
vector<size_t> mMapPos;
|
||||
|
||||
private:
|
||||
|
@ -317,7 +314,7 @@ namespace MultiArrayTools
|
|||
virtual IndexType begin() 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;
|
||||
|
||||
vector<size_t> mapPos() const;
|
||||
|
@ -331,8 +328,8 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr bool HASMETACONT = false;
|
||||
static constexpr bool defaultable = false;
|
||||
static constexpr size_t ISSTATIC = SubProp<Op,Ranges...>::ISSTATIC;
|
||||
static constexpr size_t SIZE = SubProp<Op,Ranges...>::SIZE;
|
||||
static constexpr size_t ISSTATIC = Op::ISSTATIC & (... & Ranges::ISSTATIC);
|
||||
static constexpr size_t SIZE = Op::SIZE * (... * Ranges::SIZE);
|
||||
};
|
||||
|
||||
// for legacy
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __map_range_factory_product_map_h__
|
||||
#define __map_range_factory_product_map_h__
|
||||
#ifndef __cxz_map_range_factory_product_map_h__
|
||||
#define __cxz_map_range_factory_product_map_h__
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -8,7 +8,7 @@
|
|||
#include "ranges/rbase_def.h"
|
||||
#include "mbase_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
class MapRangeFactoryProductMap
|
||||
{
|
||||
|
|
|
@ -1,69 +1,75 @@
|
|||
|
||||
#ifndef __mbase_def_h__
|
||||
#define __mbase_def_h__
|
||||
#ifndef __cxz_mbase_def_h__
|
||||
#define __cxz_mbase_def_h__
|
||||
|
||||
#include "ranges/rbase_def.h"
|
||||
#include "allocator.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/***********************
|
||||
* Provided Types *
|
||||
***********************/
|
||||
|
||||
// multi_array.h
|
||||
template <typename T, class... SRanges>
|
||||
class MultiArrayBase;
|
||||
template <class... Ranges>
|
||||
using ContainerRangeFactory = MultiRangeFactory<Ranges...>;
|
||||
|
||||
// multi_array.h
|
||||
template <typename T, class... SRanges>
|
||||
class MutableMultiArrayBase;
|
||||
template <class... Ranges>
|
||||
using ContainerRange = MultiRange<Ranges...>;
|
||||
|
||||
// multi_array.h
|
||||
// container_index.h
|
||||
template <typename T, class... Indices>
|
||||
class ConstContainerIndex;
|
||||
|
||||
// cxz_array.h
|
||||
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>
|
||||
class OperationBase;
|
||||
|
||||
// multi_array_operation.h
|
||||
//template <typename T>
|
||||
//class MutableOperationBase;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class OperationClass>
|
||||
class OperationTemplate;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class... Ranges>
|
||||
class OperationRoot;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class... Ranges>
|
||||
class ParallelOperationRoot;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T>
|
||||
class OperationValue;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class... Ranges>
|
||||
class ConstOperationRoot;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class Op>
|
||||
class OperationPointer;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class OpFunction, class... Ops>
|
||||
class Operation;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class Op, class IndexType>
|
||||
class Contraction;
|
||||
|
||||
// multi_array_operation.h
|
||||
// cxz_operation.h
|
||||
template <typename T, class Op, class... Indices>
|
||||
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
|
72
src/include/op_expressions.cc.h
Normal file
72
src/include/op_expressions.cc.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
|
||||
#include "op_expressions.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
/************************
|
||||
* AssignmentExpr *
|
||||
************************/
|
||||
|
||||
template <OpIndexAff OIA, class ExtType>
|
||||
inline size_t opIndexResolve(size_t start, ExtType last)
|
||||
{
|
||||
if constexpr(OIA == OpIndexAff::EXTERN){
|
||||
return last.val();
|
||||
}
|
||||
if constexpr(OIA == OpIndexAff::TARGET){
|
||||
return start;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::AssignmentExpr(const AccessTemplate<AT>& dataAcc, const Target& tar, const OpClass& sec) :
|
||||
mTar(tar), mSec(sec), mDataAcc(static_cast<const AT&>(dataAcc)) {}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
inline void AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::operator()(size_t start)
|
||||
{
|
||||
ExtType last = rootSteps();
|
||||
last.zero();
|
||||
// TODO: ask MA container for data (ptr)!!!
|
||||
mDataAcc.template exec<Func>(opIndexResolve<OIA>(start,last),mSec,last.next());
|
||||
}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
inline void AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::operator()(size_t start, ExtType last)
|
||||
{
|
||||
mDataAcc.template exec<Func>(opIndexResolve<OIA>(start,last),mSec,last.next());
|
||||
}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
typename AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::ExtType
|
||||
AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::rootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return mTar.rootSteps(iPtrNum).extend( mSec.rootSteps(iPtrNum) );
|
||||
}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
inline void AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::operator()(size_t mlast, DExt last)
|
||||
{
|
||||
(*this)(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||
}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
inline DExt AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::dRootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||
}
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA>
|
||||
inline DExt AssignmentExpr<T,Func,AT,Target,OpClass,OIA>::dExtension() const
|
||||
{
|
||||
return nullptr; //???!!!
|
||||
}
|
||||
|
||||
|
||||
} // namespace CNORXZ
|
60
src/include/op_expressions.h
Normal file
60
src/include/op_expressions.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
|
||||
#ifndef __cxz_op_expressions__
|
||||
#define __cxz_op_expressions__
|
||||
|
||||
#include "xfor/xfor.h"
|
||||
#include "access.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
enum class OpIndexAff {
|
||||
EXTERN = 0,
|
||||
TARGET = 1
|
||||
};
|
||||
|
||||
template <typename T, class Func, class AT, class Target, class OpClass, OpIndexAff OIA=OpIndexAff::EXTERN>
|
||||
class AssignmentExpr : public ExpressionBase
|
||||
{
|
||||
private:
|
||||
AssignmentExpr() = default;
|
||||
|
||||
Target mTar;
|
||||
OpClass mSec;
|
||||
AT mDataAcc;
|
||||
|
||||
public:
|
||||
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t NHLAYER = 0;
|
||||
static constexpr size_t SIZE = Target::SIZE + OpClass::SIZE;
|
||||
typedef decltype(mTar.rootSteps(0).extend( mSec.rootSteps(0) )) ExtType;
|
||||
|
||||
AssignmentExpr(const AccessTemplate<AT>& dataAcc, const Target& tar, const OpClass& sec);
|
||||
AssignmentExpr(const AssignmentExpr& in) = default;
|
||||
AssignmentExpr(AssignmentExpr&& in) = default;
|
||||
AssignmentExpr& operator=(const AssignmentExpr& in) = default;
|
||||
AssignmentExpr& operator=(AssignmentExpr&& in) = default;
|
||||
|
||||
virtual std::shared_ptr<ExpressionBase> deepCopy() const override final
|
||||
{
|
||||
return std::make_shared<AssignmentExpr<T,Func,AT,Target,OpClass,OIA>>(*this);
|
||||
}
|
||||
|
||||
inline void operator()(size_t start = 0);
|
||||
inline void operator()(size_t start, ExtType last);
|
||||
auto rootSteps(std::intptr_t iPtrNum = 0) const -> ExtType;
|
||||
|
||||
inline void operator()(size_t mlast, DExt last) override final;
|
||||
|
||||
inline DExt dRootSteps(std::intptr_t iPtrNum = 0) const override final;
|
||||
inline DExt dExtension() const override final;
|
||||
};
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
#ifndef __operation_def_h__
|
||||
#define __operation_def_h__
|
||||
#ifndef __cxz_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>
|
||||
|
|
|
@ -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++ -*-
|
||||
|
||||
#ifndef __anonymous_range_h__
|
||||
#define __anonymous_range_h__
|
||||
#ifndef __cxz_anonymous_range_h__
|
||||
#define __cxz_anonymous_range_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
@ -11,7 +11,7 @@
|
|||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
typedef GenSingleIndex<size_t,SpaceType::ANON,MUI> AnonymousIndex;
|
||||
|
@ -133,7 +133,7 @@ namespace MultiArrayTools
|
|||
* --- TEMPLATE CODE --- *
|
||||
* ========================= */
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
/***********************
|
||||
|
@ -171,38 +171,38 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<AnonymousRange> defaultRange(size_t size = 0);
|
||||
}
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZ
|
||||
{
|
||||
using namespace MultiArrayTools;
|
||||
|
||||
template <>
|
||||
inline void resolveSetRange<AnonymousRange>(std::shared_ptr<AnonymousRange>& rp,
|
||||
const vector<std::shared_ptr<RangeBase> >& orig,
|
||||
size_t origpos, size_t size)
|
||||
namespace RangeHelper
|
||||
{
|
||||
AnonymousRangeFactory arf;
|
||||
for(size_t op = origpos; op != origpos + size; ++op){
|
||||
//VCHECK(op);
|
||||
arf.append(orig[op]);
|
||||
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;
|
||||
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,
|
||||
std::shared_ptr<AnonymousRange> r)
|
||||
{
|
||||
if(not r->isEmpty()){
|
||||
for(size_t i = r->anonymousDim(); i != 0; --i){
|
||||
v.insert(v.begin(), r->sub(i-1));
|
||||
|
||||
template <>
|
||||
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){
|
||||
v.insert(v.begin(), r->sub(i-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/***********************
|
||||
* AnonymousRange *
|
||||
|
@ -212,8 +212,12 @@ namespace MultiArrayTools
|
|||
GenSingleRange<size_t,SpaceType::ANON,MUI>::GenSingleRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
||||
RangeInterface<AnonymousIndex>()
|
||||
{
|
||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
|
||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
|
||||
mOrig.resize(sizeof...(RangeTypes));
|
||||
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)){
|
||||
mEmpty = false;
|
||||
}
|
||||
|
@ -224,8 +228,12 @@ namespace MultiArrayTools
|
|||
RangeInterface<AnonymousIndex>()
|
||||
{
|
||||
auto rst = std::make_tuple(origs...);
|
||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
||||
mOrig.resize(sizeof...(RangeTypes));
|
||||
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)){
|
||||
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::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);
|
||||
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__
|
||||
#define __dynamic_meta_h__
|
||||
#ifndef __cxz_dynamic_meta_h__
|
||||
#define __cxz_dynamic_meta_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
|
||||
#include "allocator.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
typedef std::pair<const char*,size_t> DynamicMetaElem;
|
||||
|
@ -66,6 +66,6 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
|
||||
} // namespace MultiArrayTools
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
|
||||
#include "ranges/dynamic_range.h"
|
||||
//#include "ranges/dynamic_meta.h"
|
||||
|
||||
//#include "rpack_num.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,8 +140,12 @@ namespace MultiArrayTools
|
|||
DynamicRange::DynamicRange(const std::tuple<std::shared_ptr<RangeTypes>...>& origs) :
|
||||
RangeInterface<DynamicIndex>()
|
||||
{
|
||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( origs, mOrig );
|
||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( origs );
|
||||
mOrig.resize(sizeof...(RangeTypes));
|
||||
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)){
|
||||
mEmpty = false;
|
||||
}
|
||||
|
@ -156,8 +157,12 @@ namespace MultiArrayTools
|
|||
RangeInterface<DynamicIndex>()
|
||||
{
|
||||
auto rst = std::make_tuple(origs...);
|
||||
RPackNum<sizeof...(RangeTypes)-1>::RangesToVec( rst, mOrig );
|
||||
mSize = RPackNum<sizeof...(RangeTypes)-1>::getSize( rst );
|
||||
mOrig.resize(sizeof...(RangeTypes));
|
||||
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)){
|
||||
mEmpty = false;
|
||||
}
|
||||
|
@ -175,60 +180,59 @@ namespace MultiArrayTools
|
|||
std::shared_ptr<MultiRange<Ranges...> > DynamicRange::scast(SIZET<Ranges>... sizes) const
|
||||
{
|
||||
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);
|
||||
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,
|
||||
size_t origpos, size_t size)
|
||||
{
|
||||
DynamicRangeFactory arf;
|
||||
for(size_t op = origpos; op != origpos + size; ++op){
|
||||
//VCHECK(op);
|
||||
arf.append(orig[op]);
|
||||
template <>
|
||||
inline void resolveSetRange<DynamicRange>(std::shared_ptr<DynamicRange>& rp,
|
||||
const vector<std::shared_ptr<RangeBase> >& orig,
|
||||
size_t origpos, size_t size)
|
||||
{
|
||||
DynamicRangeFactory arf;
|
||||
for(size_t op = origpos; op != origpos + size; ++op){
|
||||
//VCHECK(op);
|
||||
arf.append(orig[op]);
|
||||
}
|
||||
rp = std::dynamic_pointer_cast<DynamicRange>( arf.create() );
|
||||
}
|
||||
rp = std::dynamic_pointer_cast<DynamicRange>( arf.create() );
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
|
||||
std::shared_ptr<DynamicRange> r)
|
||||
{
|
||||
if(not r->isEmpty()){
|
||||
for(size_t i = r->dim(); i != 0; --i){
|
||||
v.insert(v.begin(), r->sub(i-1));
|
||||
template <>
|
||||
inline void setRangeToVec<DynamicRange>(vector<std::shared_ptr<RangeBase> >& v,
|
||||
std::shared_ptr<DynamicRange> r)
|
||||
{
|
||||
if(not r->isEmpty()){
|
||||
for(size_t i = r->dim(); i != 0; --i){
|
||||
v.insert(v.begin(), r->sub(i-1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j)
|
||||
{
|
||||
size_t ss = 0;
|
||||
size_t sx = 1;
|
||||
for(size_t k = ii.dim(); k != 0; --k){
|
||||
const size_t i = k-1;
|
||||
const auto& ni = ii.get(i);
|
||||
const size_t max = ni.max();
|
||||
const size_t tmp = ni.getStepSizeComp(j);
|
||||
ss += tmp * ii.getStepSize(i);
|
||||
sx *= max;
|
||||
}
|
||||
return ss;
|
||||
template <>
|
||||
inline size_t getStepSize<DynamicIndex>(const DynamicIndex& ii, std::intptr_t j)
|
||||
{
|
||||
size_t ss = 0;
|
||||
size_t sx = 1;
|
||||
for(size_t k = ii.dim(); k != 0; --k){
|
||||
const size_t i = k-1;
|
||||
const auto& ni = ii.get(i);
|
||||
const size_t max = ni.max();
|
||||
const size_t tmp = ni.getStepSizeComp(j);
|
||||
ss += tmp * ii.getStepSize(i);
|
||||
sx *= max;
|
||||
}
|
||||
return ss;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __dynamic_range_h__
|
||||
#define __dynamic_range_h__
|
||||
#ifndef __cxz_dynamic_range_h__
|
||||
#define __cxz_dynamic_range_h__
|
||||
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
|
@ -11,19 +11,17 @@
|
|||
|
||||
#include "xfor/xfor.h"
|
||||
|
||||
//#include "ranges/rpheader.h"
|
||||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
#include "ranges/dynamic_meta.h"
|
||||
|
||||
#include "index_wrapper.h"
|
||||
#include "rpack_num.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
class DynamicIndex : public IndexInterface<DynamicIndex,vector<char>>
|
||||
|
@ -111,9 +109,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n) const;
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
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"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __index_base_h__
|
||||
#define __index_base_h__
|
||||
#ifndef __cxz_index_base_h__
|
||||
#define __cxz_index_base_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "xfor/xfor.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <class I, typename MetaType>
|
||||
|
@ -57,15 +57,11 @@ namespace MultiArrayTools
|
|||
|
||||
operator size_t() const;
|
||||
|
||||
std::string id() const { return THIS().id(); }
|
||||
|
||||
std::string stringMeta() const { return THIS().stringMeta(); }
|
||||
MetaType meta() const { return THIS().meta(); }
|
||||
MetaType metaPtr() const { return THIS().metaPtr(); }
|
||||
I& at(const MetaType& meta) { return THIS().at(meta); }
|
||||
|
||||
void print(size_t offset = 0) const { THIS().print(offset); }
|
||||
|
||||
// CHECK / IMPLEMENT !!!!!!
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, const Expr ex) const
|
||||
|
@ -93,7 +89,6 @@ namespace MultiArrayTools
|
|||
|
||||
std::shared_ptr<RangeBase> mRangePtr;
|
||||
size_t mPos = 0;
|
||||
size_t mId;
|
||||
size_t mMax = 0;
|
||||
|
||||
std::intptr_t mPtrNum;
|
||||
|
@ -111,14 +106,14 @@ namespace MultiArrayTools
|
|||
* --- TEMPLATE CODE --- *
|
||||
* ========================= */
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/**********************
|
||||
* IndexInterface *
|
||||
**********************/
|
||||
|
||||
template <class I, typename MetaType>
|
||||
IndexInterface<I,MetaType>::IndexInterface() : mId(indexId())
|
||||
IndexInterface<I,MetaType>::IndexInterface()
|
||||
{
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
@ -128,7 +123,6 @@ namespace MultiArrayTools
|
|||
mPos(in.mPos),
|
||||
mMax(in.mMax)
|
||||
{
|
||||
mId = indexId();
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
||||
|
@ -137,7 +131,6 @@ namespace MultiArrayTools
|
|||
mPos(in.mPos),
|
||||
mMax(in.mMax)
|
||||
{
|
||||
mId = indexId();
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
||||
|
@ -165,7 +158,6 @@ namespace MultiArrayTools
|
|||
mPos(pos),
|
||||
mMax(mRangePtr->size())
|
||||
{
|
||||
mId = indexId();
|
||||
mPtrNum = reinterpret_cast<std::intptr_t>(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#ifndef __index_type_h__
|
||||
#define __index_type_h__
|
||||
#ifndef __cxz_index_type_h__
|
||||
#define __cxz_index_type_h__
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
enum class IndexType{
|
||||
SINGLE = 0,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#include "index_wrapper.h"
|
||||
#include "rpack_num.h"
|
||||
#include "range_helper.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <class Index>
|
||||
|
@ -117,9 +117,9 @@ namespace MultiArrayTools
|
|||
template <class Index>
|
||||
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){
|
||||
out = MultiArrayHelper::getStepSize(*mCI, j);
|
||||
out = RangeHelper::getStepSize(*mCI, j);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -153,14 +153,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
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>
|
||||
std::shared_ptr<Index> IndexWrapper<Index>::getIndex() const
|
||||
{
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
|
||||
#ifndef __index_wrapper_h__
|
||||
#define __index_wrapper_h__
|
||||
#ifndef __cxz_index_wrapper_h__
|
||||
#define __cxz_index_wrapper_h__
|
||||
|
||||
#include "ranges/rbase_def.h"
|
||||
#include "xfor/xfor.h"
|
||||
#include "hl_reg_ind.h"
|
||||
#include "ranges/rheader.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
class IndexWrapperBase
|
||||
|
@ -50,13 +50,6 @@ namespace MultiArrayTools
|
|||
|
||||
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)
|
||||
{
|
||||
// ignore spaces, " and ' (string identifiers)
|
||||
|
@ -150,7 +143,6 @@ namespace MultiArrayTools
|
|||
virtual DynamicExpression iforh(size_t step, DynamicExpression ex) const override final;
|
||||
|
||||
virtual std::shared_ptr<IndexWrapperBase> duplicate() const override final;
|
||||
//virtual RegIndInfo regN() const override final;
|
||||
|
||||
std::shared_ptr<Index> getIndex() const;
|
||||
virtual std::shared_ptr<ClassicIndex> reduced() const override final;
|
||||
|
|
|
@ -1,27 +1,28 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __multi_range_h__
|
||||
#define __multi_range_h__
|
||||
#ifndef __cxz_multi_range_h__
|
||||
#define __cxz_multi_range_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
//#include "base_def.h"
|
||||
#include "ranges/range_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/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
#include "statics/static_for.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
|
@ -39,7 +40,7 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr IndexType sType() { return IndexType::MULTI; }
|
||||
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 bool PARALLEL = std::tuple_element<0,std::tuple<Indices...>>::type::PARALLEL;
|
||||
|
@ -57,10 +58,6 @@ namespace MultiArrayTools
|
|||
|
||||
// NO DEFAULT HERE !!!
|
||||
// ( 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>
|
||||
MultiIndex(const std::shared_ptr<MRange>& range);
|
||||
|
@ -80,7 +77,7 @@ namespace MultiArrayTools
|
|||
template <size_t N>
|
||||
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
|
||||
// NO foreign/external controll)
|
||||
// Do NOT share index instances between two or more MultiIndex instances
|
||||
|
@ -113,21 +110,14 @@ namespace MultiArrayTools
|
|||
|
||||
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;
|
||||
|
||||
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));
|
||||
auto iforh(size_t step, Exprs exs) const;
|
||||
|
||||
template <class Exprs>
|
||||
auto pifor(size_t step, Exprs exs) const
|
||||
-> decltype(RPackNum<sizeof...(Indices)-1>::mkPFor(step, mIPack, mBlockSizes, exs));
|
||||
|
||||
auto pifor(size_t step, Exprs exs) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -146,9 +136,6 @@ namespace MultiArrayTools
|
|||
MultiRangeFactory(const std::shared_ptr<Ranges>&... rs);
|
||||
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;
|
||||
|
||||
private:
|
||||
|
@ -171,7 +158,6 @@ namespace MultiArrayTools
|
|||
typedef std::tuple<typename Ranges::IndexType::MetaType...> MetaType;
|
||||
typedef MultiRange RangeType;
|
||||
typedef MultiRangeFactory<Ranges...> FType;
|
||||
//typedef typename RangeInterface<MultiIndex<typename Ranges::IndexType...> >::IndexType IndexType;
|
||||
|
||||
protected:
|
||||
MultiRange() = delete;
|
||||
|
@ -222,8 +208,8 @@ namespace MultiArrayTools
|
|||
|
||||
static constexpr bool HASMETACONT = false;
|
||||
static constexpr bool defaultable = false;
|
||||
static constexpr size_t ISSTATIC = SubProp<Ranges...>::ISSTATIC;
|
||||
static constexpr size_t SIZE = SubProp<Ranges...>::SIZE;
|
||||
static constexpr size_t ISSTATIC = (... & Ranges::ISSTATIC);
|
||||
static constexpr size_t SIZE = (... * Ranges::SIZE);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -232,12 +218,12 @@ namespace MultiArrayTools
|
|||
* --- TEMPLATE CODE --- *
|
||||
* ========================= */
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
// -> define in range_base.cc
|
||||
|
@ -246,43 +232,28 @@ namespace MultiArrayTools
|
|||
/******************
|
||||
* 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 MRange>
|
||||
MultiIndex<Indices...>::MultiIndex(const std::shared_ptr<MRange>& range) :
|
||||
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;
|
||||
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>
|
||||
|
@ -290,8 +261,16 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::up()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos += RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::pp( mIPack );
|
||||
IB::mPos += sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](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;
|
||||
}
|
||||
|
||||
|
@ -300,8 +279,16 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::down()
|
||||
{
|
||||
static_assert(DIR < sizeof...(Indices), "DIR exceeds number of sub-indices");
|
||||
IB::mPos -= RPackNum<sizeof...(Indices)-DIR-1>::blockSize( mIPack );
|
||||
RPackNum<DIR>::mm( mIPack );
|
||||
IB::mPos -= sfor_p<DIR,sizeof...(Indices)>
|
||||
( [&](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;
|
||||
}
|
||||
|
||||
|
@ -322,16 +309,15 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(std::shared_ptr<Indices>&... indices)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices...);
|
||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
||||
return *this;
|
||||
return (*this)(std::make_tuple(indices...));
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator()(const std::tuple<std::shared_ptr<Indices>...>& indices)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::swapIndices(mIPack, indices);
|
||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, IB::mPos);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -345,14 +331,20 @@ namespace MultiArrayTools
|
|||
MultiIndex<Indices...>& MultiIndex<Indices...>::operator=(size_t pos)
|
||||
{
|
||||
IB::mPos = pos;
|
||||
RPackNum<sizeof...(Indices)-1>::setIndexPack(mIPack, pos);
|
||||
RangeHelper::setIndexPack<sizeof...(Indices)-1>(mIPack, pos);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
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;
|
||||
return *this;
|
||||
}
|
||||
|
@ -360,15 +352,22 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
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;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <class... Indices>
|
||||
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;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -376,7 +375,7 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
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;
|
||||
return tmp;
|
||||
}
|
||||
|
@ -391,15 +390,19 @@ namespace MultiArrayTools
|
|||
typename MultiIndex<Indices...>::MetaType MultiIndex<Indices...>::meta() const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
template <class... Indices>
|
||||
MultiIndex<Indices...>& MultiIndex<Indices...>::at(const MetaType& metaPos)
|
||||
{
|
||||
RPackNum<sizeof...(Indices)-1>::setMeta(mIPack, metaPos);
|
||||
IB::mPos = RPackNum<sizeof...(Indices)-1>::makePos(mIPack);
|
||||
sfor_pn<0,sizeof...(Indices)>
|
||||
( [&](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;
|
||||
}
|
||||
|
||||
|
@ -444,47 +447,26 @@ namespace MultiArrayTools
|
|||
}
|
||||
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 Exprs>
|
||||
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 Exprs>
|
||||
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 Exprs>
|
||||
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 ) );
|
||||
}
|
||||
|
||||
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>
|
||||
std::shared_ptr<RangeBase> MultiRangeFactory<Ranges...>::create()
|
||||
{
|
||||
|
@ -525,7 +500,9 @@ namespace MultiArrayTools
|
|||
bool check = false;
|
||||
for(auto& x: MultiRangeFactoryProductMap::mAleadyCreated){
|
||||
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){
|
||||
out = x.first;
|
||||
break;
|
||||
|
@ -534,7 +511,8 @@ namespace MultiArrayTools
|
|||
}
|
||||
if(not check){
|
||||
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;
|
||||
out = mProd;
|
||||
}
|
||||
|
@ -561,7 +539,7 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
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>
|
||||
|
@ -574,7 +552,10 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
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>
|
||||
|
@ -586,7 +567,9 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
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>
|
||||
|
@ -605,7 +588,7 @@ namespace MultiArrayTools
|
|||
vector<size_t> MultiRange<Ranges...>::typeNum() const
|
||||
{
|
||||
vector<size_t> o;
|
||||
RPackNum<sizeof...(Ranges)-1>::getTypeNum(o,mSpace);
|
||||
RangeHelper::getTypeNum<sizeof...(Ranges)-1>(o,mSpace);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
@ -614,13 +597,13 @@ namespace MultiArrayTools
|
|||
{
|
||||
const size_t off = cmetaSize();
|
||||
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>
|
||||
size_t MultiRange<Ranges...>::cmetaSize() const
|
||||
{
|
||||
return RPackNum<sizeof...(Ranges)-1>::getCMetaSize(mSpace);
|
||||
return RangeHelper::getCMetaSize<0>(mSpace);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
|
@ -628,7 +611,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
auto i = begin();
|
||||
i = pos;
|
||||
return "[" + RPackNum<sizeof...(Ranges)-1>::getStringMeta(i) + "]";
|
||||
return "[" + RangeHelper::getStringMeta<0>(i) + "]";
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
|
@ -639,7 +622,12 @@ namespace MultiArrayTools
|
|||
//out.reserve(h.metaSize + sizeof(DataHeader));
|
||||
char* hcp = reinterpret_cast<char*>(&h);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
|
||||
#ifndef __multi_range_factory_product_map_h__
|
||||
#define __multi_range_factory_product_map_h__
|
||||
#ifndef __cxz_multi_range_factory_product_map_h__
|
||||
#define __cxz_multi_range_factory_product_map_h__
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "ranges/rbase_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
class MultiRangeFactoryProductMap
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __range_base_h__
|
||||
#define __range_base_h__
|
||||
#ifndef __cxz_range_base_h__
|
||||
#define __cxz_range_base_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
@ -9,12 +9,12 @@
|
|||
|
||||
#include "rbase_def.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
class RangeBase;
|
||||
}
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
size_t indexId();
|
||||
|
@ -116,6 +116,8 @@ namespace MultiArrayTools
|
|||
|
||||
virtual Index begin() 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
|
||||
{ return mkIndexWrapper(this->begin()); }
|
||||
//{ 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
|
||||
|
||||
#ifndef include_range_type
|
||||
#ifdef __ranges_header__
|
||||
#ifdef __cxz_ranges_header__
|
||||
// assert, that this is only used within range_types/header.h
|
||||
|
||||
#ifndef __range_type_classic_def__
|
||||
#define __range_type_classic_def__
|
||||
#ifndef __cxz_range_type_classic_def__
|
||||
#define __cxz_range_type_classic_def__
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
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
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
|
||||
#ifdef include_range_type
|
||||
#define __incl_this__
|
||||
#define __cxz_incl_this__
|
||||
#endif
|
||||
#ifdef __single_range_h__
|
||||
#ifdef __cxz_single_range_h__
|
||||
// singel_range is template which is specialized here
|
||||
// therefore it must be defined before...
|
||||
#define __incl_this__
|
||||
#define __cxz_incl_this__
|
||||
#endif
|
||||
|
||||
#ifdef __incl_this__
|
||||
#ifdef __cxz_incl_this__
|
||||
|
||||
|
||||
#define __ranges_header__
|
||||
//#ifndef __ranges_header__
|
||||
//#define __ranges_header__
|
||||
#define __cxz_ranges_header__
|
||||
//#ifndef __cxz_ranges_header__
|
||||
//#define __cxz_ranges_header__
|
||||
|
||||
#include "null_range.h"
|
||||
#include "spin_range.h"
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
include_range_type(NUL,-2)
|
||||
#else
|
||||
|
||||
#ifdef __ranges_header__
|
||||
#ifdef __cxz_ranges_header__
|
||||
// assert, that this is only used within range_types/header.h
|
||||
|
||||
#ifndef __range_type_null_def__
|
||||
#define __range_type_null_def__
|
||||
#ifndef __cxz_range_type_null_def__
|
||||
#define __cxz_range_type_null_def__
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
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
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
include_range_type(PSPACE,3) // Periodic 1dim space
|
||||
#else
|
||||
|
||||
#ifdef __ranges_header__
|
||||
#ifdef __cxz_ranges_header__
|
||||
|
||||
#ifndef __range_type_space_def__
|
||||
#define __range_type_space_def__
|
||||
#ifndef __cxz_range_type_space_def__
|
||||
#define __cxz_range_type_space_def__
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
// Periodic 1dim space
|
||||
typedef GenSingleIndex<int,SpaceType::PSPACE,MUI> XSpaceIndex;
|
||||
|
@ -128,8 +128,8 @@ namespace MultiArrayTools
|
|||
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
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
include_range_type(SPIN,2)
|
||||
#else
|
||||
|
||||
#ifdef __ranges_header__
|
||||
#ifdef __cxz_ranges_header__
|
||||
// assert, that this is only used within range_types/header.h
|
||||
|
||||
#ifndef __range_type_spin_def__
|
||||
#define __range_type_spin_def__
|
||||
#ifndef __cxz_range_type_spin_def__
|
||||
#define __cxz_range_type_spin_def__
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
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
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "rpack_num.cc.h"
|
||||
#include "ranges/dynamic_range.cc.h"
|
||||
#include "ranges/index_wrapper.cc.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __ranges_base_def_h__
|
||||
#define __ranges_base_def_h__
|
||||
#ifndef __cxz_ranges_base_def_h__
|
||||
#define __cxz_ranges_base_def_h__
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
|||
#include "allocator.h"
|
||||
#define MUI static_cast<size_t>(-1)
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <class R>
|
||||
|
@ -80,28 +80,9 @@ namespace MultiArrayTools
|
|||
template <class... Indices>
|
||||
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
|
||||
class AnonymousRangeFactory;
|
||||
|
||||
// anonymous_range.h
|
||||
//class AnonymousRange;
|
||||
|
||||
// dynamic_range.h
|
||||
class IndexWrapperBase;
|
||||
|
||||
|
@ -110,15 +91,12 @@ namespace MultiArrayTools
|
|||
class IndexWrapper;
|
||||
|
||||
// dynamic_range.h
|
||||
//template <class EC>
|
||||
class DynamicIndex;
|
||||
|
||||
// dynamic_range.h
|
||||
//template <class EC>
|
||||
class DynamicRangeFactory;
|
||||
|
||||
// dynamic_range.h
|
||||
//template <class EC>
|
||||
class DynamicRange;
|
||||
|
||||
// value_range.h
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __reg_ind_num_h__
|
||||
#define __reg_ind_num_h__
|
||||
#ifndef __cxz_reg_ind_num_h__
|
||||
#define __cxz_reg_ind_num_h__
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
//#ifndef __rheader_h__
|
||||
//#define __rheader_h__
|
||||
//#ifndef __cxz_rheader_h__
|
||||
//#define __cxz_rheader_h__
|
||||
|
||||
#include "dynamic_range.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__
|
||||
//#define __rpheader_h__
|
||||
//#ifndef __cxz_rpheader_h__
|
||||
//#define __cxz_rpheader_h__
|
||||
|
||||
#include "single_range.h"
|
||||
#include "multi_range.h"
|
||||
#include "container_range.h"
|
||||
#include "subrange.h"
|
||||
//#include "anonymous_range.h"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
#ifndef __single_range_h__
|
||||
#define __single_range_h__
|
||||
#ifndef __cxz_single_range_h__
|
||||
#define __cxz_single_range_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
@ -9,22 +9,18 @@
|
|||
#include <map>
|
||||
|
||||
#include "base_def.h"
|
||||
//#include "ranges/rpack_num.h"
|
||||
#include "ranges/index_base.h"
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/type_map.h"
|
||||
|
||||
#include "xfor/for_type.h"
|
||||
//#include "xfor/xfor.h"
|
||||
|
||||
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,9 +74,6 @@ namespace MultiArrayTools
|
|||
void getPtr();
|
||||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
|
@ -334,7 +327,7 @@ namespace MultiArrayTools
|
|||
* --- TEMPLATE CODE --- *
|
||||
* ========================= */
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/******************
|
||||
* GenSingleIndex *
|
||||
|
@ -492,23 +485,6 @@ namespace MultiArrayTools
|
|||
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 <class Expr>
|
||||
auto GenSingleIndex<U,TYPE,S>::ifor(size_t step, Expr ex) const
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __subrange_h__
|
||||
#define __subrange_h__
|
||||
#ifndef __cxz_subrange_h__
|
||||
#define __cxz_subrange_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
@ -8,7 +8,6 @@
|
|||
#include <map>
|
||||
|
||||
#include "base_def.h"
|
||||
//#include "ranges/rpack_num.h"
|
||||
#include "ranges/index_base.h"
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/x_to_string.h"
|
||||
|
@ -16,11 +15,11 @@
|
|||
|
||||
#include "xfor/for_type.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
template <class Index>
|
||||
|
@ -71,9 +70,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
-> 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;
|
||||
}
|
||||
|
||||
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 Expr>
|
||||
auto SubIndex<Index>::ifor(size_t step, Expr ex) const
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __ma_type_map_h__
|
||||
#define __ma_type_map_h__
|
||||
#ifndef __cxz_type_map_h__
|
||||
#define __cxz_type_map_h__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "allocator.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
template <size_t N>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __value_range_h__
|
||||
#define __value_range_h__
|
||||
#ifndef __cxz_value_range_h__
|
||||
#define __cxz_value_range_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
@ -17,12 +17,12 @@
|
|||
|
||||
#include "xfor/for_type.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
|
@ -69,9 +69,6 @@ namespace MultiArrayTools
|
|||
|
||||
size_t getStepSize(size_t n);
|
||||
|
||||
std::string id() const;
|
||||
void print(size_t offset);
|
||||
|
||||
template <class Expr>
|
||||
auto ifor(size_t step, Expr ex) const
|
||||
-> For<ValueIndex<U>,Expr>;
|
||||
|
@ -141,13 +138,13 @@ namespace MultiArrayTools
|
|||
ValueRange() = default;
|
||||
};
|
||||
|
||||
} // namespace MultiArrayTools
|
||||
} // namespace CNORXZ
|
||||
|
||||
/* ========================= *
|
||||
* --- TEMPLATE CODE --- *
|
||||
* ========================= */
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/*****************
|
||||
* ValueIndex *
|
||||
|
@ -275,23 +272,6 @@ namespace MultiArrayTools
|
|||
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 <class Expr>
|
||||
auto ValueIndex<U>::ifor(size_t step, Expr ex) const
|
||||
|
@ -430,6 +410,6 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
|
||||
} // namespace MultiArrayTools
|
||||
} // namespace CNORXZ
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __x_to_string_h__
|
||||
#define __x_to_string_h__
|
||||
#ifndef __cxz_x_to_string_h__
|
||||
#define __cxz_x_to_string_h__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "ranges/dynamic_meta.h"
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
template <typename T>
|
||||
inline std::string xToString(const T& x);
|
||||
|
@ -22,7 +22,7 @@ namespace MultiArrayHelper
|
|||
template <>
|
||||
inline std::string xToString<std::string>(const std::string& x);
|
||||
|
||||
using MultiArrayTools::DynamicMetaT;
|
||||
using CNORXZ::DynamicMetaT;
|
||||
|
||||
template <>
|
||||
inline std::string xToString<DynamicMetaT>(const DynamicMetaT& x);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "slice.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
/*******************
|
||||
|
@ -17,7 +17,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class... SRanges>
|
||||
ConstSlice<T,SRanges...>::ConstSlice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
||||
const T* data) :
|
||||
MultiArrayBase<T,SRanges...>(ranges),
|
||||
ArrayBase<T,SRanges...>(ranges),
|
||||
mData(data)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -25,15 +25,15 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... SRanges>
|
||||
ConstSlice<T,SRanges...>::ConstSlice(const std::shared_ptr<SRanges>&... ranges, const T* data) :
|
||||
MultiArrayBase<T,SRanges...>(ranges...),
|
||||
ArrayBase<T,SRanges...>(ranges...),
|
||||
mData(data)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
ConstSlice<T,SRanges...>::ConstSlice(const MultiArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) :
|
||||
MultiArrayBase<T,SRanges...>
|
||||
ConstSlice<T,SRanges...>::ConstSlice(const ArrayBase<T,AnonymousRange>& ma, SIZET<SRanges>... sizes) :
|
||||
ArrayBase<T,SRanges...>
|
||||
( ma.range()->template get<0>().template scast<SRanges...>(sizes...)->space() ),
|
||||
mData( ma.data() )
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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(not MAB::mProtoI->sliceMode()); // only originally ordered slices!
|
||||
|
@ -118,13 +118,13 @@ namespace MultiArrayTools
|
|||
|
||||
template <typename T, class... SRanges>
|
||||
Slice<T,SRanges...>::Slice(const std::shared_ptr<SRanges>&... ranges, T* data) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges...),
|
||||
MutableArrayBase<T,SRanges...>(ranges...),
|
||||
mData(data) {}
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
Slice<T,SRanges...>::Slice(const std::tuple<std::shared_ptr<SRanges>...>& ranges,
|
||||
T* data) :
|
||||
MutableMultiArrayBase<T,SRanges...>(ranges),
|
||||
MutableArrayBase<T,SRanges...>(ranges),
|
||||
mData(data)
|
||||
{
|
||||
MAB::mInit = true;
|
||||
|
@ -208,14 +208,14 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
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!!!!
|
||||
return nullptr;
|
||||
}
|
||||
/*
|
||||
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!!!!
|
||||
return nullptr;
|
||||
|
@ -243,8 +243,12 @@ namespace MultiArrayTools
|
|||
SliceDef<T,SRanges...>& SliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
|
||||
{
|
||||
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
||||
PackNum<sizeof...(SRanges)-1>::
|
||||
template mkSliceBlocks<T,OperationRoot<T,ORanges...>,SRanges...>(blocks, mIndex, op);
|
||||
sfor_pn<0,sizeof...(SRanges)>
|
||||
( [&](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.mData = op.data();
|
||||
return *this;
|
||||
|
@ -264,8 +268,12 @@ namespace MultiArrayTools
|
|||
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const ConstOperationRoot<T,ORanges...>& op)
|
||||
{
|
||||
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
||||
PackNum<sizeof...(SRanges)-1>::
|
||||
template mkSliceBlocks<T,ConstOperationRoot<T,ORanges...>,SRanges...>(blocks, mIndex, op);
|
||||
sfor_pn<0,sizeof...(SRanges)>
|
||||
( [&](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.mData = op.data();
|
||||
return *this;
|
||||
|
@ -276,13 +284,17 @@ namespace MultiArrayTools
|
|||
ConstSliceDef<T,SRanges...>& ConstSliceDef<T,SRanges...>::operator=(const OperationRoot<T,ORanges...>& op)
|
||||
{
|
||||
std::array<size_t,sizeof...(SRanges)+1> blocks;
|
||||
PackNum<sizeof...(SRanges)-1>::
|
||||
template mkSliceBlocks<T,OperationRoot<T,ORanges...>,SRanges...>(blocks, mIndex, op);
|
||||
sfor_pn<0,sizeof...(SRanges)>
|
||||
( [&](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.mData = op.data();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
} // end namespace CNORXZ
|
||||
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
|
||||
#ifndef __slice_h__
|
||||
#define __slice_h__
|
||||
#ifndef __cxz_slice_h__
|
||||
#define __cxz_slice_h__
|
||||
|
||||
#include "multi_array_base.h"
|
||||
#include "multi_array_operation.h"
|
||||
#include "cxz_array_base.h"
|
||||
#include "cxz_operation.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
template <typename T, class... SRanges>
|
||||
class ConstSlice : public MultiArrayBase<T,SRanges...>
|
||||
class ConstSlice : public ArrayBase<T,SRanges...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ContainerRange<T,SRanges...> CRange;
|
||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef ArrayBase<T,SRanges...> MAB;
|
||||
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
|
||||
using MultiArrayBase<T,SRanges...>::operator();
|
||||
using MultiArrayBase<T,SRanges...>::operator[];
|
||||
using ArrayBase<T,SRanges...>::operator();
|
||||
using ArrayBase<T,SRanges...>::operator[];
|
||||
|
||||
DEFAULT_MEMBERS(ConstSlice);
|
||||
|
||||
ConstSlice(const std::tuple<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& at(const typename IType::MetaType& meta) const override;
|
||||
|
@ -36,7 +36,7 @@ namespace MultiArrayTools
|
|||
virtual auto begin() 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)
|
||||
-> ConstSliceDef<T,SRanges...>;
|
||||
|
@ -51,18 +51,18 @@ namespace MultiArrayTools
|
|||
|
||||
|
||||
template <typename T, class... SRanges>
|
||||
class Slice : public MutableMultiArrayBase<T,SRanges...>
|
||||
class Slice : public MutableArrayBase<T,SRanges...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef ContainerRange<T,SRanges...> CRange;
|
||||
typedef MultiArrayBase<T,SRanges...> MAB;
|
||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
typedef ContainerRange<SRanges...> CRange;
|
||||
typedef ArrayBase<T,SRanges...> MAB;
|
||||
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
|
||||
using MultiArrayBase<T,SRanges...>::operator();
|
||||
using MutableMultiArrayBase<T,SRanges...>::operator();
|
||||
using MultiArrayBase<T,SRanges...>::operator[];
|
||||
using MutableMultiArrayBase<T,SRanges...>::operator[];
|
||||
using ArrayBase<T,SRanges...>::operator();
|
||||
using MutableArrayBase<T,SRanges...>::operator();
|
||||
using ArrayBase<T,SRanges...>::operator[];
|
||||
using MutableArrayBase<T,SRanges...>::operator[];
|
||||
|
||||
DEFAULT_MEMBERS(Slice);
|
||||
|
||||
|
@ -85,8 +85,8 @@ namespace MultiArrayTools
|
|||
virtual auto begin() 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<MultiArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||
virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymous(bool slice = false) const override;
|
||||
//virtual std::shared_ptr<ArrayBase<T,AnonymousRange> > anonymousMove() override;
|
||||
|
||||
auto define(const std::shared_ptr<typename SRanges::IndexType>&... inds)
|
||||
-> SliceDef<T,SRanges...>;
|
||||
|
@ -104,17 +104,20 @@ namespace MultiArrayTools
|
|||
class SliceDef
|
||||
{
|
||||
public:
|
||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
|
||||
template <class Op>
|
||||
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);
|
||||
std::array<size_t,sizeof...(SRanges)+1> ff;
|
||||
for(size_t i = 0; i != sizeof...(SRanges)+1; ++i){
|
||||
PackNum<sizeof...(SRanges)-1>::mkSliceBlocks(ff, ind, op);
|
||||
}
|
||||
sfor_pn<0,sizeof...(SRanges)>
|
||||
( [&](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);
|
||||
return out;
|
||||
}
|
||||
|
@ -137,7 +140,7 @@ namespace MultiArrayTools
|
|||
class ConstSliceDef
|
||||
{
|
||||
public:
|
||||
typedef ContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
typedef ConstContainerIndex<T,typename SRanges::IndexType...> IType;
|
||||
|
||||
template <class Op>
|
||||
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);
|
||||
std::array<size_t,sizeof...(SRanges)+1> ff;
|
||||
for(size_t i = 0; i != sizeof...(SRanges)+1; ++i){
|
||||
PackNum<sizeof...(SRanges)-1>::mkSliceBlocks(ff, ind, op);
|
||||
}
|
||||
sfor_pn<0,sizeof...(SRanges)>
|
||||
( [&](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);
|
||||
return out;
|
||||
}
|
||||
|
@ -182,7 +188,7 @@ namespace MultiArrayTools
|
|||
return SliceDef<T,Ranges...>::mkSlice(ind, op);
|
||||
}
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
} // end namespace CNORXZ
|
||||
|
||||
/* ========================= *
|
||||
* --- 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__
|
||||
#define __type_operations_h__
|
||||
#ifndef __cxz_type_operations_h__
|
||||
#define __cxz_type_operations_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
@ -9,16 +9,18 @@
|
|||
#include "base_def.h"
|
||||
#include "mbase_def.h"
|
||||
|
||||
#include "pack_num.h"
|
||||
#include "statics/static_for.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
#include <cmath>
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
// MultiArray
|
||||
// Array
|
||||
|
||||
template <typename T, class... Ranges>
|
||||
class operate
|
||||
|
@ -28,10 +30,13 @@ namespace MultiArrayTools
|
|||
|
||||
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...>
|
||||
{
|
||||
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:
|
||||
|
@ -41,9 +46,9 @@ namespace MultiArrayTools
|
|||
};
|
||||
|
||||
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)
|
||||
-> Operation<OperationRoot<T,Ranges...>,operate<T,Ranges...>,OperationClass>
|
||||
|
@ -470,7 +475,49 @@ namespace MultiArrayTools
|
|||
xsdiv<4>( o._x, a._x );
|
||||
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
|
||||
|
|
|
@ -1,48 +1,96 @@
|
|||
|
||||
#ifndef __exttype_h__
|
||||
#define __exttype_h__
|
||||
#ifndef __cxz_exttype_h__
|
||||
#define __cxz_exttype_h__
|
||||
|
||||
#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;
|
||||
|
||||
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>
|
||||
class MExt
|
||||
{
|
||||
|
@ -82,10 +130,18 @@ namespace MultiArrayHelper
|
|||
inline const X& next() const;
|
||||
|
||||
template <size_t N>
|
||||
inline auto nn() const
|
||||
-> decltype(Getter<N>::getX(*this))
|
||||
{ return Getter<N>::getX(*this); }
|
||||
|
||||
inline auto nn() const;
|
||||
|
||||
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 None& in) const;
|
||||
inline MExt operator*(size_t in) const;
|
||||
|
@ -110,7 +166,17 @@ namespace MultiArrayHelper
|
|||
None(const Y& y) {}
|
||||
|
||||
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*(size_t in) const { return None(); }
|
||||
|
||||
|
@ -157,16 +223,24 @@ namespace MultiArrayHelper
|
|||
|
||||
template <class 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 None next() const { return None(); }
|
||||
|
||||
inline void zero();
|
||||
|
||||
template <size_t N>
|
||||
inline auto nn() const
|
||||
-> decltype(Getter<N>::getX(*this))
|
||||
{ return Getter<N>::getX(*this); }
|
||||
inline auto nn() const;
|
||||
|
||||
inline MExt operator+(const MExt& 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 --- *
|
||||
* ========================= */
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
|
||||
template <class X>
|
||||
|
@ -233,6 +426,13 @@ namespace MultiArrayHelper
|
|||
mNext.zero();
|
||||
}
|
||||
|
||||
template <class X>
|
||||
template <size_t N>
|
||||
inline auto MExt<X>::nn() const
|
||||
{
|
||||
return getX<N>(*this);
|
||||
}
|
||||
|
||||
template <class X>
|
||||
inline MExt<X> MExt<X>::operator+(const MExt<X>& in) const
|
||||
{
|
||||
|
@ -282,6 +482,12 @@ namespace MultiArrayHelper
|
|||
mExt = 0u;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
inline auto MExt<None>::nn() const
|
||||
{
|
||||
return getX<N>(*this);
|
||||
}
|
||||
|
||||
inline const size_t& MExt<None>::val() const
|
||||
{
|
||||
return mExt;
|
||||
|
@ -304,8 +510,14 @@ namespace MultiArrayHelper
|
|||
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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#ifndef __for_type_h__
|
||||
#define __for_type_h__
|
||||
#ifndef __cxz_for_type_h__
|
||||
#define __cxz_for_type_h__
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
|
||||
enum class ForType {
|
||||
|
@ -10,11 +10,14 @@ namespace MultiArrayHelper
|
|||
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;
|
||||
|
||||
template <class IndexClass, class Expr, size_t DIV = 1>
|
||||
class PFor;
|
||||
|
||||
|
||||
} // end namespace MultiArrayHelper
|
||||
} // end namespace CNORXZInternal
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
#ifndef __for_utils_h__
|
||||
#define __for_utils_h__
|
||||
#ifndef __cxz_for_utils_h__
|
||||
#define __cxz_for_utils_h__
|
||||
|
||||
//#include "ranges/rheader.h"
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
namespace {
|
||||
template <class Op>
|
||||
|
@ -34,6 +34,6 @@ namespace MultiArrayHelper
|
|||
|
||||
};
|
||||
|
||||
} // end namespace MultiArrayHelper
|
||||
} // end namespace CNORXZInternal
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __ma_iloop_h__
|
||||
#define __ma_iloop_h__
|
||||
#ifndef __cxz_iloop_h__
|
||||
#define __cxz_iloop_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
@ -9,7 +9,7 @@
|
|||
#include <omp.h>
|
||||
#include "xfor.h"
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
template <size_t N>
|
||||
struct NN
|
||||
|
@ -116,6 +116,7 @@ namespace MultiArrayHelper
|
|||
|
||||
public:
|
||||
//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 bool CONT = false;
|
||||
typedef decltype(NN<LTpSize-1>::rootSteps(mLTp)) ExtType;
|
||||
|
@ -248,6 +249,8 @@ namespace MultiArrayHelper
|
|||
static constexpr size_t VarTpSize = LType::VarTpSize;
|
||||
|
||||
public:
|
||||
|
||||
static constexpr size_t NHLAYER = 10; // some large value
|
||||
static constexpr size_t SIZE = LType::SIZE;
|
||||
static constexpr bool CONT = LType::CONT;
|
||||
typedef typename LType::ExtType ExtType;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef __xfor_h__
|
||||
#define __xfor_h__
|
||||
#ifndef __cxz_xfor_h__
|
||||
#define __cxz_xfor_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
@ -15,155 +15,15 @@
|
|||
#define VCHECK(a) std::cout << __FILE__ << ": @" << __LINE__ \
|
||||
<< " 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.
|
||||
// (NO COUNTING OF MASTER POSITION !!!!!)
|
||||
|
||||
//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
|
||||
{
|
||||
|
@ -175,6 +35,9 @@ namespace MultiArrayHelper
|
|||
ExpressionBase& operator=(const 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 void operator()(size_t mlast, DExt last) = 0;
|
||||
|
@ -217,20 +80,20 @@ namespace MultiArrayHelper
|
|||
template <size_t ISSTATIC>
|
||||
struct ForBound
|
||||
{
|
||||
template <size_t BOUND>
|
||||
template <size_t BOUND, size_t DIV = 1>
|
||||
static inline size_t bound(size_t bound)
|
||||
{
|
||||
return bound;
|
||||
return bound / DIV;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ForBound<1>
|
||||
{
|
||||
template <size_t BOUND>
|
||||
template <size_t BOUND, size_t DIV = 1>
|
||||
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 SIZE = Expr::SIZE;
|
||||
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||
|
||||
SingleExpression(const SingleExpression& in) = default;
|
||||
SingleExpression& operator=(const SingleExpression& in) = default;
|
||||
|
@ -273,6 +137,9 @@ namespace MultiArrayHelper
|
|||
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, ExtType last);
|
||||
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 SIZE = Expr::SIZE + 1;
|
||||
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||
|
||||
SubExpr(const SubExpr& in) = default;
|
||||
SubExpr& operator=(const SubExpr& in) = default;
|
||||
|
@ -326,6 +194,9 @@ namespace MultiArrayHelper
|
|||
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, ExtType last) ;
|
||||
inline void operator()(size_t mlast = 0) override final;
|
||||
|
@ -337,15 +208,95 @@ namespace MultiArrayHelper
|
|||
auto extension() const -> ExtType;
|
||||
};
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
class PFor;
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
template <size_t LAYER, bool ISV>
|
||||
struct MkVFor
|
||||
{
|
||||
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
|
||||
{
|
||||
private:
|
||||
For() = default;
|
||||
|
||||
typedef typename IndexClass::RangeType RangeType;
|
||||
const IndexClass* mIndPtr;
|
||||
size_t mSPos;
|
||||
size_t mMax;
|
||||
|
@ -359,10 +310,12 @@ namespace MultiArrayHelper
|
|||
|
||||
public:
|
||||
typedef ExpressionBase EB;
|
||||
|
||||
|
||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||
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& operator=(const For& in) = default;
|
||||
For(For&& in) = default;
|
||||
|
@ -376,14 +329,35 @@ namespace MultiArrayHelper
|
|||
|
||||
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, ExtType last) ;
|
||||
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 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
|
||||
{
|
||||
private:
|
||||
PFor() = default;
|
||||
|
||||
typedef typename IndexClass::RangeType RangeType;
|
||||
const IndexClass* mIndPtr;
|
||||
size_t mSPos;
|
||||
size_t mMax;
|
||||
|
@ -415,18 +391,40 @@ namespace MultiArrayHelper
|
|||
|
||||
static constexpr size_t LAYER = Expr::LAYER + 1;
|
||||
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& operator=(const PFor& in) = default;
|
||||
PFor(PFor&& in) = default;
|
||||
PFor& operator=(PFor&& in) = default;
|
||||
|
||||
|
||||
PFor(const std::shared_ptr<IndexClass>& indPtr,
|
||||
size_t step, Expr expr);
|
||||
|
||||
PFor(const IndexClass* indPtr,
|
||||
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
|
||||
{
|
||||
return std::make_shared<PFor<IndexClass,Expr>>(*this);
|
||||
|
@ -462,6 +460,7 @@ namespace MultiArrayHelper
|
|||
|
||||
static constexpr size_t LAYER = 0;
|
||||
static constexpr size_t SIZE = 0;
|
||||
static constexpr size_t NHLAYER = 0;
|
||||
|
||||
DynamicExpression(const DynamicExpression& in) :
|
||||
mThreadId(omp_get_thread_num()),
|
||||
|
@ -504,6 +503,9 @@ namespace MultiArrayHelper
|
|||
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, DExtT last) { (*this)(mlast,last.get()); }
|
||||
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 SIZE = Expr::SIZE;
|
||||
static constexpr size_t NHLAYER = Expr::NHLAYER + 1;
|
||||
|
||||
ExpressionHolder(const ExpressionHolder& in) = default;
|
||||
ExpressionHolder(ExpressionHolder&& in) = default;
|
||||
|
@ -559,7 +562,7 @@ namespace MultiArrayHelper
|
|||
|
||||
};
|
||||
|
||||
} // namespace MultiArrayHelper
|
||||
} // namespace CNORXZInternal
|
||||
|
||||
/* ========================= *
|
||||
* --- TEMPLATE CODE --- *
|
||||
|
@ -567,7 +570,7 @@ namespace MultiArrayHelper
|
|||
|
||||
#include <iostream>
|
||||
|
||||
namespace MultiArrayHelper
|
||||
namespace CNORXZInternal
|
||||
{
|
||||
template <class ExtType>
|
||||
const ExtType& ExtBase::expl() const
|
||||
|
@ -579,50 +582,54 @@ namespace MultiArrayHelper
|
|||
* F o r *
|
||||
*****************/
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
For<IndexClass,Expr,FT>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
For<IndexClass,Expr,FT,DIV>::For(const std::shared_ptr<IndexClass>& indPtr,
|
||||
size_t step, Expr expr) :
|
||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||
{
|
||||
assert(mMax % DIV == 0);
|
||||
assert(mIndPtr != nullptr);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
For<IndexClass,Expr,FT>::For(const IndexClass* indPtr,
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
For<IndexClass,Expr,FT,DIV>::For(const IndexClass* indPtr,
|
||||
size_t step, Expr expr) :
|
||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||
{
|
||||
//VCHECK(mMax);
|
||||
//VCHECK(DIV);
|
||||
//assert(mMax % DIV == 0);
|
||||
assert(mIndPtr != nullptr);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast, DExt last)
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
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, *reinterpret_cast<ExtType const*>(last.first));
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast,
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast,
|
||||
ExtType last)
|
||||
{
|
||||
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 ExtType npos = last + mExt*pos;
|
||||
mExpr(mnpos, npos);
|
||||
}
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
inline void For<IndexClass,Expr,FT>::operator()(size_t mlast)
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
inline void For<IndexClass,Expr,FT,DIV>::operator()(size_t mlast)
|
||||
{
|
||||
typedef typename IndexClass::RangeType RangeType;
|
||||
ExtType last = rootSteps();
|
||||
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 ExtType npos = last + mExt*pos;
|
||||
mExpr(mnpos, npos);
|
||||
|
@ -630,22 +637,22 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
auto For<IndexClass,Expr,FT>::rootSteps(std::intptr_t iPtrNum) const
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
auto For<IndexClass,Expr,FT,DIV>::rootSteps(std::intptr_t iPtrNum) const
|
||||
-> ExtType
|
||||
{
|
||||
return mExpr.rootSteps(iPtrNum);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
auto For<IndexClass,Expr,FT>::extension() const
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
auto For<IndexClass,Expr,FT,DIV>::extension() const
|
||||
-> ExtType
|
||||
{
|
||||
return mExt;
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
DExt For<IndexClass,Expr,FT>::dRootSteps(std::intptr_t iPtrNum) const
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
DExt For<IndexClass,Expr,FT,DIV>::dRootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||
//mRootSteps = rootSteps(iPtrNum);
|
||||
|
@ -653,52 +660,54 @@ namespace MultiArrayHelper
|
|||
// sizeof(ExtType)/sizeof(size_t));
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
DExt For<IndexClass,Expr,FT>::dExtension() const
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
DExt For<IndexClass,Expr,FT,DIV>::dExtension() const
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(mExt);
|
||||
//return std::make_pair<size_t const*,size_t>(reinterpret_cast<size_t const*>(&mExt),
|
||||
// sizeof(ExtType)/sizeof(size_t));
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr, ForType FT>
|
||||
PFor<IndexClass,Expr> For<IndexClass,Expr,FT>::parallel() const
|
||||
template <class IndexClass, class Expr, ForType FT, size_t DIV>
|
||||
PFor<IndexClass,Expr,DIV> For<IndexClass,Expr,FT,DIV>::parallel() const
|
||||
{
|
||||
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 *
|
||||
******************/
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
PFor<IndexClass,Expr>::PFor(const std::shared_ptr<IndexClass>& indPtr,
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
PFor<IndexClass,Expr,DIV>::PFor(const std::shared_ptr<IndexClass>& indPtr,
|
||||
size_t step, Expr expr) :
|
||||
mIndPtr(indPtr.get()), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||
{
|
||||
//assert(mMax % DIV == 0);
|
||||
assert(mIndPtr != nullptr);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
PFor<IndexClass,Expr>::PFor(const IndexClass* indPtr,
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
PFor<IndexClass,Expr,DIV>::PFor(const IndexClass* indPtr,
|
||||
size_t step, Expr expr) :
|
||||
mIndPtr(indPtr), mSPos(mIndPtr->pos()), mMax(mIndPtr->max()), mStep(step),
|
||||
mExpr(expr), mExt(mExpr.rootSteps( reinterpret_cast<std::intptr_t>( mIndPtr )))
|
||||
{
|
||||
assert(mMax % DIV == 0);
|
||||
assert(mIndPtr != nullptr);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
inline void PFor<IndexClass,Expr>::operator()(size_t mlast, DExt last)
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast, DExt last)
|
||||
{
|
||||
operator()(mlast, std::dynamic_pointer_cast<ExtT<ExtType>>(last)->ext());
|
||||
//operator()(mlast, *reinterpret_cast<ExtType const*>(last.first));
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
inline void PFor<IndexClass,Expr>::operator()(size_t mlast,
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast,
|
||||
ExtType last)
|
||||
{
|
||||
CHECK;
|
||||
|
@ -710,7 +719,7 @@ namespace MultiArrayHelper
|
|||
{
|
||||
auto expr = mExpr;
|
||||
#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);
|
||||
npos = last + mExt*static_cast<size_t>(pos);
|
||||
expr(mnpos, npos);
|
||||
|
@ -718,11 +727,10 @@ namespace MultiArrayHelper
|
|||
}
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
inline void PFor<IndexClass,Expr>::operator()(size_t mlast)
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
inline void PFor<IndexClass,Expr,DIV>::operator()(size_t mlast)
|
||||
{
|
||||
CHECK;
|
||||
typedef typename IndexClass::RangeType RangeType;
|
||||
ExtType last = rootSteps();
|
||||
last.zero();
|
||||
int pos = 0;
|
||||
|
@ -733,7 +741,7 @@ namespace MultiArrayHelper
|
|||
{
|
||||
auto expr = mExpr;
|
||||
#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);
|
||||
npos = last + mExt*static_cast<size_t>(pos);
|
||||
expr(mnpos, npos);
|
||||
|
@ -742,22 +750,22 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
auto PFor<IndexClass,Expr>::rootSteps(std::intptr_t iPtrNum) const
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
auto PFor<IndexClass,Expr,DIV>::rootSteps(std::intptr_t iPtrNum) const
|
||||
-> ExtType
|
||||
{
|
||||
return mExpr.rootSteps(iPtrNum);
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
auto PFor<IndexClass,Expr>::extension() const
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
auto PFor<IndexClass,Expr,DIV>::extension() const
|
||||
-> ExtType
|
||||
{
|
||||
return mExt;
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
DExt PFor<IndexClass,Expr>::dRootSteps(std::intptr_t iPtrNum) const
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
DExt PFor<IndexClass,Expr,DIV>::dRootSteps(std::intptr_t iPtrNum) const
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(rootSteps(iPtrNum));
|
||||
//mRootSteps = rootSteps(iPtrNum);
|
||||
|
@ -765,8 +773,8 @@ namespace MultiArrayHelper
|
|||
// sizeof(ExtType)/sizeof(size_t));
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
DExt PFor<IndexClass,Expr>::dExtension() const
|
||||
template <class IndexClass, class Expr, size_t DIV>
|
||||
DExt PFor<IndexClass,Expr,DIV>::dExtension() const
|
||||
{
|
||||
return std::make_shared<ExtT<ExtType>>(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 mnpos = mlast;
|
||||
const ExtType npos = last + mExt*pos;
|
||||
mExpr(mnpos, Getter<1>::template getX<ExtType>( npos ));
|
||||
mExpr(mnpos, getX<1>( npos ));
|
||||
}
|
||||
|
||||
template <class IndexClass, class Expr>
|
||||
|
@ -912,7 +920,7 @@ namespace MultiArrayHelper
|
|||
const size_t pos = (*mSubSet)[last.val()];
|
||||
const size_t mnpos = mlast;
|
||||
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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mk_hl_op.sh
|
||||
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/anonymous_range.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/multi_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
|
||||
)
|
||||
#message(WARNING ${libhlcnorxz_a_SOURCES})
|
||||
|
||||
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/ranges/range_types/*.cc")
|
||||
foreach(ccfile ${cc_files})
|
||||
set(libmultiarray_a_SOURCES ${libmultiarray_a_SOURCES}
|
||||
set(libcnorxz_a_SOURCES ${libcnorxz_a_SOURCES}
|
||||
${ccfile})
|
||||
endforeach(ccfile)
|
||||
|
||||
file(GLOB cc_files "${CMAKE_SOURCE_DIR}/src/lib/hl_ops/*.cc")
|
||||
foreach(ccfile ${cc_files})
|
||||
set(libmultiarray_a_SOURCES ${libmultiarray_a_SOURCES}
|
||||
set(libhlcnorxz_a_SOURCES ${libhlcnorxz_a_SOURCES}
|
||||
${ccfile})
|
||||
endforeach(ccfile)
|
||||
|
||||
add_library(multiarray_obj OBJECT
|
||||
${libmultiarray_a_SOURCES}
|
||||
add_library(cnorxz_obj OBJECT
|
||||
${libcnorxz_a_SOURCES}
|
||||
)
|
||||
set_target_properties(multiarray_obj PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||
|
||||
add_library(multiarray SHARED
|
||||
$<TARGET_OBJECTS:multiarray_obj>
|
||||
add_library(hlcnorxz_obj OBJECT
|
||||
${libhlcnorxz_a_SOURCES}
|
||||
)
|
||||
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
|
||||
$<TARGET_OBJECTS:multiarray_obj>
|
||||
add_library(cnorxz SHARED
|
||||
$<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
|
||||
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
|
||||
LIBRARY DESTINATION ${INSTALL_PATH}/lib)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
#include "multi_array_header.h"
|
||||
#include "high_level_operation.h"
|
||||
#include "cnorxz.h"
|
||||
#include "hl_cnorxz.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
std::shared_ptr<DynamicIndex> mkSubSpaceX(const std::shared_ptr<DynamicIndex>& di,
|
||||
size_t max)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "map_range_factory_product_map.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
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%\)}
|
||||
file=hl_ops/${fff}.cc
|
||||
test -f ${file} && rm -f ${file}
|
||||
echo "#include \"multi_array_header.h\"" >> ${file}
|
||||
echo "#include \"high_level_operation.h\"" >> ${file}
|
||||
echo "#include \"cnorxz.h\"" >> ${file}
|
||||
echo "#include \"hl_cnorxz.h\"" >> ${file}
|
||||
echo "" >> ${file}
|
||||
echo "namespace MultiArrayTools" >> ${file}
|
||||
echo "namespace CNORXZ" >> ${file}
|
||||
echo "{" >> ${file}
|
||||
echo " template class HighLevelOp<OpCD,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
|
||||
file=hl_ops/${fff}.cc
|
||||
test -f ${file} && rm -f ${file}
|
||||
echo "#include \"multi_array_header.h\"" >> ${file}
|
||||
echo "#include \"high_level_operation.h\"" >> ${file}
|
||||
echo "#include \"cnorxz.h\"" >> ${file}
|
||||
echo "#include \"hl_cnorxz.h\"" >> ${file}
|
||||
echo "" >> ${file}
|
||||
echo "namespace MultiArrayTools" >> ${file}
|
||||
echo "namespace CNORXZ" >> ${file}
|
||||
echo "{" >> ${file}
|
||||
echo " template class HighLevelOp<OpCD,${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
|
||||
file=hl_ops/${fff}.cc
|
||||
test -f ${file} && rm -f ${file}
|
||||
echo "#include \"multi_array_header.h\"" >> ${file}
|
||||
echo "#include \"high_level_operation.h\"" >> ${file}
|
||||
echo "#include \"cnorxz.h\"" >> ${file}
|
||||
echo "#include \"hl_cnorxz.h\"" >> ${file}
|
||||
echo "" >> ${file}
|
||||
echo "namespace MultiArrayTools" >> ${file}
|
||||
echo "namespace CNORXZ" >> ${file}
|
||||
echo "{" >> ${file}
|
||||
echo " template class HighLevelOp<OpCD,${fff}<double>,1>;" >> ${file}
|
||||
echo " template class HighLevelOp<OpD,${fff}<double>,1>;" >> ${file}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
#include "ranges/anonymous_range.h"
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
#include "ma_assert.h"
|
||||
#include "cxz_assert.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/******************************
|
||||
* AnonymousRangeFactory *
|
||||
|
@ -294,4 +294,4 @@ namespace MultiArrayTools
|
|||
|
||||
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
} // end namespace CNORXZ
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "ranges/dynamic_meta.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/ranges_header.cc.h"
|
||||
#include "ma_assert.h"
|
||||
#include "cxz_assert.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace MultiArrayHelper;
|
||||
using namespace CNORXZInternal;
|
||||
}
|
||||
|
||||
|
||||
|
@ -303,23 +303,6 @@ namespace MultiArrayTools
|
|||
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 *
|
||||
|
@ -501,5 +484,5 @@ namespace MultiArrayTools
|
|||
return mOrig;
|
||||
}
|
||||
|
||||
} // end namespace MultiArrayTools
|
||||
} // end namespace CNORXZ
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "ranges/multi_range_factory_product_map.h"
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
std::map<std::shared_ptr<RangeBase>,vector<std::intptr_t> > MultiRangeFactoryProductMap::mAleadyCreated;
|
||||
}
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
#include "ranges/range_helper.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
//using namespace MultiArrayHelpers;
|
||||
//using namespace CNORXZInternals;
|
||||
|
||||
template <class... Ranges>
|
||||
using STP = std::tuple<std::shared_ptr<Ranges>...>;
|
||||
|
@ -23,8 +24,7 @@ namespace MultiArrayTools
|
|||
template <class... Ranges>
|
||||
inline bool compareSpaceTypes(const RVEC& rvec)
|
||||
{
|
||||
return RPackNum<sizeof...(Ranges)-1>::
|
||||
template compareSpaceTypes<sizeof...(Ranges),Ranges...>(rvec);
|
||||
return RangeHelper::compareSpaceTypes<sizeof...(Ranges)-1,sizeof...(Ranges),Ranges...>(rvec);
|
||||
}
|
||||
|
||||
template <class... Ranges>
|
||||
|
@ -32,7 +32,7 @@ namespace MultiArrayTools
|
|||
{
|
||||
if(compareSpaceTypes<Ranges...>(rvec)) {
|
||||
STP<Ranges...> stp;
|
||||
RPackNum<sizeof...(Ranges)-1>::setSpace(rvec, stp);
|
||||
RangeHelper::setSpace<sizeof...(Ranges)-1>(rvec, stp);
|
||||
fptr = std::make_shared<MultiRangeFactory<Ranges...> >(stp);
|
||||
return true;
|
||||
}
|
||||
|
@ -215,4 +215,4 @@ namespace MultiArrayTools
|
|||
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/ranges_header.cc.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
/********************
|
||||
* GenSingleRange *
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
std::shared_ptr<NullRF> mkNUL(const char* dp, size_t size)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
std::shared_ptr<PSpaceRF> mkPSPACE(const char* dp, size_t size)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "ranges/x_to_string.h"
|
||||
#include "ranges/ranges_header.cc.h"
|
||||
|
||||
namespace MultiArrayTools
|
||||
namespace CNORXZ
|
||||
{
|
||||
std::shared_ptr<SpinRF> mkSPIN(const char* dp, size_t size)
|
||||
{
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue