Sleipnir C++ API
Loading...
Searching...
No Matches
slp::VariableMatrix Class Reference

#include <sleipnir/autodiff/variable_matrix.hpp>

Classes

struct  empty_t
 

Public Member Functions

 VariableMatrix ()=default
 
 VariableMatrix (int rows)
 
 VariableMatrix (int rows, int cols)
 
 VariableMatrix (empty_t, int rows, int cols)
 
 VariableMatrix (std::initializer_list< std::initializer_list< Variable > > list)
 
 VariableMatrix (const std::vector< std::vector< double > > &list)
 
 VariableMatrix (const std::vector< std::vector< Variable > > &list)
 
template<typename Derived >
 VariableMatrix (const Eigen::MatrixBase< Derived > &values)
 
template<typename Derived >
 VariableMatrix (const Eigen::DiagonalBase< Derived > &values)
 
template<typename Derived >
VariableMatrixoperator= (const Eigen::MatrixBase< Derived > &values)
 
VariableMatrixoperator= (ScalarLike auto value)
 
template<typename Derived >
requires std::same_as<typename Derived::Scalar, double>
void set_value (const Eigen::MatrixBase< Derived > &values)
 
 VariableMatrix (const Variable &variable)
 
 VariableMatrix (Variable &&variable)
 
 VariableMatrix (const VariableBlock< VariableMatrix > &values)
 
 VariableMatrix (const VariableBlock< const VariableMatrix > &values)
 
 VariableMatrix (std::span< const Variable > values)
 
 VariableMatrix (std::span< const Variable > values, int rows, int cols)
 
Variableoperator() (int row, int col)
 
const Variableoperator() (int row, int col) const
 
Variableoperator[] (int row)
 
const Variableoperator[] (int row) const
 
VariableBlock< VariableMatrixblock (int row_offset, int col_offset, int block_rows, int block_cols)
 
const VariableBlock< const VariableMatrixblock (int row_offset, int col_offset, int block_rows, int block_cols) const
 
VariableBlock< VariableMatrixoperator() (Slice row_slice, Slice col_slice)
 
const VariableBlock< const VariableMatrixoperator() (Slice row_slice, Slice col_slice) const
 
VariableBlock< VariableMatrixoperator() (Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length)
 
const VariableBlock< const VariableMatrixoperator() (Slice row_slice, int row_slice_length, Slice col_slice, int col_slice_length) const
 
VariableBlock< VariableMatrixsegment (int offset, int length)
 
const VariableBlock< const VariableMatrixsegment (int offset, int length) const
 
VariableBlock< VariableMatrixrow (int row)
 
const VariableBlock< const VariableMatrixrow (int row) const
 
VariableBlock< VariableMatrixcol (int col)
 
const VariableBlock< const VariableMatrixcol (int col) const
 
VariableMatrixoperator*= (const MatrixLike auto &rhs)
 
VariableMatrixoperator*= (const ScalarLike auto &rhs)
 
VariableMatrixoperator/= (const ScalarLike auto &rhs)
 
VariableMatrixoperator+= (const MatrixLike auto &rhs)
 
VariableMatrixoperator+= (const ScalarLike auto &rhs)
 
VariableMatrixoperator-= (const MatrixLike auto &rhs)
 
VariableMatrixoperator-= (const ScalarLike auto &rhs)
 
 operator Variable () const
 
VariableMatrix T () const
 
int rows () const
 
int cols () const
 
double value (int row, int col)
 
double value (int index)
 
Eigen::MatrixXd value ()
 
VariableMatrix cwise_transform (function_ref< Variable(const Variable &x)> unary_op) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
size_t size () const
 

Static Public Member Functions

static VariableMatrix zero (int rows, int cols)
 
static VariableMatrix ones (int rows, int cols)
 

Static Public Attributes

static constexpr empty_t empty {}
 

Friends

