g2o
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
g2o::JacobianWorkspace Class Reference

provide memory workspace for computing the Jacobians More...

#include <jacobian_workspace.h>

Public Types

using WorkspaceVector = std::vector< VectorX >
 

Public Member Functions

 JacobianWorkspace ()
 
 ~JacobianWorkspace ()
 
bool allocate ()
 
void updateSize (const HyperGraph::Edge *e, bool reset)
 
void updateSize (const HyperGraph::Edge *e)
 
void updateSize (const OptimizableGraph &graph, bool reset=false)
 
void updateSize (int numVertices, int dimension, bool reset=false)
 
void setZero ()
 
double * workspaceForVertex (int vertexIndex)
 

Protected Attributes

WorkspaceVector _workspace
 the memory pre-allocated for computing the Jacobians
 
int _maxNumVertices
 
int _maxDimension
 

Detailed Description

provide memory workspace for computing the Jacobians

The workspace is used by an OptimizableGraph to provide temporary memory for computing the Jacobian of the error functions. Before calling linearizeOplus on an edge, the workspace needs to be allocated by calling allocate().

By default, the sizes are updated incrementally with each call. If the reset flag is set to true, the counts are set back to

Definition at line 53 of file jacobian_workspace.h.

Member Typedef Documentation

◆ WorkspaceVector

Definition at line 55 of file jacobian_workspace.h.

Constructor & Destructor Documentation

◆ JacobianWorkspace()

g2o::JacobianWorkspace::JacobianWorkspace ( )

◆ ~JacobianWorkspace()

g2o::JacobianWorkspace::~JacobianWorkspace ( )

Definition at line 41 of file jacobian_workspace.cpp.

41{}

Member Function Documentation

◆ allocate()

bool g2o::JacobianWorkspace::allocate ( )

allocate the workspace

Definition at line 43 of file jacobian_workspace.cpp.

43 {
44 if (_maxNumVertices <= 0 || _maxDimension <= 0) return false;
46 for (WorkspaceVector::iterator it = _workspace.begin();
47 it != _workspace.end(); ++it) {
48 it->resize(_maxDimension);
49 it->setZero();
50 }
51 return true;
52}
WorkspaceVector _workspace
the memory pre-allocated for computing the Jacobians

References _maxDimension, _maxNumVertices, and _workspace.

Referenced by g2o::G2oSlamInterface::addEdge(), g2o::StructureOnlySolver< PointDoF >::calc(), g2o::SparseOptimizer::initializeOptimization(), and g2o::SparseOptimizer::initializeOptimization().

◆ setZero()

void g2o::JacobianWorkspace::setZero ( )

set the full workspace to zero

Definition at line 54 of file jacobian_workspace.cpp.

54 {
55 for (auto& wp : _workspace) wp.setZero();
56}

References _workspace.

◆ updateSize() [1/4]

void g2o::JacobianWorkspace::updateSize ( const HyperGraph::Edge e)

update the maximum required workspace needed by taking into account this edge

Definition at line 66 of file jacobian_workspace.cpp.

66 {
67 const OptimizableGraph::Edge* e =
68 static_cast<const OptimizableGraph::Edge*>(e_);
69 int errorDimension = e->dimension();
70 int numVertices = e->vertices().size();
71 int maxDimensionForEdge = -1;
72
73 for (const auto& vv : e->vertices()) {
74 const OptimizableGraph::Vertex* v =
75 static_cast<const OptimizableGraph::Vertex*>(vv);
76 assert(v && "Edge has no vertex assigned");
77 maxDimensionForEdge =
78 max(v->dimension() * errorDimension, maxDimensionForEdge);
79 }
80 _maxNumVertices = max(numVertices, _maxNumVertices);
81 _maxDimension = max(maxDimensionForEdge, _maxDimension);
82}

References _maxDimension, _maxNumVertices, g2o::OptimizableGraph::Vertex::dimension(), g2o::OptimizableGraph::Edge::dimension(), and g2o::HyperGraph::Edge::vertices().

◆ updateSize() [2/4]

void g2o::JacobianWorkspace::updateSize ( const HyperGraph::Edge e,
bool  reset 
)

update the maximum required workspace needed by taking into account this edge

Definition at line 58 of file jacobian_workspace.cpp.

58 {
59 if (reset) {
60 _maxNumVertices = -1;
61 _maxDimension = -1;
62 }
63 updateSize(e_);
64}
void updateSize(const HyperGraph::Edge *e, bool reset)

References _maxDimension, _maxNumVertices, and updateSize().

Referenced by g2o::OptimizableGraph::addEdge(), g2o::StructureOnlySolver< PointDoF >::calc(), g2o::BaseDynamicVertex< T >::setDimension(), g2o::OptimizableGraph::setEdgeVertex(), updateSize(), and updateSize().

◆ updateSize() [3/4]

void g2o::JacobianWorkspace::updateSize ( const OptimizableGraph graph,
bool  reset = false 
)

update the required workspace by looking at a full graph

Definition at line 84 of file jacobian_workspace.cpp.

84 {
85 if (reset) {
86 _maxNumVertices = -1;
87 _maxDimension = -1;
88 }
89
90 for (OptimizableGraph::EdgeSet::const_iterator it = graph.edges().begin();
91 it != graph.edges().end(); ++it) {
92 const OptimizableGraph::Edge* e =
93 static_cast<const OptimizableGraph::Edge*>(*it);
94 updateSize(e);
95 }
96}

References _maxDimension, _maxNumVertices, g2o::HyperGraph::edges(), and updateSize().

◆ updateSize() [4/4]

void g2o::JacobianWorkspace::updateSize ( int  numVertices,
int  dimension,
bool  reset = false 
)

manually update with the given parameters

Definition at line 98 of file jacobian_workspace.cpp.

98 {
99 if (reset) {
100 _maxNumVertices = -1;
101 _maxDimension = -1;
102 }
103
104 _maxNumVertices = max(numVertices, _maxNumVertices);
105 _maxDimension = max(dimension, _maxDimension);
106}

References _maxDimension, and _maxNumVertices.

◆ workspaceForVertex()

double * g2o::JacobianWorkspace::workspaceForVertex ( int  vertexIndex)
inline

return the workspace for a vertex in an edge

Definition at line 95 of file jacobian_workspace.h.

95 {
96 assert(vertexIndex >= 0 && (size_t)vertexIndex < _workspace.size() &&
97 "Index out of bounds");
98 return _workspace[vertexIndex].data();
99 }

Referenced by g2o::BlockSolver< Traits >::buildSystem(), g2o::BaseVariableSizedEdge< D, E >::linearizeOplus(), and g2o::BaseFixedSizedEdge< D, E, VertexTypes >::linearizeOplus_allocate().

Member Data Documentation

◆ _maxDimension

int g2o::JacobianWorkspace::_maxDimension
protected

the maximum dimension (number of elements) for a Jacobian

Definition at line 106 of file jacobian_workspace.h.

Referenced by allocate(), updateSize(), updateSize(), updateSize(), and updateSize().

◆ _maxNumVertices

int g2o::JacobianWorkspace::_maxNumVertices
protected

the maximum number of vertices connected by a hyper-edge

Definition at line 104 of file jacobian_workspace.h.

Referenced by allocate(), updateSize(), updateSize(), updateSize(), and updateSize().

◆ _workspace

WorkspaceVector g2o::JacobianWorkspace::_workspace
protected

the memory pre-allocated for computing the Jacobians

Definition at line 103 of file jacobian_workspace.h.

Referenced by allocate(), and setZero().


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