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

Rename the python library as gz.math7 #503

Merged
merged 8 commits into from
Sep 15, 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
3 changes: 2 additions & 1 deletion Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ release will remove the deprecated code.
* CMake `-config` files
* Paths that depend on the project name

1. Python library imports such `import ignition.math` and `from ignition import math` should be replaced with `import gz.math7` and `from gz import math7`. Note the change from `ignition` to `gz` and the addition of the major version number as a suffix to the package name.

### Deprecations

1. **Angle.hh**
Expand Down Expand Up @@ -89,7 +91,6 @@ release will remove the deprecated code.
1. `IGN_MASSMATRIX3_DEFAULT_TOLERANCE`
1. All `IGN_*_SIZE_T` variables are deprecated and will be removed in future versions.
Please use `GZ_*_SIZE_T` instead.
1. Python library `ignition` namespaces should be replaced with `gz`.


### Modifications
Expand Down
10 changes: 5 additions & 5 deletions examples/angle_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH
#

import gz.math
import gz.math7

print("PI in degrees = {}\n".format(gz.math.Angle.PI.degree()))
print("PI in degrees = {}\n".format(gz.math7.Angle.PI.degree()))

a1 = gz.math.Angle(1.5707)
a2 = gz.math.Angle(0.7854)
a1 = gz.math7.Angle(1.5707)
a2 = gz.math7.Angle(0.7854)
print("a1 = {} radians, {} degrees\n".format(a1.radian(), a1.degree()))
print("a2 = {} radians, {} degrees\n".format(a2.radian(), a2.degree()))
print("a1 * a2 = {} radians, {} degrees\n".format((a1 * a2).radian(),
Expand All @@ -36,7 +36,7 @@
print("a1 - a2 = {} radians, {} degrees\n".format((a1 - a2).radian(),
(a1 - a2).degree()))

a3 = gz.math.Angle(15.707)
a3 = gz.math7.Angle(15.707)
print("a3 = {} radians, {} degrees\n".format(a3.radian(), a3.degree()))
a3.normalize()
print("a3.Normalize = {} radians, {} degrees\n".format(a3.radian(),
Expand Down
2 changes: 1 addition & 1 deletion examples/diff_drive_odometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import datetime
import math

from gz.math import Angle, DiffDriveOdometry
from gz.math7 import Angle, DiffDriveOdometry

odom = DiffDriveOdometry()

Expand Down
2 changes: 1 addition & 1 deletion examples/gauss_markov_process_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# 2. Use gnuplot to create a plot:
# gnuplot -e 'set terminal jpeg; plot "plot.data" with lines' > out.jpg
import datetime
from gz.math import GaussMarkovProcess
from gz.math7 import GaussMarkovProcess

# Create the process with:
# * Start value of 20.2
Expand Down
2 changes: 1 addition & 1 deletion examples/kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


from gz.math import Kmeans, Vector3d
from gz.math7 import Kmeans, Vector3d

# Create some observations.
obs = list([])
Expand Down
2 changes: 1 addition & 1 deletion examples/rand_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# 2. Use gnuplot to create a plot:
# gnuplot -c rand_view_normal.gp > normal.jpg
# gnuplot -c rand_view_uniform.gp > uniform.jpg
from gz.math import Rand
from gz.math7 import Rand
import sys

if (len(sys.argv) < 2):
Expand Down
8 changes: 4 additions & 4 deletions examples/vector2_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH
#
import gz.math
import gz.math7

va = gz.math.Vector2d(1, 2)
vb = gz.math.Vector2d(3, 4)
vc = gz.math.Vector2d(vb)
va = gz.math7.Vector2d(1, 2)
vb = gz.math7.Vector2d(3, 4)
vc = gz.math7.Vector2d(vb)

print("va = {} {}\n".format(va.x(), va.y()))
print("vb = {} {}\n".format(vb.x(), vb.y()))
Expand Down
6 changes: 3 additions & 3 deletions examples/vector3_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#
# $ export PYTHONPATH=/usr/lib/python:$PYTHONPATH
#
import gz.math
import gz.math7

v1 = gz.math.Vector3d(0, 0, 3)
v1 = gz.math7.Vector3d(0, 0, 3)
print("v =: {} {} {}\n".format(v1.x(), v1.y(), v1.z()))

v2 = gz.math.Vector3d(4, 0, 0)
v2 = gz.math7.Vector3d(4, 0, 0)
print("v2 = {} {} {}\n".format(v2.x(), v2.y(), v2.z()))

v3 = v1 + v2
Expand Down
36 changes: 9 additions & 27 deletions src/python_pybind11/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()

message(STATUS "Building pybind11 interfaces")
set(BINDINGS_MODULE_NAME "math${PROJECT_VERSION_MAJOR}")
# Split from main extension and converted to pybind11
pybind11_add_module(math MODULE
pybind11_add_module(${BINDINGS_MODULE_NAME} MODULE
src/_gz_math_pybind11.cc
src/Angle.cc
src/AxisAlignedBox.cc
Expand Down Expand Up @@ -51,21 +52,24 @@ pybind11_add_module(math MODULE
src/Vector3Stats.cc
)

target_link_libraries(math PRIVATE
target_link_libraries(${BINDINGS_MODULE_NAME} PRIVATE
${PROJECT_LIBRARY_TARGET_NAME}
)

target_compile_definitions(${BINDINGS_MODULE_NAME} PRIVATE
BINDINGS_MODULE_NAME=${BINDINGS_MODULE_NAME})

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Workaround for Clang and pybind11 on Focal
# https://github.com/pybind/pybind11/issues/1604
# Resolved by newer versions of pybind11
if(${pybind11_VERSION} VERSION_LESS "2.4.4")
target_compile_options(math PRIVATE -fsized-deallocation)
target_compile_options(${BINDINGS_MODULE_NAME} PRIVATE -fsized-deallocation)
endif()

# Suppress warnings that clang misidentifies:
# https://github.com/pybind/pybind11/issues/1893
target_compile_options(math PRIVATE -Wno-self-assign-overloaded)
target_compile_options(${BINDINGS_MODULE_NAME} PRIVATE -Wno-self-assign-overloaded)
endif()

if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION)
Expand Down Expand Up @@ -107,31 +111,9 @@ function(configure_build_install_location _library_name)
install(TARGETS ${_library_name}
DESTINATION "${GZ_PYTHON_INSTALL_PATH}/"
)

# TODO(CH3): Deprecated. Remove on tock.
# Install Python library symlinks
if(${GZ_PYTHON_INSTALL_PATH} MATCHES "gz$")
cmake_policy(SET CMP0087 NEW) # Allow evaluation of generator expressions in install(CODE )
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/ignition")

string(REGEX REPLACE "gz$" "ignition" IGN_PYTHON_INSTALL_PATH ${GZ_PYTHON_INSTALL_PATH})
if (WIN32) # Windows requires copy instead of symlink
install(TARGETS ${_library_name}
DESTINATION "${IGN_PYTHON_INSTALL_PATH}/"
)
else()
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \
../gz/$<TARGET_FILE_NAME:${_library_name}> \
${PROJECT_BINARY_DIR}\/ignition/$<TARGET_FILE_NAME:${_library_name}>)")
install(FILES ${PROJECT_BINARY_DIR}\/ignition/$<TARGET_FILE_NAME:${_library_name}>
DESTINATION "${IGN_PYTHON_INSTALL_PATH}/"
)
endif()
endif()

endfunction()

configure_build_install_location(math)
configure_build_install_location(${BINDINGS_MODULE_NAME})

if (BUILD_TESTING)
# Add the Python tests
Expand Down
2 changes: 1 addition & 1 deletion src/python_pybind11/src/_gz_math_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

namespace py = pybind11;

PYBIND11_MODULE(math, m)
PYBIND11_MODULE(BINDINGS_MODULE_NAME, m)
{
m.doc() = "Gazebo Math Python Library.";

Expand Down
2 changes: 1 addition & 1 deletion src/python_pybind11/test/Angle_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import unittest
import math
from gz.math import Angle
from gz.math7 import Angle


class TestAngle(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion src/python_pybind11/test/AxisAlignedBox_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import math
import unittest

from gz.math import AxisAlignedBox, Helpers, Line3d, Vector3d
from gz.math7 import AxisAlignedBox, Helpers, Line3d, Vector3d


class TestAxisAlignedBox(unittest.TestCase):
Expand Down
18 changes: 9 additions & 9 deletions src/python_pybind11/test/Box_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import unittest

import gz
from gz.math import Boxd, MassMatrix3d, Material, Planed, Vector3d
from gz.math7 import Boxd, MassMatrix3d, Material, Planed, Vector3d


class TestBox(unittest.TestCase):
Expand Down Expand Up @@ -46,30 +46,30 @@ def test_constructor(self):
self.assertEqual(box, box2)

# Dimension and mat constructor
box = Boxd(1.0, 2.0, 5.0, Material(gz.math.MaterialType.WOOD))
box = Boxd(1.0, 2.0, 5.0, Material(gz.math7.MaterialType.WOOD))
self.assertEqual(Vector3d(1.0, 2.0, 5.0), box.size())
self.assertEqual(Material(gz.math.MaterialType.WOOD), box.material())
self.assertEqual(Material(gz.math7.MaterialType.WOOD), box.material())

box2 = Boxd(1.0, 2.0, 5.0, Material(gz.math.MaterialType.WOOD))
box2 = Boxd(1.0, 2.0, 5.0, Material(gz.math7.MaterialType.WOOD))
self.assertEqual(box, box2)

# Vector Dimension and mat constructor
box = Boxd(Vector3d(2.2, 2.0, 10.0), Material(gz.math.MaterialType.WOOD))
box = Boxd(Vector3d(2.2, 2.0, 10.0), Material(gz.math7.MaterialType.WOOD))
self.assertEqual(Vector3d(2.2, 2.0, 10.0), box.size())
self.assertEqual(Material(gz.math.MaterialType.WOOD), box.material())
self.assertEqual(Material(gz.math7.MaterialType.WOOD), box.material())

box2 = Boxd(Vector3d(2.2, 2.0, 10.0), Material(gz.math.MaterialType.WOOD))
box2 = Boxd(Vector3d(2.2, 2.0, 10.0), Material(gz.math7.MaterialType.WOOD))
self.assertEqual(box, box2)

def test_mutators(self):
box = Boxd()
box.set_size(100.1, 2.3, 5.6)
box.set_material(Material(gz.math.MaterialType.PINE))
box.set_material(Material(gz.math7.MaterialType.PINE))

self.assertEqual(100.1, box.size().x())
self.assertEqual(2.3, box.size().y())
self.assertEqual(5.6, box.size().z())
self.assertEqual(Material(gz.math.MaterialType.PINE), box.material())
self.assertEqual(Material(gz.math7.MaterialType.PINE), box.material())

box.set_size(Vector3d(3.4, 1.2, 0.5))
self.assertEqual(3.4, box.size().x())
Expand Down
12 changes: 6 additions & 6 deletions src/python_pybind11/test/Capsule_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import unittest

import gz
from gz.math import Capsuled, Material, MassMatrix3d
from gz.math7 import Capsuled, Material, MassMatrix3d

import math

Expand All @@ -41,14 +41,14 @@ def test_constructor(self):

# Length, radius, mat
capsule = Capsuled(1.0, 2.0,
Material(gz.math.MaterialType.WOOD));
Material(gz.math7.MaterialType.WOOD));
self.assertEqual(1.0, capsule.length());
self.assertEqual(2.0, capsule.radius());
self.assertEqual(Material(gz.math.MaterialType.WOOD),
self.assertEqual(Material(gz.math7.MaterialType.WOOD),
capsule.material());

capsule2 = Capsuled(1.0, 2.0,
Material(gz.math.MaterialType.WOOD));
Material(gz.math7.MaterialType.WOOD));
self.assertEqual(capsule, capsule2);


Expand All @@ -60,11 +60,11 @@ def test_mutators(self):

capsule.set_length(100.1);
capsule.set_radius(.123);
capsule.set_material(Material(gz.math.MaterialType.PINE));
capsule.set_material(Material(gz.math7.MaterialType.PINE));

self.assertEqual(100.1, capsule.length());
self.assertEqual(.123, capsule.radius());
self.assertEqual(Material(gz.math.MaterialType.PINE),
self.assertEqual(Material(gz.math7.MaterialType.PINE),
capsule.material());


Expand Down
4 changes: 2 additions & 2 deletions src/python_pybind11/test/Color_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import math
import unittest
from gz.math import Color
from gz.math import Vector3f
from gz.math7 import Color
from gz.math7 import Vector3f


class TestColor(unittest.TestCase):
Expand Down
12 changes: 6 additions & 6 deletions src/python_pybind11/test/Cylinder_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unittest

import gz
from gz.math import Cylinderd, MassMatrix3d, Material, Quaterniond
from gz.math7 import Cylinderd, MassMatrix3d, Material, Quaterniond


class TestCylinder(unittest.TestCase):
Expand Down Expand Up @@ -54,14 +54,14 @@ def test_constructor(self):
self.assertEqual(cylinder, cylinder2)

# Length, radius, mat and rot constructor
cylinder = Cylinderd(1.0, 2.0, Material(gz.math.MaterialType.WOOD),
cylinder = Cylinderd(1.0, 2.0, Material(gz.math7.MaterialType.WOOD),
Quaterniond(0.1, 0.2, 0.3))
self.assertEqual(1.0, cylinder.length())
self.assertEqual(2.0, cylinder.radius())
self.assertEqual(Quaterniond(0.1, 0.2, 0.3), cylinder.rotational_offset())
self.assertEqual(Material(gz.math.MaterialType.WOOD), cylinder.mat())
self.assertEqual(Material(gz.math7.MaterialType.WOOD), cylinder.mat())

cylinder2 = Cylinderd(1.0, 2.0, Material(gz.math.MaterialType.WOOD),
cylinder2 = Cylinderd(1.0, 2.0, Material(gz.math7.MaterialType.WOOD),
Quaterniond(0.1, 0.2, 0.3))
self.assertEqual(cylinder, cylinder2)

Expand All @@ -75,12 +75,12 @@ def test_mutators(self):
cylinder.set_length(100.1)
cylinder.set_radius(.123)
cylinder.set_rotational_offset(Quaterniond(1.2, 2.3, 3.4))
cylinder.set_mat(Material(gz.math.MaterialType.PINE))
cylinder.set_mat(Material(gz.math7.MaterialType.PINE))

self.assertEqual(100.1, cylinder.length())
self.assertEqual(.123, cylinder.radius())
self.assertEqual(Quaterniond(1.2, 2.3, 3.4), cylinder.rotational_offset())
self.assertEqual(Material(gz.math.MaterialType.PINE), cylinder.mat())
self.assertEqual(Material(gz.math7.MaterialType.PINE), cylinder.mat())

def test_volume_and_density(self):
mass = 1.0
Expand Down
2 changes: 1 addition & 1 deletion src/python_pybind11/test/DiffDriveOdometry_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import math
import unittest

from gz.math import Angle, DiffDriveOdometry
from gz.math7 import Angle, DiffDriveOdometry


class TestDiffDriveOdometry(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions src/python_pybind11/test/Ellipsoid_TEST.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import unittest

import gz
from gz.math import Ellipsoidd, Material, MassMatrix3d, Vector3d
from gz.math7 import Ellipsoidd, Material, MassMatrix3d, Vector3d

import math

Expand All @@ -40,7 +40,7 @@ def test_constructor(self):

# Vector3 of radii and material
expectedRadii = Vector3d(1.0, 2.0, 3.0)
expectedMaterial = Material(gz.math.MaterialType.WOOD)
expectedMaterial = Material(gz.math7.MaterialType.WOOD)
ellipsoid = Ellipsoidd(expectedRadii, expectedMaterial)
self.assertEqual(expectedRadii, ellipsoid.radii())
self.assertEqual(expectedMaterial, ellipsoid.material())
Expand All @@ -57,7 +57,7 @@ def test_mutators(self):
expectedRadii = Vector3d(1.0, 2.0, 3.0)
ellipsoid.set_radii(expectedRadii)

expectedMaterial = Material(gz.math.MaterialType.PINE)
expectedMaterial = Material(gz.math7.MaterialType.PINE)
ellipsoid.set_material(expectedMaterial)

self.assertEqual(expectedRadii, ellipsoid.radii())
Expand Down
Loading