gtsam
linear
Scatter.cpp
Go to the documentation of this file.
1
/* ----------------------------------------------------------------------------
2
3
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
4
* Atlanta, Georgia 30332-0415
5
* All Rights Reserved
6
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8
* See LICENSE for the license information
9
10
* -------------------------------------------------------------------------- */
11
19
#include <
gtsam/linear/GaussianFactorGraph.h
>
20
#include <
gtsam/linear/Scatter.h
>
21
#include <
gtsam/inference/Ordering.h
>
22
23
#include <algorithm>
24
25
using namespace
std
;
26
27
namespace
gtsam
{
28
29
/* ************************************************************************* */
30
string
SlotEntry::toString()
const
{
31
ostringstream oss;
32
oss <<
"SlotEntry: key="
<<
key
<<
", dim="
<< dimension;
33
return
oss.str();
34
}
35
36
Scatter::Scatter(
const
GaussianFactorGraph
& gfg) :
Scatter
(gfg,
Ordering
()) {}
37
38
/* ************************************************************************* */
39
Scatter::Scatter
(
const
GaussianFactorGraph
& gfg,
40
const
Ordering
&
ordering
) {
41
gttic
(Scatter_Constructor);
42
43
// If we have an ordering, pre-fill the ordered variables first
44
for
(
Key
key
:
ordering
) {
45
add
(
key
, 0);
46
}
47
48
// Now, find dimensions of variables and/or extend
49
for
(
const
auto
&
factor
: gfg) {
50
if
(!
factor
)
51
continue
;
52
53
// TODO: Fix this hack to cope with zero-row Jacobians that come from BayesTreeOrphanWrappers
54
const
JacobianFactor
* asJacobian =
dynamic_cast<
const
JacobianFactor
*
>
(
factor
.get());
55
if
(asJacobian && asJacobian->
cols
() <= 1)
continue
;
56
57
// loop over variables
58
for
(
GaussianFactor::const_iterator
variable =
factor
->begin();
59
variable !=
factor
->end(); ++variable) {
60
const
Key
key
= *variable;
61
iterator
it =
find
(
key
);
// theoretically expensive, yet cache friendly
62
if
(it!=
end
())
63
it->dimension =
factor
->getDim(variable);
64
else
65
add
(
key
,
factor
->getDim(variable));
66
}
67
}
68
69
// To keep the same behavior as before, sort the keys after the ordering
70
iterator
first = begin();
71
first +=
ordering
.size();
72
if
(first !=
end
()) std::sort(first,
end
());
73
}
74
75
/* ************************************************************************* */
76
void
Scatter::add
(
Key
key
,
size_t
dim) {
77
emplace_back(
SlotEntry
(
key
, dim));
78
}
79
80
/* ************************************************************************* */
81
FastVector<SlotEntry>::iterator
Scatter::find
(
Key
key
) {
82
iterator
it = begin();
83
while
(it !=
end
()) {
84
if
(it->key ==
key
)
85
return
it;
86
++it;
87
}
88
return
it;
// end()
89
}
90
91
/* ************************************************************************* */
92
93
}
// gtsam
GaussianFactorGraph.h
Linear Factor Graph where all factors are Gaussians.
gtsam::FastVector
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition:
FastVector.h:34
gtsam::Scatter::find
iterator find(Key key)
Find the SlotEntry with the right key (linear time worst case)
Definition:
Scatter.cpp:81
gtsam::JacobianFactor
Definition:
JacobianFactor.h:91
Ordering.h
Variable ordering for the elimination algorithm.
iterator
Definition:
pytypes.h:1460
pruning_fixture::factor
DecisionTreeFactor factor(D &C &B &A, "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0")
gtsam::GaussianFactorGraph
Definition:
GaussianFactorGraph.h:73
gtsam::Scatter
Definition:
Scatter.h:49
gtsam::JacobianFactor::cols
size_t cols() const
Definition:
JacobianFactor.h:289
ordering
static enum @1096 ordering
key
const gtsam::Symbol key('X', 0)
gtsam::Factor::const_iterator
KeyVector::const_iterator const_iterator
Const iterator over keys.
Definition:
Factor.h:83
gtsam
traits
Definition:
SFMdata.h:40
std
Definition:
BFloat16.h:88
gtsam::Scatter::add
GTSAM_EXPORT void add(Key key, size_t dim)
Add a key/dim pair.
Definition:
Scatter.cpp:76
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition:
IndexedViewHelper.h:181
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition:
types.h:97
gtsam::SlotEntry
One SlotEntry stores the slot index for a variable, as well its dim.
Definition:
Scatter.h:32
gtsam::Ordering
Definition:
inference/Ordering.h:33
Scatter.h
Maps global variable indices to slot indices.
gttic
#define gttic(label)
Definition:
timing.h:295
gtsam::Scatter::Scatter
GTSAM_EXPORT Scatter()
Default Constructor.
Definition:
Scatter.h:52
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:09