Drake
BasicVector< T > Class Template Reference

Detailed Description

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

BasicVector is a semantics-free wrapper around an Eigen vector that satisfies VectorBase.

Once constructed, its size is fixed.

Template Parameters
TThe vector element type, which must be a valid Eigen scalar.

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

Public Member Functions

 BasicVector ()
 Constructs an empty BasicVector. More...
 
 BasicVector (int size)
 Initializes with the given size using the drake::dummy_value<T>, which is NaN when T = double. More...
 
 BasicVector (VectorX< T > vec)
 Constructs a BasicVector with the specified vec data. More...
 
 BasicVector (const std::initializer_list< T > &init)
 Constructs a BasicVector whose elements are the elements of init. More...
 
int size () const final
 Returns the number of elements in the vector. More...
 
void set_value (const Eigen::Ref< const VectorX< T >> &value)
 Sets the vector to the given value. More...
 
Eigen::VectorBlock< const VectorX< T > > get_value () const
 Returns the entire vector as a const Eigen::VectorBlock. More...
 
Eigen::VectorBlock< VectorX< T > > get_mutable_value ()
 Returns the entire vector as a mutable Eigen::VectorBlock, which allows mutation of the values, but does not allow resizing the vector itself. More...
 
void SetFromVector (const Eigen::Ref< const VectorX< T >> &value) final
 Replaces the entire vector with the contents of value. More...
 
VectorX< T > CopyToVector () const final
 Copies this entire VectorBase into a contiguous Eigen Vector. More...
 
void ScaleAndAddToVector (const T &scale, EigenPtr< VectorX< T >> vec) const final
 Adds a scaled version of this vector to Eigen vector vec, which must be the same size. More...
 
void SetZero () final
 
std::unique_ptr< BasicVector< T > > Clone () const
 Copies the entire vector to a new BasicVector, with the same concrete implementation type. More...
 
Does not allow copy, move, or assignment
 BasicVector (const BasicVector &)=delete
 
BasicVectoroperator= (const BasicVector &)=delete
 
 BasicVector (BasicVector &&)=delete
 
BasicVectoroperator= (BasicVector &&)=delete
 
- Public Member Functions inherited from VectorBase< T >
virtual ~VectorBase ()
 
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 CopyToPreSizedVector (EigenPtr< VectorX< T >> vec) const
 Copies this entire VectorBase into a pre-sized Eigen Vector. 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...
 
 VectorBase (const VectorBase &)=delete
 
VectorBaseoperator= (const VectorBase &)=delete
 
 VectorBase (VectorBase &&)=delete
 
VectorBaseoperator= (VectorBase &&)=delete
 

Static Public Member Functions

static std::unique_ptr< BasicVector< T > > Make (const std::initializer_list< T > &init)
 Constructs a BasicVector whose elements are the elements of init. More...
 
template<typename... Fargs>
static std::unique_ptr< BasicVector< T > > Make (Fargs &&... args)
 Constructs a BasicVector where each element is constructed using the placewise-corresponding member of args as the sole constructor argument. More...
 

Protected Member Functions

const T & DoGetAtIndex (int index) const final
 Implementations should ensure this operation is O(1) and allocates no memory. More...
 
T & DoGetAtIndex (int index) final
 Implementations should ensure this operation is O(1) and allocates no memory. More...
 
virtual DRAKE_NODISCARD BasicVector< T > * DoClone () const
 Returns a new BasicVector containing a copy of the entire vector. More...
 
const VectorX< T > & values () const
 Provides const access to the element storage. More...
 
VectorX< T > & values ()
 Provides mutable access to the element storage. More...
 
- Protected Member Functions inherited from VectorBase< T >
 VectorBase ()
 

Static Protected Member Functions

template<typename F , typename... Fargs>
static void MakeRecursive (BasicVector< T > *data, int index, F constructor_arg, Fargs &&... recursive_args)
 Sets data at index to an object of type T, which must have a single-argument constructor invoked via constructor_arg, and then recursively invokes itself on the next index with recursive args. More...
 
template<typename F , typename... Fargs>
static void MakeRecursive (BasicVector< T > *data, int index, F constructor_arg)
 Base case for the MakeRecursive template recursion. More...
 

Constructor & Destructor Documentation

