Skip to content

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

Merged
dirk-thomas merged 9 commits into
masterfrom
array-sequence-mapping
Mar 27, 2019
Merged

map Arrays to numpy.ndarray() and Sequences to array.array()#35
dirk-thomas merged 9 commits into
masterfrom
array-sequence-mapping

Conversation

@dirk-thomas

Copy link
Copy Markdown
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-thomasdirk-thomas added enhancement New feature or request in progress Actively being worked on (Kanban column) labels Mar 25, 2019
@dirk-thomasdirk-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-thomasforce-pushed the array-sequence-mapping branch 2 times, most recently from 18df5bf to 6475261CompareMarch 27, 2019 04:44
@dirk-thomas

dirk-thomas commented Mar 27, 2019

Copy link
Copy Markdown
MemberAuthor
  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Ready for review.

@dirk-thomasdirk-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
Copy Markdown
MemberAuthor

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
Copy Markdown

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.

from rosidl_parser.definition import String
from rosidl_parser.definition import WString
}@
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
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-thomasdirk-thomas mentioned this pull request Mar 27, 2019
20 tasks

@hidmichidmic left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadrosidl_generator_py/resource/_msg.py.em Outdated
Comment threadrosidl_generator_py/test/test_interfaces.py
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
dirk-thomasforce-pushed the array-sequence-mapping branch from 6475261 to 739c50fCompareMarch 27, 2019 17:24
@dirk-thomas

Copy link
Copy Markdown
MemberAuthor

pending green CI

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

@hidmic

Copy link
Copy Markdown
Contributor

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

@mjcarrollmjcarroll left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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
dirk-thomas merged commit a47c064 into masterMar 27, 2019
@dirk-thomas
dirk-thomas deleted the array-sequence-mapping branch March 27, 2019 19:24
@dirk-thomasdirk-thomas removed the in review Waiting for review (Kanban column) label Mar 27, 2019
@dirk-thomas

Copy link
Copy Markdown
MemberAuthor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dirk-thomas@kervel@hidmic@mjcarroll