Peano
Loading...
Searching...
No Matches
tarch::la::SmartPointerVector< Size, Scalar > Struct Template Reference

Simple SmartPointerVector class. More...

#include <SmartPointerVector.h>

Collaboration diagram for tarch::la::SmartPointerVector< Size, Scalar >:

Public Member Functions

 SmartPointerVector () InlineMethod
 Clang requires the always_inline attribute, as it otherwise makes weird decisions.
 
 SmartPointerVector (const Scalar *values) InlineMethod
 
 SmartPointerVector (std::initializer_list< Scalar > values)
 Initialisation via initialisation list.
 
 SmartPointerVector (const std::bitset< Size > &values) InlineMethod
 
 SmartPointerVector (const Scalar &initialValue)
 Construct new SmartPointerVector and initialize all components with initialValue.
 
 SmartPointerVector (const SmartPointerVector< Size, Scalar > &toCopy)
 Copy constructor to copy from any SmartPointerVector type.
 
 SmartPointerVector (const Vector< Size, Scalar > &toCopy)
 
SmartPointerVector< Size, Scalar > & operator= (const SmartPointerVector< Size, Scalar > &toAssign) InlineMethod
 Assignment operator for any SmartPointerVector type.
 
SmartPointerVector< Size, Scalar > & operator= (const Vector< Size, Scalar > &vector)
 Conversion assignment operator.
 
SmartPointerVector< Size, Scalar > & operator= (const Scalar &vector)
 Assign all entries the same value.
 
int size () const
 Returns the number of components of the SmartPointerVector.
 
const Scalar & operator[] (int index) const InlineMethod
 Returns read-only ref.
 
Scalar & operator[] (int index) InlineMethod
 Returns ref.
 
const Scalar & operator() (int index) const InlineMethod
 Returns read-only ref.
 
Scalar & operator() (int index) InlineMethod
 Returns ref.
 
Scalar * data ()
 This routine returns a pointer to the first data element.
 
const Scalar * data () const
 
Vector< Size, Scalar > toVector () const
 

Private Attributes

Scalar * _values
 In the original vector, this is.
 
std::shared_ptr< Scalar[] > _dataSmartPointer
 

Detailed Description

template<int Size, typename Scalar>
struct tarch::la::SmartPointerVector< Size, Scalar >

Simple SmartPointerVector class.

Mirrors exactly tarch::la::Vector, but internally uses a smart pointer rather than a scalar. The class tries to minimise replication. Therefore, it provides extensive conversion routines to and from a normal Vector but limited functionality directly on the smart vector (where appropriate).

Definition at line 47 of file SmartPointerVector.h.

Constructor & Destructor Documentation

