wuzp
Wrong Unit? Zero Points! Compile-time checks for units, coordinate systems and points vs. vectors.
Loading...
Searching...
No Matches
wuzp::Quantities< ValuesT_, UnitsT_ > Class Template Reference

Container to store quantities. More...

#include <wuzp/core/Quantities.hpp>

Public Types

using ValuesT = ValuesT_
using UnitsT = UnitsT_
using ValueT = typename ValuesT::ValueT
using ThisT = Quantities<ValuesT, UnitsT>

Public Member Functions

 Quantities ()=default
template<typename T0, typename... Ts>
requires (!IsSpecialization<T0, Tag>::value && !CopiesOrMoves<Quantities, T0, Ts...>)
 explicit (!IsValidConversion< ThisT, std::remove_cvref_t< T0 >, std::remove_cvref_t< Ts >... >::value) Quantities(T0 &&t0
Ts Ts std::forward (t0)
Ts Ts std::forward (ts)...)
auto get () const
template<int RowIdV_, int ColIdV_>
auto get () const
template<int IdV_>
requires (Dimension<ThisT>::value <= 1)
auto get () const
 The quantity with the single index IdV_ of quantities of dimension 0 or 1: the row of a column, e.g. of a vector, the column of a row, e.g. of a covector, or 0 for a 1x1 matrix (see internal::vectorElementRowId()).
auto get (const int rowId, const int colId) const
auto get (const int id) const
 The quantity with the single index id of quantities of dimension 0 or 1, like get<IdV_>(), but with an index known at run time, which, like get(rowId, colId), requires all elements to have the same unit.
template<typename ValueT_, typename UnitT_>
requires (Dimension<ThisT>::value == 0)
void set (const Quantity< ValueT_, UnitT_ > &quantity)
template<int RowIdV_, int ColIdV_, typename ValueT_, typename UnitT_>
void set (const Quantity< ValueT_, UnitT_ > &quantity)
template<int IdV_, typename ValueT_, typename UnitT_>
requires (Dimension<ThisT>::value <= 1)
void set (const Quantity< ValueT_, UnitT_ > &quantity)
 Sets the quantity with the single index IdV_ of quantities of dimension 0 or 1 (see get<IdV_>()), like set<RowIdV_, ColIdV_>(), which checks the index and the unit at compile time.
template<typename ValueT_, typename UnitT_>
void set (const int rowId, const int colId, const Quantity< ValueT_, UnitT_ > &quantity)
template<typename ValueT_, typename UnitT_>
requires (Dimension<ThisT>::value <= 1)
void set (const int id, const Quantity< ValueT_, UnitT_ > &quantity)
 Sets the quantity with the single index id of quantities of dimension 0 or 1, like set<IdV_>(), but with an index known at run time, which, like set(rowId, colId, quantity), requires all elements to have the same unit.
template<typename ValuesOtherT_>
void setValues (const ValuesOtherT_ &values)
 Set the values of the quantities.
template<typename ValueOtherT_>
requires (Dimension<ThisT>::value == 0)
void setValue (ValueOtherT_ value)
 Sets the value of a quantity.
const ValuesT & getValues () const &
 Get the values of the quantities.
ValuesT getValues () &&
 The values of a temporary are moved out of it, which avoids a copy and does not refer to the destroyed temporary.
ValueT getValue () const
template<typename ValuesOtherT_, typename UnitsOtherT_>
bool isApprox (const Quantities< ValuesOtherT_, UnitsOtherT_ > &other, const ValueT precision=Precision< ValueT >::value()) const
template<int BlockRowIdV_, int BlockColIdV_, int BlockRowsV_, int BlockColsV_>
auto block () const
auto transpose () const
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto innerProduct (const Quantities< ValuesOtherT_, UnitsOtherT_ > &other) const
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto outerProduct (const Quantities< ValuesOtherT_, UnitsOtherT_ > &other) const
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto dotProduct (const Quantities< ValuesOtherT_, UnitsOtherT_ > &other) const
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto crossProduct (const Quantities< ValuesOtherT_, UnitsOtherT_ > &other) const
auto inverse () const
 The matrix inverse of a square matrix, whose units must describe a linear map, M_ij = a_i / b_j: the units of the inverse are (M^-1)_ij = b_i / a_j (see Inverse<TypeMatrixImpl<...>> in Units.hpp).
