From e72efd4934d229a9e6f94bf83d550cd5fa0aadd6 Mon Sep 17 00:00:00 2001 From: Daniel HUANG <75546345+Hykaruu@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:00:52 +0800 Subject: [PATCH] Update variable.py Fix assertion was being thrown when numpy.int64 detected while it shouldn't --- textgrad/variable.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/textgrad/variable.py b/textgrad/variable.py index 01b9020..ef5f46c 100644 --- a/textgrad/variable.py +++ b/textgrad/variable.py @@ -40,8 +40,8 @@ def __init__( raise Exception("If the variable does not require grad, none of its predecessors should require grad." f"In this case, following predecessors require grad: {_predecessor_requires_grad}") - assert type(value) in [str, bytes, int], "Value must be a string, int, or image (bytes). Got: {}".format(type(value)) - if isinstance(value, int): + assert isinstance(value, (str, bytes, int)) or np.issubdtype(type(value), np.integer), "Value must be a string, int, or image (bytes). Got: {}".format(type(value)) + if isinstance(value, int) or np.issubdtype(type(value), np.integer): value = str(value) # We'll currently let "empty variables" slide, but we'll need to handle this better in the future. # if value == "" and image_path == "": @@ -354,4 +354,4 @@ def _backward_idempotent(variables: List[Variable], summation: Variable, backwar variable.gradients.add(Variable(value=variable_gradient_value, role_description=f"feedback to {variable.get_role_description()}")) - \ No newline at end of file +