OpenMD 3.2
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.
DynamicVector< Real > abs () const
 Returns a vector containing the absolute value of each element.
Real max () const
 Returns the largest element 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 74 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 77 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 86 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 84 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 82 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 88 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 80 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 85 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 83 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 81 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 87 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 79 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 76 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 78 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 94 of file DynamicVector.hpp.

Referenced by abs(), add(), add(), div(), mul(), negate(), operator!=(), operator*=(), operator+=(), operator-=(), operator/=(), operator==(), sub(), and sub().

◆ 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 105 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 117 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 128 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 137 of file DynamicVector.hpp.

Member Function Documentation

◆ abs()

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

Returns a vector containing the absolute value of each element.

Definition at line 330 of file DynamicVector.hpp.

References DynamicVector().

◆ 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 208 of file DynamicVector.hpp.

References DynamicVector().

Referenced by OpenMD::operator+(), and 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 218 of file DynamicVector.hpp.

References DynamicVector().

◆ begin() [1/2]

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

Definition at line 150 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 149 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 151 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 155 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 283 of file DynamicVector.hpp.

References DynamicVector().

◆ 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 272 of file DynamicVector.hpp.

Referenced by OpenMD::operator/(), and operator/=().

◆ empty()

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

Definition at line 158 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 154 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 153 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 357 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 354 of file DynamicVector.hpp.

References OpenMD::equal(), and 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 321 of file DynamicVector.hpp.

References lengthSquare().

Referenced by OpenMD::distance(), and 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 327 of file DynamicVector.hpp.

References OpenMD::dot().

Referenced by OpenMD::distanceSquare(), isNormalized(), and length().

◆ max()

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

Returns the largest element of this vector.

Definition at line 338 of file DynamicVector.hpp.

◆ 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 260 of file DynamicVector.hpp.

References DynamicVector().

◆ 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 249 of file DynamicVector.hpp.

Referenced by OpenMD::operator*(), OpenMD::operator*(), and 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 190 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 199 of file DynamicVector.hpp.

References DynamicVector().

◆ normalize()

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

Normalizes this vector in place.

Definition at line 341 of file DynamicVector.hpp.

References 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 187 of file DynamicVector.hpp.

References DynamicVector().

◆ operator()() [1/2]

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

Definition at line 145 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 146 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 303 of file DynamicVector.hpp.

References DynamicVector(), and 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 291 of file DynamicVector.hpp.

References add(), and DynamicVector().

◆ 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 297 of file DynamicVector.hpp.

References DynamicVector(), and 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 309 of file DynamicVector.hpp.

References div(), and DynamicVector().

◆ 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 174 of file DynamicVector.hpp.

References DynamicVector().

◆ 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.

◆ reserve()

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

Definition at line 167 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 162 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 163 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 315 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 159 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 228 of file DynamicVector.hpp.

References DynamicVector().

Referenced by OpenMD::operator-(), and 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 239 of file DynamicVector.hpp.

References DynamicVector().


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