From f045104e100fab06a73c28443d2040126fc7e386 Mon Sep 17 00:00:00 2001 From: "Randolph R. Settgast" Date: Wed, 31 Aug 2022 15:08:15 -0700 Subject: [PATCH 1/2] added equal assignment operator Array::operator=(ArrayView &) --- src/Array.hpp | 17 +++++++++++++++++ src/ArrayView.hpp | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Array.hpp b/src/Array.hpp index 2f1eb66b..ead9deb6 100644 --- a/src/Array.hpp +++ b/src/Array.hpp @@ -184,6 +184,23 @@ class Array : public ArrayView< T, return *this; } + LVARRAY_HOST_DEVICE + Array & operator=( typename ParentClass::ViewTypeConst const & rhs ) + { + bufferManipulation::copyInto( this->m_dataBuffer, this->size(), rhs.dataBuffer(), rhs.size() ); + + INDEX_TYPE const * const dims = rhs.dims(); + INDEX_TYPE const * const strides = rhs.strides(); + for( int i = 0; i < NDIM; ++i ) + { + this->m_dims[ i ] = dims[ i ]; + this->m_strides[ i ] = strides[ i ]; + } + + setSingleParameterResizeIndex( rhs.getSingleParameterResizeIndex() ); + return *this; + } + /** * @brief Move assignment operator, performs a shallow copy of rhs. * @param rhs Source for the assignment. diff --git a/src/ArrayView.hpp b/src/ArrayView.hpp index cbbf6690..aabd48bf 100644 --- a/src/ArrayView.hpp +++ b/src/ArrayView.hpp @@ -85,6 +85,10 @@ class ArrayView /// The integer type used for indexing. using IndexType = INDEX_TYPE; + /// The type when the data type is const. + using ViewTypeConst = ArrayView< std::remove_const_t< T > const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >; + + /// The type when all inner array classes are converted to const views. using NestedViewType = ArrayView< std::remove_reference_t< typeManipulation::NestedViewType< T > >, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >; @@ -274,12 +278,12 @@ class ArrayView * @return Return a new ArrayView where @c T is @c const. */ inline LVARRAY_HOST_DEVICE constexpr - ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const & + ViewTypeConst toViewConst() const & { - return ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >( m_dims, - m_strides, - m_singleParameterResizeIndex, - m_dataBuffer ); + return ViewTypeConst( m_dims, + m_strides, + m_singleParameterResizeIndex, + m_dataBuffer ); } /** From 3584cb18f561970ca88fabc7a19e0bba94299faf Mon Sep 17 00:00:00 2001 From: "Randolph R. Settgast" Date: Fri, 2 Sep 2022 16:12:56 -0700 Subject: [PATCH 2/2] added doxygen for new operator --- src/Array.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Array.hpp b/src/Array.hpp index ead9deb6..d05769cd 100644 --- a/src/Array.hpp +++ b/src/Array.hpp @@ -184,6 +184,11 @@ class Array : public ArrayView< T, return *this; } + /** + * @brief Copy assignment operator, performs a deep copy of rhs. + * @param rhs Source for the assignment. + * @return *this. + */ LVARRAY_HOST_DEVICE Array & operator=( typename ParentClass::ViewTypeConst const & rhs ) {