auto pseudoInverse () const
 The Moore-Penrose pseudo-inverse A^+ of a matrix A of full rank: A^T (A A^T)^-1 if it has fewer rows than columns, i.e. full row rank, e.g. the joint velocities q' = J^+ x' of the smallest norm for a redundant robot, (A^T A)^-1 A^T if it has more, i.e. full column rank, the least squares solution, and the inverse A^-1 if it is square.
auto cwiseInverse () const
 The elementwise reciprocal, whose units are the reciprocals of the units.
auto norm () const
auto squaredNorm () const
auto determinant () const
 Get the determinant of a square matrix, including a 1x1 matrix, whose units must describe a linear map.
auto evaluate () const &
auto evaluate () &&

Static Public Member Functions

static ThisT zero ()
static ThisT random ()

Public Attributes

Ts && ts: Quantities(typename GetTag<ThisT
Ts T0

Detailed Description

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
class wuzp::Quantities< ValuesT_, UnitsT_ >

Container to store quantities.

Every quantity consists of a value and a unit. The values are evaluated at run-time, the units at compile-time.

Template Parameters
ValuesT_Container type to store the values (e.g. a scalar, vector, matrix, etc.).
UnitsT_Container storing the units (e.g. a scalar, vector, matrix, etc.).

Definition at line 42 of file Quantities.hpp.

Member Typedef Documentation

◆ ThisT

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
using wuzp::Quantities< ValuesT_, UnitsT_ >::ThisT = Quantities<ValuesT, UnitsT>

Definition at line 47 of file Quantities.hpp.

◆ UnitsT

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
using wuzp::Quantities< ValuesT_, UnitsT_ >::UnitsT = UnitsT_

Definition at line 45 of file Quantities.hpp.

◆ ValuesT

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
using wuzp::Quantities< ValuesT_, UnitsT_ >::ValuesT = ValuesT_

Definition at line 44 of file Quantities.hpp.

◆ ValueT

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
using wuzp::Quantities< ValuesT_, UnitsT_ >::ValueT = typename ValuesT::ValueT

Definition at line 46 of file Quantities.hpp.

Constructor & Destructor Documentation

◆ Quantities()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
wuzp::Quantities< ValuesT_, UnitsT_ >::Quantities ( )
default

Member Function Documentation

◆ block()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<int BlockRowIdV_, int BlockColIdV_, int BlockRowsV_, int BlockColsV_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::block ( ) const
inline

Definition at line 180 of file Quantities.hpp.

◆ crossProduct()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::crossProduct ( const Quantities< ValuesOtherT_, UnitsOtherT_ > & other) const
inline

Definition at line 206 of file Quantities.hpp.

◆ cwiseInverse()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::cwiseInverse ( ) const
inline

The elementwise reciprocal, whose units are the reciprocals of the units.

Definition at line 238 of file Quantities.hpp.

◆ determinant()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::determinant ( ) const
inline

Get the determinant of a square matrix, including a 1x1 matrix, whose units must describe a linear map.

Its unit is the product of the units on the diagonal, e.g. u^n for a matrix with a single unit u (see Determinant<TypeMatrixImpl<...>>).

Definition at line 246 of file Quantities.hpp.

◆ dotProduct()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::dotProduct ( const Quantities< ValuesOtherT_, UnitsOtherT_ > & other) const
inline

Definition at line 200 of file Quantities.hpp.

◆ evaluate() [1/2]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::evaluate ( ) &&
inline

Definition at line 253 of file Quantities.hpp.

◆ evaluate() [2/2]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::evaluate ( ) const &
inline

Definition at line 252 of file Quantities.hpp.

◆ explicit()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename T0, typename... Ts>
requires (!IsSpecialization<T0, Tag>::value && !CopiesOrMoves<Quantities, T0, Ts...>)
wuzp::Quantities< ValuesT_, UnitsT_ >::explicit ( !IsValidConversion< ThisT, std::remove_cvref_t< T0 >, std::remove_cvref_t< Ts >... >::value ) &&

◆ get() [1/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<int IdV_>
requires (Dimension<ThisT>::value <= 1)
auto wuzp::Quantities< ValuesT_, UnitsT_ >::get ( ) const
inline

The quantity with the single index IdV_ of quantities of dimension 0 or 1: the row of a column, e.g. of a vector, the column of a row, e.g. of a covector, or 0 for a 1x1 matrix (see internal::vectorElementRowId()).

Like get<RowIdV_, ColIdV_>(), it checks the index at compile time and has the unit of the element.

Definition at line 79 of file Quantities.hpp.

◆ get() [2/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<int RowIdV_, int ColIdV_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::get ( ) const
inline

Definition at line 71 of file Quantities.hpp.

◆ get() [3/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::get ( ) const
inline

Definition at line 64 of file Quantities.hpp.

◆ get() [4/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::get ( const int id) const
inline

The quantity with the single index id of quantities of dimension 0 or 1, like get<IdV_>(), but with an index known at run time, which, like get(rowId, colId), requires all elements to have the same unit.

Definition at line 89 of file Quantities.hpp.

◆ get() [5/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::get ( const int rowId,
const int colId ) const
inline

Definition at line 85 of file Quantities.hpp.

◆ getValue()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
ValueT wuzp::Quantities< ValuesT_, UnitsT_ >::getValue ( ) const
inline

Definition at line 164 of file Quantities.hpp.

◆ getValues() [1/2]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
ValuesT wuzp::Quantities< ValuesT_, UnitsT_ >::getValues ( ) &&
inline

The values of a temporary are moved out of it, which avoids a copy and does not refer to the destroyed temporary.

Definition at line 162 of file Quantities.hpp.

◆ getValues() [2/2]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
const ValuesT & wuzp::Quantities< ValuesT_, UnitsT_ >::getValues ( ) const &
inline

Get the values of the quantities.

WARNING: This method circumvents quantity type safety. This method is provided even if the dimension is 0, to ensure all quantities have the same interface in templated functions.

Returns
ValueMatrix of the quantities.

Definition at line 160 of file Quantities.hpp.

◆ innerProduct()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::innerProduct ( const Quantities< ValuesOtherT_, UnitsOtherT_ > & other) const
inline

Definition at line 188 of file Quantities.hpp.

◆ inverse()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::inverse ( ) const
inline

The matrix inverse of a square matrix, whose units must describe a linear map, M_ij = a_i / b_j: the units of the inverse are (M^-1)_ij = b_i / a_j (see Inverse<TypeMatrixImpl<...>> in Units.hpp).

Definition at line 213 of file Quantities.hpp.

◆ isApprox()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValuesOtherT_, typename UnitsOtherT_>
bool wuzp::Quantities< ValuesT_, UnitsT_ >::isApprox ( const Quantities< ValuesOtherT_, UnitsOtherT_ > & other,
const ValueT precision = Precision<ValueT>::value() ) const
inline

Definition at line 171 of file Quantities.hpp.

◆ norm()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::norm ( ) const
inline

Definition at line 240 of file Quantities.hpp.

◆ outerProduct()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValuesOtherT_, typename UnitsOtherT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::outerProduct ( const Quantities< ValuesOtherT_, UnitsOtherT_ > & other) const
inline

Definition at line 194 of file Quantities.hpp.

◆ pseudoInverse()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::pseudoInverse ( ) const
inline

The Moore-Penrose pseudo-inverse A^+ of a matrix A of full rank: A^T (A A^T)^-1 if it has fewer rows than columns, i.e. full row rank, e.g. the joint velocities q' = J^+ x' of the smallest norm for a redundant robot, (A^T A)^-1 A^T if it has more, i.e. full column rank, the least squares solution, and the inverse A^-1 if it is square.

Its units are those of an inverse, (A^+)_ij = b_i / a_j for A_ij = a_i / b_j. A A^T and A^T A sum over the columns or the rows, so the columns of a matrix with fewer rows must have the same unit, and the rows of a matrix with more rows, otherwise it fails with "Units do not match.": the pseudo-inverse minimizes a Euclidean norm, which needs components with the same unit, and for other units it depends on the choice of units (Doty, Melchiorri and Bonivento, "A theory of generalized inverses applied to robotics", The International Journal of Robotics Research 12(1), 1993). Use a weighted pseudo-inverse for them. A matrix that does not have full rank has no pseudo-inverse of this form, the inverse of A A^T or A^T A is not finite or huge, unlike kindr's pseudoInverse(), which takes the singular value decomposition, which not every value matrix backend provides. It needs matrix inverses (InvertibleValueMatrixBackend) and floating-point values.

Definition at line 228 of file Quantities.hpp.

◆ random()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
ThisT wuzp::Quantities< ValuesT_, UnitsT_ >::random ( )
inlinestatic

Definition at line 62 of file Quantities.hpp.

◆ set() [1/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValueT_, typename UnitT_>
requires (Dimension<ThisT>::value <= 1)
void wuzp::Quantities< ValuesT_, UnitsT_ >::set ( const int id,
const Quantity< ValueT_, UnitT_ > & quantity )
inline

Sets the quantity with the single index id of quantities of dimension 0 or 1, like set<IdV_>(), but with an index known at run time, which, like set(rowId, colId, quantity), requires all elements to have the same unit.

Definition at line 127 of file Quantities.hpp.

◆ set() [2/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValueT_, typename UnitT_>
void wuzp::Quantities< ValuesT_, UnitsT_ >::set ( const int rowId,
const int colId,
const Quantity< ValueT_, UnitT_ > & quantity )
inline

Definition at line 118 of file Quantities.hpp.

◆ set() [3/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<int IdV_, typename ValueT_, typename UnitT_>
requires (Dimension<ThisT>::value <= 1)
void wuzp::Quantities< ValuesT_, UnitsT_ >::set ( const Quantity< ValueT_, UnitT_ > & quantity)
inline

Sets the quantity with the single index IdV_ of quantities of dimension 0 or 1 (see get<IdV_>()), like set<RowIdV_, ColIdV_>(), which checks the index and the unit at compile time.

Definition at line 111 of file Quantities.hpp.

◆ set() [4/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<int RowIdV_, int ColIdV_, typename ValueT_, typename UnitT_>
void wuzp::Quantities< ValuesT_, UnitsT_ >::set ( const Quantity< ValueT_, UnitT_ > & quantity)
inline

Definition at line 103 of file Quantities.hpp.

◆ set() [5/5]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValueT_, typename UnitT_>
requires (Dimension<ThisT>::value == 0)
void wuzp::Quantities< ValuesT_, UnitsT_ >::set ( const Quantity< ValueT_, UnitT_ > & quantity)
inline

Definition at line 96 of file Quantities.hpp.

◆ setValue()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValueOtherT_>
requires (Dimension<ThisT>::value == 0)
void wuzp::Quantities< ValuesT_, UnitsT_ >::setValue ( ValueOtherT_ value)
inline

Sets the value of a quantity.

Like ValuesWrapper::set(), it converts the value into the value type only if their common type is the value type (see isConvertedToValueType), e.g. not a double for int values, which could truncate it.

Definition at line 148 of file Quantities.hpp.

◆ setValues()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
template<typename ValuesOtherT_>
void wuzp::Quantities< ValuesT_, UnitsT_ >::setValues ( const ValuesOtherT_ & values)
inline

Set the values of the quantities.

WARNING: This method circumvents quantity type safety. This method is provided even if the dimension is 0, to ensure all quantities have the same interface in templated functions.

Parameters
valuesValueMatrix of the same size.

Definition at line 140 of file Quantities.hpp.

◆ squaredNorm()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::squaredNorm ( ) const
inline

Definition at line 242 of file Quantities.hpp.

◆ std::forward() [1/2]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
Ts Ts wuzp::Quantities< ValuesT_, UnitsT_ >::std::forward ( t0 )

◆ std::forward() [2/2]

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
Ts Ts wuzp::Quantities< ValuesT_, UnitsT_ >::std::forward ( ts )
inline

Definition at line 59 of file Quantities.hpp.

◆ transpose()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
auto wuzp::Quantities< ValuesT_, UnitsT_ >::transpose ( ) const
inline

Definition at line 185 of file Quantities.hpp.

◆ zero()

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
ThisT wuzp::Quantities< ValuesT_, UnitsT_ >::zero ( )
inlinestatic

Definition at line 61 of file Quantities.hpp.

Member Data Documentation

◆ T0

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
Ts wuzp::Quantities< ValuesT_, UnitsT_ >::T0

Definition at line 59 of file Quantities.hpp.

◆ ts

template<AnyValuesWrapper ValuesT_, AnyUnitMatrix UnitsT_>
Ts&& wuzp::Quantities< ValuesT_, UnitsT_ >::ts

Definition at line 58 of file Quantities.hpp.


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