Skip to content

Commit 38f697d

Browse files
Add a LatentConcat node. (Comfy-Org#9587)
1 parent 3aad339 commit 38f697d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

comfy_extras/nodes_latent.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,38 @@ def op(self, samples1, samples2, ratio):
105105
samples_out["samples"] = st * (m1 * ratio + m2 * (1.0 - ratio))
106106
return (samples_out,)
107107

108+
class LatentConcat:
109+
@classmethod
110+
def INPUT_TYPES(s):
111+
return {"required": { "samples1": ("LATENT",), "samples2": ("LATENT",), "dim": (["x", "-x", "y", "-y", "t", "-t"], )}}
112+
113+
RETURN_TYPES = ("LATENT",)
114+
FUNCTION = "op"
115+
116+
CATEGORY = "latent/advanced"
117+
118+
def op(self, samples1, samples2, dim):
119+
samples_out = samples1.copy()
120+
121+
s1 = samples1["samples"]
122+
s2 = samples2["samples"]
123+
s2 = comfy.utils.repeat_to_batch_size(s2, s1.shape[0])
124+
125+
if "-" in dim:
126+
c = (s2, s1)
127+
else:
128+
c = (s1, s2)
129+
130+
if "x" in dim:
131+
dim = -1
132+
elif "y" in dim:
133+
dim = -2
134+
elif "t" in dim:
135+
dim = -3
136+
137+
samples_out["samples"] = torch.cat(c, dim=dim)
138+
return (samples_out,)
139+
108140
class LatentBatch:
109141
@classmethod
110142
def INPUT_TYPES(s):
@@ -279,6 +311,7 @@ def sharpen(latent, **kwargs):
279311
"LatentSubtract": LatentSubtract,
280312
"LatentMultiply": LatentMultiply,
281313
"LatentInterpolate": LatentInterpolate,
314+
"LatentConcat": LatentConcat,
282315
"LatentBatch": LatentBatch,
283316
"LatentBatchSeedBehavior": LatentBatchSeedBehavior,
284317
"LatentApplyOperation": LatentApplyOperation,

0 commit comments

Comments
 (0)