diff --git a/more_math/Parser/UnifiedMathVisitor.py b/more_math/Parser/UnifiedMathVisitor.py index 56d1b29..77a9c4d 100644 --- a/more_math/Parser/UnifiedMathVisitor.py +++ b/more_math/Parser/UnifiedMathVisitor.py @@ -2550,10 +2550,13 @@ class UnifiedMathVisitor(MathExprVisitor): def _bitwise_op(self, a, b, torch_op, scalar_op,ctx): """Binary bitwise operation handler supporting tensors, lists, and scalars.""" - if self._is_tensor(a) and a.numel() == 1: - a = int(a.flatten()[0].item()) - if self._is_tensor(b) and b.numel() == 1: - b = int(b.flatten()[0].item()) + try: + if self._is_tensor(a) and a.numel() == 1: + a = int(a.flatten()[0].item()) + if self._is_tensor(b) and b.numel() == 1: + b = int(b.flatten()[0].item()) + except Exception as e: + raise ValueError(f"Invalid tensor value for bitwise operation: {e}") # Handle tensor-list combinations if self._is_tensor(a) and self._is_list(b):