2018-10-30 15:06:29 +01:00
|
|
|
|
2021-07-28 19:55:37 +02:00
|
|
|
#include "functional_array.h"
|
2018-10-30 15:06:29 +01:00
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
namespace CNORXZ
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/****************************
|
2021-07-28 20:59:31 +02:00
|
|
|
* FunctionalArray *
|
2018-10-30 15:06:29 +01:00
|
|
|
****************************/
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const std::shared_ptr<SRanges>&... ranges,
|
2018-10-30 15:06:29 +01:00
|
|
|
const std::shared_ptr<Function>& func) :
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>(ranges...), mFunc(func) {}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const std::shared_ptr<SRanges>&... ranges) :
|
|
|
|
ArrayBase<T,SRanges...>(ranges...) {}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const typename CRange::Space& space) :
|
|
|
|
ArrayBase<T,SRanges...>(space) {}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
FunctionalArray<T,Function,SRanges...>::FunctionalArray(const typename CRange::Space& space,
|
2018-10-30 15:06:29 +01:00
|
|
|
const std::shared_ptr<Function>& func) :
|
2021-07-28 20:59:31 +02:00
|
|
|
ArrayBase<T,SRanges...>(space), mFunc(func) {}
|
2018-10-30 15:06:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
const T& FunctionalArray<T,Function,SRanges...>::operator[](const IndexType& i) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-04-11 16:54:46 +02:00
|
|
|
if constexpr(Function::FISSTATIC){
|
|
|
|
mVal = Function::apply(i.meta());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mVal = (*mFunc)(i.meta());
|
|
|
|
}
|
2018-10-30 15:06:29 +01:00
|
|
|
return mVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
const T& FunctionalArray<T,Function,SRanges...>::at(const typename CRange::IndexType::MetaType& meta) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
2021-04-11 16:54:46 +02:00
|
|
|
if constexpr(Function::FISSTATIC){
|
|
|
|
mVal = Function::apply(meta);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mVal = (*mFunc)(meta);
|
|
|
|
}
|
2018-10-30 15:06:29 +01:00
|
|
|
return mVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
const T* FunctionalArray<T,Function,SRanges...>::data() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return &mVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
bool FunctionalArray<T,Function,SRanges...>::isConst() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
bool FunctionalArray<T,Function,SRanges...>::isSlice() const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
std::shared_ptr<ArrayBase<T,AnonymousRange> > FunctionalArray<T,Function,SRanges...>::anonymous(bool slice) const
|
2018-10-30 15:06:29 +01:00
|
|
|
{
|
|
|
|
assert(0); // think about it carefully
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
ConstOperationRoot<T,SRanges...> FunctionalArray<T,Function,SRanges...>::
|
2018-10-30 15:06:29 +01:00
|
|
|
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... );
|
|
|
|
}
|
|
|
|
|
2018-11-26 13:13:23 +01:00
|
|
|
template <typename T, class Function, class... SRanges>
|
2021-07-28 20:59:31 +02:00
|
|
|
auto FunctionalArray<T,Function,SRanges...>::
|
2018-11-26 13:13:23 +01:00
|
|
|
exec(const std::shared_ptr<typename SRanges::IndexType>&... inds) const
|
|
|
|
-> Operation<T,Function,MetaOperationRoot<SRanges>...>
|
|
|
|
{
|
|
|
|
return mkOperation( mFunc, MetaOperationRoot<SRanges>( inds ) ... );
|
|
|
|
}
|
|
|
|
|
2021-07-28 20:29:56 +02:00
|
|
|
} // namespace CNORXZ
|