template<MatrixLike LHS, MatrixLike RHS>
requires SleipnirMatrixLike<LHS> || SleipnirMatrixLike<RHS>
SLEIPNIR_DLLEXPORT VariableMatrix operator* (const LHS &lhs, const RHS &rhs)
 
SLEIPNIR_DLLEXPORT VariableMatrix operator* (const SleipnirMatrixLike auto &lhs, const ScalarLike auto &rhs)
 
SLEIPNIR_DLLEXPORT VariableMatrix operator* (const MatrixLike auto &lhs, const Variable &rhs)
 
SLEIPNIR_DLLEXPORT VariableMatrix operator* (const ScalarLike auto &lhs, const SleipnirMatrixLike auto &rhs)
 
SLEIPNIR_DLLEXPORT VariableMatrix operator* (const Variable &lhs, const MatrixLike auto &rhs)
 
SLEIPNIR_DLLEXPORT VariableMatrix operator/ (const MatrixLike auto &lhs, const ScalarLike auto &rhs)
 
template<MatrixLike LHS, MatrixLike RHS>
requires SleipnirMatrixLike<LHS> || SleipnirMatrixLike<RHS>
SLEIPNIR_DLLEXPORT VariableMatrix operator+ (const LHS &lhs, const RHS &rhs)
 
template<MatrixLike LHS, MatrixLike RHS>
requires SleipnirMatrixLike<LHS> || SleipnirMatrixLike<RHS>
SLEIPNIR_DLLEXPORT VariableMatrix operator- (const LHS &lhs, const RHS &rhs)
 
SLEIPNIR_DLLEXPORT VariableMatrix operator- (const SleipnirMatrixLike auto &lhs)
 

Detailed Description

A matrix of autodiff variables.

Constructor & Destructor Documentation

◆ VariableMatrix() [1/15]

slp::VariableMatrix::VariableMatrix ( )
default

Constructs an empty VariableMatrix.

◆ VariableMatrix() [2/15]

slp::VariableMatrix::VariableMatrix ( int  rows)
inlineexplicit

Constructs a VariableMatrix column vector with the given rows.

Parameters
rowsThe number of matrix rows.

◆ VariableMatrix() [3/15]

slp::VariableMatrix::VariableMatrix ( int  rows,
int  cols 
)
inline

Constructs a zero-initialized VariableMatrix with the given dimensions.

Parameters
rowsThe number of matrix rows.
colsThe number of matrix columns.

◆ VariableMatrix() [4/15]

slp::VariableMatrix::VariableMatrix ( empty_t  ,
int  rows,
int  cols 
)
inline

Constructs an empty VariableMatrix with the given dimensions.

Parameters
rowsThe number of matrix rows.
colsThe number of matrix columns.

◆ VariableMatrix() [5/15]

slp::VariableMatrix::VariableMatrix ( std::initializer_list< std::initializer_list< Variable > >  list)
inline

Constructs a scalar VariableMatrix from a nested list of Variables.

Parameters
listThe nested list of Variables.

◆ VariableMatrix() [6/15]

slp::VariableMatrix::VariableMatrix ( const std::vector< std::vector< double > > &  list)
inline

Constructs a scalar VariableMatrix from a nested list of doubles.

This overload is for Python bindings only.

Parameters
listThe nested list of Variables.

◆ VariableMatrix() [7/15]

slp::VariableMatrix::VariableMatrix ( const std::vector< std::vector< Variable > > &  list)
inline

Constructs a scalar VariableMatrix from a nested list of Variables.

This overload is for Python bindings only.

Parameters
listThe nested list of Variables.

◆ VariableMatrix() [8/15]

template<typename Derived >
slp::VariableMatrix::VariableMatrix ( const Eigen::MatrixBase< Derived > &  values)
inline

Constructs a VariableMatrix from an Eigen matrix.

Parameters
valuesEigen matrix of values.

◆ VariableMatrix() [9/15]

