From e4e5b21b5677311467a7d864dc36a8a5889a384b Mon Sep 17 00:00:00 2001 From: mcDandy Date: Sun, 22 Feb 2026 16:15:10 +0100 Subject: [PATCH] crop works as substr --- more_math/Parser/UnifiedMathVisitor.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/more_math/Parser/UnifiedMathVisitor.py b/more_math/Parser/UnifiedMathVisitor.py index cdade3e..8ea6473 100644 --- a/more_math/Parser/UnifiedMathVisitor.py +++ b/more_math/Parser/UnifiedMathVisitor.py @@ -752,8 +752,6 @@ class UnifiedMathVisitor(MathExprVisitor): pos_list = yield ctx.expr(1) size_list = yield ctx.expr(2) - inp = self._promote_to_tensor(inp) - def to_int_list(x): if self._is_list(x): return [int(v) for v in x] if self._is_tensor(x): return x.int().tolist() @@ -762,6 +760,16 @@ class UnifiedMathVisitor(MathExprVisitor): p_l = to_int_list(pos_list) s_l = to_int_list(size_list) + # Handle strings + if isinstance(inp, str): + start = p_l[0] if p_l else 0 + length = s_l[0] if s_l else len(inp) + start = max(0, start) + end = min(len(inp), start + length) + return inp[start:end] + + inp = self._promote_to_tensor(inp) + if len(p_l) != inp.ndim or len(s_l) != inp.ndim: # Basic safety fallback if dims don't match, though robust logic might handle slices properly if we truncate? # Let's enforce or just take first N?