Skip to content

Commit abd35b0

Browse files
authored
Merge pull request #193 from zyang37/bug
bug:fix variable.py convert numpy int to int before assert
2 parents 4ac6c86 + 690985b commit abd35b0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

textgrad/variable.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ def __init__(
4040
raise Exception("If the variable does not require grad, none of its predecessors should require grad."
4141
f"In this case, following predecessors require grad: {_predecessor_requires_grad}")
4242

43+
# Handle numpy types by converting them to native Python types
44+
try:
45+
import numpy as np
46+
if isinstance(value, np.integer):
47+
value = int(value)
48+
elif isinstance(value, np.floating):
49+
value = float(value)
50+
except ImportError:
51+
pass # numpy not available, continue without conversion
52+
4353
assert type(value) in [str, bytes, int], "Value must be a string, int, or image (bytes). Got: {}".format(type(value))
4454
if isinstance(value, int):
4555
value = str(value)

0 commit comments

Comments
 (0)