35 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
36 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
45 #include <boost/core/ignore_unused.hpp>
46 #include <boost/multi_array.hpp>
53 template<
typename Dim,
typename DataType>
57 template<
typename DataType>
63 void (*m_callback)(
void *);
82 m_pythonInfo(nullptr),
100 m_pythonInfo(nullptr),
103 m_capacity( dim1Size ),
123 m_pythonInfo(nullptr),
126 m_capacity( dim1Size ),
144 m_pythonInfo(nullptr),
147 m_capacity( dim1Size ),
167 m_pythonInfo(rhs.m_pythonInfo),
170 m_capacity(rhs.m_capacity),
172 m_count(rhs.m_count),
173 m_offset(rhs.m_offset)
177 larger than input array size.");
186 Array(size_type dim1Size, DataType* data,
void* memory_pointer,
187 void (*python_decrement)(
void *)) :
189 m_capacity( dim1Size ),
194 m_count =
new size_type();
197 m_pythonInfo =
new PythonInfo *();
198 *m_pythonInfo =
new PythonInfo();
199 (*m_pythonInfo)->m_callback = python_decrement;
200 (*m_pythonInfo)->m_pyObject = memory_pointer;
207 m_pythonInfo(rhs.m_pythonInfo),
210 m_capacity(rhs.m_capacity),
212 m_count(rhs.m_count),
213 m_offset(rhs.m_offset)
220 if( m_count ==
nullptr )
229 if (*m_pythonInfo ==
nullptr)
236 (*m_pythonInfo)->m_callback((*m_pythonInfo)->m_pyObject);
237 delete *m_pythonInfo;
260 if (*m_pythonInfo ==
nullptr)
265 else if ((*rhs.m_pythonInfo) !=
nullptr && (*m_pythonInfo)->m_pyObject != (*rhs.m_pythonInfo)->m_pyObject)
267 (*m_pythonInfo)->m_callback((*m_pythonInfo)->m_pyObject);
268 delete *m_pythonInfo;
287 m_pythonInfo = rhs.m_pythonInfo;
298 std::string(
"Element ") + std::to_string(i) +
299 std::string(
" requested in an array of size ") +
300 std::to_string(m_size));
301 return *( m_data + i + m_offset );
321 "member function num_elements() is deprecated, "
322 "use size() instead.");
339 const element* end = start + m_size;
344 return (rhs_start >= start && rhs_start <= end) ||
345 (rhs_end >= start && rhs_end <= end);
351 return *m_pythonInfo !=
nullptr;
354 void ToPythonArray(
void* memory_pointer,
void (*python_decrement)(
void *))
356 *m_pythonInfo =
new PythonInfo();
357 (*m_pythonInfo)->m_callback = python_decrement;
358 (*m_pythonInfo)->m_pyObject = memory_pointer;
383 PythonInfo **m_pythonInfo;
422 m_pythonInfo =
new PythonInfo*();
423 *m_pythonInfo =
nullptr;
431 result.m_offset += offset;
432 result.m_size = rhs.m_size - offset;
440 template<
typename DataType>
448 typedef typename ArrayType::index
index;
467 m_data->num_elements());
474 m_data->num_elements(), initValue);
481 m_data->num_elements(), data);
490 const DataType>& rhs)
509 "member function num_elements() is deprecated, "
510 "use size() instead.");
511 return m_data->num_elements();
540 template<
typename DataType>
592 Array(size_type dim1Size, DataType* data,
void* memory_pointer,
void (*python_decrement)(
void *)) :
593 BaseType(dim1Size, data, memory_pointer, python_decrement)
597 void ToPythonArray(
void* memory_pointer,
void (*python_decrement)(
void *))
599 BaseType::ToPythonArray(memory_pointer, python_decrement);
605 BaseType::operator=(rhs);
622 iterator end() {
return this->m_data + this->m_offset + this->m_size; }
624 using BaseType::operator[];
628 std::string(
"Element ") + std::to_string(i) +
629 std::string(
" requested in an array of size ") +
630 std::to_string(this->size()));
638 using BaseType::data;
641 template<
typename T1>
644 template<
typename T1,
typename T3>
653 boost::ignore_unused(a);
658 ASSERTL1(newSize <= this->m_capacity,
"Can't change an array size to something larger than its capacity.");
659 this->m_size = newSize;
667 template<
typename DataType>
690 BaseType(dim1Size, dim2Size, initValue)
706 BaseType::operator=(rhs);
710 using BaseType::begin;
716 using BaseType::operator[];
722 using BaseType::data;
731 inline bool IsEqualImpl(
const T& lhs,
const T& rhs, std::false_type)
738 inline bool IsEqualImpl(
const T& lhs,
const T& rhs, std::true_type)
744 inline bool IsEqual(
const T& lhs,
const T& rhs)
746 return IsEqualImpl(lhs, rhs, std::is_floating_point<T>());
749 template<
typename T1,
typename T2>
753 if (lhs.size() != rhs.size())
758 if (lhs.data() == rhs.data())
775 template<
typename T1,
typename T2>
779 return !(lhs == rhs);
782 template<
typename DataType>
789 template<
typename DataType>
796 template<
typename ConstDataType,
typename DataType>
799 if( dest.
size() != source.size() )
804 std::copy(source.data(), source.data() + source.size(), dest.
data());
807 template<
typename ConstDataType,
typename DataType>
811 if( dest.size() != n )
816 std::copy(source.data(), source.data() + n, dest.data());
871 template<
typename T1,
typename T2>
875 if ( (lhs.GetRows() != rhs.GetRows()) ||
876 (lhs.GetColumns() != rhs.GetColumns()) )
881 if ( lhs.data() == rhs.data() )
889 j < lhs.GetColumns(); ++j)
891 if (!
IsEqual(lhs[i][j], rhs[i][j]))
901 template<
typename T1,
typename T2>
905 return !(lhs == rhs);
908 namespace LibUtilities
#define WARNINGL1(condition, msg)
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
reference operator[](size_type i)
Array(size_type dim1Size, const Array< OneD, DataType > &rhs)
BaseType::reference reference
Array< OneD, const DataType >::const_iterator begin() const
Array(size_type dim1Size, const DataType *data)
Array(size_type dim1Size)
Array(const Array< OneD, const DataType > &rhs)
BaseType::element element
Array(const Array< OneD, const DataType > &rhs, AllowWrappingOfConstArrays a)
static Array< OneD, DataType > CreateWithOffset(const Array< OneD, DataType > &rhs, unsigned int offset)
BaseType::size_type size_type
BaseType::iterator iterator
Array(const Array< OneD, DataType > &rhs)
Array< OneD, const DataType > BaseType
Array(size_type dim1Size, const DataType &initValue)
Array(size_type dim1Size, const Array< OneD, const DataType > &rhs)
Array< OneD, DataType > & operator=(const Array< OneD, DataType > &rhs)
void ChangeSize(size_type newSize)
1D Array of constant elements with garbage collection and bounds checking.
friend Array< OneD, T > operator+(const Array< OneD, T > &lhs, typename Array< OneD, T >::size_type offset)
Creates an array with a specified offset.
Array< OneD, const DataType > & operator=(const Array< OneD, const DataType > &rhs)
Creates a reference to rhs.
const element * data() const
Returns a c-style pointer to the underlying array.
static Array< OneD, T > CreateWithOffset(const Array< OneD, T > &rhs, size_type offset)
const DataType & const_reference
Array(size_type dim1Size, const Array< OneD, const DataType > &rhs)
Creates a 1D array that references rhs.
friend Array< OneD, T > operator+(typename Array< OneD, T >::size_type offset, const Array< OneD, T > &rhs)
size_type GetCount() const
Returns the array's reference counter.
void CreateStorage(size_type size)
Array(size_type dim1Size, const DataType *data)
Creates a 1D array a copies data into it.
const_iterator end() const
Array()
Creates an empty array.
const_iterator begin() const
bool Overlaps(const Array< OneD, const DataType > &rhs) const
Returns true is this array and rhs overlap.
Array(size_type dim1Size)
Creates an array of size dim1Size.
const_reference operator[](size_type i) const
const element * get() const
Returns a c-style pointer to the underlying array.
size_type capacity() const
Returns the array's capacity.
Array(const Array< OneD, const DataType > &rhs)
Creates a reference to rhs.
size_type size() const
Returns the array's size.
size_type num_dimensions() const
Returns 1.
DEPRECATED(5.1.0, size) size_type num_elements() const
Returns the array's size. Deprecated.
size_type GetOffset() const
Returns the array's offset.
const DataType * const_iterator
Array(size_type dim1Size, const DataType &initValue)
Creates a 1D array with each element initialized to an initial value.
BaseType::iterator iterator
Array(const Array< TwoD, DataType > &rhs)
Array(size_type dim1Size, size_type dim2Size, const DataType *data)
BaseType::reference reference
reference operator[](index i)
Array< TwoD, DataType > & operator=(const Array< TwoD, DataType > &rhs)
Array(size_type dim1Size, size_type dim2Size)
Array(size_type dim1Size, size_type dim2Size, const DataType &initValue)
BaseType::size_type size_type
BaseType::element element
Array< TwoD, const DataType > BaseType
2D array with garbage collection and bounds checking.
const element * data() const
Array(size_type dim1Size, size_type dim2Size, const DataType &initValue)
ArrayType::size_type size_type
Array(size_type dim1Size, size_type dim2Size, const DataType *data)
const_iterator end() const
Array< TwoD, const DataType > & operator=(const Array< TwoD, const DataType > &rhs)
ArrayType::const_reference const_reference
size_type num_dimensions() const
ArrayType::element element
Array(size_type dim1Size, size_type dim2Size)
Constructs a 2 dimensional array. The elements of the array are not initialized.
ArrayType::iterator iterator
std::shared_ptr< ArrayType > m_data
ArrayType::const_iterator const_iterator
boost::multi_array_ref< DataType, 2 > ArrayType
size_type GetRows() const
Array(const Array< TwoD, const DataType > &rhs)
DEPRECATED(5.1.0, size) size_type num_elements() const
ArrayType::reference reference
const size_type * shape() const
const_iterator begin() const
const_reference operator[](index i) const
size_type GetColumns() const
const element * get() const
static void RawDeallocate(DataType *array, size_t NumberOfElements)
Deallocates memory allocated from RawAllocate.
static DataType * RawAllocate(size_t NumberOfElements)
Allocates a chunk of raw, uninitialized memory, capable of holding NumberOfElements objects.
static std::vector< unsigned int > NullUnsignedIntVector
static std::vector< std::vector< NekDouble > > NullVectorNekDoubleVector
static std::vector< NekDouble > NullNekDoubleVector
bool IsRealEqual(T1 &&lhs, T2 &&rhs, const unsigned int factor=NekConstants::kNekFloatCompFact)
compare reals of same type with relative tolerance
The above copyright notice and this permission notice shall be included.
std::shared_ptr< boost::multi_array_ref< DataType, Dim::Value > > CreateStorage(const ExtentListType &extent)
bool operator==(const Array< OneD, T1 > &lhs, const Array< OneD, T2 > &rhs)
AllowWrappingOfConstArrays
static Array< OneD, int > NullInt1DArray
Array< OneD, DataType > operator+(const Array< OneD, DataType > &lhs, typename Array< OneD, DataType >::size_type offset)
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayOfArray
bool IsEqual(const T &lhs, const T &rhs)
static Array< OneD, Array< OneD, Array< OneD, NekDouble > > > NullNekDoubleTensorOfArray3D
bool IsEqualImpl(const T &lhs, const T &rhs, std::false_type)
void CopyArrayN(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest, typename Array< OneD, DataType >::size_type n)
static Array< OneD, NekDouble > NullNekDouble1DArray
bool operator!=(const Array< OneD, T1 > &lhs, const Array< OneD, T2 > &rhs)
void CopyArray(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest)