Skip to content

Commit bb56010

Browse files
committed
Fix overflow issue
1 parent d314dfe commit bb56010

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pytensor/tensor/basic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,6 +3224,8 @@ def __init__(self, dtype):
32243224
self.dtype = dtype
32253225

32263226
def make_node(self, start, stop, step):
3227+
from math import ceil
3228+
32273229
types = TensorConstant
32283230
shape = (None,)
32293231
# if it is possible to directly determine the shape i.e static shape is present, we find it.
@@ -3232,11 +3234,9 @@ def make_node(self, start, stop, step):
32323234
and isinstance(stop, types)
32333235
and isinstance(step, types)
32343236
):
3237+
# Convert to int32 or int64 before calculation
32353238
length = max(
3236-
np.max(np.ceil((stop.value - start.value) / step.value))
3237-
.astype(int)
3238-
.item(),
3239-
0,
3239+
ceil((float(stop.value) - float(start.value)) / float(step.value)), 0
32403240
)
32413241
shape = (length,)
32423242

tests/tensor/test_basic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,7 @@ def test_static_shape(self):
28662866
assert np.arange(10, 1, -1).shape == arange(10, 1, -1).type.shape
28672867
assert np.arange(1, -9, 2).shape == arange(1, -9, 2).type.shape
28682868
assert np.arange(1.3, 17.48, 2.67).shape == arange(1.3, 17.48, 2.67).type.shape
2869+
assert np.arange(-64, 64).shape == arange(-64, 64).type.shape
28692870

28702871

28712872
class TestNdGrid:

0 commit comments

Comments
 (0)