[docs]defpad_ragged_array(new_array,target_shape,padded_value):"""pad ragged array to match sequence lengths"""padded_array=RaggedArray([[padded_valuefor_inrange(target_shape[1][ind])]forindinrange(target_shape[0])])forrow_indinrange(target_shape[0]):np.put(padded_array[row_ind],0,new_array[row_ind])returnpadded_array
[docs]defmerge_dataclass_objects(objects:list):# TODO: replace with equivalent from npstructuresfield_names=sorted(list(set(chain.from_iterable([field.nameforfieldinget_fields(obj)]forobjinobjects))))forobjinobjects:assertall(hasattr(obj,field)forfieldinfield_names),(obj,field_names)cls=type(objects[0])returncls(**{field_name:list(chain.from_iterable([getattr(obj,field_name)forobjinobjects]))forfield_nameinfield_names})