template<typename Derived >
slp::VariableMatrix::VariableMatrix ( const Eigen::DiagonalBase< Derived > &  values)
inline

Constructs a VariableMatrix from an Eigen diagonal matrix.

Parameters
valuesDiagonal matrix of values.

◆ VariableMatrix() [10/15]

slp::VariableMatrix::VariableMatrix ( const Variable variable)
inline

Constructs a scalar VariableMatrix from a Variable.

Parameters
variableVariable.

◆ VariableMatrix() [11/15]

slp::VariableMatrix::VariableMatrix ( Variable &&  variable)
inline

Constructs a scalar VariableMatrix from a Variable.

Parameters
variableVariable.

◆ VariableMatrix() [12/15]

slp::VariableMatrix::VariableMatrix ( const VariableBlock< VariableMatrix > &  values)
inline

Constructs a VariableMatrix from a VariableBlock.

Parameters
valuesVariableBlock of values.

◆ VariableMatrix() [13/15]

slp::VariableMatrix::VariableMatrix ( const VariableBlock< const VariableMatrix > &  values)
inline

Constructs a VariableMatrix from a VariableBlock.

Parameters
valuesVariableBlock of values.

◆ VariableMatrix() [14/15]

slp::VariableMatrix::VariableMatrix ( std::span< const Variable values)
inlineexplicit

Constructs a column vector wrapper around a Variable array.

Parameters
valuesVariable array to wrap.

◆ VariableMatrix() [15/15]

slp::VariableMatrix::VariableMatrix ( std::span< const Variable values,
int  rows,
int  cols 
)
inline

Constructs a matrix wrapper around a Variable array.

Parameters
valuesVariable array to wrap.
rowsThe number of matrix rows.
colsThe number of matrix columns.

Member Function Documentation

◆ begin() [1/2]

iterator slp::VariableMatrix::begin ( )
inline

Returns begin iterator.

Returns
Begin iterator.

◆ begin() [2/2]

const_iterator slp::VariableMatrix::begin ( ) const
inline

Returns begin iterator.

Returns
Begin iterator.

◆ block() [1/2]

VariableBlock< VariableMatrix > slp::VariableMatrix::block ( int  row_offset,
int  col_offset,
int  block_rows,
int  block_cols 
)
inline

Returns a block of the variable matrix.

Parameters
row_offsetThe row offset of the block selection.
col_offsetThe column offset of the block selection.
block_rowsThe number of rows in the block selection.
block_colsThe number of columns in the block selection.
Returns
A block of the variable matrix.

◆ block() [2/2]

const VariableBlock< const VariableMatrix > slp::VariableMatrix::block ( int  row_offset,
int  col_offset,
int  block_rows,
int  block_cols 
) const
inline

Returns a block of the variable matrix.

Parameters
row_offsetThe row offset of the block selection.
col_offsetThe column offset of the block selection.
block_rowsThe number of rows in the block selection.
block_colsThe number of columns in the block selection.
Returns
A block of the variable matrix.

◆ cbegin()

const_iterator slp::VariableMatrix::cbegin ( ) const
inline

Returns begin iterator.

Returns
Begin iterator.

◆ cend()

const_iterator slp::VariableMatrix::cend ( ) const
inline

Returns end iterator.

Returns
End iterator.

◆ col() [1/2]

VariableBlock< VariableMatrix > slp::VariableMatrix::col ( int  col)
inline

Returns a column slice of the variable matrix.

Parameters
colThe column to slice.
Returns
A column slice of the variable matrix.

◆ col() [2/2]

const VariableBlock< const VariableMatrix > slp::VariableMatrix::col ( int  col) const
inline

Returns a column slice of the variable matrix.

Parameters
colThe column to slice.
Returns
A column slice of the variable matrix.

◆ cols()

int slp::VariableMatrix::cols ( ) const
inline

Returns the number of columns in the matrix.

