LvArray
Array.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, Lawrence Livermore National Security, LLC and LvArray contributors.
3  * All rights reserved.
4  * See the LICENSE file for details.
5  * SPDX-License-Identifier: (BSD-3-Clause)
6  */
7 
13 #pragma once
14 
15 // Source includes
16 #include "indexing.hpp"
17 #include "ArrayView.hpp"
18 #include "bufferManipulation.hpp"
19 #include "StackBuffer.hpp"
20 
24 namespace LvArray
25 {
26 
50 template< typename T,
51  int NDIM,
52  typename PERMUTATION,
53  typename INDEX_TYPE,
54  template< typename > class BUFFER_TYPE >
55 class Array : public ArrayView< T,
56  NDIM,
57  typeManipulation::getStrideOneDimension( PERMUTATION {} ),
58  INDEX_TYPE,
59  BUFFER_TYPE >
60 {
61 public:
62 
63  // Check that the template arguments are valid.
64  static_assert( NDIM >= 0, "The dimension of the Array must be positive." );
65  static_assert( typeManipulation::isValidPermutation( PERMUTATION {} ), "The permutation must be valid." );
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." );
69 
71  using Permutation = PERMUTATION;
72 
74  using ParentClass = ArrayView< T, NDIM, typeManipulation::getStrideOneDimension( Permutation {} ), INDEX_TYPE, BUFFER_TYPE >;
75 
76  using ParentClass::USD;
77  using typename ParentClass::NestedViewType;
78  using typename ParentClass::NestedViewTypeConst;
79 
83 
89  inline Array():
90  ParentClass( true )
91  {
92  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
93 
94 #if !defined(LVARRAY_DEVICE_COMPILE)
95  setName( "" );
96 #endif
97 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE)
98  Array::TV_ttf_display_type( nullptr );
99 #endif
100  }
101 
106  template< typename ... DIMS,
107  typename=std::enable_if_t< sizeof ... ( DIMS ) == NDIM &&
108  typeManipulation::all_of_t< std::is_integral< DIMS > ... >::value > >
110  inline explicit Array( DIMS const ... dims ):
111  Array()
112  { resize( dims ... ); }
113 
119  Array( BUFFER_TYPE< T > && buffer ):
120  ParentClass( std::move( buffer ) )
121  {
122  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
123 
124 #if !defined(LVARRAY_DEVICE_COMPILE)
125  setName( "" );
126 #endif
127 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE)
128  Array::TV_ttf_display_type( nullptr );
129 #endif
130  }
131 
138  Array( Array const & source ):
139  Array()
140  { *this = source; }
141 
150  Array( Array && source ):
151  ParentClass( std::move( source ) )
152  {
153  for( int i = 0; i < NDIM; ++i )
154  {
155  source.m_dims[ i ] = 0;
156  source.m_strides[ i ] = 0;
157  }
158  }
159 
165  { bufferManipulation::free( this->m_dataBuffer, this->size() ); }
166 
173  Array & operator=( Array const & rhs )
174  {
175  bufferManipulation::copyInto( this->m_dataBuffer, this->size(), rhs.m_dataBuffer, rhs.size() );
176 
177  for( int i = 0; i < NDIM; ++i )
178  {
179  this->m_dims[ i ] = rhs.m_dims[ i ];
180  this->m_strides[ i ] = rhs.m_strides[ i ];
181  }
182 
184  return *this;
185  }
186 
193  Array & operator=( typename ParentClass::ViewTypeConst const & rhs )
194  {
195  bufferManipulation::copyInto( this->m_dataBuffer, this->size(), rhs.dataBuffer(), rhs.size() );
196 
197  INDEX_TYPE const * const dims = rhs.dims();
198  INDEX_TYPE const * const strides = rhs.strides();
199  for( int i = 0; i < NDIM; ++i )
200  {
201  this->m_dims[ i ] = dims[ i ];
202  this->m_strides[ i ] = strides[ i ];
203  }
204 
206  return *this;
207  }
208 
215  Array & operator=( Array && rhs )
216  {
217  bufferManipulation::free( this->m_dataBuffer, this->size() );
218 
219  ParentClass::operator=( std::move( rhs ) );
220 
221  for( int i = 0; i < NDIM; ++i )
222  {
223  rhs.m_dims[ i ] = 0;
224  rhs.m_strides[ i ] = 0;
225  }
226 
227  return *this;
228  }
229 
231 
235 
237  using ParentClass::toView;
238 
246  inline LVARRAY_HOST_DEVICE constexpr
248 
250 
258  inline LVARRAY_HOST_DEVICE constexpr
260 
262 
270  inline LVARRAY_HOST_DEVICE constexpr
271  NestedViewType toNestedView() const && = delete;
272 
274 
282  inline LVARRAY_HOST_DEVICE constexpr
283  NestedViewTypeConst toNestedViewConst() const && = delete;
284 
289  inline LVARRAY_HOST_DEVICE constexpr
291  { return toViewConst(); }
292 
300  template< typename _T=T >
301  inline LVARRAY_HOST_DEVICE constexpr
302  operator std::enable_if_t< !std::is_const< _T >::value,
303  ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > >() const && noexcept = delete;
304 
306 
310 
318  template< typename DIMS_TYPE >
320  void resize( int const numDims, DIMS_TYPE const * const dims )
321  {
322  LVARRAY_ERROR_IF_NE( numDims, NDIM );
323 
324  INDEX_TYPE const oldSize = this->size();
325  for( int i = 0; i < NDIM; ++i )
326  {
327  this->m_dims[ i ] = LvArray::integerConversion< INDEX_TYPE >( dims[ i ] );
328  LVARRAY_ERROR_IF_LT( this->m_dims[ i ], 0 );
329  }
330 
331  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
332 
333  bufferManipulation::resize( this->m_dataBuffer, oldSize, this->size() );
334  }
335 
343  template< typename ... DIMS >
345  std::enable_if_t< sizeof ... ( DIMS ) == NDIM && typeManipulation::all_of_t< std::is_integral< DIMS > ... >::value >
346  resize( DIMS const ... newDims )
347  {
348  static_assert( sizeof ... ( DIMS ) == NDIM, "The number of arguments provided does not equal NDIM!" );
349  INDEX_TYPE const oldSize = this->size();
350 
351  int curDim = 0;
352  typeManipulation::forEachArg( [&]( auto const newDim )
353  {
354  this->m_dims[ curDim ] = LvArray::integerConversion< INDEX_TYPE >( newDim );
355  LVARRAY_ERROR_IF_LT( this->m_dims[ curDim ], 0 );
356  ++curDim;
357  }, newDims ... );
358 
359  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
360 
361  bufferManipulation::resize( this->m_dataBuffer, oldSize, this->size() );
362  }
363 
371  template< typename ... DIMS >
373  void resizeWithoutInitializationOrDestruction( DIMS const ... newDims )
374  {
375  return resizeWithoutInitializationOrDestruction( MemorySpace::host, newDims ... );
376  }
377 
386  template< typename ... DIMS >
388  void resizeWithoutInitializationOrDestruction( MemorySpace const space, DIMS const ... newDims )
389  {
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." );
393 
394  INDEX_TYPE const oldSize = this->size();
395 
396  int i = 0;
397  typeManipulation::forEachArg( [&]( auto const newDim )
398  {
399  this->m_dims[ i ] = LvArray::integerConversion< INDEX_TYPE >( newDim );
400  LVARRAY_ERROR_IF_LT( this->m_dims[ i ], 0 );
401  ++i;
402  }, newDims ... );
403 
404  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
405 
406  bufferManipulation::reserve( this->m_dataBuffer, oldSize, space, this->size() );
407  }
408 
417  template< INDEX_TYPE... INDICES, typename ... DIMS >
419  void resizeDimension( DIMS const ... newDims )
420  {
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." );
424  static_assert( typeManipulation::all_of< ( 0 <= INDICES ) ... >::value, "INDICES must all be positive." );
425  static_assert( typeManipulation::all_of< ( INDICES < NDIM ) ... >::value, "INDICES must all be less than NDIM." );
426 
427  INDEX_TYPE const oldSize = this->size();
428 
429  typeManipulation::forEachArg( [&]( auto const & pair )
430  {
431  this->m_dims[ camp::get< 0 >( pair ) ] = LvArray::integerConversion< INDEX_TYPE >( camp::get< 1 >( pair ) );
432  LVARRAY_ERROR_IF_LT( this->m_dims[ camp::get< 0 >( pair ) ], 0 );
433  }, camp::make_tuple( INDICES, newDims )... );
434 
435  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
436 
437  bufferManipulation::resize( this->m_dataBuffer, oldSize, this->size() );
438  }
439 
447  void resize( INDEX_TYPE const newdim )
448  { resizeDefaultDimension( newdim ); }
449 
458  void resizeDefault( INDEX_TYPE const newdim, T const & defaultValue )
459  { resizeDefaultDimension( newdim, defaultValue ); }
460 
466  void clear()
467  {
468  bufferManipulation::resize( this->m_dataBuffer, this->size(), 0 );
469 
470  this->m_dims[ this->getSingleParameterResizeIndex() ] = 0;
471 
472  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
473  }
474 
480  inline void setSingleParameterResizeIndex( int const index )
481  {
482  LVARRAY_ERROR_IF_LT( index, 0 );
483  LVARRAY_ERROR_IF_GE( index, NDIM );
484  this->m_singleParameterResizeIndex = index;
485  }
486 
488 
492 
499  void reserve( INDEX_TYPE const newCapacity )
500  { bufferManipulation::reserve( this->m_dataBuffer, this->size(), MemorySpace::host, newCapacity ); }
501 
503 
508 
517  template< typename ... ARGS, int _NDIM=NDIM >
518  std::enable_if_t< _NDIM == 1 >
519  emplace_back( ARGS && ... args )
520  {
521  bufferManipulation::emplaceBack( this->m_dataBuffer, this->size(), std::forward< ARGS >( args ) ... );
522  ++this->m_dims[ 0 ];
523  }
524 
533  template< typename ... ARGS, int _NDIM=NDIM >
534  std::enable_if_t< _NDIM == 1 >
535  emplace( INDEX_TYPE const pos, ARGS && ... args )
536  {
537  bufferManipulation::emplace( this->m_dataBuffer, this->size(), pos, std::forward< ARGS >( args ) ... );
538  ++this->m_dims[ 0 ];
539  }
540 
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 )
553  { this->m_dims[ 0 ] += bufferManipulation::insert( this->m_dataBuffer, this->size(), pos, first, last ); }
554 
560  template< int _NDIM=NDIM >
561  std::enable_if_t< _NDIM == 1 >
563  {
565  --this->m_dims[ 0 ];
566  }
567 
574  template< int _NDIM=NDIM >
575  std::enable_if_t< _NDIM == 1 >
576  erase( INDEX_TYPE const pos )
577  {
578  bufferManipulation::erase( this->m_dataBuffer, this->size(), pos );
579  --this->m_dims[ 0 ];
580  }
581 
583 
588  void setName( std::string const & name )
589  { this->m_dataBuffer.template setName< decltype(*this) >( name ); }
590 
591 #if defined(LVARRAY_USE_TOTALVIEW_OUTPUT) && !defined(LVARRAY_DEVICE_COMPILE)
592 
597  static int TV_ttf_display_type( Array const * av )
598  {
599  return ParentClass::TV_ttf_display_type( av );
600  }
601 #endif
602 
603 private:
604 
614  template< typename ... ARGS >
616  void resizeDefaultDimension( INDEX_TYPE const newDimLength, ARGS && ... args )
617  {
618  LVARRAY_ERROR_IF_LT( newDimLength, 0 );
619 
620  // If m_singleParameterResizeIndex is the first dimension in memory than a simple 1D resizing is sufficient. The
621  // check if NDIM == 1 is to give the compiler compile time knowledge that this path is always taken for 1D arrays.
622  if( NDIM == 1 || typeManipulation::asArray( PERMUTATION {} )[ 0 ] == this->m_singleParameterResizeIndex )
623  {
624  INDEX_TYPE const oldSize = this->size();
625  this->m_dims[ this->m_singleParameterResizeIndex ] = newDimLength;
626  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
627 
628  bufferManipulation::resize( this->m_dataBuffer, oldSize, this->size(), std::forward< ARGS >( args )... );
629  return;
630  }
631 
632  // Get the current length and stride of the dimension as well as the size of the whole Array.
633  INDEX_TYPE const curDimLength = this->m_dims[ this->m_singleParameterResizeIndex ];
634  INDEX_TYPE const curDimStride = this->m_strides[ this->m_singleParameterResizeIndex ];
635  INDEX_TYPE const curSize = this->size();
636 
637  // Set the size of the dimension, recalculate the strides and get the new total size.
638  this->m_dims[ this->m_singleParameterResizeIndex ] = newDimLength;
639  this->m_strides = indexing::calculateStrides< PERMUTATION >( this->m_dims );
640 
641  INDEX_TYPE const newSize = this->size();
642 
643  // If we aren't changing the total size then we can return early.
644  if( newSize == curSize ) return;
645 
646  // If the size is increasing do one thing, if it's decreasing do another.
647  if( newDimLength > curDimLength )
648  {
649  // Reserve space in the buffer but don't initialize the values.
650  bufferManipulation::reserve( this->m_dataBuffer, curSize, MemorySpace::host, newSize );
651  T * const ptr = this->data();
652 
653  // The resizing consists of iterations where each iteration consists of the addition of a
654  // contiguous segment of new values.
655  INDEX_TYPE const valuesToAddPerIteration = curDimStride * ( newDimLength - curDimLength );
656  INDEX_TYPE const valuesToShiftPerIteration = curDimStride * curDimLength;
657  INDEX_TYPE const numIterations = ( newSize - curSize ) / valuesToAddPerIteration;
658 
659  // Iterate backwards over the iterations.
660  for( INDEX_TYPE i = numIterations - 1; i >= 0; --i )
661  {
662  // First shift the values up to make remove for the values of subsequent iterations.
663  // This step is a no-op on the last iteration (i=0).
664  INDEX_TYPE const valuesLeftToInsert = valuesToAddPerIteration * i;
665  T * const startOfShift = ptr + valuesToShiftPerIteration * i;
666  arrayManipulation::shiftUp( startOfShift, valuesToShiftPerIteration, INDEX_TYPE( 0 ), valuesLeftToInsert );
667 
668  // Initialize the new values.
669  T * const startOfNewValues = startOfShift + valuesToShiftPerIteration + valuesLeftToInsert;
670  for( INDEX_TYPE j = 0; j < valuesToAddPerIteration; ++j )
671  {
672  new ( startOfNewValues + j ) T( args ... );
673  }
674  }
675  }
676  else
677  {
678  T * const ptr = this->data();
679 
680  // The resizing consists of iterations where each iteration consists of the removal of a
681  // contiguous segment of new values.
682  INDEX_TYPE const valuesToRemovePerIteration = curDimStride * ( curDimLength - newDimLength );
683  INDEX_TYPE const valuesToShiftPerIteration = curDimStride * newDimLength;
684  INDEX_TYPE const numIterations = ( curSize - newSize ) / valuesToRemovePerIteration;
685 
686  // Iterate over the iterations, skipping the first.
687  for( INDEX_TYPE i = 1; i < numIterations; ++i )
688  {
689  INDEX_TYPE const amountToShift = valuesToRemovePerIteration * i;
690  T * const startOfShift = ptr + valuesToShiftPerIteration * i;
691  arrayManipulation::shiftDown( startOfShift,
692  valuesToShiftPerIteration + amountToShift,
693  amountToShift, amountToShift );
694  }
695 
696  // After the iterations are complete all the values to remove have been moved to the end of the array.
697  // We destroy them here.
698  INDEX_TYPE const totalValuesToRemove = valuesToRemovePerIteration * numIterations;
699  for( INDEX_TYPE i = 0; i < totalValuesToRemove; ++i )
700  {
701  ptr[ newSize + i ].~T();
702  }
703  }
704  }
705 };
706 
710 template< typename >
711 constexpr bool isArray = false;
712 
721 template< typename T,
722  int NDIM,
723  typename PERMUTATION,
724  typename INDEX_TYPE,
725  template< typename > class BUFFER_TYPE >
726 constexpr bool isArray< Array< T, NDIM, PERMUTATION, INDEX_TYPE, BUFFER_TYPE > > = true;
727 
728 namespace internal
729 {
730 
731 // Since Array expects the BUFFER to only except a single template parameter we need to
732 // create an alias for a StackBuffer with a given length.
741 template< typename T,
742  int NDIM,
743  typename PERMUTATION,
744  typename INDEX_TYPE,
745  int LENGTH >
747 {
752  template< typename U >
754 
757 };
758 
759 } // namespace internal
760 
769 template< typename T,
770  int NDIM,
771  typename PERMUTATION,
772  typename INDEX_TYPE,
773  int LENGTH >
775 
776 } /* namespace LvArray */
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&#39;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 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&#39;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&#39;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&#39;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
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