obj_handle: get function + RArray

This commit is contained in:
Christian Zimmermann 2024-04-22 00:38:35 +02:00
parent 066e267753
commit e5782ac327
4 changed files with 241 additions and 3 deletions

View file

@ -69,6 +69,18 @@ namespace CNORXZ
return &*mC;
}
template <typename T>
T* ObjHandle<T>::get()
{
return &*mC;
}
template <typename T>
const T* ObjHandle<T>::get() const
{
return &*mC;
}
}
#endif

View file

@ -77,6 +77,12 @@ namespace CNORXZ
/** get pointer to data (const) */
const T* operator->() const;
/** get object. */
T* get();
/** get object. */
const T* get() const;
};
}

View file

@ -21,6 +21,10 @@ namespace CNORXZ
namespace mpi
{
/*===============+
| RCArray |
+===============*/
template <typename T>
RCArray<T>::RCArray(const RCArray& a) :
mA(a.mA->copy()),
@ -43,6 +47,14 @@ namespace CNORXZ
mGlobal(RRangeFactory(rangeCast<YRange>(a.range()),rangeCast<YRange>(mGeom)).create())
{}
template <typename T>
template <class IndexI, class IndexK>
RCArray<T>::RCArray(const RRange<IndexI,IndexK>& range) :
mA(std::make_unique<T>(range->local())),
mGeom(range->geom()),
mGlobal(range)
{}
template <typename T>
template <typename I, typename M>
T RCArray<T>::operator[](const IndexInterface<I,M>& i) const
@ -241,11 +253,146 @@ namespace CNORXZ
Sptr<Vector<SizeT>> RCArray<T>::load(const Sptr<Index>& i, const F& f) const
{
Sptr<Vector<SizeT>> imap = std::make_shared<Vector<SizeT>>();
CXZ_ERROR("!!!");
//load(i, /**/, imap);
return imap;
}
/*===============+
| RCArray |
+===============*/
template <typename T>
RArray<T>::RArray(const RArray& a) :
RCArray<T>(a),
mB(dynamic_cast<ArrayBase<T>*>(RCA::mA.get()))
{}
template <typename T>
RArray<T>& RArray<T>::operator=(const RArray& a)
{
RCArray<T>::operator=(a);
mB = dynamic_cast<ArrayBase<T>*>(RCA::mA.get());
return *this;
}
template <typename T>
template <class IndexI, class IndexK>
RArray<T>::RArray(const RRange<IndexI,IndexK>& range) :
RCArray<T>(range),
mB(dynamic_cast<ArrayBase<T>*>(RCA::mA.get()))
{}
template <typename T>
RArray<T>::RArray(const ArrayBase<T>& a, const RangePtr& geom) :
RCArray<T>(a, geom),
mB(dynamic_cast<ArrayBase<T>*>(RCA::mA.get()))
{}
template <typename T>
template <typename I, typename M>
RArray<T>& RArray<T>::set(const IndexInterface<I,M>& i, const T& val)
{
auto it = begin() + i.lex();
it.set(val);
return *this;
}
template <typename T>
template <class... Indices>
RArray<T>& RArray<T>::set(const SPack<Indices...>& pack, const T& val)
{
auto it = begin() + pack.lex();
it.set(val);
return *this;
}
template <typename T>
RArray<T>& RArray<T>::set(const DPack& pack, const T& val)
{
auto it = begin() + pack.lex();
it.set(val);
return *this;
}
template <typename T>
template <typename I, typename M>
Sptr<ArrayBase<T>> RArray<T>::sl(const IndexInterface<I,M>& begin,
const IndexInterface<I,M>& end)
{
if constexpr(is_rank_index<I>::value){
CXZ_ERROR("not implemented");
return nullptr;
}
else {
return mB->sl(begin, end);
}
}
template <typename T>
template <class Index>
OpRoot<T,Index> RArray<T>::operator()(const Sptr<Index>& i)
{
CXZ_ERROR("not implemented");
return OpRoot<T,Index>();
}
template <typename T>
template <class... Indices>
inline decltype(auto) RArray<T>::operator()(const SPack<Indices...>& pack)
{
typedef typename std::remove_reference<decltype(*pack[CSizeT<0>{}])>::type I0;
if constexpr(is_rank_index<I0>::value){
// preliminary:
CXZ_ASSERT(this->formatIsTrivial(),
"array has non-trivial format, rank operations require trivial format");
auto ri = pack[CSizeT<0>{}];
auto li = iter<1,sizeof...(Indices)>
( [&](auto i) { return pack[CSizeT<i>{}]; },
[](const auto&... x) { return mindexPtr( (x * ...) ); } );
return croproot(*this, ri, li);
}
else {
return (*mB)(pack);
}
}
template <typename T>
inline decltype(auto) RArray<T>::operator()(const DPack& pack)
{
// TODO: assert that none of the indices is rank index
return (*mB)(pack);
}
template <typename T>
T* RArray<T>::data()
{
return mB->data();
}
template <typename T>
typename RArray<T>::iterator RArray<T>::begin()
{
return iterator(mB->data(), RCA::mGlobal);
}
template <typename T>
typename RArray<T>::iterator RArray<T>::end()
{
return iterator(mB->data(), RCA::mGlobal, RCA::mGlobal->size());
}
template <typename T>
ArrayBase<T>& RArray<T>::local()
{
return *mB;
}
/*============================+
| non-member functions |
+============================*/
template <class TarI, class RTarI, class SrcI, class RSrcI, typename T>
void setupBuffer(const Sptr<RIndex<TarI,RTarI>>& rgi, const Sptr<RIndex<SrcI,RSrcI>>& rgj,
const Sptr<Vector<SizeT>>& imap, const CArrayBase<T>& data,

View file

@ -33,6 +33,12 @@ namespace CNORXZ
DEFAULT_MOVE(RCArray);
RCArray(const RCArray& a);
RCArray& operator=(const RCArray& a);
/** Construct from a rank range.
@param range The range.
*/
template <class IndexI, class IndexK>
RCArray(const RRange<IndexI,IndexK>& range);
/** Construct from local array object.
@param a Local array.
@ -153,6 +159,8 @@ namespace CNORXZ
{
public:
typedef RCArray<T> RCA;
typedef typename RCA::const_iterator const_iterator;
typedef RBIndex<T> iterator;
using RCA::operator[];
using RCA::operator();
@ -164,9 +172,74 @@ namespace CNORXZ
using RCA::cend;
using RCA::sl;
DEFAULT_MEMBERS(RArray);
DEFAULT_C(RArray);
DEFAULT_MOVE(RArray);
RArray(const RArray& a);
RArray& operator=(const RArray& a);
/** Construct from a rank range.
@param range The range.
*/
template <class IndexI, class IndexK>
RArray(const RRange<IndexI,IndexK>& range);
/** Construct from local array object.
@param a Local array.
@param geom Rank geometry.
*/
RArray(const ArrayBase<T>& a, const RangePtr& geom);
/** Assign value at a position indicated by an index.
@param i Index indicating the position.
@param val Value.
*/
template <typename I, typename M>
RArray& set(const IndexInterface<I,M>& i, const T& val);
/** Assign value at a position indicated by an index pack.
@param pack Index pack indicating the position.
@param val Value.
*/
template <class... Indices>
RArray& set(const SPack<Indices...>& pack, const T& val);
/** Assign value at a position indicated by an index pack.
@param pack Index pack indicating the position.
@param val Value.
*/
RArray& set(const DPack& pack, const T& val);
/** @copydoc ArrayBase::sl() */
template <typename I, typename M>
Sptr<ArrayBase<T>> sl(const IndexInterface<I,M>& begin,
const IndexInterface<I,M>& end);
/** @copydoc ArrayBase::operator() */
template <class Index>
OpRoot<T,Index> operator()(const Sptr<Index>& i);
/** @copydoc ArrayBase::operator() */
template <class... Indices>
inline decltype(auto) operator()(const SPack<Indices...>& pack);
/** @copydoc ArrayBase::operator() */
inline decltype(auto) operator()(const DPack& pack);
/** @copydoc ArrayBase::data() */
T* data();
/** @copydoc ArrayBase::begin() */
iterator begin();
/** @copydoc ArrayBase::end() */
iterator end();
/** Get local array object. */
ArrayBase<T>& local();
private:
ArrayBase<T>* mB = nullptr;
};
template <class TarI, class RTarI, class SrcI, class RSrcI, typename T>