◆ SmartPointerVector() [1/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( )

Clang requires the always_inline attribute, as it otherwise makes weird decisions.

◆ SmartPointerVector() [2/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( const Scalar * values)

◆ SmartPointerVector() [3/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( std::initializer_list< Scalar > values)

Initialisation via initialisation list.

You can't inline an initialisation list, as the realisation of this routine relies on an iterator and the iterator within the C++ std lib won't be inlined.

◆ SmartPointerVector() [4/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( const std::bitset< Size > & values)

◆ SmartPointerVector() [5/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( const Scalar & initialValue)

Construct new SmartPointerVector and initialize all components with initialValue.

◆ SmartPointerVector() [6/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( const SmartPointerVector< Size, Scalar > & toCopy)

Copy constructor to copy from any SmartPointerVector type.

The only way to accomplish this with enable-if is to specify a second dummy argument with default value, which is (hopefully) optimized away.

See also
operator= for a discussion of SSE optimisation.

◆ SmartPointerVector() [7/7]

template<int Size, typename Scalar >
tarch::la::SmartPointerVector< Size, Scalar >::SmartPointerVector ( const Vector< Size, Scalar > & toCopy)
 Copy constructor

 As we are working with smart pointers, we do not realy copy under the
 hood.

 I originally had

 ~~~~~~~~~~~~~~~~~~~~~~

_dataSmartPointer( toCopy._dataSmartPointer ), _values( _dataSmartPointer.get() ) { ~~~~~~~~~~~~~~~~~~~~~~

but the the compiler told me that _dataSmartPointer is not initialised at this point. Which I find weird. So now I initialise it explicitly.

Member Function Documentation

◆ data() [1/2]

template<int Size, typename Scalar >
Scalar * tarch::la::SmartPointerVector< Size, Scalar >::data ( )

This routine returns a pointer to the first data element.

Not a beautiful one as it harms the OO idea, but in many cases it is convenient to have this operation.

Definition at line 213 of file SmartPointerVector.h.

References tarch::la::SmartPointerVector< Size, Scalar >::_values.

Referenced by peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__generate_dastgen_input_file(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_file_name(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_full_qualified_file_name(), swift2.particle.Particle.Particle::__init__(), swift2.particle.Particle.Particle::_add_dependency_checks(), swift2.particle.Particle.Particle::_dependency_checks_modify_steps(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_enum_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_string_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_user_defined_attributes(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::_get_dictionary_for_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::construct_output(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::construct_output(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::construct_output(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::construct_output(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::construct_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_header_file_include(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_header_file_include(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_header_file_include(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_stack_container(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_stack_container(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_stack_container(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_stack_container(), peano4.datamodel.DaStGen2.DaStGen2::hosts_smart_pointer_attribute(), swift2.particle.Particle.Particle::readme_descriptor(), swift2.particle.SPHLeapfrogFixedSearchRadius.SPHLeapfrogFixedSearchRadius::set_parameters(), swift2.particle.SPHParticle.SPHParticle::set_parameters(), and swift2.particle.tests.testLeapfrogFixedTimeStepSize.testLeapfrogFixedTimeStepSize::set_parameters().

Here is the caller graph for this function:

◆ data() [2/2]

template<int Size, typename Scalar >
const Scalar * tarch::la::SmartPointerVector< Size, Scalar >::data ( ) const

Definition at line 217 of file SmartPointerVector.h.

References tarch::la::SmartPointerVector< Size, Scalar >::_values.

Referenced by peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__generate_dastgen_input_file(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_file_name(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::__get_full_qualified_file_name(), swift2.particle.Particle.Particle::__init__(), swift2.particle.Particle.Particle::_add_dependency_checks(), swift2.particle.Particle.Particle::_dependency_checks_modify_steps(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_boolean_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_double_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_enum_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_integer_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_double_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_peano_integer_array_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_string_attributes(), swift2.particle.tests.DastgenTestDummyParticle.DastgenTestDummyParticle::_generate_user_defined_attributes(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::_get_dictionary_for_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::construct_output(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::construct_output(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::construct_output(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::construct_output(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::construct_output(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_header_file_include(), peano4.datamodel.DynamicArrayOverPrimitivesToStdVector.DynamicArrayOverPrimitivesToStdVector::get_header_file_include(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_header_file_include(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_header_file_include(), peano4.datamodel.DaStGenToLegacyTool.DaStGenToLegacyTool::get_stack_container(), peano4.datamodel.PatchToDoubleArray.PatchToDoubleArray::get_stack_container(), peano4.datamodel.PatchToDoubleArrayOnHeap.PatchToDoubleArrayOnHeap::get_stack_container(), peano4.datamodel.PatchToDoubleArrayWithSmartPointer.PatchToDoubleArrayWithSmartPointer::get_stack_container(), peano4.datamodel.DaStGen2.DaStGen2::hosts_smart_pointer_attribute(), swift2.particle.Particle.Particle::readme_descriptor(), swift2.particle.SPHLeapfrogFixedSearchRadius.SPHLeapfrogFixedSearchRadius::set_parameters(), swift2.particle.SPHParticle.SPHParticle::set_parameters(), and swift2.particle.tests.testLeapfrogFixedTimeStepSize.testLeapfrogFixedTimeStepSize::set_parameters().

Here is the caller graph for this function:

◆ operator()() [1/2]

template<int Size, typename Scalar >
const Scalar & tarch::la::SmartPointerVector< Size, Scalar >::operator() ( int index) const

Returns read-only ref.

to component of given index.

If we use the SmartPointerVector on the GPU, we cannot have assertions. If we use SYCL on the CPU for the multitasking, we cannot have assertions in the SYCL part either, as SYCL aims to be platform-independent, i.e. has to assume that the code generated also will be deployed to a GPU. See discussion on SYCL support.

See also
operator[] for remarks on SSE

Definition at line 187 of file SmartPointerVector.h.

References tarch::la::SmartPointerVector< Size, Scalar >::_values, assertion3, and tarch::toString().

Here is the call graph for this function:

◆ operator()() [2/2]

template<int Size, typename Scalar >
Scalar & tarch::la::SmartPointerVector< Size, Scalar >::operator() ( int index)

Returns ref.

to component of given index.

See also
operator[] for remarks on SSE

Definition at line 200 of file SmartPointerVector.h.

References tarch::la::SmartPointerVector< Size, Scalar >::_values, assertion3, and tarch::toString().

Here is the call graph for this function:

◆ operator=() [1/3]

template<int Size, typename Scalar >
SmartPointerVector< Size, Scalar > & tarch::la::SmartPointerVector< Size, Scalar >::operator= ( const Scalar & vector)

Assign all entries the same value.

As we work with smart pointers, we can return a copy here. Actually, I got some compiler errors when I tried to return a reference.

◆ operator=() [2/3]

template<int Size, typename Scalar >
SmartPointerVector< Size, Scalar > & tarch::la::SmartPointerVector< Size, Scalar >::operator= ( const SmartPointerVector< Size, Scalar > & toAssign)

Assignment operator for any SmartPointerVector type.

SmartPointerVectorisation

We do not allow assignment of a SmartPointerVector this itself. Consequently, we can insert an ivdep statement and thus allow the compiler to optimise.

◆ operator=() [3/3]

template<int Size, typename Scalar >
SmartPointerVector< Size, Scalar > & tarch::la::SmartPointerVector< Size, Scalar >::operator= ( const Vector< Size, Scalar > & vector)

Conversion assignment operator.

This operator realises an explicit copy, i.e. we assume that this already holds a valid memory region, so we can take each element of vector and copy it over.

◆ operator[]() [1/2]

template<int Size, typename Scalar >
const Scalar & tarch::la::SmartPointerVector< Size, Scalar >::operator[] ( int index) const

Returns read-only ref.

to component of given index.

SSE Optimisation

  • We have to manually inline this operation. Otherwise, icc interprets operator calls, i.e. SmartPointerVector element accesses, as function calls and does not SmartPointerVectorise loops containing SmartPointerVector element accesses.

Definition at line 155 of file SmartPointerVector.h.

References tarch::la::SmartPointerVector< Size, Scalar >::_values, assertion3, assertion4, and tarch::toString().

Here is the call graph for this function:

◆ operator[]() [2/2]

template<int Size, typename Scalar >
Scalar & tarch::la::SmartPointerVector< Size, Scalar >::operator[] ( int index)

Returns ref.

to component of given index.

See also
operator[] for remarks on SSE

Definition at line 168 of file SmartPointerVector.h.

References tarch::la::SmartPointerVector< Size, Scalar >::_values, assertion3, and tarch::toString().

Here is the call graph for this function:

◆ size()

template<int Size, typename Scalar >
int tarch::la::SmartPointerVector< Size, Scalar >::size ( ) const

Returns the number of components of the SmartPointerVector.

Referenced by peano4.visualisation.input.Patch.Patch::__repr__().

Here is the caller graph for this function:

◆ toVector()

template<int Size, typename Scalar >
Vector< Size, Scalar > tarch::la::SmartPointerVector< Size, Scalar >::toVector ( ) const

Field Documentation

◆ _dataSmartPointer

template<int Size, typename Scalar >
std::shared_ptr< Scalar[] > tarch::la::SmartPointerVector< Size, Scalar >::_dataSmartPointer
private

Definition at line 58 of file SmartPointerVector.h.

◆ _values


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