Skip to content

Commit 9aa4cc7

Browse files
authored
Avoid an assert and add a declarations include (#155)
1 parent cadce18 commit 9aa4cc7

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed

include/albatross/Common

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323

2424
#include <math.h>
2525
#include <iomanip>
26-
#include <map>
2726
#include <set>
28-
#include <string>
2927
#include <iostream>
3028
#include <unordered_map>
3129
#include <functional>
@@ -34,7 +32,7 @@
3432
#include <numeric>
3533
#include <random>
3634

37-
#include <albatross/src/core/declarations.hpp>
35+
#include "ForwardDeclarations"
3836

3937
#include <albatross/src/details/traits.hpp>
4038
#include <albatross/src/details/has_any_macros.hpp>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2019 Swift Navigation Inc.
3+
* Contact: Swift Navigation <[email protected]>
4+
*
5+
* This source is subject to the license found in the file 'LICENSE' which must
6+
* be distributed together with this source. All other rights reserved.
7+
*
8+
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9+
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
10+
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#ifndef ALBATROSS_FORWARD_DECLARATIONS_H
14+
#define ALBATROSS_FORWARD_DECLARATIONS_H
15+
16+
#include <map>
17+
#include <string>
18+
19+
#include <Eigen/src/Core/util/ForwardDeclarations.h>
20+
21+
#include <albatross/src/core/declarations.hpp>
22+
23+
#endif

include/albatross/src/core/parameter_handling_mixin.hpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,32 @@ class ParameterHandlingMixin {
142142
}
143143
}
144144

145+
void set_params_if_exists(const ParameterStore &params) {
146+
const ParameterStore current_params = get_params();
147+
for (const auto &pair : params) {
148+
if (map_contains(current_params, pair.first)) {
149+
unchecked_set_param(pair.first, pair.second);
150+
}
151+
}
152+
}
153+
145154
void set_param_values(const std::map<ParameterKey, ParameterValue> &values) {
146155
for (const auto &pair : values) {
147156
check_param_key(pair.first);
148157
unchecked_set_param(pair.first, pair.second);
149158
}
150159
}
151160

161+
void set_param_values_if_exists(
162+
const std::map<ParameterKey, ParameterValue> &values) {
163+
const ParameterStore current_params = get_params();
164+
for (const auto &pair : values) {
165+
if (map_contains(current_params, pair.first)) {
166+
unchecked_set_param(pair.first, pair.second);
167+
}
168+
}
169+
}
170+
152171
void set_param_value(const ParameterKey &key, const ParameterValue &value) {
153172
check_param_key(key);
154173
unchecked_set_param(key, value);
@@ -247,14 +266,13 @@ class ParameterHandlingMixin {
247266
}
248267

249268
const double lb = pair.second.prior.lower_bound();
250-
const double ub = pair.second.prior.upper_bound();
251-
252-
// this silly diversion is to make lint think lb and ub get used;
253269
if (v < lb) {
254-
assert(false);
270+
v = lb;
255271
};
272+
273+
const double ub = pair.second.prior.upper_bound();
256274
if (v > ub) {
257-
assert(false);
275+
v = ub;
258276
};
259277

260278
unchecked_set_param(pair.first, v);

0 commit comments

Comments
 (0)