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.
T | The 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... | |
VectorBase & | PlusEqScaled (const T &scale, const VectorBase< T > &rhs) |
Add in scaled vector rhs to this vector. More... | |
VectorBase & | PlusEqScaled (const std::initializer_list< std::pair< T, const VectorBase< T > & >> &rhs_scale) |
Add in multiple scaled vectors to this vector. More... | |
VectorBase & | operator+= (const VectorBase< T > &rhs) |
Add in vector rhs to this vector. More... | |
VectorBase & | operator-= (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 | |
VectorBase & | operator= (const VectorBase &)=delete |
VectorBase (VectorBase &&)=delete | |
VectorBase & | operator= (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 |
|
delete |
|
delete |
|
virtual |
|
protected |
Copies this entire VectorBase into a pre-sized Eigen Vector.
Implementations should ensure this operation is O(N) in the size of the value.
std::exception | if vec is the wrong size. |
|
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 >.
|
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 >.
|
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 >.
|
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 >.
|
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 >.
|
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.
const T& GetAtIndex | ( | int | index | ) | const |
Returns the element at the given index in the vector.
std::exception | if the index is >= size() or negative. Consider operator[]() instead if bounds-checking is unwanted. |
T& GetAtIndex | ( | int | index | ) |
Returns the element at the given index in the vector.
std::exception | if the index is >= size() or negative. Consider operator[]() instead if bounds-checking is unwanted. |
|
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.
Reimplemented in AcrobotParams< T >, CompassGaitParams< T >, BeamModelParams< T >, RimlessWheelParams< T >, SpongControllerParams< T >, ClothSpringModelParams< T >, CartPoleParams< T >, and PendulumParams< T >.
VectorBase& operator+= | ( | const VectorBase< T > & | rhs | ) |
Add in vector rhs
to this vector.
std::exception | if rhs is a different size than this. |
VectorBase& operator-= | ( | const VectorBase< T > & | rhs | ) |
Subtract in vector rhs
to this vector.
std::exception | if rhs is a different size than this. |
|
delete |
|
delete |
T& operator[] | ( | int | index | ) |
Returns the element at the given index in the vector.
index
< size() const T& operator[] | ( | int | index | ) | const |
Returns the element at the given index in the vector.
index
< size() VectorBase& PlusEqScaled | ( | const T & | scale, |
const VectorBase< T > & | rhs | ||
) |
Add in scaled vector rhs
to this vector.
std::exception | if rhs is a different size than this. |
VectorBase& PlusEqScaled | ( | const std::initializer_list< std::pair< T, const VectorBase< T > & >> & | rhs_scale | ) |
Add in multiple scaled vectors to this vector.
std::exception | if any rhs are a different size than this. |
Adds a scaled version of this vector to Eigen vector vec
.
std::exception | if 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 >.
void SetAtIndex | ( | int | index, |
const T & | value | ||
) |
Replaces the state at the given index with the value.
std::exception | if the index is >= size(). Consider operator[]() instead if bounds-checking is unwanted. |
|
virtual |
Replaces the entire vector with the contents of value
.
std::exception | 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.
|
virtual |
Replaces the entire vector with the contents of value
.
std::exception | 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.
Reimplemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.
|
virtual |
Sets all elements of this vector to zero.
Reimplemented in BasicVector< T >, BasicVector< Element::T >, BasicVector< double >, BasicVector< AutoDiffXd >, and BasicVector< drake::symbolic::Expression >.
|
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 >.
|
protected |
|
protected |