Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Matthias Mayr
limbo
Commits
94c5d8a4
Unverified
Commit
94c5d8a4
authored
Jul 05, 2018
by
JB Mouret
Committed by
GitHub
Jul 05, 2018
Browse files
Merge pull request #277 from resibots/fix_inline
fix issue #276
parents
5b2bef82
92678edf
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/limbo/opt/optimizer.hpp
View file @
94c5d8a4
...
...
@@ -62,11 +62,11 @@ namespace limbo {
///@ingroup opt_tools
///return with opt::no_grad(your_val) if no gradient is available (to be used in functions to be optimized)
eval_t
no_grad
(
double
x
)
{
return
eval_t
{
x
,
boost
::
optional
<
Eigen
::
VectorXd
>
{}};
}
inline
eval_t
no_grad
(
double
x
)
{
return
eval_t
{
x
,
boost
::
optional
<
Eigen
::
VectorXd
>
{}};
}
///@ingroup opt_tools
/// get the gradient from a function evaluation (eval_t)
const
Eigen
::
VectorXd
&
grad
(
const
eval_t
&
fg
)
inline
const
Eigen
::
VectorXd
&
grad
(
const
eval_t
&
fg
)
{
assert
(
std
::
get
<
1
>
(
fg
).
is_initialized
());
return
std
::
get
<
1
>
(
fg
).
get
();
...
...
@@ -74,7 +74,7 @@ namespace limbo {
///@ingroup opt_tools
/// get the value from a function evaluation (eval_t)
double
fun
(
const
eval_t
&
fg
)
inline
double
fun
(
const
eval_t
&
fg
)
{
return
std
::
get
<
0
>
(
fg
);
}
...
...
@@ -82,7 +82,7 @@ namespace limbo {
///@ingroup opt_tools
/// Evaluate f without gradient (to be called from the optimization algorithms that do not use the gradient)
template
<
typename
F
>
double
eval
(
const
F
&
f
,
const
Eigen
::
VectorXd
&
x
)
inline
double
eval
(
const
F
&
f
,
const
Eigen
::
VectorXd
&
x
)
{
return
std
::
get
<
0
>
(
f
(
x
,
false
));
}
...
...
@@ -90,7 +90,7 @@ namespace limbo {
///@ingroup opt_tools
/// Evaluate f with gradient (to be called from the optimization algorithms that use the gradient)
template
<
typename
F
>
eval_t
eval_grad
(
const
F
&
f
,
const
Eigen
::
VectorXd
&
x
)
inline
eval_t
eval_grad
(
const
F
&
f
,
const
Eigen
::
VectorXd
&
x
)
{
return
f
(
x
,
true
);
}
...
...
src/limbo/tools/math.hpp
View file @
94c5d8a4
...
...
@@ -61,7 +61,7 @@ namespace limbo {
/// @ingroup tools
/// make a 1-D vector from a double (useful when we need to return vectors)
Eigen
::
VectorXd
make_vector
(
double
x
)
inline
Eigen
::
VectorXd
make_vector
(
double
x
)
{
Eigen
::
VectorXd
res
(
1
);
res
(
0
)
=
x
;
...
...
src/limbo/tools/parallel.hpp
View file @
94c5d8a4
...
...
@@ -80,7 +80,7 @@ namespace limbo {
/// @ingroup par_tools
/// convert a std::vector to something else (e.g. a std::list)
template
<
typename
V
>
std
::
vector
<
typename
V
::
value_type
>
convert_vector
(
const
V
&
v
)
inline
std
::
vector
<
typename
V
::
value_type
>
convert_vector
(
const
V
&
v
)
{
std
::
vector
<
typename
V
::
value_type
>
v2
(
v
.
size
());
std
::
copy
(
v
.
begin
(),
v
.
end
(),
v2
.
begin
());
...
...
@@ -99,7 +99,7 @@ namespace limbo {
#endif
template
<
typename
V
>
V
convert_vector
(
const
V
&
v
)
inline
V
convert_vector
(
const
V
&
v
)
{
return
v
;
}
...
...
@@ -114,7 +114,7 @@ namespace limbo {
#else
/// @ingroup par_tools
/// init TBB (if activated) for multi-core computing
void
init
()
inline
void
init
()
{
}
#endif
...
...
@@ -152,7 +152,7 @@ namespace limbo {
/// @ingroup par_tools
/// parallel max
template
<
typename
T
,
typename
F
,
typename
C
>
T
max
(
const
T
&
init
,
int
num_steps
,
const
F
&
f
,
const
C
&
comp
)
inline
T
max
(
const
T
&
init
,
int
num_steps
,
const
F
&
f
,
const
C
&
comp
)
{
#ifdef USE_TBB
auto
body
=
[
&
](
const
tbb
::
blocked_range
<
size_t
>&
r
,
T
current_max
)
->
T
{
...
...
src/limbo/tools/random_generator.hpp
View file @
94c5d8a4
...
...
@@ -104,7 +104,7 @@ namespace limbo {
///
/// - this function is thread safe because we use a random generator for each thread
/// - we use a C++11 random number generator
Eigen
::
VectorXd
random_vector_bounded
(
int
size
)
inline
Eigen
::
VectorXd
random_vector_bounded
(
int
size
)
{
static
thread_local
rgen_double_t
rgen
(
0.0
,
1.0
);
Eigen
::
VectorXd
res
(
size
);
...
...
@@ -118,7 +118,7 @@ namespace limbo {
///
/// - this function is thread safe because we use a random generator for each thread
/// - we use a C++11 random number generator
Eigen
::
VectorXd
random_vector_unbounded
(
int
size
)
inline
Eigen
::
VectorXd
random_vector_unbounded
(
int
size
)
{
static
thread_local
rgen_gauss_t
rgen
(
0.0
,
10.0
);
Eigen
::
VectorXd
res
(
size
);
...
...
@@ -129,7 +129,7 @@ namespace limbo {
/// @ingroup tools
/// random vector wrapper for both bounded and unbounded versions
Eigen
::
VectorXd
random_vector
(
int
size
,
bool
bounded
=
true
)
inline
Eigen
::
VectorXd
random_vector
(
int
size
,
bool
bounded
=
true
)
{
if
(
bounded
)
return
random_vector_bounded
(
size
);
...
...
@@ -138,7 +138,7 @@ namespace limbo {
/// @ingroup tools
/// generate n random samples with Latin Hypercube Sampling (LHS) in [0, 1]^dim
Eigen
::
MatrixXd
random_lhs
(
int
dim
,
int
n
)
inline
Eigen
::
MatrixXd
random_lhs
(
int
dim
,
int
n
)
{
Eigen
::
VectorXd
cut
=
Eigen
::
VectorXd
::
LinSpaced
(
n
+
1
,
0.
,
1.
);
Eigen
::
MatrixXd
u
=
Eigen
::
MatrixXd
::
Zero
(
n
,
dim
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment