SpECTRE  v2024.09.29
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
VectorImpl< T, VectorType, StaticSize > Class Template Reference

Base class template for various DataVector and related types. More...

#include <VectorImpl.hpp>

Public Types

using value_type = T
 
using size_type = size_t
 
using difference_type = std::ptrdiff_t
 
using BaseType = blaze::CustomVector< T, blaze::AlignmentFlag::unaligned, blaze::PaddingFlag::unpadded, blaze::defaultTransposeFlag, blaze::GroupTag< 0 >, VectorType >
 
using ElementType = T
 
using TransposeType = VectorImpl< T, VectorType, StaticSize >
 
using CompositeType = const VectorImpl< T, VectorType, StaticSize > &
 
using iterator = typename BaseType::Iterator
 
using const_iterator = typename BaseType::ConstIterator
 

Public Member Functions

 VectorImpl (size_t set_size)
 Create with the given size. In debug mode, the vector is initialized to 'NaN' by default. If not initialized to 'NaN', the memory is allocated but not initialized. More...
 
 VectorImpl (size_t set_size, T value)
 Create with the given size and value. More...
 
template<typename Container , Requires< std::is_same_v< typename Container::value_type, T > > = nullptr>
 VectorImpl (const Container &container)
 Create from a copy of the given container. More...
 
 VectorImpl (T *start, size_t set_size)
 Create a non-owning VectorImpl that points to start
 
template<class U , Requires< std::is_same_v< U, T > > = nullptr>
 VectorImpl (std::initializer_list< U > list)
 Create from an initializer list of T.
 
 VectorImpl ()=default
 Empty VectorImpl.
 
VectorImploperator= (const T &rhs)
 
decltype(auto) operator[] (const size_t index)
 
decltype(auto) operator[] (const size_t index) const
 
void destructive_resize (const size_t new_size)
 A common operation for checking the size and resizing a memory buffer if needed to ensure that it has the desired size. This operation is not permitted on a non-owning vector. More...
 
bool is_owning () const
 Returns true if the class owns the data.
 
void clear ()
 Put the class in the default-constructed state.
 
void pup (PUP::er &p)
 Serialization for Charm++.
 
const BaseType & operator* () const
 Upcast to BaseType More...
 
BaseType & operator* ()
 Upcast to BaseType More...
 
void set_data_ref (gsl::not_null< VectorType * > rhs)
 Set the VectorImpl to be a reference to another VectorImpl object.
 
void set_data_ref (T *const start, const size_t set_size)
 Set the VectorImpl to be a reference to another VectorImpl object.
 

Static Public Attributes

static constexpr bool transpose_flag = blaze::defaultTransposeFlag
 
static constexpr size_t static_size = StaticSize
 

Protected Member Functions

void reset_pointer_vector (const size_t set_size)
 
std::unique_ptr< value_type[]> heap_alloc_if_necessary (const size_t set_size)
 

Protected Attributes

std::unique_ptr< value_type[]> owned_data_ {}
 
std::array< T, StaticSize > static_owned_data_ {}
 
bool owning_ {true}
 

Detailed Description

template<typename T, typename VectorType, size_t StaticSize = default_vector_impl_static_size>
class VectorImpl< T, VectorType, StaticSize >

Base class template for various DataVector and related types.

Details

The VectorImpl class is the generic parent class for vectors representing collections of related function values, such as DataVectors for contiguous data over a computational domain.

The VectorImpl does not itself define any particular mathematical operations on the contained values. The VectorImpl template class and the macros defined in VectorImpl.hpp assist in the construction of various derived classes supporting a chosen set of mathematical operations.

In addition, the equivalence operator == is inherited from the underlying blaze::CustomVector type, and returns true if and only if the size and contents of the two compared vectors are equivalent.

Template parameters:

  • T is the underlying stored type, e.g. double, std::complex<double>, float, etc.
  • VectorType is the type that should be associated with the VectorImpl during mathematical computations. In most cases, inherited types should have themselves as the second template argument, e.g.
    class DataVector : VectorImpl<double, DataVector> {
    Stores a collection of function values.
    Definition: DataVector.hpp:48
    Base class template for various DataVector and related types.
    Definition: VectorImpl.hpp:143
  • StaticSize is the size for the static part of the vector. If the vector is constructed or resized with a size that is less than or equal to this StaticSize, no heap allocations will be done. It will instead use the stack allocation. Default is default_vector_impl_static_size.

    The second template parameter communicates arithmetic type restrictions to the underlying Blaze framework. For example, if VectorType is DataVector, then the underlying architecture will prevent addition with a vector type whose ResultType (which is aliased to its VectorType) is ModalVector. Since DataVectors and ModalVectors represent data in different spaces, we wish to forbid several operations between them. This vector-type-tracking through an expression prevents accidental mixing of vector types in math expressions.

Note
  • If either SPECTRE_DEBUG or SPECTRE_NAN_INIT are defined, then the VectorImpl is default initialized to signaling_NaN(). Otherwise, the vector is filled with uninitialized memory for performance.

Constructor & Destructor Documentation

◆ VectorImpl() [1/3]

template<typename T , typename VectorType , size_t StaticSize = default_vector_impl_static_size>
VectorImpl< T, VectorType, StaticSize >::VectorImpl ( size_t  set_size)
inlineexplicit

Create with the given size. In debug mode, the vector is initialized to 'NaN' by default. If not initialized to 'NaN', the memory is allocated but not initialized.

  • set_size number of values

◆ VectorImpl() [2/3]

template<typename T , typename VectorType , size_t StaticSize = default_vector_impl_static_size>
VectorImpl< T, VectorType, StaticSize >::VectorImpl ( size_t  set_size,
value 
)
inline

Create with the given size and value.

  • set_size number of values
  • value the value to initialize each element

◆ VectorImpl() [3/3]

template<typename T , typename VectorType , size_t StaticSize = default_vector_impl_static_size>
template<typename Container , Requires< std::is_same_v< typename Container::value_type, T > > = nullptr>
VectorImpl< T, VectorType, StaticSize >::VectorImpl ( const Container &  container)
inlineexplicit

Create from a copy of the given container.

Parameters
containerA container with a value_type that is the same as T. Currently restricted to std::vector<T> and std::array<T>.

Member Function Documentation

◆ destructive_resize()

template<typename T , typename VectorType , size_t StaticSize = default_vector_impl_static_size>
void VectorImpl< T, VectorType, StaticSize >::destructive_resize ( const size_t  new_size)
inline

A common operation for checking the size and resizing a memory buffer if needed to ensure that it has the desired size. This operation is not permitted on a non-owning vector.

Note
This utility should NOT be used when it is anticipated that the supplied buffer will typically be the wrong size (in that case, suggest either manual checking or restructuring so that resizing is less common). This uses UNLIKELY to perform the check most quickly when the buffer needs no resizing, but will be slower when resizing is common.

◆ operator*() [1/2]

template<typename T , typename VectorType , size_t StaticSize = default_vector_impl_static_size>
BaseType & VectorImpl< T, VectorType, StaticSize >::operator* ( )
inline

Upcast to BaseType

Attention
upcast should only be used when implementing a derived vector type, not in calling code

◆ operator*() [2/2]

template<typename T , typename VectorType , size_t StaticSize = default_vector_impl_static_size>
const BaseType & VectorImpl< T, VectorType, StaticSize >::operator* ( ) const
inline

Upcast to BaseType

Attention
upcast should only be used when implementing a derived vector type, not in calling code

The documentation for this class was generated from the following file: