Loading...
Searching...
No Matches
VariableSlots.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/global_includes.h>
#include <gtsam/base/FastMap.h>
#include <gtsam/base/FastVector.h>
#include <gtsam/base/timing.h>
#include <gtsam/base/Testable.h>
#include <boost/tuple/tuple.hpp>
#include <iostream>
#include <string>
namespace gtsam {
class VariableSlots : public FastMap<Key, FastVector<size_t> > {
public:
typedef FastMap<Key, FastVector<size_t> > Base;
GTSAM_EXPORT static const size_t Empty;
template<class FG>
VariableSlots(const FG& factorGraph);
GTSAM_EXPORT void print(const std::string& str = "VariableSlots: ") const;
GTSAM_EXPORT bool equals(const VariableSlots& rhs, double tol = 0.0) const;
};
template<> struct traits<VariableSlots> : public Testable<VariableSlots> {};
/* ************************************************************************* */
template<class FG>
VariableSlots::VariableSlots(const FG& factorGraph)
{
gttic(VariableSlots_constructor);
static const bool debug = false;
// Compute a mapping (called variableSlots) *from* each involved
// variable that will be in the new joint factor *to* the slot in each
// removed factor in which that variable appears. For each variable,
// this is stored as a vector of slot numbers, stored in order of the
// removed factors. The slot number is the max integer value if the
// factor does not involve that variable.
size_t jointFactorPos = 0;
for(const typename FG::sharedFactor& factor: factorGraph) {
if (!factor) {
continue;
}
size_t factorVarSlot = 0;
for(const Key involvedVariable: *factor) {
// Set the slot in this factor for this variable. If the
// variable was not already discovered, create an array for it
// that we'll fill with the slot indices for each factor that
// we're combining. Initially we put the max integer value in
// the array entry for each factor that will indicate the factor
// does not involve the variable.
iterator thisVarSlots; bool inserted;
boost::tie(thisVarSlots, inserted) = this->insert(std::make_pair(involvedVariable, FastVector<size_t>()));
if(inserted)
thisVarSlots->second.resize(factorGraph.nrFactors(), Empty);
thisVarSlots->second[jointFactorPos] = factorVarSlot;
if(debug) std::cout << " var " << involvedVariable << " rowblock " << jointFactorPos << " comes from factor's slot " << factorVarSlot << std::endl;
++ factorVarSlot;
}
++ jointFactorPos;
}
}
}
timing.h
Timing utilities.
FastMap.h
A thin wrapper around std::map that uses boost's fast_pool_allocator.
Testable.h
Concept check for values that can be used in unit tests.
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
global_includes.h
Included from all GTSAM files.
gtsam::FastVector
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::FastMap< Key, FastVector< size_t > >::FastMap
FastMap()
Definition FastMap.h:46
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::VariableSlots
A combined factor is assembled as one block of rows for each component factor.
Definition VariableSlots.h:52
gtsam::VariableSlots::print
GTSAM_EXPORT void print(const std::string &str="VariableSlots: ") const
print
Definition VariableSlots.cpp:29
gtsam::VariableSlots::equals
GTSAM_EXPORT bool equals(const VariableSlots &rhs, double tol=0.0) const
equals
Definition VariableSlots.cpp:52
gtsam::VariableSlots::VariableSlots
VariableSlots(const FG &factorGraph)
Constructor from a set of factors to be combined.
Definition VariableSlots.h:89