54 template<
typename >
class BUFFER_TYPE >
57 typeManipulation::getStrideOneDimension( PERMUTATION {} ),
64 static_assert( NDIM >= 0,
"The dimension of the Array must be positive." );
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." );
93 #if !defined(__CUDA_ARCH__) 96 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(__CUDA_ARCH__) 97 Array::TV_ttf_display_type(
nullptr );
105 template<
typename ... DIMS,
106 typename=std::enable_if_t<
sizeof ... ( DIMS ) == NDIM &&
134 for(
int i = 0; i <
NDIM; ++i )
137 source.m_strides[ i ] = 0;
158 for(
int i = 0; i <
NDIM; ++i )
178 for(
int i = 0; i <
NDIM; ++i )
181 rhs.m_strides[ i ] = 0;
257 template<
typename _T=T >
259 operator std::enable_if_t< !std::is_const< _T >::value,
275 template<
typename DIMS_TYPE >
277 void resize(
int const numDims, DIMS_TYPE
const *
const dims )
281 INDEX_TYPE
const oldSize = this->
size();
282 for(
int i = 0; i <
NDIM; ++i )
284 this->
m_dims[ i ] = LvArray::integerConversion< INDEX_TYPE >( dims[ i ] );
300 template<
typename ... DIMS >
305 static_assert(
sizeof ... ( DIMS ) == NDIM,
"The number of arguments provided does not equal NDIM!" );
306 INDEX_TYPE
const oldSize = this->
size();
311 this->
m_dims[ curDim ] = LvArray::integerConversion< INDEX_TYPE >( newDim );
328 template<
typename ... DIMS >
332 static_assert(
sizeof ... ( DIMS ) == NDIM,
"The number of arguments provided does not equal NDIM!" );
333 static_assert( std::is_trivially_destructible< T >::value,
334 "This function is only safe if T is trivially destructable." );
336 INDEX_TYPE
const oldSize = this->
size();
341 this->
m_dims[ i ] = LvArray::integerConversion< INDEX_TYPE >( newDim );
359 template< INDEX_TYPE... INDICES,
typename ... DIMS >
363 static_assert(
sizeof ... (INDICES) <= NDIM,
"Too many arguments provided." );
364 static_assert(
sizeof ... (INDICES) ==
sizeof ... (DIMS),
365 "The number of indices must match the number of dimensions." );
369 INDEX_TYPE
const oldSize = this->
size();
373 this->
m_dims[ camp::get< 0 >( pair ) ] = LvArray::integerConversion< INDEX_TYPE >( camp::get< 1 >( pair ) );
375 }, camp::make_tuple( INDICES, newDims )... );
390 { resizeDefaultDimension( newdim ); }
401 { resizeDefaultDimension( newdim, defaultValue ); }
459 template<
typename ... ARGS,
int _NDIM=NDIM >
460 std::enable_if_t< _NDIM == 1 >
475 template<
typename ... ARGS,
int _NDIM=NDIM >
476 std::enable_if_t< _NDIM == 1 >
477 emplace( INDEX_TYPE
const pos, ARGS && ... args )
492 template<
typename ITER,
int _NDIM=NDIM >
493 std::enable_if_t< _NDIM == 1 >
494 insert( INDEX_TYPE
const pos, ITER
const first, ITER
const last )
502 template<
int _NDIM=NDIM >
503 std::enable_if_t< _NDIM == 1 >
516 template<
int _NDIM=NDIM >
517 std::enable_if_t< _NDIM == 1 >
531 { this->
m_dataBuffer.template setName< decltype(*this) >( name ); }
533 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(__CUDA_ARCH__) 539 static int TV_ttf_display_type(
Array const * av )
541 return ParentClass::TV_ttf_display_type( av );
552 void CalculateStrides()
555 INDEX_TYPE foldedStrides[
NDIM ];
557 for(
int i = 0; i <
NDIM; ++i )
559 foldedStrides[ i ] = 1;
560 for(
int j = i + 1; j <
NDIM; ++j )
562 foldedStrides[ i ] *= this->
m_dims[ perm[ j ] ];
566 for(
int i = 0; i <
NDIM; ++i )
568 this->
m_strides[ perm[ i ] ] = foldedStrides[ i ];
581 template<
typename ... ARGS >
583 void resizeDefaultDimension( INDEX_TYPE
const newDimLength, ARGS && ... args )
591 INDEX_TYPE
const oldSize = this->
size();
601 INDEX_TYPE
const curSize = this->
size();
606 INDEX_TYPE
const newSize = this->
size();
609 if( newSize == curSize )
return;
612 if( newDimLength > curDimLength )
616 T *
const ptr = this->
data();
620 INDEX_TYPE
const valuesToAddPerIteration = curDimStride * ( newDimLength - curDimLength );
621 INDEX_TYPE
const valuesToShiftPerIteration = curDimStride * curDimLength;
622 INDEX_TYPE
const numIterations = ( newSize - curSize ) / valuesToAddPerIteration;
625 for( INDEX_TYPE i = numIterations - 1; i >= 0; --i )
629 INDEX_TYPE
const valuesLeftToInsert = valuesToAddPerIteration * i;
630 T *
const startOfShift = ptr + valuesToShiftPerIteration * i;
634 T *
const startOfNewValues = startOfShift + valuesToShiftPerIteration + valuesLeftToInsert;
635 for( INDEX_TYPE j = 0; j < valuesToAddPerIteration; ++j )
637 new ( startOfNewValues + j ) T( args ... );
643 T *
const ptr = this->
data();
647 INDEX_TYPE
const valuesToRemovePerIteration = curDimStride * ( curDimLength - newDimLength );
648 INDEX_TYPE
const valuesToShiftPerIteration = curDimStride * newDimLength;
649 INDEX_TYPE
const numIterations = ( curSize - newSize ) / valuesToRemovePerIteration;
652 for( INDEX_TYPE i = 1; i < numIterations; ++i )
654 INDEX_TYPE
const amountToShift = valuesToRemovePerIteration * i;
655 T *
const startOfShift = ptr + valuesToShiftPerIteration * i;
657 valuesToShiftPerIteration + amountToShift,
658 amountToShift, amountToShift );
663 INDEX_TYPE
const totalValuesToRemove = valuesToRemovePerIteration * numIterations;
664 for( INDEX_TYPE i = 0; i < totalValuesToRemove; ++i )
666 ptr[ newSize + i ].~T();
686 template<
typename T,
688 typename PERMUTATION,
690 template<
typename >
class BUFFER_TYPE >
691 constexpr
bool isArray< Array< T, NDIM, PERMUTATION, INDEX_TYPE, BUFFER_TYPE > > =
true;
706 template<
typename T,
708 typename PERMUTATION,
711 struct StackArrayHelper
717 template<
typename U >
734 template<
typename T,
736 typename PERMUTATION,
void emplace(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos, ARGS &&... args)
Construct a new value at position pos.
std::enable_if_t< _NDIM==1 > erase(INDEX_TYPE const pos)
Remove the value at the given position.
void clear()
Sets the size of the Array to zero and destroys all the values.
void setName(std::string const &name)
Set the name to be displayed whenever the underlying Buffer's user call back is called.
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.
void resize(INDEX_TYPE const newdim)
Resize the default dimension of the Array.
void reserve(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newCapacity)
Reserve space in the buffer for at least the given capacity.
void emplaceBack(BUFFER &buf, std::ptrdiff_t const size, ARGS &&... args)
Construct a new value at the end of the buffer.
Array(Array const &source)
Copy constructor.
constexpr int getSingleParameterResizeIndex() const
constexpr bool isValidPermutation(PERMUTATION)
#define LVARRAY_ERROR_IF_LT(lhs, rhs)
Raise a hard error if one value compares less than the other.
constexpr NestedViewType toNestedView() const &&=delete
Overload for rvalues that is deleted.
INDEX_TYPE size() const noexcept
Contains the implementation of LvArray:StackBuffer.
Array(DIMS const ... dims)
Constructor that takes in the dimensions as a variadic parameter list.
PERMUTATION Permutation
The permutation of the array.
constexpr bool isArray
True if the template type is an Array.
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.
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.
Array & operator=(Array &&rhs)
Move assignment operator, performs a shallow copy of rhs.
constexpr ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const &
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...
constexpr ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const &&=delete
Overload for rvalues that is deleted.
constexpr T * data() const
void popBack(BUFFER &buf, std::ptrdiff_t const size)
Remove a value from the end of the buffer.
This class serves to provide a "view" of a multidimensional array.
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.
std::enable_if_t< _NDIM==1 > emplace(INDEX_TYPE const pos, ARGS &&... args)
Insert a value into the array constructing it in place.
std::enable_if_t< _NDIM==1 > emplace_back(ARGS &&... args)
Construct a value in place at the end of the array.
typeManipulation::CArray< INDEX_TYPE, NDIM > m_dims
the dimensions of the array.
Array & operator=(Array const &rhs)
Copy assignment operator, performs a deep copy of rhs.
void reserve(INDEX_TYPE const newCapacity)
Reserve space in the Array to hold at least the given number of values.
void resizeDefault(INDEX_TYPE const newdim, T const &defaultValue)
Resize the default dimension of the Array.
void free(BUFFER &buf, std::ptrdiff_t const size)
Destroy the values in the buffer and free it's memory.
constexpr ArrayView toView() const &
Contains functions for manipulating buffers.
void setSingleParameterResizeIndex(int const index)
Set the default resize dimension.
constexpr INDEX_TYPE const * dims() const noexcept
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.
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.
BUFFER_TYPE< T > m_dataBuffer
this data member contains the actual data for the array.
static constexpr int USD
The unit stride dimension.
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...
typeManipulation::CArray< INDEX_TYPE, NDIM > m_strides
the strides of the array.
constexpr camp::idx_t getStrideOneDimension(camp::idx_seq< INDICES... >)
void resizeDimension(DIMS const ... newDims)
Resize specific dimensions of the array.
void move(MemorySpace const space, bool const touch=true) const
Move the Array to the given execution space, optionally touching it.
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.
~Array()
Destructor, free's the data.
typename internal::StackArrayHelper< T, NDIM, PERMUTATION, INDEX_TYPE, LENGTH >::type StackArray
An alias for a Array backed by a StackBuffer.
std::enable_if_t< _NDIM==1 > pop_back()
Remove the last value in the array.
void resize(int const numDims, DIMS_TYPE const *const dims)
Resize the dimensions of the Array to match the given dimensions.
#define LVARRAY_ERROR_IF_GE(lhs, rhs)
Raise a hard error if one value compares greater than or equal to the other.
constexpr camp::idx_t getDimension(camp::idx_seq< INDICES... >)
constexpr ArrayView< T, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toView() const &&=delete
Overload for rvalues that is deleted.
constexpr NestedViewTypeConst toNestedViewConst() const &&=delete
Overload for rvalues that is deleted.
A wrapper around a compile time c array.
constexpr NestedViewTypeConst toNestedViewConst() const &
int m_singleParameterResizeIndex
std::string string
String type.
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...
constexpr NestedViewType toNestedView() const &
constexpr CArray< camp::idx_t, sizeof...(INDICES) > asArray(camp::idx_seq< INDICES... >)
#define DISABLE_HD_WARNING
Disable host device warnings.
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...
This class implements the Buffer interface using a c-array.
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
static constexpr int NDIM
The number of dimensions.
Array()
default constructor
Contains functions to aid in multidimensional indexing.
#define LVARRAY_ERROR_IF_NE(lhs, rhs)
Raise a hard error if two values are not equal.
Array(Array &&source)
Move constructor.
void erase(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const pos)
Erase a value from the buffer.
LVARRAY_INTEL_CONSTEXPR ArrayView & operator=(ArrayView &&rhs)
Move assignment operator, creates a shallow copy and invalidates the source.
constexpr void forEachArg(F &&f)
The recursive base case where no argument is provided.
void resize(BUFFER &buf, std::ptrdiff_t const size, std::ptrdiff_t const newSize, ARGS &&... args)
Resize the buffer to the given size.
Contains the implementation of LvArray::ArrayView.
#define LVARRAY_HOST_DEVICE
Mark a function for both host and device usage.