g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
autodiff
parameter_dims.h
Go to the documentation of this file.
1
// Ceres Solver - A fast non-linear least squares minimizer
2
// Copyright 2018 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: jodebo_beck@gmx.de (Johannes Beck)
30
31
#ifndef G2O_CERES_PUBLIC_INTERNAL_PARAMETER_DIMS_H_
32
#define G2O_CERES_PUBLIC_INTERNAL_PARAMETER_DIMS_H_
33
34
#include <array>
35
#include <utility>
36
37
#include "
integer_sequence_algorithm.h
"
38
39
namespace
g2o
{
40
namespace
ceres
{
41
namespace
internal
{
42
43
// Checks, whether the given parameter block sizes are valid. Valid means every
44
// dimension is bigger than zero.
45
constexpr
bool
IsValidParameterDimensionSequence
(std::integer_sequence<int>) {
46
return
true
;
47
}
48
49
template
<
int
N,
int
... Ts>
50
constexpr
bool
IsValidParameterDimensionSequence
(
51
std::integer_sequence<int, N, Ts...>) {
52
return
(N <= 0) ? false
53
:
IsValidParameterDimensionSequence
(
54
std::integer_sequence<int, Ts...>());
55
}
56
57
// Helper class that represents the parameter dimensions. The parameter
58
// dimensions are either dynamic or the sizes are known at compile time. It is
59
// used to pass parameter block dimensions around (e.g. between functions or
60
// classes).
61
//
62
// As an example if one have three parameter blocks with dimensions (2, 4, 1),
63
// one would use 'StaticParameterDims<2, 4, 1>' which is a synonym for
64
// 'ParameterDims<false, 2, 4, 1>'.
65
// For dynamic parameter dims, one would just use 'DynamicParameterDims', which
66
// is a synonym for 'ParameterDims<true>'.
67
template
<
bool
IsDynamic,
int
... Ns>
68
class
ParameterDims
{
69
public
:
70
using
Parameters
= std::integer_sequence<int, Ns...>;
71
72
// The parameter dimensions are only valid if all parameter block dimensions
73
// are greater than zero.
74
static
constexpr
bool
kIsValid
=
75
IsValidParameterDimensionSequence
(
Parameters
());
76
static_assert
(
kIsValid
,
77
"Invalid parameter block dimension detected. Each parameter "
78
"block dimension must be bigger than zero."
);
79
80
static
constexpr
bool
kIsDynamic
= IsDynamic;
81
static
constexpr
int
kNumParameterBlocks
=
sizeof
...(Ns);
82
static_assert
(
kIsDynamic
||
kNumParameterBlocks
> 0,
83
"At least one parameter block must be specified."
);
84
85
static
constexpr
int
kNumParameters
=
86
Sum
<std::integer_sequence<int, Ns...>>::Value;
87
88
static
constexpr
int
GetDim
(
int
dim) {
return
params_
[dim]; }
89
90
// If one has all parameters packed into a single array this function unpacks
91
// the parameters.
92
template
<
typename
T>
93
static
inline
std::array<T*, kNumParameterBlocks>
GetUnpackedParameters
(
94
T* ptr) {
95
using
Offsets =
ExclusiveScan<Parameters>
;
96
return
GetUnpackedParameters
(ptr, Offsets());
97
}
98
99
private
:
100
template
<
typename
T,
int
... Indices>
101
static
inline
std::array<T*, kNumParameterBlocks>
GetUnpackedParameters
(
102
T* ptr, std::integer_sequence<int, Indices...>) {
103
return
std::array<T*, kNumParameterBlocks>{{ptr + Indices...}};
104
}
105
106
static
constexpr
std::array<int, kNumParameterBlocks>
params_
{Ns...};
107
};
108
109
// Even static constexpr member variables needs to be defined (not only
110
// declared). As the ParameterDims class is tempalted this definition must
111
// be in the header file.
112
template
<
bool
IsDynamic,
int
... Ns>
113
constexpr
std::array<int, ParameterDims<IsDynamic, Ns...>::kNumParameterBlocks>
114
ParameterDims
<IsDynamic, Ns...>
::params_
;
115
116
// Using declarations for static and dynamic parameter dims. This makes client
117
// code easier to read.
118
template
<
int
... Ns>
119
using
StaticParameterDims
=
ParameterDims
<
false
, Ns...>;
120
using
DynamicParameterDims
=
ParameterDims<true>
;
121
122
}
// namespace internal
123
}
// namespace ceres
124
}
// namespace g2o
125
126
#endif
// G2O_CERES_PUBLIC_INTERNAL_PARAMETER_DIMS_H_
g2o::ceres::internal::ParameterDims
Definition
parameter_dims.h:68
g2o::ceres::internal::ParameterDims::GetDim
static constexpr int GetDim(int dim)
Definition
parameter_dims.h:88
g2o::ceres::internal::ParameterDims< false, Ns... >::kIsValid
static constexpr bool kIsValid
Definition
parameter_dims.h:74
g2o::ceres::internal::ParameterDims< false, Ns... >::kNumParameters
static constexpr int kNumParameters
Definition
parameter_dims.h:85
g2o::ceres::internal::ParameterDims< false, Ns... >::kNumParameterBlocks
static constexpr int kNumParameterBlocks
Definition
parameter_dims.h:81
g2o::ceres::internal::ParameterDims::Parameters
std::integer_sequence< int, Ns... > Parameters
Definition
parameter_dims.h:70
g2o::ceres::internal::ParameterDims< false, Ns... >::kIsDynamic
static constexpr bool kIsDynamic
Definition
parameter_dims.h:80
g2o::ceres::internal::ParameterDims::GetUnpackedParameters
static std::array< T *, kNumParameterBlocks > GetUnpackedParameters(T *ptr)
Definition
parameter_dims.h:93
g2o::ceres::internal::ParameterDims< false, Ns... >::params_
static constexpr std::array< int, kNumParameterBlocks > params_
Definition
parameter_dims.h:106
g2o::ceres::internal::ParameterDims::GetUnpackedParameters
static std::array< T *, kNumParameterBlocks > GetUnpackedParameters(T *ptr, std::integer_sequence< int, Indices... >)
Definition
parameter_dims.h:101
g2o::ceres::internal::Sum
Definition
integer_sequence_algorithm.h:99
integer_sequence_algorithm.h
g2o::ceres::internal
Definition
array_selector.h:43
g2o::ceres::internal::IsValidParameterDimensionSequence
constexpr bool IsValidParameterDimensionSequence(std::integer_sequence< int >)
Definition
parameter_dims.h:45
g2o::ceres::internal::StaticParameterDims
ParameterDims< false, Ns... > StaticParameterDims
Definition
parameter_dims.h:119
g2o::ceres::internal::params_
constexpr std::array< int, ParameterDims< IsDynamic, Ns... >::kNumParameterBlocks > ParameterDims< IsDynamic, Ns... >::params_
Definition
parameter_dims.h:114
g2o::ceres::internal::DynamicParameterDims
ParameterDims< true > DynamicParameterDims
Definition
parameter_dims.h:120
g2o::ceres::internal::ExclusiveScan
typename ExclusiveScanT< Seq >::Type ExclusiveScan
Definition
integer_sequence_algorithm.h:162
g2o::ceres
Definition
array_selector.h:42
g2o
Definition
dl_wrapper.cpp:55
Generated on
for g2o by
1.17.0