Drake
VectorBase< T > Class Template Referenceabstract

VectorBase is an abstract base class that real-valued signals between Systems and real-valued System state vectors must implement. More...

#include <drake/systems/framework/vector_base.h>

Public Member Functions

virtual ~VectorBase ()

virtual int size () const =0
Returns the number of elements in the vector. More...

T & operator[] (int index)
Returns the element at the given index in the vector. More...

const T & operator[] (int index) const
Returns the element at the given index in the vector. More...

const T & GetAtIndex (int index) const
Returns the element at the given index in the vector. More...

T & GetAtIndex (int index)
Returns the element at the given index in the vector. More...

void SetAtIndex (int index, const T &value)
Replaces the state at the given index with the value. More...

virtual void SetFrom (const VectorBase< T > &value)
Replaces the entire vector with the contents of value. More...

virtual void SetFromVector (const Eigen::Ref< const VectorX< T >> &value)
Replaces the entire vector with the contents of value. More...

virtual void SetZero ()

virtual VectorX< T > CopyToVector () const
Copies this entire VectorBase into a contiguous Eigen Vector. More...

virtual void CopyToPreSizedVector (EigenPtr< VectorX< T >> vec) const
Copies this entire VectorBase into a pre-sized Eigen Vector. More...

virtual void ScaleAndAddToVector (const T &scale, EigenPtr< VectorX< T >> vec) const
Adds a scaled version of this vector to Eigen vector vec, which must be the same size. More...

void ScaleAndAddToVector (const T &scale, Eigen::Ref< VectorX< T >> vec) const
(Deprecated.) More...

VectorBasePlusEqScaled (const T &scale, const VectorBase< T > &rhs)
Add in scaled vector rhs to this vector. More...

VectorBasePlusEqScaled (const std::initializer_list< std::pair< T, const VectorBase< T > & >> &rhs_scale)
Add in multiple scaled vectors to this vector. More...

VectorBaseoperator+= (const VectorBase< T > &rhs)
Add in vector rhs to this vector. More...

VectorBaseoperator-= (const VectorBase< T > &rhs)
Subtract in vector rhs to this vector. More...

virtual T NormInf () const
(Deprecated.) More...

virtual void GetElementBounds (Eigen::VectorXd *lower, Eigen::VectorXd *upper) const
Get the bounds for the elements. More...

Does not allow copy, move, or assignment
VectorBase (const VectorBase &)=delete

VectorBaseoperator= (const VectorBase &)=delete

VectorBase (VectorBase &&)=delete

VectorBaseoperator= (VectorBase &&)=delete

Protected Member Functions

VectorBase ()

virtual const T & DoGetAtIndex (int index) const =0
Implementations should ensure this operation is O(1) and allocates no memory. More...

virtual T & DoGetAtIndex (int index)=0
Implementations should ensure this operation is O(1) and allocates no memory. More...

virtual void DoPlusEqScaled (const std::initializer_list< std::pair< T, const VectorBase< T > & >> &rhs_scale)
Adds in multiple scaled vectors to this vector. More...

Detailed Description

template<typename T> class drake::systems::VectorBase< T >

VectorBase is an abstract base class that real-valued signals between Systems and real-valued System state vectors must implement.

Classes that inherit from VectorBase will typically provide names for the elements of the vector, and may also provide other computations for the convenience of Systems handling the signal. The vector is always a column vector. It may or may not be contiguous in memory. Contiguous subclasses should typically inherit from BasicVector, not from VectorBase directly.

Template Parameters
 T Must be a Scalar compatible with Eigen.

◆ VectorBase() [1/3]

 VectorBase ( const VectorBase< T > & )
delete

◆ VectorBase() [2/3]

 VectorBase ( VectorBase< T > && )
delete

◆ ~VectorBase()

 virtual ~VectorBase ( )
virtual

◆ VectorBase() [3/3]

 VectorBase ( )
protected

◆ CopyToPreSizedVector()

 virtual void CopyToPreSizedVector ( EigenPtr< VectorX< T >> vec ) const
virtual

Copies this entire VectorBase into a pre-sized Eigen Vector.

Implementations should ensure this operation is O(N) in the size of the value.

Exceptions
 std::exception if vec is the wrong size.

◆ CopyToVector()

 virtual VectorX CopyToVector ( ) const
virtual

Copies this entire VectorBase into a contiguous Eigen Vector.

Implementations should ensure this operation is O(N) in the size of the value and allocates only the O(N) memory that it returns.

◆ DoGetAtIndex() [1/2]

 virtual const T& DoGetAtIndex ( int index ) const
protectedpure virtual

Implementations should ensure this operation is O(1) and allocates no memory.

The index has already been checked for negative, but not size.

◆ DoGetAtIndex() [2/2]

 virtual T& DoGetAtIndex ( int index )
protectedpure virtual

