OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
OpenMD::DynamicVector< Real, Alloc > Class Template Reference

Dynamically-sized vector class. More...

#include "math/DynamicVector.hpp"

Public Types

using value_type = Real
 
using allocator_type = Alloc
 
using VectorType = std::vector<Real, Alloc>
 
using size_type = typename VectorType::size_type
 
using difference_type = typename VectorType::difference_type
 
using reference = typename VectorType::reference
 
using const_reference = typename VectorType::const_reference
 
using pointer = typename VectorType::pointer
 
using const_pointer = typename VectorType::const_pointer
 
using iterator = typename VectorType::iterator
 
using const_iterator = typename VectorType::const_iterator
 
using reverse_iterator = typename VectorType::reverse_iterator
 
using const_reverse_iterator = typename VectorType::const_reverse_iterator
 

Public Member Functions

 DynamicVector (const allocator_type &alloc=allocator_type())
 Default constructor creates no elements.
 
 DynamicVector (size_type n, const value_type &value, const allocator_type &alloc=allocator_type())
 Create a DynamicVector with copies of an exemplar element.
 
 DynamicVector (size_type n, const allocator_type &alloc=allocator_type())
 Create a DynamicVector with default elements.
 
template<typename InputIterator >
 DynamicVector (InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type())
 Create a DynamicVector using an iterator range.
 
 DynamicVector (std::initializer_list< value_type > init, const allocator_type &alloc=allocator_type())
 Create a DynamicVector with the contents of an initializer_list.
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
reference operator() (size_type i)
 
const_reference operator() (size_type i) const
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
bool empty () const noexcept
 
size_type size () const noexcept
 
void resize (size_type n)
 
void resize (size_type n, const value_type &value)
 
void reserve (size_type new_cap)
 
bool operator== (const DynamicVector< Real > &v)
 Tests if this vetor is equal to other vector.
 
bool operator!= (const DynamicVector< Real > &v)
 Tests if this vetor is not equal to other vector.
 
void negate ()
 Negates the value of this vector in place.
 
void negate (const DynamicVector< Real > &v1)
 Sets the value of this vector to the negation of vector v1.
 
void add (const DynamicVector< Real > &v1)
 Sets the value of this vector to the sum of itself and v1 (*this += v1).
 
