some utilities
This commit is contained in:
parent
9b79c96eea
commit
b257ab4db3
2 changed files with 63 additions and 0 deletions
|
@ -52,6 +52,12 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
template <class IndexType>
|
template <class IndexType>
|
||||||
inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll);
|
inline void For(const std::shared_ptr<IndexType>& ind, const std::function<void(void)>& ll);
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline auto mkOp(const std::shared_ptr<Index>& i)
|
||||||
|
-> decltype(std::declval<FunctionalMultiArray<typename Index::MetaType,
|
||||||
|
identity<typename Index::MetaType>,typename Index::RangeType> >
|
||||||
|
().exec(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================= *
|
/* ========================= *
|
||||||
|
@ -151,6 +157,18 @@ namespace MultiArrayTools
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Index>
|
||||||
|
inline auto mkOp(const std::shared_ptr<Index>& i)
|
||||||
|
-> decltype(std::declval<FunctionalMultiArray<typename Index::MetaType,
|
||||||
|
identity<typename Index::MetaType>,typename Index::RangeType> >
|
||||||
|
().exec(i))
|
||||||
|
{
|
||||||
|
FunctionalMultiArray<typename Index::MetaType,
|
||||||
|
identity<typename Index::MetaType>,
|
||||||
|
typename Index::RangeType> fma(i->range());
|
||||||
|
return fma.exec(i);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#define __type_operations_h__
|
#define __type_operations_h__
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "base_def.h"
|
#include "base_def.h"
|
||||||
#include "mbase_def.h"
|
#include "mbase_def.h"
|
||||||
|
@ -16,6 +18,8 @@ namespace MultiArrayTools
|
||||||
using namespace MultiArrayHelper;
|
using namespace MultiArrayHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MultiArray
|
||||||
|
|
||||||
template <typename T, class... Ranges>
|
template <typename T, class... Ranges>
|
||||||
class operate
|
class operate
|
||||||
{
|
{
|
||||||
|
@ -54,7 +58,48 @@ namespace MultiArrayTools
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// vector
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class getter
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
size_t mPos;
|
||||||
|
public:
|
||||||
|
static constexpr bool FISSTATIC = false;
|
||||||
|
|
||||||
|
getter(size_t i) : mPos(i) {}
|
||||||
|
|
||||||
|
inline T operator()(const std::vector<T>& in)
|
||||||
|
{
|
||||||
|
return in[mPos];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::vector<T>& operator+=(std::vector<T>& a, const std::vector<T>& b)
|
||||||
|
{
|
||||||
|
std::transform(a.begin(), a.end(), b.begin(), a.begin(), std::plus<T>());
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class OperationClass, typename T>
|
||||||
|
class OperationTemplate<std::vector<T>,OperationClass> : public OperationBase<std::vector<T>,OperationClass>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef OperationBase<std::vector<T>,OperationClass> OB;
|
||||||
|
|
||||||
|
auto operator[](size_t i)
|
||||||
|
-> Operation<T,getter<T>,OperationClass>
|
||||||
|
{
|
||||||
|
std::shared_ptr<getter<T> > ff = std::make_shared<getter<T> >(i);
|
||||||
|
return Operation<T,getter<T>,OperationClass>(ff,OB::THIS());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
OperationTemplate() = default;
|
||||||
|
friend OperationClass;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace MultiArrayTools
|
} // namespace MultiArrayTools
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue