diff --git a/README.md b/README.md index 8b5989e..b2f8106 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ You can also get the node from comfy manager under the name of More math. - Boolean: `<`, `<=`, `>`, `>=`, `==`, `!=` (`false = 0.0`, `true = 1.0`) - Lists: `[v1, v2, ...]` (Vector math supported, mostly usefull in `conv` and `permute`) - - You can also use lists to do math with input tensor (image, noise, conditioing, latent, audio) which results in batched output. + - You can also use lists to do math with input tensor (image, noise, conditioing, latent, audio) which results in batched output as long as batch size is different to list size. - print_shape(a) = torch.Shape[1,1024,1024,3]; b = a*[0,0.2,-0.3]; print_shape(b) = torch.Shape[3,1024,1024,3] - You can <operator> batched tensor with another tensor which is not batched (dim[0] = 1) - the non batched tensor will be duplicated along batch dimension - In imageMath node you can use 3 element list to specify a color of image. You cannot use any imput tensor, doing so will result in behaviour in subpoint 1 in list diff --git a/more_math/Parser/UnifiedMathVisitor.py b/more_math/Parser/UnifiedMathVisitor.py index 0371bd0..a1db845 100644 --- a/more_math/Parser/UnifiedMathVisitor.py +++ b/more_math/Parser/UnifiedMathVisitor.py @@ -34,7 +34,10 @@ class UnifiedMathVisitor(MathExprVisitor): """ # one of them is a list and one is tensor if self._is_tensor(a) and self._is_list(b): - return torch.cat([self._bin_op(a, x, torch_op, scalar_op) for x in b], dim=0) + if(a.shape[0]==len(b)): + c = torch.split(a,1) + return torch.cat([self._bin_op(x, y, torch_op, scalar_op) for x,y in zip(a,c)],dim=0) + return torch.cat([self._bin_op(a, x, torch_op, scalar_op) for x in b], dim=0) if self._is_list(a) and self._is_tensor(b): if(b.shape[0]==len(a)): c = torch.split(a,1)