Skip to content

Commit

Permalink
Merge pull request #781 from francesco-romano/bindings/fix_after_PR767
Browse files Browse the repository at this point in the history
Fix pybind11 bindings compilation after #767.
  • Loading branch information
traversaro authored Nov 24, 2020
2 parents 17d5a7d + a302322 commit 437c93a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.1] - 2020-11-24

### Fixed
- Fixed problem in pybind11-based Python bindings (https://github.com/robotology/idyntree/pull/781).

## [2.0.0] - 2020-11-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

cmake_minimum_required(VERSION 3.16)

project(iDynTree VERSION 2.0.0
project(iDynTree VERSION 2.0.1
LANGUAGES C CXX)

# Disable in source build, unless Eclipse is used
Expand Down
23 changes: 13 additions & 10 deletions bindings/pybind11/idyntree_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <cstddef>

namespace iDynTree {
namespace bindings {
namespace {
Expand All @@ -25,10 +27,10 @@ namespace py = ::pybind11;
void vectorDynSizeClassDefinition(py::class_<VectorDynSize>& vector) {
vector.def(py::init())
.def(py::init<unsigned>())
.def("__getitem__", py::overload_cast<const unsigned>(
.def("__getitem__", py::overload_cast<const std::size_t>(
&VectorDynSize::operator(), py::const_))
.def("__setitem__",
[](VectorDynSize& the_vector, unsigned index, double new_value) {
[](VectorDynSize& the_vector, std::size_t index, double new_value) {
the_vector(index) = new_value;
})
.def(
Expand Down Expand Up @@ -61,10 +63,10 @@ void createFixSizeVector(pybind11::module& module,
py::class_<VectorFixSize<size>>(module, class_name.c_str(),
py::buffer_protocol())
.def(py::init())
.def("__getitem__", py::overload_cast<const unsigned>(
.def("__getitem__", py::overload_cast<const std::size_t>(
&VectorFixSize<size>::operator(), py::const_))
.def("__setitem__",
[](VectorFixSize<size>& the_vector, unsigned index,
[](VectorFixSize<size>& the_vector, std::size_t index,
double new_value) { the_vector(index) = new_value; })
.def("__len__", &VectorFixSize<size>::size)
.def(
Expand Down Expand Up @@ -93,12 +95,13 @@ void matrixDynSizeClassDefinition(py::class_<MatrixDynSize>& matrix) {
matrix.def(py::init())
.def(py::init<unsigned, unsigned>())
.def("__getitem__",
[](MatrixDynSize& matrix, std::pair<unsigned, unsigned> indices) {
[](MatrixDynSize& matrix,
std::pair<std::size_t, std::size_t> indices) {
return matrix.getVal(indices.first, indices.second);
})
.def("__setitem__",
[](MatrixDynSize& matrix, std::pair<unsigned, unsigned> indices,
double item) {
[](MatrixDynSize& matrix,
std::pair<std::size_t, std::size_t> indices, double item) {
return matrix.setVal(indices.first, indices.second, item);
})
.def("rows", &MatrixDynSize::rows)
Expand Down Expand Up @@ -127,12 +130,12 @@ void createFixSizeMatrix(pybind11::module& module,
.def(py::init())
.def("__getitem__",
[](MatrixFixSize<rows, cols>& matrix,
std::pair<unsigned, unsigned> indices) {
std::pair<std::size_t, std::size_t> indices) {
return matrix.getVal(indices.first, indices.second);
})
.def("__setitem__",
[](MatrixFixSize<rows, cols>& matrix,
std::pair<unsigned, unsigned> indices, double item) {
std::pair<std::size_t, std::size_t> indices, double item) {
return matrix.setVal(indices.first, indices.second, item);
})
.def("rows", &MatrixFixSize<rows, cols>::rows)
Expand Down Expand Up @@ -261,4 +264,4 @@ void iDynTreeCoreBindings(pybind11::module& module) {
});
}
} // namespace bindings
} // namespace iDynTree
} // namespace iDynTree

0 comments on commit 437c93a

Please sign in to comment.