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

map Arrays to numpy.ndarray() and Sequences to array.array() #35

Merged
merged 9 commits into from
Mar 27, 2019

Conversation

dirk-thomas
Copy link
Member

Implements the latest version of the design article describing the type mapping for Python (including the latest change ros2/design#217).

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dirk-thomas dirk-thomas added enhancement New feature or request in progress Actively being worked on (Kanban column) labels Mar 25, 2019
@dirk-thomas dirk-thomas self-assigned this Mar 25, 2019
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
@dirk-thomas dirk-thomas force-pushed the array-sequence-mapping branch 2 times, most recently from 18df5bf to 6475261 Compare March 27, 2019 04:44
@dirk-thomas
Copy link
Member Author

dirk-thomas commented Mar 27, 2019

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Ready for review.

@dirk-thomas dirk-thomas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Mar 27, 2019
@dirk-thomas
Copy link
Member Author

A great example of the performance improvement this change provides is to run the following two commands:

  • ros2 run image_tools cam2image -x 1280 -y 720
  • ros2 topic echo /image

Without this patch the Python CLI takes about 600-700ms to convert the incoming ROS message into a Python object. As a consequence only every 15th-20th frames is being shown and the command line tool uses 100% of one CPU core.

With the patch the conversion time is reduced by two orders of magnitude to about 7-8ms and the command line tool can print information for every image message without utilizing a full CPU core. Also the memory usage is reduced for the Python tool since an array.array uses only roughly the size of the underlaying C array (rather than a Python list with Python int items).

@kervel
Copy link

kervel commented Mar 27, 2019

Great, i think quite a few people would be helped by this (it would make the python API useable for us at least). See also ros2/ros2#509 and various threads on discourse.

@@ -18,6 +19,52 @@ from rosidl_parser.definition import Sequence
from rosidl_parser.definition import String
from rosidl_parser.definition import WString
}@
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider using a different delimiter here? These look a lot like git conflict markers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of delimiter already exists in numerous em templates throughout the various generators. So for this PR I would rather stick with it. But a set of follow up PRs could replace them with whatever else is preferred.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I guess I hadn't noticed it before. It really jumped out at me this time. I'm good with it staying, then.

@dirk-thomas dirk-thomas mentioned this pull request Mar 27, 2019
20 tasks
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but for tiny comments and pending green CI

rosidl_generator_py/resource/_msg.py.em Outdated Show resolved Hide resolved
rosidl_generator_py/test/test_interfaces.py Show resolved Hide resolved
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
…ray()

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
@dirk-thomas
Copy link
Member Author

pending green CI

@hidmic CI builds have already been run and are referenced in the comment above.

@hidmic
Copy link
Contributor

hidmic commented Mar 27, 2019

Oh, I see now that test failures are unrelated. LGTM then.

Copy link
Member

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, sorry for long review, was testing it out locally 👍

CI failures are unrelated to this change.

@dirk-thomas
Copy link
Member Author

Merging without squashing to keep the commits separate for easier history reading. Since these changes won't be backported the separated commits shouldn't be a problem.

@dirk-thomas
Copy link
Member Author

Addressed compiler warnings about unused variables in release mode in a follow up commit: 4f11d87.

mikaelarguedas added a commit to mikaelarguedas/rosidl_python that referenced this pull request Mar 28, 2019
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
mikaelarguedas added a commit to mikaelarguedas/rosidl_python that referenced this pull request May 2, 2019
Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

simplify logic by printing member type directly

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move dict construction to rosidl_runtime_py

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add utility to import complex message and add support for nested array in set_message

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests and remove coverage for dict to avoid circular dependency

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

more descriptive variable name

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

refactor import logic according to ros2#35

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move imports to top of file

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

string maximum size doesn't need quoting or str conversion

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update docblock

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

slot_types_dict_from_message -> get_message_slot_types

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

check Abstrct type instead of 'list'

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add conditional is namespaces is an empty list

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

one liner

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

extend test suite to cover NesteTypes of NamespacedTypes

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

single message fixture to use

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add coverage for static array of nested messages

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

restore old API

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

SLOT_TYPES improvement from dirk-thomas

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

resolve conflicts

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
dirk-thomas pushed a commit that referenced this pull request May 3, 2019
* store types as constant and return ordered dict

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

simplify logic by printing member type directly

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move dict construction to rosidl_runtime_py

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add utility to import complex message and add support for nested array in set_message

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests and remove coverage for dict to avoid circular dependency

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

more descriptive variable name

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

refactor import logic according to #35

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move imports to top of file

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

string maximum size doesn't need quoting or str conversion

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update docblock

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

slot_types_dict_from_message -> get_message_slot_types

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

check Abstrct type instead of 'list'

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add conditional is namespaces is an empty list

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

one liner

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

extend test suite to cover NesteTypes of NamespacedTypes

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

single message fixture to use

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add coverage for static array of nested messages

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

restore old API

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

SLOT_TYPES improvement from dirk-thomas

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

resolve conflicts

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* add back I100 ignore

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* use new rosidl_parser.definition types and new test interfaces

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* restore original test, add test for SLOT_TYPES

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
jacobperron pushed a commit to ros2/rosidl_runtime_py that referenced this pull request Sep 19, 2019
* store types as constant and return ordered dict

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

simplify logic by printing member type directly

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move dict construction to rosidl_runtime_py

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add utility to import complex message and add support for nested array in set_message

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update tests and remove coverage for dict to avoid circular dependency

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

more descriptive variable name

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

refactor import logic according to ros2/rosidl_python#35

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

move imports to top of file

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

string maximum size doesn't need quoting or str conversion

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

update docblock

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

slot_types_dict_from_message -> get_message_slot_types

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

check Abstrct type instead of 'list'

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add conditional is namespaces is an empty list

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

one liner

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

extend test suite to cover NesteTypes of NamespacedTypes

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

single message fixture to use

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

use NestedType

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

add coverage for static array of nested messages

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

restore old API

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

SLOT_TYPES improvement from dirk-thomas

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

resolve conflicts

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* add back I100 ignore

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* use new rosidl_parser.definition types and new test interfaces

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>

* restore original test, add test for SLOT_TYPES

Signed-off-by: Mikael Arguedas <mikael.arguedas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants