Skip to content
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

Reduce memory required to compile pybind11 interface #371

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/python_pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pybind11_add_module(math SHARED
src/Spline.cc
src/StopWatch.cc
src/Temperature.cc
src/Vector2.cc
src/Vector3Stats.cc
)

Expand Down
1 change: 1 addition & 0 deletions src/python_pybind11/src/Angle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <string>

#include <ignition/math/Angle.hh>
#include <pybind11/operators.h>

#include "Angle.hh"
Expand Down
2 changes: 0 additions & 2 deletions src/python_pybind11/src/Angle.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include <pybind11/pybind11.h>

#include <ignition/math/Angle.hh>

namespace py = pybind11;

namespace ignition
Expand Down
37 changes: 37 additions & 0 deletions src/python_pybind11/src/Vector2.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <string>

#include "Vector2.hh"

namespace ignition
{
namespace math
{
namespace python
{
void defineMathVector2(py::module &m, const std::string &typestr)
{
helpDefineMathVector2<double>(m, typestr + "d");
helpDefineMathVector2<float>(m, typestr + "f");
helpDefineMathVector2<int>(m, typestr + "i");
}

} // namespace python
} // namespace gazebo
} // namespace ignition
15 changes: 10 additions & 5 deletions src/python_pybind11/src/Vector2.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*
*/

#ifndef IGNITION_MATH_PYTHON__VECTOR2D_HH_
#define IGNITION_MATH_PYTHON__VECTOR2D_HH_
#ifndef IGNITION_MATH_PYTHON__VECTOR2_HH_
#define IGNITION_MATH_PYTHON__VECTOR2_HH_

#include <string>

Expand All @@ -34,12 +34,12 @@ namespace math
{
namespace python
{
/// Define a pybind11 wrapper for an ignition::math::Vector2
/// Help define a pybind11 wrapper for an ignition::math::Vector2
/**
* \param[in] module a pybind11 module to add the definition to
*/
template<typename T>
void defineMathVector2(py::module &m, const std::string &typestr)
void helpDefineMathVector2(py::module &m, const std::string &typestr)
{
using Class = ignition::math::Vector2<T>;
auto toString = [](const Class &si) {
Expand Down Expand Up @@ -136,8 +136,13 @@ void defineMathVector2(py::module &m, const std::string &typestr)
.def("__repr__", toString);
}

/// Define a pybind11 wrapper for an ignition::math::Vector2
/**
* \param[in] module a pybind11 module to add the definition to
*/
void defineMathVector2(py::module &m, const std::string &typestr);
} // namespace python
} // namespace gazebo
} // namespace ignition

#endif // IGNITION_MATH_PYTHON__VECTOR2D_HH_
#endif // IGNITION_MATH_PYTHON__VECTOR2_HH_
4 changes: 1 addition & 3 deletions src/python_pybind11/src/_ignition_math_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ PYBIND11_MODULE(math, m)

ignition::math::python::defineMathTemperature(m, "Temperature");

ignition::math::python::defineMathVector2<double>(m, "Vector2d");
ignition::math::python::defineMathVector2<int>(m, "Vector2i");
ignition::math::python::defineMathVector2<float>(m, "Vector2f");
ignition::math::python::defineMathVector2(m, "Vector2");

ignition::math::python::defineMathVector3<double>(m, "Vector3d");
ignition::math::python::defineMathVector3<int>(m, "Vector3i");
Expand Down