void add (const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
 Sets the value of this vector to the sum of v1 and v2 (*this = v1 + v2).
 
void sub (const DynamicVector< Real > &v1)
 Sets the value of this vector to the difference of itself and v1 (*this -= v1).
 
void sub (const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
 Sets the value of this vector to the difference of vector v1 and v2 (*this = v1 - v2).
 
void mul (Real s)
 Sets the value of this vector to the scalar multiplication of itself (*this *= s).
 
void mul (const DynamicVector< Real > &v1, Real s)
 Sets the value of this vector to the scalar multiplication of vector v1 (*this = s * v1).
 
void div (Real s)
 Sets the value of this vector to the scalar division of itself (*this /= s).
 
void div (const DynamicVector< Real > &v1, Real s)
 Sets the value of this vector to the scalar division of vector v1 (*this = v1 / s).
 
DynamicVector< Real > & operator+= (const DynamicVector< Real > &v1)
 
DynamicVector< Real > & operator-= (const DynamicVector< Real > &v1)
 
DynamicVector< Real > & operator*= (Real s)
 
DynamicVector< Real > & operator/= (Real s)
 
void setZero ()
 zero out the vector
 
Real length ()
 Returns the length of this vector.
 
Real lengthSquare ()
 Returns the squared length of this vector.
 
void normalize ()
 Normalizes this vector in place.
 
bool isNormalized ()
 Tests if this vector is normalized.
 
template<class VectorType >
void getSubVector (size_type beginning, VectorType &v)
 

Detailed Description

template<typename Real, typename Alloc = std::allocator<Real>>
class OpenMD::DynamicVector< Real, Alloc >

Dynamically-sized vector class.

Definition at line 71 of file DynamicVector.hpp.

Member Typedef Documentation

◆ allocator_type

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::allocator_type = Alloc

Definition at line 74 of file DynamicVector.hpp.

◆ const_iterator

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::const_iterator = typename VectorType::const_iterator

Definition at line 83 of file DynamicVector.hpp.

◆ const_pointer

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::const_pointer = typename VectorType::const_pointer

Definition at line 81 of file DynamicVector.hpp.

◆ const_reference

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::const_reference = typename VectorType::const_reference

Definition at line 79 of file DynamicVector.hpp.

◆ const_reverse_iterator

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::const_reverse_iterator = typename VectorType::const_reverse_iterator

Definition at line 85 of file DynamicVector.hpp.

◆ difference_type

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::difference_type = typename VectorType::difference_type

Definition at line 77 of file DynamicVector.hpp.

◆ iterator

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::iterator = typename VectorType::iterator

Definition at line 82 of file DynamicVector.hpp.

◆ pointer

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::pointer = typename VectorType::pointer

Definition at line 80 of file DynamicVector.hpp.

◆ reference

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::reference = typename VectorType::reference

Definition at line 78 of file DynamicVector.hpp.

◆ reverse_iterator

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::reverse_iterator = typename VectorType::reverse_iterator

Definition at line 84 of file DynamicVector.hpp.

◆ size_type

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::size_type = typename VectorType::size_type

Definition at line 76 of file DynamicVector.hpp.

◆ value_type

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::value_type = Real

Definition at line 73 of file DynamicVector.hpp.

◆ VectorType

template<typename Real , typename Alloc = std::allocator<Real>>
using OpenMD::DynamicVector< Real, Alloc >::VectorType = std::vector<Real, Alloc>

Definition at line 75 of file DynamicVector.hpp.

Constructor & Destructor Documentation

◆ DynamicVector() [1/5]

template<typename Real , typename Alloc = std::allocator<Real>>
OpenMD::DynamicVector< Real, Alloc >::DynamicVector ( const allocator_type & alloc = allocator_type())
inlineexplicit

Default constructor creates no elements.

Parameters
allocThe allocator_type to use

Definition at line 91 of file DynamicVector.hpp.

◆ DynamicVector() [2/5]

template<typename Real , typename Alloc = std::allocator<Real>>
OpenMD::DynamicVector< Real, Alloc >::DynamicVector ( size_type n,
const value_type & value,
const allocator_type & alloc = allocator_type() )
inline

Create a DynamicVector with copies of an exemplar element.

Parameters
nThe number of elements to initially create.
valueAn element to copy.
allocThe allocator_type to use

This constructor fills the DynamicVector with n copies of value.

Definition at line 102 of file DynamicVector.hpp.

◆ DynamicVector() [3/5]

template<typename Real , typename Alloc = std::allocator<Real>>
OpenMD::DynamicVector< Real, Alloc >::DynamicVector ( size_type n,
const allocator_type & alloc = allocator_type() )
inlineexplicit

Create a DynamicVector with default elements.

Parameters
nThe number of elements to initially create.
allocThe allocator_type to use

This constructor fills the DynamicVector with n copies of a default-constructed element.

Definition at line 114 of file DynamicVector.hpp.

◆ DynamicVector() [4/5]

template<typename Real , typename Alloc = std::allocator<Real>>
template<typename InputIterator >
OpenMD::DynamicVector< Real, Alloc >::DynamicVector ( InputIterator first,
InputIterator last,
const allocator_type & alloc = allocator_type() )
inline

Create a DynamicVector using an iterator range.

Parameters
firstThe beginning of the range to copy the elements from
lastThe end of the range to copy the elements from
allocThe allocator_type to use

Definition at line 125 of file DynamicVector.hpp.

◆ DynamicVector() [5/5]

template<typename Real , typename Alloc = std::allocator<Real>>
OpenMD::DynamicVector< Real, Alloc >::DynamicVector ( std::initializer_list< value_type > init,
const allocator_type & alloc = allocator_type() )
inline

Create a DynamicVector with the contents of an initializer_list.

Parameters
initInitializer list to initialize the elements with
allocThe allocator_type to use

Definition at line 134 of file DynamicVector.hpp.

Member Function Documentation

◆ add() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::add ( const DynamicVector< Real > & v1)
inline

Sets the value of this vector to the sum of itself and v1 (*this += v1).

Parameters
v1the other vector

Definition at line 205 of file DynamicVector.hpp.

Referenced by OpenMD::operator+(), and OpenMD::DynamicVector< Real, Alloc >::operator+=().

◆ add() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::add ( const DynamicVector< Real > & v1,
const DynamicVector< Real > & v2 )
inline

Sets the value of this vector to the sum of v1 and v2 (*this = v1 + v2).

Parameters
v1the first vector
v2the second vector

Definition at line 215 of file DynamicVector.hpp.

◆ begin() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
const_iterator OpenMD::DynamicVector< Real, Alloc >::begin ( ) const
inlinenoexcept

Definition at line 147 of file DynamicVector.hpp.

◆ begin() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
iterator OpenMD::DynamicVector< Real, Alloc >::begin ( )
inlinenoexcept

Definition at line 146 of file DynamicVector.hpp.

◆ cbegin()

template<typename Real , typename Alloc = std::allocator<Real>>
const_iterator OpenMD::DynamicVector< Real, Alloc >::cbegin ( ) const
inlinenoexcept

Definition at line 148 of file DynamicVector.hpp.

◆ cend()

template<typename Real , typename Alloc = std::allocator<Real>>
const_iterator OpenMD::DynamicVector< Real, Alloc >::cend ( ) const
inlinenoexcept

Definition at line 152 of file DynamicVector.hpp.

◆ div() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::div ( const DynamicVector< Real > & v1,
Real s )
inline

Sets the value of this vector to the scalar division of vector v1 (*this = v1 / s).

Parameters
v1the source vector
sthe scalar value

Definition at line 280 of file DynamicVector.hpp.

◆ div() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::div ( Real s)
inline

Sets the value of this vector to the scalar division of itself (*this /= s).

Parameters
sthe scalar value

Definition at line 269 of file DynamicVector.hpp.

Referenced by OpenMD::operator/(), and OpenMD::DynamicVector< Real, Alloc >::operator/=().

◆ empty()

template<typename Real , typename Alloc = std::allocator<Real>>
bool OpenMD::DynamicVector< Real, Alloc >::empty ( ) const
inlinenoexcept

Definition at line 155 of file DynamicVector.hpp.

◆ end() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
const_iterator OpenMD::DynamicVector< Real, Alloc >::end ( ) const
inlinenoexcept

Definition at line 151 of file DynamicVector.hpp.

◆ end() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
iterator OpenMD::DynamicVector< Real, Alloc >::end ( )
inlinenoexcept

Definition at line 150 of file DynamicVector.hpp.

◆ getSubVector()

template<typename Real , typename Alloc = std::allocator<Real>>
template<class VectorType >
void OpenMD::DynamicVector< Real, Alloc >::getSubVector ( size_type beginning,
VectorType & v )
inline

Definition at line 343 of file DynamicVector.hpp.

◆ isNormalized()

template<typename Real , typename Alloc = std::allocator<Real>>
bool OpenMD::DynamicVector< Real, Alloc >::isNormalized ( )
inline

Tests if this vector is normalized.

Returns
true if this vector is normalized, otherwise return false

Definition at line 340 of file DynamicVector.hpp.

References OpenMD::equal(), and OpenMD::DynamicVector< Real, Alloc >::lengthSquare().

◆ length()

template<typename Real , typename Alloc = std::allocator<Real>>
Real OpenMD::DynamicVector< Real, Alloc >::length ( )
inline

Returns the length of this vector.

Returns
the length of this vector

Definition at line 318 of file DynamicVector.hpp.

References OpenMD::DynamicVector< Real, Alloc >::lengthSquare().

Referenced by OpenMD::distance(), and OpenMD::DynamicVector< Real, Alloc >::normalize().

◆ lengthSquare()

template<typename Real , typename Alloc = std::allocator<Real>>
Real OpenMD::DynamicVector< Real, Alloc >::lengthSquare ( )
inline

Returns the squared length of this vector.

Returns
the squared length of this vector

Definition at line 324 of file DynamicVector.hpp.

References OpenMD::dot().

Referenced by OpenMD::distanceSquare(), OpenMD::DynamicVector< Real, Alloc >::isNormalized(), and OpenMD::DynamicVector< Real, Alloc >::length().

◆ mul() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::mul ( const DynamicVector< Real > & v1,
Real s )
inline

Sets the value of this vector to the scalar multiplication of vector v1 (*this = s * v1).

Parameters
v1the vector
sthe scalar value

Definition at line 257 of file DynamicVector.hpp.

◆ mul() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::mul ( Real s)
inline

Sets the value of this vector to the scalar multiplication of itself (*this *= s).

Parameters
sthe scalar value

Definition at line 246 of file DynamicVector.hpp.

Referenced by OpenMD::operator*(), OpenMD::operator*(), and OpenMD::DynamicVector< Real, Alloc >::operator*=().

◆ negate() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::negate ( )
inline

Negates the value of this vector in place.

Definition at line 187 of file DynamicVector.hpp.

Referenced by OpenMD::operator-().

◆ negate() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::negate ( const DynamicVector< Real > & v1)
inline

Sets the value of this vector to the negation of vector v1.

Parameters
v1the source vector

Definition at line 196 of file DynamicVector.hpp.

◆ normalize()

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::normalize ( )
inline

Normalizes this vector in place.

Definition at line 327 of file DynamicVector.hpp.

References OpenMD::DynamicVector< Real, Alloc >::length().

◆ operator!=()

template<typename Real , typename Alloc = std::allocator<Real>>
bool OpenMD::DynamicVector< Real, Alloc >::operator!= ( const DynamicVector< Real > & v)
inline

Tests if this vetor is not equal to other vector.

Returns
true if equal, otherwise return false
Parameters
vvector to be compared

Definition at line 184 of file DynamicVector.hpp.

◆ operator()() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
reference OpenMD::DynamicVector< Real, Alloc >::operator() ( size_type i)
inline

Definition at line 142 of file DynamicVector.hpp.

◆ operator()() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
const_reference OpenMD::DynamicVector< Real, Alloc >::operator() ( size_type i) const
inline

Definition at line 143 of file DynamicVector.hpp.

◆ operator*=()

template<typename Real , typename Alloc = std::allocator<Real>>
DynamicVector< Real > & OpenMD::DynamicVector< Real, Alloc >::operator*= ( Real s)
inline
See also
mul

Definition at line 300 of file DynamicVector.hpp.

References OpenMD::DynamicVector< Real, Alloc >::mul().

◆ operator+=()

template<typename Real , typename Alloc = std::allocator<Real>>
DynamicVector< Real > & OpenMD::DynamicVector< Real, Alloc >::operator+= ( const DynamicVector< Real > & v1)
inline
See also
add

Definition at line 288 of file DynamicVector.hpp.

References OpenMD::DynamicVector< Real, Alloc >::add().

◆ operator-=()

template<typename Real , typename Alloc = std::allocator<Real>>
DynamicVector< Real > & OpenMD::DynamicVector< Real, Alloc >::operator-= ( const DynamicVector< Real > & v1)
inline
See also
sub

Definition at line 294 of file DynamicVector.hpp.

References OpenMD::DynamicVector< Real, Alloc >::sub().

◆ operator/=()

template<typename Real , typename Alloc = std::allocator<Real>>
DynamicVector< Real > & OpenMD::DynamicVector< Real, Alloc >::operator/= ( Real s)
inline
See also
div

Definition at line 306 of file DynamicVector.hpp.

References OpenMD::DynamicVector< Real, Alloc >::div().

◆ operator==()

template<typename Real , typename Alloc = std::allocator<Real>>
bool OpenMD::DynamicVector< Real, Alloc >::operator== ( const DynamicVector< Real > & v)
inline

Tests if this vetor is equal to other vector.

Returns
true if equal, otherwise return false
Parameters
vvector to be compared

Definition at line 171 of file DynamicVector.hpp.

◆ operator[]() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
reference OpenMD::DynamicVector< Real, Alloc >::operator[] ( size_type i)
inline

Definition at line 139 of file DynamicVector.hpp.

◆ operator[]() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
const_reference OpenMD::DynamicVector< Real, Alloc >::operator[] ( size_type i) const
inline

Definition at line 140 of file DynamicVector.hpp.

◆ reserve()

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::reserve ( size_type new_cap)
inline

Definition at line 164 of file DynamicVector.hpp.

◆ resize() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::resize ( size_type n)
inline

Definition at line 159 of file DynamicVector.hpp.

◆ resize() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::resize ( size_type n,
const value_type & value )
inline

Definition at line 160 of file DynamicVector.hpp.

◆ setZero()

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::setZero ( )
inline

zero out the vector

Definition at line 312 of file DynamicVector.hpp.

◆ size()

template<typename Real , typename Alloc = std::allocator<Real>>
size_type OpenMD::DynamicVector< Real, Alloc >::size ( ) const
inlinenoexcept

Definition at line 156 of file DynamicVector.hpp.

◆ sub() [1/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::sub ( const DynamicVector< Real > & v1)
inline

Sets the value of this vector to the difference of itself and v1 (*this -= v1).

Parameters
v1the other vector

Definition at line 225 of file DynamicVector.hpp.

Referenced by OpenMD::operator-(), and OpenMD::DynamicVector< Real, Alloc >::operator-=().

◆ sub() [2/2]

template<typename Real , typename Alloc = std::allocator<Real>>
void OpenMD::DynamicVector< Real, Alloc >::sub ( const DynamicVector< Real > & v1,
const DynamicVector< Real > & v2 )
inline

Sets the value of this vector to the difference of vector v1 and v2 (*this = v1 - v2).

Parameters
v1the first vector
v2the second vector

Definition at line 236 of file DynamicVector.hpp.


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