From fff14743d0d64488362504ab8b603b1cd376a0b5 Mon Sep 17 00:00:00 2001 From: City <125218114+city96@users.noreply.github.com> Date: Sun, 30 Apr 2023 20:01:52 +0200 Subject: [PATCH] Rewrite addWeighted to use torch.mul iteratively. --- nodes.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/nodes.py b/nodes.py index abb60675b..4e4e6b55f 100644 --- a/nodes.py +++ b/nodes.py @@ -71,16 +71,14 @@ class ConditioningAverage : CATEGORY = "conditioning" def addWeighted(self, conditioning_from, conditioning_to, conditioning_from_strength): - conditioning_to_strength = (1-conditioning_from_strength) - conditioning_from_tensor = conditioning_from[0][0] - conditioning_to_tensor = conditioning_to[0][0] - output = conditioning_from - if conditioning_from_tensor.shape[0] > conditioning_to_tensor.shape[1]: - conditioning_to_tensor = torch.cat((conditioning_to_tensor, torch.zeros((1, conditioning_from_tensor.shape[1] - conditioning_to_tensor.shape[1], conditioning_from_tensor.shape[1].value))), dim=1) - elif conditioning_to_tensor.shape[1] > conditioning_from_tensor.shape[1]: - conditioning_from_tensor = torch.cat((conditioning_from_tensor, torch.zeros((1, conditioning_to_tensor.shape[1] - conditioning_from_tensor.shape[1], conditioning_to_tensor.shape[1].value))), dim=1) - output[0][0] = ((conditioning_from_tensor * conditioning_from_strength) + (conditioning_to_tensor * conditioning_to_strength)) - return (output, ) + out = [] + for i in range(min(len(conditioning_from),len(conditioning_to))): + t0 = conditioning_from[i] + t1 = conditioning_to[i] + tw = torch.mul(t0[0],(1-conditioning_from_strength)) + torch.mul(t1[0],conditioning_from_strength) + n = [tw, t0[1].copy()] + out.append(n) + return (out, ) class ConditioningSetArea: @classmethod