Returns
The number of columns in the matrix.

◆ cwise_transform()

VariableMatrix slp::VariableMatrix::cwise_transform ( function_ref< Variable(const Variable &x)>  unary_op) const
inline

Transforms the matrix coefficient-wise with an unary operator.

Parameters
unary_opThe unary operator to use for the transform operation.
Returns
Result of the unary operator.

◆ end() [1/2]

iterator slp::VariableMatrix::end ( )
inline

Returns end iterator.

Returns
End iterator.

◆ end() [2/2]

const_iterator slp::VariableMatrix::end ( ) const
inline

Returns end iterator.

Returns
End iterator.

◆ ones()

static VariableMatrix slp::VariableMatrix::ones ( int  rows,
int  cols 
)
inlinestatic

Returns a variable matrix filled with ones.

Parameters
rowsThe number of matrix rows.
colsThe number of matrix columns.
Returns
A variable matrix filled with ones.

◆ operator Variable()

slp::VariableMatrix::operator Variable ( ) const
inline

Implicit conversion operator from 1x1 VariableMatrix to Variable.

◆ operator()() [1/6]

Variable & slp::VariableMatrix::operator() ( int  row,
int  col 
)
inline

Returns a block pointing to the given row and column.

Parameters
rowThe block row.
colThe block column.
Returns
A block pointing to the given row and column.

◆ operator()() [2/6]

const Variable & slp::VariableMatrix::operator() ( int  row,
int  col 
) const
inline

Returns a block pointing to the given row and column.

Parameters
rowThe block row.
colThe block column.
Returns
A block pointing to the given row and column.

◆ operator()() [3/6]

VariableBlock< VariableMatrix > slp::VariableMatrix::operator() ( Slice  row_slice,
int  row_slice_length,
Slice  col_slice,
int  col_slice_length 
)
inline

Returns a slice of the variable matrix.

The given slices aren't adjusted. This overload is for Python bindings only.

Parameters
row_sliceThe row slice.
row_slice_lengthThe row slice length.
col_sliceThe column slice.
col_slice_lengthThe column slice length.
Returns
A slice of the variable matrix.

◆ operator()() [4/6]

const VariableBlock< const VariableMatrix > slp::VariableMatrix::operator() ( Slice  row_slice,
int  row_slice_length,
Slice  col_slice,
int  col_slice_length 
) const
inline

Returns a slice of the variable matrix.

The given slices aren't adjusted. This overload is for Python bindings only.

Parameters
row_sliceThe row slice.
row_slice_lengthThe row slice length.
col_sliceThe column slice.
col_slice_lengthThe column slice length.
Returns
A slice of the variable matrix.

◆ operator()() [5/6]

VariableBlock< VariableMatrix > slp::VariableMatrix::operator() ( Slice  row_slice,
Slice  col_slice 
)
inline

Returns a slice of the variable matrix.

Parameters
row_sliceThe row slice.
col_sliceThe column slice.
Returns
A slice of the variable matrix.

◆ operator()() [6/6]

const VariableBlock< const VariableMatrix > slp::VariableMatrix::operator() ( Slice  row_slice,
Slice  col_slice 
) const
inline

Returns a slice of the variable matrix.

Parameters
row_sliceThe row slice.
col_sliceThe column slice.
Returns
A slice of the variable matrix.

◆ operator*=() [1/2]

VariableMatrix & slp::VariableMatrix::operator*= ( const MatrixLike auto &  rhs)
inline

Compound matrix multiplication-assignment operator.

Parameters
rhsVariable to multiply.
Returns
Result of multiplication.

◆ operator*=() [2/2]

VariableMatrix & slp::VariableMatrix::operator*= ( const ScalarLike auto &  rhs)
inline

Compound matrix-scalar multiplication-assignment operator.

Parameters
rhsVariable to multiply.
Returns
Result of multiplication.

◆ operator+=() [1/2]

