[docs]deffill_wheatsheaf_mean_items(wheatsheaf_mean_items,wheatsheaf_items,wheatsheaf_items_start_end,maxcounts,max_summary_id,num_sidxs,):# Track start and end indices for each summary_iditems_start_end=np.full((max_summary_id,2),-1,dtype=np.int32)# Compute cumulative start indicespos=0foridxinrange(max_summary_id):ifmaxcounts[idx]>0:items_start_end[idx][0]=pos# Start indexpos+=maxcounts[idx]items_start_end[idx][1]=pos# End indexforidxinrange(max_summary_id*num_sidxs):ws_start,ws_end=wheatsheaf_items_start_end[idx]ifws_start==-1:continuesidx,summary_id=get_wheatsheaf_items_idx_data(idx,num_sidxs)filtered_items=wheatsheaf_items[ws_start:ws_end]sorted_idxs=np.argsort(filtered_items["value"])[::-1]sorted_items=filtered_items[sorted_idxs]wsm_start,wsm_end=items_start_end[summary_id-1]fori,iteminenumerate(sorted_items):# Compute position in the flat arrayinsert_idx=wsm_start+i# Store valueswheatsheaf_mean_items[insert_idx]["summary_id"]=summary_idwheatsheaf_mean_items[insert_idx]["value"]+=item["value"]returnitems_start_end