LIST / BATCH 入力を any_* と length に分解。MASK バッチの [B,1,H,W] 正規化と旧名 Any List Split の互換登録を含む。 Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
808 B
JavaScript
34 lines
808 B
JavaScript
/**
|
|
* Any Split — BATCH テンソル形状の正規化(ComfyUI 非依存)。
|
|
*
|
|
* Python ``_canonicalize_batch_tensor`` と同等の shape 判定。
|
|
*/
|
|
|
|
/**
|
|
* @param {number} ndim
|
|
* @param {number[]} shape
|
|
* @returns {{ ndim: number, shape: number[] }}
|
|
*/
|
|
export function canonicalizeBatchTensorShape(ndim, shape) {
|
|
if (ndim === 4 && shape[1] === 1) {
|
|
return { ndim: 3, shape: [shape[0], shape[2], shape[3]] }
|
|
}
|
|
return { ndim, shape: [...shape] }
|
|
}
|
|
|
|
/**
|
|
* @param {number} ndim
|
|
* @param {number[]} shape
|
|
* @returns {number|null}
|
|
*/
|
|
export function batchSizeFromTensorShape(ndim, shape) {
|
|
const canon = canonicalizeBatchTensorShape(ndim, shape)
|
|
if (canon.ndim === 2) {
|
|
return 1
|
|
}
|
|
if (canon.ndim >= 1 && canon.shape.length) {
|
|
return canon.shape[0]
|
|
}
|
|
return null
|
|
}
|