VariableMatrix & slp::VariableMatrix::operator+= ( const MatrixLike auto &  rhs)
inline

Compound addition-assignment operator.

Parameters
rhsVariable to add.
Returns
Result of addition.

◆ operator+=() [2/2]

VariableMatrix & slp::VariableMatrix::operator+= ( const ScalarLike auto &  rhs)
inline

Compound addition-assignment operator.

Parameters
rhsVariable to add.
Returns
Result of addition.

◆ operator-=() [1/2]

VariableMatrix & slp::VariableMatrix::operator-= ( const MatrixLike auto &  rhs)
inline

Compound subtraction-assignment operator.

Parameters
rhsVariable to subtract.
Returns
Result of subtraction.

◆ operator-=() [2/2]

VariableMatrix & slp::VariableMatrix::operator-= ( const ScalarLike auto &  rhs)
inline

Compound subtraction-assignment operator.

Parameters
rhsVariable to subtract.
Returns
Result of subtraction.

◆ operator/=()

VariableMatrix & slp::VariableMatrix::operator/= ( const ScalarLike auto &  rhs)
inline

Compound matrix division-assignment operator.

Parameters
rhsVariable to divide.
Returns
Result of division.

◆ operator=() [1/2]

template<typename Derived >
VariableMatrix & slp::VariableMatrix::operator= ( const Eigen::MatrixBase< Derived > &  values)
inline

Assigns an Eigen matrix to a VariableMatrix.

Parameters
valuesEigen matrix of values.
Returns
This VariableMatrix.

◆ operator=() [2/2]

VariableMatrix & slp::VariableMatrix::operator= ( ScalarLike auto  value)
inline

Assigns a double to the matrix.

This only works for matrices with one row and one column.

Parameters
valueValue to assign.
Returns
This VariableMatrix.

◆ operator[]() [1/2]

Variable & slp::VariableMatrix::operator[] ( int  row)
inline

Returns a block pointing to the given row.

Parameters
rowThe block row.
Returns
A block pointing to the given row.

◆ operator[]() [2/2]

const Variable & slp::VariableMatrix::operator[] ( int  row) const
inline

Returns a block pointing to the given row.

Parameters
rowThe block row.
Returns
A block pointing to the given row.

◆ row() [1/2]

VariableBlock< VariableMatrix > slp::VariableMatrix::row ( int  row)
inline

Returns a row slice of the variable matrix.

Parameters
rowThe row to slice.
Returns
A row slice of the variable matrix.

◆ row() [2/2]

const VariableBlock< const VariableMatrix > slp::VariableMatrix::row ( int  row) const
inline

Returns a row slice of the variable matrix.

Parameters
rowThe row to slice.
Returns
A row slice of the variable matrix.

◆ rows()

int slp::VariableMatrix::rows ( ) const
inline

Returns the number of rows in the matrix.

Returns
The number of rows in the matrix.

◆ segment() [1/2]

VariableBlock< VariableMatrix > slp::VariableMatrix::segment ( int  offset,
int  length 
)
inline

Returns a segment of the variable vector.

Parameters
offsetThe offset of the segment.
lengthThe length of the segment.
Returns
A segment of the variable vector.

◆ segment() [2/2]

const VariableBlock< const VariableMatrix > slp::VariableMatrix::segment ( int  offset,
int  length 
) const
inline

Returns a segment of the variable vector.

Parameters
offsetThe offset of the segment.
lengthThe length of the segment.
Returns
A segment of the variable vector.

◆ set_value()

template<typename Derived >
requires std::same_as<typename Derived::Scalar, double>
void slp::VariableMatrix::set_value ( const Eigen::MatrixBase< Derived > &  values)
inline

Sets the VariableMatrix's internal values.

Parameters
valuesEigen matrix of values.

◆ size()

size_t slp::VariableMatrix::size ( ) const
inline

Returns number of elements in matrix.

