o >g_@s<ddlZGdddZGdddZeedZdddZdS) Nc@sdeZdZeddZdZdZdZdZdZ e dd Z e d d Z e d d Z e ddZddZdS) LatentRebatchcCdddddddfdiS)NrequiredLATENTINTdefaultminmax)latents batch_sizesrrD/home/comdoleger1/zen-flux-style-shape/comfy_extras/nodes_rebatch.py INPUT_TYPESzLatentRebatch.INPUT_TYPESrTTrebatchz latent/batchcsB||d}|j}d||vr||dntj|dd|dd|ddfdd }|jd |d dks>|jd |d kr_tjjj|d d|jd |jd f|d d|d dfd d |jd|jdkr||dd|jdddddd|d}d||vr||d}n fddt|dD}|||fS)z*prepare a batch out of the list of latentssamples noise_maskrrcpu)devicebilinear)sizemodeN batch_indexcsg|]}|qSrr.0xoffsetrr sz+LatentRebatch.get_batch..) shapetorchonesnn functional interpolatereshaperepeatrange)rZlist_indr)rr+mask batch_indsrr(r get_batchs B(B2  zLatentRebatch.get_batchcCs\g}t|D]}|||||d|q||t|kr*||||dfS|dfS)zQdivides an indexable object into num slices of length batch_size, and a remainderrN)r3appendlen) indexablenumrslicesirrr get_slices!s   zLatentRebatch.get_slicescs fdd|D}tt|S)Ncsg|] }t|qSr)rr=r%rr:rrr*.sz-LatentRebatch.slice_batch..)listzip)batchr:rresultrr>r slice_batch,s zLatentRebatch.slice_batchcCs(|ddur|Sddt||D}|S)NrcSs0g|]\}}t|rt||fn||qSr)r, is_tensorcat)r&b1b2rrrr*5s0z+LatentRebatch.cat_batch..)r@)batch1batch2rBrrr cat_batch1s zLatentRebatch.cat_batchc Cs|d}g}d}d}tt|D]}||||}|t|d7}|ddur*|}nC|djd|djdksF|djd|djdkrg||d|\}} ||dd|dd|ddd|}n|||}|djd|kr|djd|} ||| |\}} t| D]}||d||d||d|dq| }q|ddur||d|\}} ||dd|dd|ddd|D] } | dd kr| d=q|fS) Nr)NNNrrr r)rrr$rg?)r3r8r6r+rCr7rJmean) selfrr output_listZ current_batch processedr<Z next_batchsliced_r: remainderrrrrr8s: 8*  , *zLatentRebatch.rebatchN)__name__ __module__ __qualname__ classmethodr RETURN_TYPES INPUT_IS_LISTOUTPUT_IS_LISTFUNCTIONCATEGORY staticmethodr6r=rCrJrrrrrrs"      rc@s4eZdZeddZdZdZdZdZdZ dd Z d S) ImageRebatchcCr)NrIMAGErrr r )imagesrrrrrrrgrzImageRebatch.INPUT_TYPESr]Trrz image/batchcCs|d}g}g}|D]}t|jdD] }||||dqq tdt||D]}|tj||||ddq*|fS)Nrr)dim)r3r+r7r8r,rE)rLr_rrMZ all_imagesimgr<rrrrts"zImageRebatch.rebatchN) rRrSrTrUrrVrWrXrYrZrrrrrr\fs  r\)ZRebatchLatentsZ RebatchImageszRebatch LatentszRebatch Images)r,rr\NODE_CLASS_MAPPINGSNODE_DISPLAY_NAME_MAPPINGSrrrrsc