-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initializer list and insert/update chaining #1359
Changes from all commits
dbf1d9f
5ee85b5
6a36275
89cb910
d2fd155
fee651a
b86c8bb
2c27669
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,21 +27,16 @@ | |
|
||
namespace gtsam { | ||
|
||
/** A map from keys to values | ||
* TODO(dellaert): Do we need this? Should we just use gtsam::DiscreteValues? | ||
* We just need another special DiscreteValue to represent labels, | ||
* However, all other Lie's operators are undefined in this class. | ||
* The good thing is we can have a Hybrid graph of discrete/continuous variables | ||
* together.. | ||
* Another good thing is we don't need to have the special DiscreteKey which | ||
* stores cardinality of a Discrete variable. It should be handled naturally in | ||
* the new class DiscreteValue, as the variable's type (domain) | ||
/** | ||
* A map from keys to values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* @ingroup discrete | ||
*/ | ||
class GTSAM_EXPORT DiscreteValues : public Assignment<Key> { | ||
public: | ||
using Base = Assignment<Key>; // base class | ||
|
||
/// @name Standard Constructors | ||
/// @{ | ||
using Assignment::Assignment; // all constructors | ||
|
||
// Define the implicit default constructor. | ||
|
@@ -50,14 +45,49 @@ class GTSAM_EXPORT DiscreteValues : public Assignment<Key> { | |
// Construct from assignment. | ||
explicit DiscreteValues(const Base& a) : Base(a) {} | ||
|
||
// Construct from initializer list. | ||
DiscreteValues(std::initializer_list<std::pair<const Key, size_t>> init) | ||
: Assignment<Key>{init} {} | ||
|
||
/// @} | ||
/// @name Testable | ||
/// @{ | ||
|
||
/// print required by Testable. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
void print(const std::string& s = "", | ||
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const; | ||
|
||
/// equals required by Testable for unit testing. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
bool equals(const DiscreteValues& x, double tol = 1e-9) const; | ||
|
||
/// @} | ||
/// @name Standard Interface | ||
/// @{ | ||
|
||
// insert in base class; | ||
std::pair<iterator, bool> insert( const value_type& value ){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. I tried. |
||
return Base::insert(value); | ||
} | ||
|
||
/** Insert all values from \c values. Throws an invalid_argument exception if | ||
* any keys to be inserted are already used. */ | ||
DiscreteValues& insert(const DiscreteValues& values); | ||
|
||
/** For all key/value pairs in \c values, replace values with corresponding | ||
* keys in this object with those in \c values. Throws std::out_of_range if | ||
* any keys in \c values are not present in this object. */ | ||
DiscreteValues& update(const DiscreteValues& values); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add |
||
|
||
/** | ||
* @brief Return a vector of DiscreteValues, one for each possible | ||
* combination of values. | ||
*/ | ||
static std::vector<DiscreteValues> CartesianProduct( | ||
const DiscreteKeys& keys) { | ||
return Base::CartesianProduct<DiscreteValues>(keys); | ||
} | ||
|
||
/// @} | ||
/// @name Wrapper support | ||
/// @{ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems odd to use boost here if you want to eventually remove it.