ros2_rust icon indicating copy to clipboard operation
ros2_rust copied to clipboard

Use ndarray in messages

Open nnmm opened this issue 3 years ago • 2 comments

In Python, arrays of primitive numbers are deserialized into numpy arrays. Rust could do the same (in its idiomatic message type, not the RMW-native message type). This would make working with these vectors and matrices much easier.

There are two ways we could go about this: Either simply always use ndarray for arrays of numbers, or keep it a regular array and add conversion functions. The latter approach has the benefit that it could be feature-gated to avoid increasing compile times too much.

Maybe this whole idea could be taken a step further and we special-case the MultiDimensionalArray messages from common_interfaces, e.g. Float64MultiArray to be ndarray types.

Maybe it would be interesting to look at https://github.com/ros2/rclcpp/pull/1557 for inspiration.

nnmm avatar Apr 22 '22 20:04 nnmm

Is it not more idiomatic to just implement Into for MultiDimensionalArray messages of number types? The user can choose to let val: Array3::<f64> = msg.into() etc. if they desire.

LaVieEstDure avatar Jul 26 '22 13:07 LaVieEstDure

Yep, that's probably better.

nnmm avatar Jul 26 '22 15:07 nnmm