From 8b2efdc522617ab63369114578727fa8efa9e7f8 Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Tue, 21 Jan 2025 17:04:10 -0800 Subject: [PATCH] array: add reform function --- src/include/array/array_base.cc.h | 10 +++ src/include/array/array_base.h | 110 ++++++++++++++++-------------- src/opt/mpi/include/rarray.cc.h | 11 +++ src/opt/mpi/include/rarray.h | 8 +++ 4 files changed, 87 insertions(+), 52 deletions(-) diff --git a/src/include/array/array_base.cc.h b/src/include/array/array_base.cc.h index c478803..299ce0b 100644 --- a/src/include/array/array_base.cc.h +++ b/src/include/array/array_base.cc.h @@ -158,6 +158,16 @@ namespace CNORXZ return operator()(yindexPtr(pack)); } + template + CArrayBase& CArrayBase::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 | +=================================================================*/ diff --git a/src/include/array/array_base.h b/src/include/array/array_base.h index bf529d5..fb1af87 100644 --- a/src/include/array/array_base.h +++ b/src/include/array/array_base.h @@ -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 const T& operator[](const IndexInterface& 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 const T& at(const IndexInterface& 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 const T& operator[](const SPack& 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 const T& at(const SPack& 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 Sptr> sl(const IndexInterface& begin, const IndexInterface& 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 COpRoot operator()(const Sptr& 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 inline decltype(auto) operator()(const SPack& 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 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 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 */ diff --git a/src/opt/mpi/include/rarray.cc.h b/src/opt/mpi/include/rarray.cc.h index 3b28503..4e52b70 100644 --- a/src/opt/mpi/include/rarray.cc.h +++ b/src/opt/mpi/include/rarray.cc.h @@ -255,6 +255,17 @@ namespace CNORXZ mBuf.resize(0); mMap.resize(0); } + + template + template + RCArray& RCArray::reform(const Sptr>& range) + { + mA->reform(range->local()); + CXZ_ASSERT(mGeom->size() == range->geom()->size(), "tried to reform geo range"); + mGlobal = range; + return *this; + } + /*==============+ | RArray | diff --git a/src/opt/mpi/include/rarray.h b/src/opt/mpi/include/rarray.h index e73e000..fb9baf3 100644 --- a/src/opt/mpi/include/rarray.h +++ b/src/opt/mpi/include/rarray.h @@ -136,7 +136,15 @@ 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 + RCArray& reform(const Sptr>& range); + protected: ObjHandle> mA; RangePtr mGeom;