54 template<
typename >
class BUFFER_TYPE >
57 typeManipulation::getStrideOneDimension( PERMUTATION {} ),
64 static_assert( NDIM >= 0,
"The dimension of the Array must be positive." );
66 static_assert( typeManipulation::getDimension< PERMUTATION > == NDIM,
67 "The dimension of the permutation must match the dimension of the Array." );
68 static_assert( std::is_integral< INDEX_TYPE >::value,
"INDEX_TYPE must be integral." );
92 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
94 #if !defined(LVARRAY_DEVICE_COMPILE) 97 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE) 98 Array::TV_ttf_display_type(
nullptr );
106 template<
typename ... DIMS,
107 typename=std::enable_if_t<
sizeof ... ( DIMS ) == NDIM &&
119 Array( BUFFER_TYPE< T > && buffer ):
122 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
124 #if !defined(LVARRAY_DEVICE_COMPILE) 127 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE) 128 Array::TV_ttf_display_type(
nullptr );
153 for(
int i = 0; i <
NDIM; ++i )
156 source.m_strides[ i ] = 0;
177 for(
int i = 0; i <
NDIM; ++i )
197 INDEX_TYPE
const *
const dims = rhs.
dims();
199 for(
int i = 0; i <
NDIM; ++i )
201 this->
m_dims[ i ] = dims[ i ];
221 for(
int i = 0; i <
NDIM; ++i )
224 rhs.m_strides[ i ] = 0;
300 template<
typename _T=T >
302 operator std::enable_if_t< !std::is_const< _T >::value,
318 template<
typename DIMS_TYPE >
320 void resize(
int const numDims, DIMS_TYPE
const *
const dims )
324 INDEX_TYPE
const oldSize = this->
size();
325 for(
int i = 0; i <
NDIM; ++i )
327 this->
m_dims[ i ] = LvArray::integerConversion< INDEX_TYPE >( dims[ i ] );
331 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
343 template<
typename ... DIMS >
348 static_assert(
sizeof ... ( DIMS ) == NDIM,
"The number of arguments provided does not equal NDIM!" );
349 INDEX_TYPE
const oldSize = this->
size();
354 this->
m_dims[ curDim ] = LvArray::integerConversion< INDEX_TYPE >( newDim );
359 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
371 template<
typename ... DIMS >
386 template<
typename ... DIMS >
390 static_assert(
sizeof ... ( DIMS ) == NDIM,
"The number of arguments provided does not equal NDIM!" );
391 static_assert( std::is_trivially_destructible< T >::value,
392 "This function is only safe if T is trivially destructable." );
394 INDEX_TYPE
const oldSize = this->
size();
399 this->
m_dims[ i ] = LvArray::integerConversion< INDEX_TYPE >( newDim );
404 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
417 template< INDEX_TYPE... INDICES,
typename ... DIMS >
421 static_assert(
sizeof ... (INDICES) <= NDIM,
"Too many arguments provided." );
422 static_assert(
sizeof ... (INDICES) ==
sizeof ... (DIMS),
423 "The number of indices must match the number of dimensions." );
427 INDEX_TYPE
const oldSize = this->
size();
431 this->
m_dims[ camp::get< 0 >( pair ) ] = LvArray::integerConversion< INDEX_TYPE >( camp::get< 1 >( pair ) );
433 }, camp::make_tuple( INDICES, newDims )... );
435 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
472 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
517 template<
typename ... ARGS,
int _NDIM=NDIM >
518 std::enable_if_t< _NDIM == 1 >
533 template<
typename ... ARGS,
int _NDIM=NDIM >
534 std::enable_if_t< _NDIM == 1 >
535 emplace( INDEX_TYPE
const pos, ARGS && ... args )
550 template<
typename ITER,
int _NDIM=NDIM >
551 std::enable_if_t< _NDIM == 1 >
552 insert( INDEX_TYPE
const pos, ITER
const first, ITER
const last )
560 template<
int _NDIM=NDIM >
561 std::enable_if_t< _NDIM == 1 >
574 template<
int _NDIM=NDIM >
575 std::enable_if_t< _NDIM == 1 >
589 { this->
m_dataBuffer.template setName< decltype(*this) >( name ); }
591 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE) 597 static int TV_ttf_display_type(
Array const * av )
599 return ParentClass::TV_ttf_display_type( av );
614 template<
typename ... ARGS >
624 INDEX_TYPE
const oldSize = this->
size();
626 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
635 INDEX_TYPE
const curSize = this->
size();
639 this->
m_strides = indexing::calculateStrides< PERMUTATION >( this->
m_dims );
641 INDEX_TYPE
const newSize = this->
size();
644 if( newSize == curSize )
return;
647 if( newDimLength > curDimLength )
651 T *
const ptr = this->
data();
655 INDEX_TYPE
const valuesToAddPerIteration = curDimStride * ( newDimLength - curDimLength );
656 INDEX_TYPE
const valuesToShiftPerIteration = curDimStride * curDimLength;
657 INDEX_TYPE
const numIterations = ( newSize - curSize ) / valuesToAddPerIteration;
660 for( INDEX_TYPE i = numIterations - 1; i >= 0; --i )
664 INDEX_TYPE
const valuesLeftToInsert = valuesToAddPerIteration * i;
665 T *
const startOfShift = ptr + valuesToShiftPerIteration * i;
669 T *
const startOfNewValues = startOfShift + valuesToShiftPerIteration + valuesLeftToInsert;
670 for( INDEX_TYPE j = 0; j < valuesToAddPerIteration; ++j )
672 new ( startOfNewValues + j ) T( args ... );
678 T *
const ptr = this->
data();
682 INDEX_TYPE
const valuesToRemovePerIteration = curDimStride * ( curDimLength - newDimLength );
683 INDEX_TYPE
const valuesToShiftPerIteration = curDimStride * newDimLength;
684 INDEX_TYPE
const numIterations = ( curSize - newSize ) / valuesToRemovePerIteration;
687 for( INDEX_TYPE i = 1; i < numIterations; ++i )
689 INDEX_TYPE
const amountToShift = valuesToRemovePerIteration * i;
690 T *
const startOfShift = ptr + valuesToShiftPerIteration * i;
692 valuesToShiftPerIteration + amountToShift,
693 amountToShift, amountToShift );
698 INDEX_TYPE
const totalValuesToRemove = valuesToRemovePerIteration * numIterations;
699 for( INDEX_TYPE i = 0; i < totalValuesToRemove; ++i )
701 ptr[ newSize + i ].~T();
721 template<
typename T,
723 typename PERMUTATION,
725 template<
typename >
class BUFFER_TYPE >
726 constexpr
bool isArray< Array< T, NDIM, PERMUTATION, INDEX_TYPE, BUFFER_TYPE > > =
true;
741 template<
typename T,
743 typename PERMUTATION,
752 template<
typename U >
769 template<
typename T,
771 typename PERMUTATION,
LVARRAY_HOST_DEVICE void resize(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the buffer to the given size.
Definition: bufferManipulation.hpp:272
void emplace(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos, ARGS &&... args)
Construct a new value at position pos.
Definition: bufferManipulation.hpp:315
std::enable_if_t< _NDIM==1 > erase(INDEX_TYPE const pos)
Remove the value at the given position.
Definition: Array.hpp:576
void clear()
Sets the size of the Array to zero and destroys all the values.
Definition: Array.hpp:466
void setName(std::string const &name)
Set the name to be displayed whenever the underlying Buffer's user call back is called.
Definition: Array.hpp:588
std::ptrdiff_t insert(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos, ITER const first, ITER const last)
Insert multiple values into the buffer.
Definition: bufferManipulation.hpp:338
void emplaceBack(BUFFER &buf, std::ptrdiff_t const size, ARGS &&... args)
Construct a new value at the end of the buffer.
Definition: bufferManipulation.hpp:297
LVARRAY_HOST_DEVICE Array(Array const &source)
Copy constructor.
Definition: Array.hpp:138
LVARRAY_HOST_DEVICE constexpr CArray< camp::idx_t, sizeof...(INDICES) > asArray(camp::idx_seq< INDICES... >)
Definition: typeManipulation.hpp:549
constexpr bool isValidPermutation(PERMUTATION)
Definition: typeManipulation.hpp:458
#define LVARRAY_ERROR_IF_LT(lhs, rhs)
Raise a hard error if one value compares less than the other.
Definition: Macros.hpp:456
LVARRAY_HOST_DEVICE Array & operator=(Array &&rhs)
Move assignment operator, performs a shallow copy of rhs.
Definition: Array.hpp:215
LVARRAY_HOST_DEVICE constexpr T * data() const
Definition: ArrayView.hpp:569
LVARRAY_HOST_DEVICE Array()
default constructor
Definition: Array.hpp:89
Contains the implementation of LvArray:StackBuffer.
LVARRAY_HOST_DEVICE void resizeDefault(INDEX_TYPE const newdim, T const &defaultValue)
Resize the default dimension of the Array.
Definition: Array.hpp:458
PERM Permutation
The permutation of the array.
Definition: Array.hpp:71
LVARRAY_HOST_DEVICE constexpr ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const &&=delete
Overload for rvalues that is deleted.
constexpr bool isArray
True if the template type is an Array.
Definition: Array.hpp:711
LVARRAY_HOST_DEVICE constexpr ViewTypeConst toViewConst() const &
Definition: ArrayView.hpp:281
ArrayView< std::remove_reference_t< typeManipulation::NestedViewTypeConst< T > >, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > NestedViewTypeConst
The type when all inner array classes are converted to const views and the inner most view's values a...
Definition: ArrayView.hpp:98
LVARRAY_HOST_DEVICE constexpr NestedViewTypeConst toNestedViewConst() const &
Definition: ArrayView.hpp:300
void popBack(BUFFER &buf, std::ptrdiff_t const size)
Remove a value from the end of the buffer.
Definition: bufferManipulation.hpp:359
This class serves to provide a "view" of a multidimensional array.
Definition: ArrayView.hpp:68
LVARRAY_HOST_DEVICE LVARRAY_INTEL_CONSTEXPR ArrayView & operator=(ArrayView &&rhs)
Move assignment operator, creates a shallow copy and invalidates the source.
Definition: ArrayView.hpp:231
std::enable_if_t< _NDIM==1 > emplace(INDEX_TYPE const pos, ARGS &&... args)
Insert a value into the array constructing it in place.
Definition: Array.hpp:535
LVARRAY_HOST_DEVICE ~Array()
Destructor, free's the data.
Definition: Array.hpp:164
Array(BUFFER_TYPE< T > &&buffer)
Construct an Array from buffer, taking ownership of its contents.
Definition: Array.hpp:119
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE size() const noexcept
Definition: ArrayView.hpp:400
std::enable_if_t< _NDIM==1 > emplace_back(ARGS &&... args)
Construct a value in place at the end of the array.
Definition: Array.hpp:519
typeManipulation::CArray< INDEX_TYPE, NDIM > m_dims
the dimensions of the array.
Definition: ArrayView.hpp:752
LVARRAY_HOST_DEVICE constexpr camp::idx_t getStrideOneDimension(camp::idx_seq< INDICES... >)
Definition: typeManipulation.hpp:445
void reserve(INDEX_TYPE const newCapacity)
Reserve space in the Array to hold at least the given number of values.
Definition: Array.hpp:499
LVARRAY_HOST_DEVICE constexpr ArrayView toView() const &
Definition: ArrayView.hpp:274
LVARRAY_HOST_DEVICE void resize(INDEX_TYPE const newdim)
Resize the default dimension of the Array.
Definition: Array.hpp:447
LVARRAY_HOST_DEVICE Array(DIMS const ... dims)
Constructor that takes in the dimensions as a variadic parameter list.
Definition: Array.hpp:110
LVARRAY_HOST_DEVICE constexpr BUFFER_TYPE< T > const & dataBuffer() const
Definition: ArrayView.hpp:499
DISABLE_HD_WARNING constexpr LVARRAY_HOST_DEVICE void forEachArg(F &&f)
The recursive base case where no argument is provided.
Definition: typeManipulation.hpp:129
Contains functions for manipulating buffers.
std::enable_if_t< _NDIM==1 > insert(INDEX_TYPE const pos, ITER const first, ITER const last)
Insert values into the array at the given position.
Definition: Array.hpp:552
BUFFER_TYPE< T > m_dataBuffer
this data member contains the actual data for the array.
Definition: ArrayView.hpp:758
static constexpr int USD
The unit stride dimension.
Definition: ArrayView.hpp:83
camp::concepts::metalib::all_of< BOOLS ... > all_of
A struct that contains a static constexpr bool value that is true if all of BOOLS are true...
Definition: typeManipulation.hpp:156
typeManipulation::CArray< INDEX_TYPE, NDIM > m_strides
the strides of the array.
Definition: ArrayView.hpp:755
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void free(BUFFER &buf, std::ptrdiff_t const size)
Destroy the values in the buffer and free it's memory.
Definition: bufferManipulation.hpp:188
camp::resources::Platform MemorySpace
an alias for camp::resources::Platform.
Definition: bufferManipulation.hpp:31
LVARRAY_HOST_DEVICE constexpr NestedViewType toNestedView() const &&=delete
Overload for rvalues that is deleted.
void move(MemorySpace const space, bool const touch=true) const
Move the Array to the given execution space, optionally touching it.
Definition: ArrayView.hpp:690
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void resizeDefaultDimension(INDEX_TYPE const newDimLength, ARGS &&... args)
Resize the default dimension of the Array.
Definition: Array.hpp:616
The top level namespace.
Definition: Array.hpp:24
LVARRAY_HOST_DEVICE void reserve(BUFFER &buf, std::ptrdiff_t const size, MemorySpace const space, std::ptrdiff_t const newCapacity)
Reserve space in the buffer for at least the given capacity.
Definition: bufferManipulation.hpp:230
LVARRAY_HOST_DEVICE constexpr NestedViewTypeConst toNestedViewConst() const &&=delete
Overload for rvalues that is deleted.
LVARRAY_HOST_DEVICE std::enable_if_t< sizeof ...(DIMS)==NDIM &&typeManipulation::all_of_t< std::is_integral< DIMS > ... >::value > resize(DIMS const ... newDims)
function to resize the array.
Definition: Array.hpp:346
LVARRAY_HOST_DEVICE Array & operator=(typename ParentClass::ViewTypeConst const &rhs)
Copy assignment operator, performs a deep copy of rhs.
Definition: Array.hpp:193
ArrayView< std::remove_reference_t< typeManipulation::NestedViewType< T > >, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > NestedViewType
The type when all inner array classes are converted to const views.
Definition: ArrayView.hpp:94
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void shiftDown(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position down by the given amount overwriting the...
Definition: arrayManipulation.hpp:363
LVARRAY_HOST_DEVICE void resizeWithoutInitializationOrDestruction(MemorySpace const space, DIMS const ... newDims)
Resize the array without initializing any new values or destroying any old values. Only safe on POD data, however it is much faster for large allocations.
Definition: Array.hpp:388
LVARRAY_HOST_DEVICE void resize(int const numDims, DIMS_TYPE const *const dims)
Resize the dimensions of the Array to match the given dimensions.
Definition: Array.hpp:320
typename internal::StackArrayHelper< T, NDIM, PERMUTATION, INDEX_TYPE, LENGTH >::type StackArray
An alias for a Array backed by a StackBuffer.
Definition: Array.hpp:774
std::enable_if_t< _NDIM==1 > pop_back()
Remove the last value in the array.
Definition: Array.hpp:562
LVARRAY_HOST_DEVICE Array & operator=(Array const &rhs)
Copy assignment operator, performs a deep copy of rhs.
Definition: Array.hpp:173
#define LVARRAY_ERROR_IF_GE(lhs, rhs)
Raise a hard error if one value compares greater than or equal to the other.
Definition: Macros.hpp:424
LVARRAY_HOST_DEVICE constexpr ArrayView< T, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toView() const &&=delete
Overload for rvalues that is deleted.
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE const * strides() const noexcept
Definition: ArrayView.hpp:484
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void shiftUp(T *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, std::ptrdiff_t const index, std::ptrdiff_t const n)
Shift the values in the array at or above the given position up by the given amount. New uninitialized values take their place.
Definition: arrayManipulation.hpp:326
LVARRAY_HOST_DEVICE void resizeDimension(DIMS const ... newDims)
Resize specific dimensions of the array.
Definition: Array.hpp:419
int m_singleParameterResizeIndex
Definition: ArrayView.hpp:762
DISABLE_HD_WARNING LVARRAY_HOST_DEVICE void copyInto(DST_BUFFER &dst, std::ptrdiff_t const dstSize, SRC_BUFFER const &src, std::ptrdiff_t const srcSize)
Copy values from the source buffer into the destination buffer.
Definition: bufferManipulation.hpp:393
LVARRAY_HOST_DEVICE constexpr INDEX_TYPE const * dims() const noexcept
Definition: ArrayView.hpp:470
#define DISABLE_HD_WARNING
Disable host device warnings.
Definition: Macros.hpp:614
camp::concepts::metalib::all_of_t< TYPES ... > all_of_t
A struct that contains a static constexpr bool value that is true if all of TYPES::value are true...
Definition: typeManipulation.hpp:164
This class implements the Buffer interface using a c-array.
Definition: StackBuffer.hpp:40
LVARRAY_HOST_DEVICE Array(Array &&source)
Move constructor.
Definition: Array.hpp:150
LVARRAY_HOST_DEVICE constexpr NestedViewType toNestedView() const &
Definition: ArrayView.hpp:293
Definition: Array.hpp:746
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
static constexpr int NDIM
The number of dimensions.
Definition: ArrayView.hpp:80
Contains functions to aid in multidimensional indexing.
#define LVARRAY_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
Definition: Macros.hpp:360
void erase(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos)
Erase a value from the buffer.
Definition: bufferManipulation.hpp:373
LVARRAY_HOST_DEVICE void setSingleParameterResizeIndex(int const index)
Set the default resize dimension.
Definition: Array.hpp:480
Contains the implementation of LvArray::ArrayView.
LVARRAY_HOST_DEVICE constexpr int getSingleParameterResizeIndex() const
Definition: ArrayView.hpp:447
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.
Definition: Macros.hpp:600
LVARRAY_HOST_DEVICE void resizeWithoutInitializationOrDestruction(DIMS const ... newDims)
Resize the array without initializing any new values or destroying any old values. Only safe on POD data, however it is much faster for large allocations.
Definition: Array.hpp:373