Implementations should ensure this operation is O(1) and allocates no memory.

The index has already been checked for negative, but not size.

◆ DoPlusEqScaled()

 virtual void DoPlusEqScaled ( const std::initializer_list< std::pair< T, const VectorBase< T > & >> & rhs_scale )
protectedvirtual

Adds in multiple scaled vectors to this vector.

All vectors are guaranteed to be the same size.

You should override this method if possible with a more efficient approach that leverages structure; the default implementation performs element-by-element computations that are likely inefficient, but even this implementation minimizes memory accesses for efficiency. If the vector is contiguous, for example, implementations that leverage SIMD operations should be far more efficient. Overriding implementations should ensure that this operation remains O(N) in the size of the value and allocates no memory.

◆ GetAtIndex() [1/2]

 const T& GetAtIndex ( int index ) const

Returns the element at the given index in the vector.

Exceptions
 std::runtime_error if the index is >= size() or negative. Consider operator[]() instead if bounds-checking is unwanted.

◆ GetAtIndex() [2/2]

 T& GetAtIndex ( int index )

Returns the element at the given index in the vector.

Exceptions
 std::runtime_error if the index is >= size() or negative. Consider operator[]() instead if bounds-checking is unwanted.

◆ GetElementBounds()

 virtual void GetElementBounds ( Eigen::VectorXd * lower, Eigen::VectorXd * upper ) const
virtual

Get the bounds for the elements.

If lower and upper are both empty size vectors, then there are no bounds. Otherwise, the bounds are (*lower)(i) <= GetAtIndex(i) <= (*upper)(i) The default output is no bounds.

◆ NormInf()

 virtual T NormInf ( ) const
virtual

(Deprecated.)

Deprecated:
"Use CopyToVector + Eigen lpNorm."
This will be removed from Drake on or after "2019-06-01" .

◆ operator+=()

 VectorBase& operator+= ( const VectorBase< T > & rhs )

Add in vector rhs to this vector.

◆ operator-=()

 VectorBase& operator-= ( const VectorBase< T > & rhs )

Subtract in vector rhs to this vector.

◆ operator=() [1/2]

 VectorBase& operator= ( VectorBase< T > && )
delete

◆ operator=() [2/2]

 VectorBase& operator= ( const VectorBase< T > & )
delete

◆ operator[]() [1/2]

 T& operator[] ( int index )

Returns the element at the given index in the vector.

Precondition
0 <= index < size()

◆ operator[]() [2/2]

 const T& operator[] ( int index ) const

Returns the element at the given index in the vector.

Precondition
0 <= index < size()

◆ PlusEqScaled() [1/2]

 VectorBase& PlusEqScaled ( const T & scale, const VectorBase< T > & rhs )

Add in scaled vector rhs to this vector.

Both vectors must be the same size.

◆ PlusEqScaled() [2/2]

 VectorBase& PlusEqScaled ( const std::initializer_list< std::pair< T, const VectorBase< T > & >> & rhs_scale )

Add in multiple scaled vectors to this vector.

All vectors must be the same size.

◆ ScaleAndAddToVector() [1/2]

 virtual void ScaleAndAddToVector ( const T & scale, EigenPtr< VectorX< T >> vec ) const
virtual

Adds a scaled version of this vector to Eigen vector vec, which must be the same size.

Implementations may override this default implementation with a more efficient approach, for instance if this vector is contiguous. Implementations should ensure this operation remains O(N) in the size of the value and allocates no memory.

◆ ScaleAndAddToVector() [2/2]

 void ScaleAndAddToVector ( const T & scale, Eigen::Ref< VectorX< T >> vec ) const

(Deprecated.)

Deprecated:
"Use the EigenPtr overload instead."
This will be removed from Drake on or after "2019-06-01" .

◆ SetAtIndex()

 void SetAtIndex ( int index, const T & value )

Replaces the state at the given index with the value.

Exceptions
 std::runtime_error if the index is >= size(). Consider operator[]() instead if bounds-checking is unwanted.

◆ SetFrom()

 virtual void SetFrom ( const VectorBase< T > & value )
virtual

Replaces the entire vector with the contents of value.

Exceptions
 std::runtime_error if value is not a column vector with size() rows.

Implementations should ensure this operation is O(N) in the size of the value and allocates no memory.

◆ SetFromVector()

 virtual void SetFromVector ( const Eigen::Ref< const VectorX< T >> & value )
virtual

Replaces the entire vector with the contents of value.

Throws std::runtime_error if value is not a column vector with size() rows.

Implementations should ensure this operation is O(N) in the size of the value and allocates no memory.

◆ SetZero()

 virtual void SetZero ( )
virtual

◆ size()

 virtual int size ( ) const
pure virtual

Returns the number of elements in the vector.

Implementations should ensure this operation is O(1) and allocates no memory.

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