Drake
Drake C++ Documentation
VectorBase< T > Class Template Referenceabstract

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
TThe scalar type, which must be one of the default scalars.

#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 ()
 Sets all elements of this vector to zero. More...
 
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. 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 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 & DoGetAtIndexUnchecked (int index) const =0
 Implementations should ensure this operation is O(1) and allocates no memory. More...
 
virtual T & DoGetAtIndexUnchecked (int index)=0
 Implementations should ensure this operation is O(1) and allocates no memory. More...
 
virtual const T & DoGetAtIndexChecked (int index) const =0
 Implementations should ensure this operation is O(1) and allocates no memory. More...
 
virtual T & DoGetAtIndexChecked (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...
 
void ThrowOutOfRange (int index) const
 
void ThrowMismatchedSize (int other_size) const
 

Constructor & Destructor Documentation

◆ VectorBase() [1/3]

VectorBase ( const VectorBase< T > &  )
delete

◆ VectorBase() [2/3]

VectorBase ( VectorBase< T > &&  )
delete

◆ ~VectorBase()

virtual ~VectorBase ( )
virtual

◆ VectorBase() [3/3]

VectorBase ( )
protected

Member Function Documentation

◆ 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::exceptionif vec is the wrong size.

◆ CopyToVector()

virtual VectorX<T> 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.

Reimplemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

◆ DoGetAtIndexChecked() [1/2]

virtual const T& DoGetAtIndexChecked ( 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. Implementations must throw an exception when index >= size().

Implemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

◆ DoGetAtIndexChecked() [2/2]

virtual T& DoGetAtIndexChecked ( 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. Implementations must throw an exception when index >= size().

Implemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

◆ DoGetAtIndexUnchecked() [1/2]

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

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

The index need not be validated when in release mode.

Implemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

◆ DoGetAtIndexUnchecked() [2/2]

virtual T& DoGetAtIndexUnchecked ( int  index)
protectedpure virtual

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

The index need not be validated when in release mode.

Implemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

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

◆ operator+=()

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

Add in vector rhs to this vector.

Exceptions
std::exceptionif rhs is a different size than this.

◆ operator-=()

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

Subtract in vector rhs to this vector.

Exceptions
std::exceptionif rhs is a different size than this.

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

Exceptions
std::exceptionif rhs is a different size than this.

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

Exceptions
std::exceptionif any rhs are a different size than this.

◆ ScaleAndAddToVector()

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

Adds a scaled version of this vector to Eigen vector vec.

Exceptions
std::exceptionif vec is the wrong size.

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

Reimplemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

◆ SetAtIndex()

void SetAtIndex ( int  index,
const T &  value 
)

Replaces the state at the given index with the value.

Exceptions
std::exceptionif 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::exceptionif 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.

Exceptions
std::exceptionif 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.

Reimplemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.

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

Implemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, BasicVector< drake::symbolic::Expression >, Subvector< T >, and Supervector< T >.

◆ ThrowMismatchedSize()

void ThrowMismatchedSize ( int  other_size) const
protected

◆ ThrowOutOfRange()

void ThrowOutOfRange ( int  index) const
protected

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