◆ BasicVector() [1/6]

BasicVector ( const BasicVector< T > &  )
delete

◆ BasicVector() [2/6]

BasicVector ( BasicVector< T > &&  )
delete

◆ BasicVector() [3/6]

BasicVector ( )
default

Constructs an empty BasicVector.

◆ BasicVector() [4/6]

BasicVector ( int  size)
explicit

Initializes with the given size using the drake::dummy_value<T>, which is NaN when T = double.

◆ BasicVector() [5/6]

BasicVector ( VectorX< T >  vec)
explicit

Constructs a BasicVector with the specified vec data.

◆ BasicVector() [6/6]

BasicVector ( const std::initializer_list< T > &  init)

Constructs a BasicVector whose elements are the elements of init.

Member Function Documentation

◆ Clone()

std::unique_ptr<BasicVector<T> > Clone ( ) const

Copies the entire vector to a new BasicVector, with the same concrete implementation type.

Uses the Non-Virtual Interface idiom because smart pointers do not have type covariance.

◆ CopyToVector()

VectorX<T> CopyToVector ( ) const
finalvirtual

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 from VectorBase< T >.

◆ DoClone()

virtual DRAKE_NODISCARD BasicVector<T>* DoClone ( ) const
protectedvirtual

Returns a new BasicVector containing a copy of the entire vector.

Caller must take ownership, and may rely on the NVI wrapper to initialize the clone elementwise.

Subclasses of BasicVector must override DoClone to return their covariant type.

Reimplemented in DepthSensorOutput< T >, PoseVector< T >, FrameVelocity< T >, GyroscopeOutput< T >, and AccelerometerOutput< T >.

◆ DoGetAtIndex() [1/2]

const T& DoGetAtIndex ( int  index) const
finalprotectedvirtual

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

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

Implements VectorBase< T >.

◆ DoGetAtIndex() [2/2]

T& DoGetAtIndex ( int  index)
finalprotectedvirtual

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

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

Implements VectorBase< T >.

◆ get_mutable_value()

Eigen::VectorBlock<VectorX<T> > get_mutable_value ( )

Returns the entire vector as a mutable Eigen::VectorBlock, which allows mutation of the values, but does not allow resizing the vector itself.

◆ get_value()

Eigen::VectorBlock<const VectorX<T> > get_value ( ) const

Returns the entire vector as a const Eigen::VectorBlock.

◆ Make() [1/2]

static std::unique_ptr<BasicVector<T> > Make ( const std::initializer_list< T > &  init)
static

Constructs a BasicVector whose elements are the elements of init.

◆ Make() [2/2]

static std::unique_ptr<BasicVector<T> > Make ( Fargs &&...  args)
static

Constructs a BasicVector where each element is constructed using the placewise-corresponding member of args as the sole constructor argument.

For instance: BasicVector<symbolic::Expression>::Make("x", "y", "z");

◆ MakeRecursive() [1/2]

static void MakeRecursive ( BasicVector< T > *  data,
int  index,
F  constructor_arg,
Fargs &&...  recursive_args 
)
staticprotected

Sets data at index to an object of type T, which must have a single-argument constructor invoked via constructor_arg, and then recursively invokes itself on the next index with recursive args.

Helper for BasicVector<T>::Make.

◆ MakeRecursive() [2/2]

static void MakeRecursive ( BasicVector< T > *  data,
int  index,
F  constructor_arg 
)
staticprotected

Base case for the MakeRecursive template recursion.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ ScaleAndAddToVector()

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

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.

Reimplemented from VectorBase< T >.

◆ set_value()

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

Sets the vector to the given value.

After a.set_value(b.get_value()), a must be identical to b.

Exceptions
std::out_of_rangeif the new value has different dimensions.

◆ SetFromVector()

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

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.

Reimplemented from VectorBase< T >.

◆ SetZero()

void SetZero ( )
finalvirtual

Reimplemented from VectorBase< T >.

◆ size()

int size ( ) const
finalvirtual

Returns the number of elements in the vector.

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

Implements VectorBase< T >.

◆ values() [1/2]

const VectorX<T>& values ( ) const
protected

Provides const access to the element storage.

◆ values() [2/2]

VectorX<T>& values ( )
protected

Provides mutable access to the element storage.


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