-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #499 from edantec/topic/edantec_std_map
Add bp::dist to std::map converter + unittest
- Loading branch information
Showing
5 changed files
with
194 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from std_map import copy, std_map_to_dict | ||
|
||
t = {"one": 1.0, "two": 2.0} | ||
|
||
assert std_map_to_dict(t) == t | ||
assert std_map_to_dict(copy(t)) == t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// @file | ||
/// @copyright Copyright 2023 CNRS INRIA | ||
|
||
#include <eigenpy/eigenpy.hpp> | ||
#include <eigenpy/std-map.hpp> | ||
#include <iostream> | ||
|
||
namespace bp = boost::python; | ||
|
||
template <typename T1> | ||
bp::dict std_map_to_dict(const std::map<std::string, T1>& map) { | ||
bp::dict dictionnary; | ||
for (auto const& x : map) { | ||
dictionnary[x.first] = x.second; | ||
} | ||
return dictionnary; | ||
} | ||
|
||
template <typename T1> | ||
std::map<std::string, T1> copy(const std::map<std::string, T1>& map) { | ||
std::map<std::string, T1> out = map; | ||
return out; | ||
} | ||
|
||
BOOST_PYTHON_MODULE(std_map) { | ||
eigenpy::enableEigenPy(); | ||
|
||
eigenpy::python::StdMapPythonVisitor< | ||
std::string, double, std::less<std::string>, | ||
std::allocator<std::pair<const std::string, double> >, | ||
true>::expose("StdMap_Double"); | ||
|
||
bp::def("std_map_to_dict", std_map_to_dict<double>); | ||
bp::def("copy", copy<double>); | ||
} |