array: add reform function
This commit is contained in:
parent
b3cbc61718
commit
8b2efdc522
4 changed files with 87 additions and 52 deletions
|
@ -158,6 +158,16 @@ namespace CNORXZ
|
|||
return operator()(yindexPtr(pack));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
CArrayBase<T>& CArrayBase<T>::reform(const RangePtr& range)
|
||||
{
|
||||
CXZ_ASSERT(this->formatIsTrivial(),
|
||||
"original format non-trivial; can only reform if trivial");
|
||||
this->checkFormatCompatibility(range->begin());
|
||||
mRange = range;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*=================================================================+
|
||||
| Implementations for protected CArrayBase member functions |
|
||||
+=================================================================*/
|
||||
|
|
|
@ -37,12 +37,12 @@ namespace CNORXZ
|
|||
|
||||
DEFAULT_MEMBERS(CArrayBase); /**< default constructors and assignments */
|
||||
|
||||
/** construct container on a range
|
||||
@param range
|
||||
/** construct container on a range.
|
||||
@param range.
|
||||
*/
|
||||
CArrayBase(const RangePtr& range);
|
||||
|
||||
/** default destructor */
|
||||
/** default destructor. */
|
||||
virtual ~CArrayBase() = default;
|
||||
|
||||
/** Return unique pointer copy of itself. */
|
||||
|
@ -51,104 +51,110 @@ namespace CNORXZ
|
|||
/** const data element access.
|
||||
If the array's format is trivial or the index is already non-trivially formatted,
|
||||
this is equivalent to data()[i.pos()]. Otherwise, the array's format is applied.
|
||||
@tparam I index type
|
||||
@tparam M meta data type
|
||||
@param i index
|
||||
@tparam I index type.
|
||||
@tparam M meta data type.
|
||||
@param i index.
|
||||
*/
|
||||
template <typename I, typename M>
|
||||
const T& operator[](const IndexInterface<I,M>& i) const;
|
||||
|
||||
/** const data element access
|
||||
performs compatibility checks
|
||||
@tparam I index type
|
||||
@tparam M meta data type
|
||||
@param i index
|
||||
/** const data element access.
|
||||
Performs compatibility checks.
|
||||
@tparam I index type.
|
||||
@tparam M meta data type.
|
||||
@param i index.
|
||||
*/
|
||||
template <typename I, typename M>
|
||||
const T& at(const IndexInterface<I,M>& i) const;
|
||||
|
||||
/** const data element access
|
||||
@tparam I index type
|
||||
@tparam M meta data type
|
||||
@param pack static index pack
|
||||
/** const data element access.
|
||||
@tparam I index type.
|
||||
@tparam M meta data type.
|
||||
@param pack static index pack.
|
||||
*/
|
||||
template <class... Indices>
|
||||
const T& operator[](const SPack<Indices...>& pack) const;
|
||||
|
||||
/** const data element access
|
||||
performs compatibility checks
|
||||
@tparam I index type
|
||||
@tparam M meta data type
|
||||
@param i static index pack
|
||||
/** const data element access.
|
||||
Performs compatibility checks.
|
||||
@tparam I index type.
|
||||
@tparam M meta data type.
|
||||
@param i static index pack.
|
||||
*/
|
||||
template <class... Indices>
|
||||
const T& at(const SPack<Indices...>& pack) const;
|
||||
|
||||
/** const data element access
|
||||
@param pack index pack
|
||||
/** const data element access.
|
||||
@param pack index pack.
|
||||
*/
|
||||
const T& operator[](const DPack& pack) const;
|
||||
|
||||
/** const data element access
|
||||
performs compatibility checks
|
||||
@param i index pack
|
||||
/** const data element access.
|
||||
Performs compatibility checks.
|
||||
@param i index pack.
|
||||
*/
|
||||
const T& at(const DPack& pack) const;
|
||||
|
||||
/** create hypercubic slice from this container
|
||||
@tparam I type of index used to indicate slice edges
|
||||
@tparam M index meta type
|
||||
@param begin begin edge
|
||||
@param end end edge
|
||||
/** Create hypercubic slice from this container.
|
||||
@tparam I type of index used to indicate slice edges.
|
||||
@tparam M index meta type.
|
||||
@param begin begin edge.
|
||||
@param end end edge.
|
||||
*/
|
||||
template <typename I, typename M>
|
||||
Sptr<CArrayBase<T>> sl(const IndexInterface<I,M>& begin,
|
||||
const IndexInterface<I,M>& end) const;
|
||||
|
||||
/** create operation on this container.
|
||||
/** Create operation on this container.
|
||||
Caution: might modify the index format.
|
||||
@tparam Index type of operation index
|
||||
@param i operation index
|
||||
@tparam Index type of operation index.
|
||||
@param i operation index.
|
||||
*/
|
||||
template <class Index>
|
||||
COpRoot<T,Index> operator()(const Sptr<Index>& i) const;
|
||||
|
||||
/** create operation on this container
|
||||
@tparam Indices types of operation indices
|
||||
@param pack pack of operation index
|
||||
/** Create operation on this container.
|
||||
@tparam Indices types of operation indices.
|
||||
@param pack pack of operation index.
|
||||
*/
|
||||
template <class... Indices>
|
||||
inline decltype(auto) operator()(const SPack<Indices...>& pack) const;
|
||||
|
||||
/** create operation on this container
|
||||
@param pack pack of operation index
|
||||
/** Create operation on this container.
|
||||
@param pack pack of operation index.
|
||||
*/
|
||||
inline decltype(auto) operator()(const DPack& pack) const;
|
||||
|
||||
/** get pointer to container data */
|
||||
/** get pointer to container data. */
|
||||
virtual const T* data() const = 0;
|
||||
|
||||
/** get number of elements in the container */
|
||||
/** get number of elements in the container. */
|
||||
virtual SizeT size() const;
|
||||
|
||||
/** get container range */
|
||||
/** get container range. */
|
||||
virtual RangePtr range() const;
|
||||
|
||||
/** get index pointing to first position */
|
||||
/** get index pointing to first position. */
|
||||
virtual const_iterator begin() const;
|
||||
|
||||
/** get index pointing to position after last position */
|
||||
/** get index pointing to position after last position. */
|
||||
virtual const_iterator end() const;
|
||||
|
||||
/** get index pointing to first position */
|
||||
/** get index pointing to first position. */
|
||||
virtual const_iterator cbegin() const = 0;
|
||||
|
||||
/** get index pointing to position after last position */
|
||||
/** get index pointing to position after last position. */
|
||||
virtual const_iterator cend() const = 0;
|
||||
|
||||
/** check if container views the data, i.e. it does not own it */
|
||||
/** check if container views the data, i.e. it does not own it. */
|
||||
virtual bool isView() const = 0;
|
||||
|
||||
/** Exchange container range.
|
||||
Original format is required to be trivial in order to work.
|
||||
@param range New container range.
|
||||
*/
|
||||
CArrayBase& reform(const RangePtr& range);
|
||||
|
||||
/** Perform compatibility checks
|
||||
@tparam Acc index type or index pack type
|
||||
@param acc index or index pack.
|
||||
|
@ -168,8 +174,8 @@ namespace CNORXZ
|
|||
/** Get valid data index.
|
||||
Create well-formated index from index pack (unformatted)
|
||||
or index using trivial format.
|
||||
@tparam Acc index type or index pack type
|
||||
@param acc index or index pack
|
||||
@tparam Acc index type or index pack type.
|
||||
@param acc index or index pack.
|
||||
*/
|
||||
template <class Acc>
|
||||
const_iterator itLex(const Acc& acc) const;
|
||||
|
@ -178,8 +184,8 @@ namespace CNORXZ
|
|||
Create well-formated index from index pack (unformatted)
|
||||
or index using trivial format.
|
||||
Perform compatibility checks.
|
||||
@tparam Acc index type or index pack type
|
||||
@param acc index or index pack
|
||||
@tparam Acc index type or index pack type.
|
||||
@param acc index or index pack.
|
||||
*/
|
||||
template <class Acc>
|
||||
const_iterator itLexSave(const Acc& acc) const;
|
||||
|
@ -187,8 +193,8 @@ namespace CNORXZ
|
|||
};
|
||||
|
||||
/** ****
|
||||
Abstract container base class
|
||||
read and write access to the data
|
||||
Abstract container base class.
|
||||
Read and write access to the data.
|
||||
|
||||
@tparam T data type
|
||||
*/
|
||||
|
|
|
@ -256,6 +256,17 @@ namespace CNORXZ
|
|||
mMap.resize(0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <class RangeI, class RangeK>
|
||||
RCArray<T>& RCArray<T>::reform(const Sptr<RRange<RangeI,RangeK>>& range)
|
||||
{
|
||||
mA->reform(range->local());
|
||||
CXZ_ASSERT(mGeom->size() == range->geom()->size(), "tried to reform geo range");
|
||||
mGlobal = range;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*==============+
|
||||
| RArray |
|
||||
+==============*/
|
||||
|
|
|
@ -137,6 +137,14 @@ namespace CNORXZ
|
|||
/** Clear data loaded from other ranks. */
|
||||
void clear() const;
|
||||
|
||||
/** Replace the container range. Geometry cannot be changed.
|
||||
The original range format is required to be trivial.
|
||||
@param range New container range.
|
||||
*/
|
||||
template <class RangeI, class RangeK>
|
||||
RCArray& reform(const Sptr<RRange<RangeI,RangeK>>& range);
|
||||
|
||||
|
||||
protected:
|
||||
ObjHandle<CArrayBase<T>> mA;
|
||||
RangePtr mGeom;
|
||||
|
|
Loading…
Reference in a new issue