dora icon indicating copy to clipboard operation
dora copied to clipboard

I want to send three numpy arrays in single message

Open blackdamn2 opened this issue 3 months ago • 2 comments

Hi Dora Team,

I'm working on a robotics application where I need to package and send three different sensor data types together in a single message:

  • image1: shape (480, 640, 3), dtype uint8
  • image2: shape (480, 640, 3), dtype uint8
  • state: shape (1, 6), dtype float32

Currently, I'm using PyArrow StructArray to package them together:

struct_data = pa.StructArray.from_arrays(
    [pa.array([image1.tolist()]), pa.array([image2.tolist()]), pa.array([state.tolist()])],
    names=['image1', 'image2', 'state']
)image1_list = packed_data[0]['image1'].as_py()  # 获取Python list
image2_list = packed_data[0]['image2'].as_py()
state_list = packed_data[0]['state'].as_py()
# 转换回numpy数组
image1 = np.array(image1_list, dtype=np.uint8)  # 根据实际类型调整
image2 = np.array(image2_list, dtype=np.uint8)
state = np.array(state_list, dtype=np.float32)  # 根据实际类型调整

return image1, image2, state

blackdamn2 avatar Oct 30 '25 12:10 blackdamn2

This works, but the as_py() conversion on the receiving end introduces significant overhead that's unacceptable for our real-time performance requirements.

My Question: What's the fastest way to package and send these three data arrays together in a single Dora message while avoiding expensive Python object conversions?

blackdamn2 avatar Oct 30 '25 12:10 blackdamn2

have you tried:

struct_data = pa.StructArray.from_arrays(
    [pa.array([image1.ravel()]), pa.array([image2.ravel()]), pa.array([state.ravel()])],
    names=['image1', 'image2', 'state']
)
image1_list = packed_data[0]['image1'].to_numpy()  # 获取Python numpy array
image2_list = packed_data[0]['image2'].to_numpy()
state_list = packed_data[0]['state'].to_numpy()

It should be significantly faster. You can check out: https://dora-rs.ai/docs/guides/Development/Arrow#cheatsheet

haixuanTao avatar Oct 30 '25 13:10 haixuanTao

@blackdamn2 What's the status of this? Have you tried @haixuanTao's suggestion?

phil-opp avatar Dec 01 '25 12:12 phil-opp