|
import numpy as np |
|
import pyarrow as pa |
|
|
|
|
|
|
|
TEST_ARRAYS = [ |
|
("std_msgs", "UInt8", pa.array([{"data": np.uint8(2)}])), |
|
( |
|
"std_msgs", |
|
"String", |
|
pa.array([{"data": "hello"}]), |
|
), |
|
( |
|
"std_msgs", |
|
"UInt8MultiArray", |
|
pa.array( |
|
[ |
|
{ |
|
"data": np.array([1, 2, 3, 4], np.uint8), |
|
"layout": { |
|
"dim": [ |
|
{ |
|
"label": "a", |
|
"size": np.uint32(10), |
|
"stride": np.uint32(20), |
|
} |
|
], |
|
"data_offset": np.uint32(30), |
|
}, |
|
} |
|
] |
|
), |
|
), |
|
( |
|
"std_msgs", |
|
"Float32MultiArray", |
|
pa.array( |
|
[ |
|
{ |
|
"data": np.array([1, 2, 3, 4], np.float32), |
|
"layout": { |
|
"dim": [ |
|
{ |
|
"label": "a", |
|
"size": np.uint32(10), |
|
"stride": np.uint32(20), |
|
} |
|
], |
|
"data_offset": np.uint32(30), |
|
}, |
|
} |
|
] |
|
), |
|
), |
|
( |
|
"visualization_msgs", |
|
"Marker", |
|
pa.array( |
|
[ |
|
{ |
|
"header": { |
|
"frame_id": "world", |
|
}, |
|
"ns": "my_namespace", |
|
"id": np.int32(1), |
|
"type": np.int32(0), |
|
"action": np.int32(0), |
|
"lifetime": { |
|
"sec": np.int32(1), |
|
"nanosec": np.uint32(2), |
|
}, |
|
"pose": { |
|
"position": { |
|
"x": np.float64(1.0), |
|
"y": np.float64(2.0), |
|
"z": np.float64(3.0), |
|
}, |
|
"orientation": { |
|
"x": np.float64(0.0), |
|
"y": np.float64(0.0), |
|
"z": np.float64(0.0), |
|
"w": np.float64(1.0), |
|
}, |
|
}, |
|
"scale": { |
|
"x": np.float64(1.0), |
|
"y": np.float64(1.0), |
|
"z": np.float64(1.0), |
|
}, |
|
"color": { |
|
"r": np.float32(1.0), |
|
"g": np.float32(0.0), |
|
"b": np.float32(0.0), |
|
"a": np.float32(1.0), |
|
}, |
|
"frame_locked": False, |
|
"points": [ |
|
{ |
|
"x": np.float64(1.0), |
|
"y": np.float64(1.0), |
|
"z": np.float64(1.0), |
|
} |
|
], |
|
"colors": [ |
|
{ |
|
"r": np.float32(1.0), |
|
"g": np.float32(1.0), |
|
"b": np.float32(1.0), |
|
"a": np.float32(1.0), |
|
} |
|
], |
|
"texture_resource": "", |
|
"uv_coordinates": [{}], |
|
"text": "", |
|
"mesh_resource": "", |
|
"mesh_use_embedded_materials": False, |
|
} |
|
] |
|
), |
|
), |
|
( |
|
"visualization_msgs", |
|
"MarkerArray", |
|
pa.array( |
|
[ |
|
{ |
|
"markers": [ |
|
{ |
|
"header": { |
|
"frame_id": "world", |
|
}, |
|
"ns": "my_namespace", |
|
"id": np.int32(1), |
|
"type": np.int32(0), |
|
"action": np.int32(0), |
|
"lifetime": { |
|
"sec": np.int32(1), |
|
"nanosec": np.uint32(2), |
|
}, |
|
"pose": { |
|
"position": { |
|
"x": np.float64(1.0), |
|
"y": np.float64(2.0), |
|
"z": np.float64(3.0), |
|
}, |
|
"orientation": { |
|
"x": np.float64(0.0), |
|
"y": np.float64(0.0), |
|
"z": np.float64(0.0), |
|
"w": np.float64(1.0), |
|
}, |
|
}, |
|
"scale": { |
|
"x": np.float64(1.0), |
|
"y": np.float64(1.0), |
|
"z": np.float64(1.0), |
|
}, |
|
"color": { |
|
"r": np.float32(1.0), |
|
"g": np.float32(0.0), |
|
"b": np.float32(0.0), |
|
"a": np.float32(1.0), |
|
}, |
|
"frame_locked": False, |
|
"points": [ |
|
{ |
|
"x": np.float64(1.0), |
|
"y": np.float64(1.0), |
|
"z": np.float64(1.0), |
|
} |
|
], |
|
"colors": [ |
|
{ |
|
"r": np.float32(1.0), |
|
"g": np.float32(1.0), |
|
"b": np.float32(1.0), |
|
"a": np.float32(1.0), |
|
} |
|
], |
|
"texture_resource": "", |
|
"uv_coordinates": [{}], |
|
"text": "", |
|
"mesh_resource": "", |
|
"mesh_use_embedded_materials": False, |
|
} |
|
] |
|
} |
|
] |
|
), |
|
), |
|
( |
|
"visualization_msgs", |
|
"ImageMarker", |
|
pa.array( |
|
[ |
|
{ |
|
"header": { |
|
"stamp": { |
|
"sec": np.int32(123456), |
|
"nanosec": np.uint32(789), |
|
}, |
|
"frame_id": "frame_example", |
|
}, |
|
"ns": "namespace", |
|
"id": np.int32(1), |
|
"type": np.int32(0), |
|
"action": np.int32(0), |
|
"position": { |
|
"x": np.float64(1.0), |
|
"y": np.float64(2.0), |
|
"z": np.float64(3.0), |
|
}, |
|
"scale": np.float32(1.0), |
|
"outline_color": { |
|
"r": np.float32(255.0), |
|
"g": np.float32(0.0), |
|
"b": np.float32(0.0), |
|
"a": np.float32(1.0), |
|
}, |
|
"filled": np.uint8(1), |
|
"fill_color": { |
|
"r": np.float32(0.0), |
|
"g": np.float32(255.0), |
|
"b": np.float32(0.0), |
|
"a": np.float32(1.0), |
|
}, |
|
"lifetime": { |
|
"sec": np.int32(300), |
|
"nanosec": np.uint32(0), |
|
}, |
|
"points": [ |
|
{ |
|
"x": np.float64(1.0), |
|
"y": np.float64(2.0), |
|
"z": np.float64(3.0), |
|
}, |
|
{ |
|
"x": np.float64(4.0), |
|
"y": np.float64(5.0), |
|
"z": np.float64(6.0), |
|
}, |
|
], |
|
"outline_colors": [ |
|
{ |
|
"r": np.float32(255.0), |
|
"g": np.float32(0.0), |
|
"b": np.float32(0.0), |
|
"a": np.float32(1.0), |
|
}, |
|
{ |
|
"r": np.float32(0.0), |
|
"g": np.float32(255.0), |
|
"b": np.float32(0.0), |
|
"a": np.float32(1.0), |
|
}, |
|
], |
|
} |
|
] |
|
), |
|
), |
|
] |
|
|
|
|
|
def is_subset(subset, superset): |
|
""" |
|
Check if subset is a subset of superset, to avoid false negatives linked to default values. |
|
""" |
|
if isinstance(subset, pa.Array): |
|
return is_subset(subset.to_pylist(), superset.to_pylist()) |
|
|
|
match subset: |
|
case dict(_): |
|
return all( |
|
key in superset and is_subset(val, superset[key]) |
|
for key, val in subset.items() |
|
) |
|
case list(_) | set(_): |
|
return all( |
|
any(is_subset(subitem, superitem) for superitem in superset) |
|
for subitem in subset |
|
) |
|
|
|
case _: |
|
return subset == superset |
|
|