g2o
Loading...
Searching...
No Matches
g2o
autodiff
variadic_evaluate.h
Go to the documentation of this file.
1
// Ceres Solver - A fast non-linear least squares minimizer
2
// Copyright 2015 Google Inc. All rights reserved.
3
// http://ceres-solver.org/
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are met:
7
//
8
// * Redistributions of source code must retain the above copyright notice,
9
// this list of conditions and the following disclaimer.
10
// * Redistributions in binary form must reproduce the above copyright notice,
11
// this list of conditions and the following disclaimer in the documentation
12
// and/or other materials provided with the distribution.
13
// * Neither the name of Google Inc. nor the names of its contributors may be
14
// used to endorse or promote products derived from this software without
15
// specific prior written permission.
16
//
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
// POSSIBILITY OF SUCH DAMAGE.
28
//
29
// Author: sameeragarwal@google.com (Sameer Agarwal)
30
// mierle@gmail.com (Keir Mierle)
31
// jodebo_beck@gmx.de (Johannes Beck)
32
33
#ifndef G2O_CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_
34
#define G2O_CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_
35
36
#include <stddef.h>
37
38
#include <type_traits>
39
#include <utility>
40
41
#include "
parameter_dims.h
"
42
43
namespace
g2o
{
44
namespace
ceres {
45
namespace
internal
{
46
47
// For fixed size cost functors
48
template
<
typename
Functor,
typename
T,
int
... Indices>
49
inline
bool
VariadicEvaluateImpl
(
const
Functor& functor, T
const
*
const
* input,
50
T* output, std::false_type
/*is_dynamic*/
,
51
std::integer_sequence<int, Indices...>) {
52
static_assert
(
sizeof
...(Indices),
53
"Invalid number of parameter blocks. At least one parameter "
54
"block must be specified."
);
55
return
functor(input[Indices]..., output);
56
}
57
58
// For dynamic sized cost functors
59
template
<
typename
Functor,
typename
T>
60
inline
bool
VariadicEvaluateImpl
(
const
Functor& functor, T
const
*
const
* input,
61
T* output, std::true_type
/*is_dynamic*/
,
62
std::integer_sequence<int>) {
63
return
functor(input, output);
64
}
65
66
// For ceres cost functors (not ceres::CostFunction)
67
template
<
typename
ParameterDims,
typename
Functor,
typename
T>
68
inline
bool
VariadicEvaluateImpl
(
const
Functor& functor, T
const
*
const
* input,
69
T* output,
const
void
*
/* NOT USED */
) {
70
using
ParameterBlockIndices =
71
std::make_integer_sequence<int, ParameterDims::kNumParameterBlocks>;
72
using
IsDynamic = std::integral_constant<bool, ParameterDims::kIsDynamic>;
73
return
VariadicEvaluateImpl
(functor, input, output, IsDynamic(),
74
ParameterBlockIndices());
75
}
76
77
// For ceres::CostFunction
78
// template <typename ParameterDims, typename Functor, typename T>
79
// inline bool VariadicEvaluateImpl(const Functor& functor,
80
// T const* const* input,
81
// T* output,
82
// const CostFunction* /* NOT USED */) {
83
// return functor.Evaluate(input, output, nullptr);
84
// }
85
86
// Variadic evaluate is a helper function to evaluate ceres cost function or
87
// functors using an input, output and the parameter dimensions. There are
88
// several ways different possibilities:
89
// 1) If the passed functor is a 'ceres::CostFunction' its evaluate method is
90
// called.
91
// 2) If the functor is not a 'ceres::CostFunction' and the specified parameter
92
// dims is dynamic, the functor must have the following signature
93
// 'bool(T const* const* input, T* output)'.
94
// 3) If the functor is not a 'ceres::CostFunction' and the specified parameter
95
// dims is not dynamic, the input is expanded by using the number of parameter
96
// blocks. The signature of the functor must have the following signature
97
// 'bool()(const T* i_1, const T* i_2, ... const T* i_n, T* output)'.
98
template
<
typename
ParameterDims,
typename
Functor,
typename
T>
99
inline
bool
VariadicEvaluate
(
const
Functor& functor, T
const
*
const
* input,
100
T* output) {
101
return
VariadicEvaluateImpl<ParameterDims>(functor, input, output, &functor);
102
}
103
104
}
// namespace internal
105
}
// namespace ceres
106
}
// namespace g2o
107
108
#endif
// G2O_CERES_PUBLIC_INTERNAL_VARIADIC_EVALUATE_H_
g2o::ceres::internal::VariadicEvaluateImpl
bool VariadicEvaluateImpl(const Functor &functor, T const *const *input, T *output, std::false_type, std::integer_sequence< int, Indices... >)
Definition
variadic_evaluate.h:49
g2o::ceres::internal::VariadicEvaluate
bool VariadicEvaluate(const Functor &functor, T const *const *input, T *output)
Definition
variadic_evaluate.h:99
g2o
Definition
dl_wrapper.cpp:55
internal
Definition
base_variable_sized_edge.hpp:29
parameter_dims.h
Generated on Tue Nov 11 2025 05:18:45 for g2o by
1.9.8