48template <
typename,
typename...>
55template <
typename T1,
typename T2>
60template <
typename T1,
typename T2,
typename T3>
66template <
typename T1,
typename T2,
typename T3,
typename T4>
73template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
81template <
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
82 typename T6,
typename... TExtra>
152template <
class OutputVec,
class... ValueTypes>
158 inline constexpr static auto N =
sizeof...(ValueTypes);
169 template <
typename From,
typename To>
170 using IsConvertible =
171 typename std::enable_if<std::is_convertible<From, To>::value,
void>::type;
174 using IndexIsValid =
typename std::enable_if<(I >= 1) && (I <=
N),
177 template <
typename Container>
178 using ContainerElementType =
179 typename std::decay<decltype(*std::declval<Container>().begin())>::type;
180 template <
typename Container>
181 using IsContainerOfKeys = IsConvertible<ContainerElementType<Container>,
Key>;
187 template <
typename Ret,
typename... Args>
189 std::enable_if_t<(... && std::is_convertible<Args, Matrix&>::value), Ret>;
191 template <
typename Arg>
192 using IsMatrixPointer = std::is_same<typename std::decay_t<Arg>, Matrix*>;
194 template <
typename Arg>
195 using IsNullpointer =
196 std::is_same<typename std::decay_t<Arg>, std::nullptr_t>;
202 template <
typename Ret,
typename... Args>
204 std::enable_if_t<(... && (IsMatrixPointer<Args>::value ||
205 IsNullpointer<Args>::value)),
213 template <
typename T =
void>
214 using OptionalMatrixTypeT = Matrix*;
218 template <
typename T>
225 template <
typename T =
void>
226 using MatrixTypeT = Matrix;
248 template <
int I,
typename = IndexIsVal
id<I>>
250 typename std::tuple_element<I - 1, std::tuple<ValueTypes...>>::type;
267 KeyType<ValueTypes>...
keys)
278 template <
typename CONTAINER = std::initializer_list<Key>,
279 typename = IsContainerOfKeys<CONTAINER>>
282 if (
keys.size() !=
N) {
283 throw std::invalid_argument(
284 "NoiseModelFactorT: wrong number of keys given");
308 static_assert(I <=
N,
"Index out of bounds");
321 const Values& values)
const override {
325 using UseFixed = std::bool_constant<Dimensions::allFixed &&
327 return linearizeImpl<Factory>(values, UseFixed{});
332 template <
typename Factory>
333 std::shared_ptr<GaussianFactor> linearizeImpl(
const Values& values,
334 std::true_type)
const {
336 constexpr int M = Dimensions::M;
338 "Fixed factor dimensions must be positive");
340 if (!this->
active(values))
return std::shared_ptr<JacobianFactor>();
342 std::vector<Matrix> jacobians(Dimensions::arity);
345 if (noiseModel &&
static_cast<size_t>(b.size()) !=
noiseModel->dim()) {
346 throw std::invalid_argument(
347 "NoiseModelFactor: NoiseModel has dimension " +
348 std::to_string(
noiseModel->dim()) +
" instead of " +
349 std::to_string(b.size()) +
".");
351 if (b.size() != M || jacobians.size() != Dimensions::arity ||
352 !internal::dimensionsMatch<Dimensions>(
353 jacobians, std::make_index_sequence<Dimensions::arity>{})) {
354 throw std::invalid_argument(
355 "NoiseModelFactorT::linearize: error or Jacobian dimension "
363 SharedDiagonal linearModel;
365 const auto constrained =
366 std::static_pointer_cast<noiseModel::Constrained>(
noiseModel);
367 linearModel = constrained->unit();
370 return Factory::create(this->
keys_, jacobians, b, linearModel);
374 template <
typename Factory>
375 std::shared_ptr<GaussianFactor> linearizeImpl(
const Values& values,
376 std::false_type)
const {
400 return unwhitenedError(gtsam::index_sequence_for<ValueTypes...>{}, x, H);
430 const ValueTypes&... x, OptionalMatrixTypeT<ValueTypes>... H)
const = 0;
440 MatrixTypeT<ValueTypes>&... H)
const {
455 return evaluateError(x..., OptionalMatrixTypeT<ValueTypes>()...);
462 template <
typename... OptionalJacArgs,
463 typename = IndexIsValid<
sizeof...(OptionalJacArgs) + 1>>
465 const ValueTypes&... x, OptionalJacArgs&&... H)
const {
473 template <
typename... OptionalJacArgs,
474 typename = IndexIsValid<
sizeof...(OptionalJacArgs) + 1>>
476 const ValueTypes&... x, OptionalJacArgs&&... H)
const {
481 return evaluateError(x..., std::forward<OptionalJacArgs>(H)...,
494 template <std::size_t... Indices>
506 return Vector::Zero(this->
dim());
510#if GTSAM_ENABLE_BOOST_SERIALIZATION
512 friend class boost::serialization::access;
513 template <
class ARCHIVE>
514 void serialize(ARCHIVE& ar,
const unsigned int ) {
515 ar& boost::serialization::make_nvp(
516 "NoiseModelFactor", boost::serialization::base_object<Base>(*
this));
524 inline Key key1()
const {
return key<1>(); }
526 inline Key key2()
const {
527 static_assert(I <=
N,
"Index out of bounds");
531 inline Key key3()
const {
532 static_assert(I <=
N,
"Index out of bounds");
536 inline Key key4()
const {
537 static_assert(I <=
N,
"Index out of bounds");
541 inline Key key5()
const {
542 static_assert(I <=
N,
"Index out of bounds");
546 inline Key key6()
const {
547 static_assert(I <=
N,
"Index out of bounds");
560template <
class... ValueTypes>
563#define NoiseModelFactor1 NoiseModelFactorN
564#define NoiseModelFactor2 NoiseModelFactorN
565#define NoiseModelFactor3 NoiseModelFactorN
566#define NoiseModelFactor4 NoiseModelFactorN
567#define NoiseModelFactor5 NoiseModelFactorN
568#define NoiseModelFactor6 NoiseModelFactorN
Arbitrary-arity Jacobian factor with compile-time block dimensions.
Non-linear factor base classes.
#define OptionalNone
These typedefs and aliases will help with making the evaluateError interface independent of boost TOD...
Definition NonlinearFactor.h:51
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
NoiseModelFactorT< Vector, ValueTypes... > NoiseModelFactorN
Noise model factor with N value types and dynamic-sized error vector.
Definition NoiseModelFactorN.h:561
std::vector< Matrix > * OptionalMatrixVecType
The OptionalMatrixVecType is a pointer to a vector of matrices.
Definition NonlinearFactor.h:63
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
Definition utilities.h:44
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:88
Compile-time residual and variable dimensions for a factor of any arity.
Definition FixedJacobianFactor.h:48
Construct the fixed-size Jacobian factor for a dimension pack.
Definition FixedJacobianFactor.h:327
Convenience base class to add aliases X1, X2, ..., X6 -> ValueType<N>.
Definition NoiseModelFactorN.h:49
A convenient base class for creating your own NoiseModelFactor with n variables.
Definition NoiseModelFactorN.h:155
NoiseModelFactorT()
Default Constructor for I/O.
Definition NoiseModelFactorN.h:257
std::enable_if_t<(... &&(IsMatrixPointer< Args >::value||IsNullpointer< Args >::value)), Ret > AreAllMatrixPtrs
Definition NoiseModelFactorN.h:203
Vector evaluateError(const ValueTypes &... x, MatrixTypeT< ValueTypes > &... H) const
If all the optional arguments are matrices then redirect the call to the one which takes pointers.
Definition NoiseModelFactorN.h:439
NoiseModelFactorT(const SharedNoiseModel &noiseModel, KeyType< ValueTypes >... keys)
Constructor.
Definition NoiseModelFactorN.h:266
std::enable_if_t<(... &&std::is_convertible< Args, Matrix & >::value), Ret > AreAllMatrixRefs
Definition NoiseModelFactorN.h:188
Vector evaluateError(const ValueTypes &... x) const
No-Jacobians requested function overload.
Definition NoiseModelFactorN.h:454
virtual OutputVec evaluateError(const ValueTypes &... x, OptionalMatrixTypeT< ValueTypes >... H) const =0
Override evaluateError to finish implementing an n-way factor.
AreAllMatrixPtrs< Vector, OptionalJacArgs... > evaluateError(const ValueTypes &... x, OptionalJacArgs &&... H) const
Some (but not all) optional Jacobians are omitted (function overload) and the jacobians are pointers ...
Definition NoiseModelFactorN.h:475
typename std::tuple_element< I - 1, std::tuple< ValueTypes... > >::type ValueType
Definition NoiseModelFactorN.h:249
static constexpr auto N
Definition NoiseModelFactorN.h:158
Key key() const
Returns a key.
Definition NoiseModelFactorN.h:307
AreAllMatrixRefs< Vector, OptionalJacArgs... > evaluateError(const ValueTypes &... x, OptionalJacArgs &&... H) const
Some (but not all) optional Jacobians are omitted (function overload) and the jacobians are l-value r...
Definition NoiseModelFactorN.h:464
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
This implements the unwhitenedError virtual function by calling the n-key specific version of evaluat...
Definition NoiseModelFactorN.h:398
std::shared_ptr< GaussianFactor > linearize(const Values &values) const override
Linearize factors whose error and argument dimensions are all fixed to an arbitrary-arity FixedJacobi...
Definition NoiseModelFactorN.h:320
NoiseModelFactorT(const SharedNoiseModel &noiseModel, CONTAINER keys)
Constructor.
Definition NoiseModelFactorN.h:280
virtual bool active(const Values &c) const
Checks whether a factor should be used based on a set of values.
Definition NonlinearFactor.h:143
std::shared_ptr< GaussianFactor > linearize(const Values &x) const override
Linearize a non-linearFactorN to get a GaussianFactor, Hence .
Definition NonlinearFactor.cpp:160
virtual Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const =0
Error function without the NoiseModel, .
size_t dim() const override
get the dimension of the factor (number of rows on linearization)
Definition NonlinearFactor.h:251
NoiseModelFactor()
Default constructor for I/O only.
Definition NonlinearFactor.h:223
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition NonlinearFactor.h:258
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65
const ValueType at(Key j) const
Retrieve a variable by key j.
Definition Values-inl.h:260