Returns
Number of elements in matrix.

◆ T()

VariableMatrix slp::VariableMatrix::T ( ) const
inline

Returns the transpose of the variable matrix.

Returns
The transpose of the variable matrix.

◆ value() [1/3]

Eigen::MatrixXd slp::VariableMatrix::value ( )
inline

Returns the contents of the variable matrix.

Returns
The contents of the variable matrix.

◆ value() [2/3]

double slp::VariableMatrix::value ( int  index)
inline

Returns a row of the variable column vector.

Parameters
indexThe index of the element to return.
Returns
A row of the variable column vector.

◆ value() [3/3]

double slp::VariableMatrix::value ( int  row,
int  col 
)
inline

Returns an element of the variable matrix.

Parameters
rowThe row of the element to return.
colThe column of the element to return.
Returns
An element of the variable matrix.

◆ zero()

static VariableMatrix slp::VariableMatrix::zero ( int  rows,
int  cols 
)
inlinestatic

Returns a variable matrix filled with zeroes.

Parameters
rowsThe number of matrix rows.
colsThe number of matrix columns.
Returns
A variable matrix filled with zeroes.

Friends And Related Symbol Documentation

◆ operator* [1/5]

template<MatrixLike LHS, MatrixLike RHS>
requires SleipnirMatrixLike<LHS> || SleipnirMatrixLike<RHS>
SLEIPNIR_DLLEXPORT VariableMatrix operator* ( const LHS &  lhs,
const RHS &  rhs 
)
friend

Matrix multiplication operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator* [2/5]

SLEIPNIR_DLLEXPORT VariableMatrix operator* ( const MatrixLike auto &  lhs,
const Variable rhs 
)
friend

Matrix-scalar multiplication operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator* [3/5]

SLEIPNIR_DLLEXPORT VariableMatrix operator* ( const ScalarLike auto &  lhs,
const SleipnirMatrixLike auto &  rhs 
)
friend

Scalar-matrix multiplication operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator* [4/5]

SLEIPNIR_DLLEXPORT VariableMatrix operator* ( const SleipnirMatrixLike auto &  lhs,
const ScalarLike auto &  rhs 
)
friend

Matrix-scalar multiplication operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator* [5/5]

SLEIPNIR_DLLEXPORT VariableMatrix operator* ( const Variable lhs,
const MatrixLike auto &  rhs 
)
friend

Scalar-matrix multiplication operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.

◆ operator+

template<MatrixLike LHS, MatrixLike RHS>
requires SleipnirMatrixLike<LHS> || SleipnirMatrixLike<RHS>
SLEIPNIR_DLLEXPORT VariableMatrix operator+ ( const LHS &  lhs,
const RHS &  rhs 
)
friend

Binary addition operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.
Returns
Result of addition.

◆ operator- [1/2]

template<MatrixLike LHS, MatrixLike RHS>
requires SleipnirMatrixLike<LHS> || SleipnirMatrixLike<RHS>
SLEIPNIR_DLLEXPORT VariableMatrix operator- ( const LHS &  lhs,
const RHS &  rhs 
)
friend

Binary subtraction operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.
Returns
Result of subtraction.

◆ operator- [2/2]

SLEIPNIR_DLLEXPORT VariableMatrix operator- ( const SleipnirMatrixLike auto &  lhs)
friend

Unary minus operator.

Parameters
lhsOperand for unary minus.

◆ operator/

SLEIPNIR_DLLEXPORT VariableMatrix operator/ ( const MatrixLike auto &  lhs,
const ScalarLike auto &  rhs 
)
friend

Binary division operator.

Parameters
lhsOperator left-hand side.
rhsOperator right-hand side.
Returns
Result of division.

Member Data Documentation

◆ empty

constexpr empty_t slp::VariableMatrix::empty {}
staticconstexpr

Designates an uninitialized VariableMatrix.


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