Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 7856f72

Browse files
committed
Replace floor_div with floor_divide
1 parent 7cef42f commit 7856f72

13 files changed

Lines changed: 49 additions & 36 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ d = a/a + (M + a).dot(v)
7070
aesara.dprint(d)
7171
# Elemwise{add,no_inplace} [id A] ''
7272
# |InplaceDimShuffle{x} [id B] ''
73-
# | |Elemwise{true_div,no_inplace} [id C] ''
73+
# | |Elemwise{true_divide,no_inplace} [id C] ''
7474
# | |a [id D]
7575
# | |a [id D]
7676
# |dot [id E] ''

aesara/scalar/basic.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def __truediv__(self, other):
797797
return true_divide(self, other)
798798

799799
def __floordiv__(self, other):
800-
return int_div(self, other)
800+
return floor_divide(self, other)
801801

802802
def __mod__(self, other):
803803
return mod_check(self, other)
@@ -2133,8 +2133,7 @@ def grad(self, inputs, g_output):
21332133
return [inp.zeros_like(dtype=config.floatX) for inp in inputs]
21342134

21352135

2136-
floor_divide = IntDiv(upcast_out, name="int_div")
2137-
2136+
floor_divide = IntDiv(upcast_out, name="floor_divide")
21382137

21392138
int_div = floor_divide
21402139

@@ -2871,7 +2870,7 @@ def c_code(self, node, name, inputs, outputs, sub):
28712870
pprint.assign(sub, printing.OperatorPrinter("-", -2, "left"))
28722871
pprint.assign(neg, printing.OperatorPrinter("-", 0, "either"))
28732872
pprint.assign(true_divide, printing.OperatorPrinter("/", -1, "left"))
2874-
pprint.assign(int_div, printing.OperatorPrinter("//", -1, "left"))
2873+
pprint.assign(floor_divide, printing.OperatorPrinter("//", -1, "left"))
28752874
pprint.assign(pow, printing.OperatorPrinter("**", 1, "right"))
28762875
pprint.assign(mod, printing.OperatorPrinter("%", -1, "left"))
28772876

aesara/tensor/elemwise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class Elemwise(OpenMPOp):
327327
the second input is completed along the first dimension to match the first input
328328
-``Elemwise(true_divide)(np.random.random(10, 5), np.random.random(10, 1))``: same but along the
329329
second dimension
330-
-``Elemwise(int_div)(np.random.random((1, 5)), np.random.random((10, 1)))``:
330+
-``Elemwise(floor_div)(np.random.random((1, 5)), np.random.random((10, 1)))``:
331331
the output has size ``(10, 5)``.
332332
-``Elemwise(log)(np.random.random((3, 4, 5)))``
333333

aesara/tensor/inplace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ def mul_inplace(a, b):
368368

369369

370370
@scalar_elemwise
371-
def true_div_inplace(a, b):
371+
def true_divide_inplace(a, b):
372372
"""elementwise division (inplace on `a`)"""
373373

374374

375375
@scalar_elemwise
376-
def int_div_inplace(a, b):
376+
def floor_divide_inplace(a, b):
377377
"""elementwise division (inplace on `a`)"""
378378

379379

@@ -401,8 +401,8 @@ def hyp2f1_inplace(a, b, c, z):
401401
pprint.assign(mul_inplace, printing.OperatorPrinter("*=", -1, "either"))
402402
pprint.assign(sub_inplace, printing.OperatorPrinter("-=", -2, "left"))
403403
pprint.assign(neg_inplace, printing.OperatorPrinter("-=", 0, "either"))
404-
pprint.assign(true_div_inplace, printing.OperatorPrinter("/=", -1, "left"))
405-
pprint.assign(int_div_inplace, printing.OperatorPrinter("//=", -1, "left"))
404+
pprint.assign(true_divide_inplace, printing.OperatorPrinter("/=", -1, "left"))
405+
pprint.assign(floor_divide_inplace, printing.OperatorPrinter("//=", -1, "left"))
406406
pprint.assign(pow_inplace, printing.OperatorPrinter("**=", 1, "right"))
407407

408408

aesara/tensor/math.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,13 +1800,13 @@ def true_divide(a, b):
18001800

18011801

18021802
@scalar_elemwise
1803-
def int_div(a, b):
1803+
def floor_divide(a, b):
18041804
"""elementwise [floor] division (inverse of multiplication)"""
18051805
# see decorator for function body
18061806

18071807

18081808
# floor_divide and int_div are the same thing
1809-
floor_divide = int_div
1809+
int_div = floor_divide
18101810

18111811

18121812
def ceil_intdiv(a, b):
@@ -1824,7 +1824,7 @@ def ceil_intdiv(a, b):
18241824

18251825
# We cast for the case when a and b are uint*; otherwise, neq will
18261826
# force their upcast to int.
1827-
div = int_div(a, b)
1827+
div = floor_divide(a, b)
18281828
ret = cast(neq(a % b, 0), div.dtype) + div
18291829
assert ret.dtype == aes.upcast(
18301830
div.owner.inputs[0].type.dtype, div.owner.inputs[1].type.dtype
@@ -1877,7 +1877,7 @@ def clip(x, min, max):
18771877
pprint.assign(sub, printing.OperatorPrinter("-", -2, "left"))
18781878
pprint.assign(neg, printing.OperatorPrinter("-", 0, "either"))
18791879
pprint.assign(true_divide, printing.OperatorPrinter("/", -1, "left"))
1880-
pprint.assign(int_div, printing.OperatorPrinter("//", -1, "left"))
1880+
pprint.assign(floor_divide, printing.OperatorPrinter("//", -1, "left"))
18811881
pprint.assign(pow, printing.OperatorPrinter("**", 1, "right"))
18821882

18831883

aesara/tensor/rewriting/math.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
erfc,
5757
exp,
5858
expm1,
59+
floor_divide,
5960
ge,
60-
int_div,
6161
isinf,
6262
le,
6363
log,
@@ -568,7 +568,7 @@ def local_mul_switch_sink(fgraph, node):
568568

569569

570570
@register_canonicalize
571-
@node_rewriter([true_divide, int_div])
571+
@node_rewriter([true_divide, floor_divide])
572572
def local_div_switch_sink(fgraph, node):
573573
"""
574574
This rewrite makes the following changes in the graph:
@@ -584,7 +584,7 @@ def local_div_switch_sink(fgraph, node):
584584
See `local_mul_switch_sink` for more details.
585585
586586
"""
587-
if node.op != true_divide and node.op != int_div:
587+
if node.op != true_divide and node.op != floor_divide:
588588
return False
589589
op = node.op
590590
if node.inputs[0].owner and node.inputs[0].owner.op == switch:
@@ -1939,10 +1939,10 @@ def local_mul_to_sqr(fgraph, node):
19391939

19401940

19411941
@register_canonicalize
1942-
@node_rewriter([int_div])
1942+
@node_rewriter([floor_divide])
19431943
def local_intdiv_by_one(fgraph, node):
19441944
"""x // 1 -> x"""
1945-
if node.op in [int_div]:
1945+
if node.op in [floor_divide]:
19461946
if isinstance(node.inputs[1], TensorConstant) and np.all(
19471947
node.inputs[1].value == 1
19481948
):
@@ -1951,7 +1951,7 @@ def local_intdiv_by_one(fgraph, node):
19511951

19521952
@register_canonicalize
19531953
@register_specialize
1954-
@node_rewriter([int_div, true_divide])
1954+
@node_rewriter([floor_divide, true_divide])
19551955
def local_zero_div(fgraph, node):
19561956
"""0 / x -> 0"""
19571957
if isinstance(node.op, Elemwise) and isinstance(

tests/scalar/test_basic.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ def _test_binary(binary_op, x_range, y_range):
356356
assert outi.dtype == outf.dtype, "incorrect dtype"
357357
assert np.allclose(outi, outf), "insufficient precision"
358358

359-
def test_true_div(self):
360-
# true_div's upcast policy is not exactly "upgrade_to_float",
359+
def test_true_divide(self):
360+
# true_divide's upcast policy is not exactly "upgrade_to_float",
361361
# so the test is a little bit different
362362
x_range = list(range(-127, 128))
363363
y_range = list(range(-127, 0)) + list(range(1, 127))
@@ -547,3 +547,15 @@ def test_deprecations():
547547

548548
with pytest.deprecated_call():
549549
from aesara.scalar import Scalar # noqa: F401 F811
550+
551+
with pytest.deprecated_call():
552+
from aesara.scalar.basic import floor_div # noqa: F401 F811
553+
554+
with pytest.deprecated_call():
555+
from aesara.scalar import floor_div # noqa: F401 F811
556+
557+
with pytest.deprecated_call():
558+
from aesara.scalar.basic import int_div # noqa: F401 F811
559+
560+
with pytest.deprecated_call():
561+
from aesara.scalar import int_div # noqa: F401 F811

tests/tensor/rewriting/test_basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
floor_divide,
4141
ge,
4242
gt,
43-
int_div,
4443
le,
4544
log,
4645
lt,
@@ -1084,7 +1083,6 @@ class TestLocalMergeSwitchSameCond:
10841083
sub,
10851084
mul,
10861085
true_divide,
1087-
int_div,
10881086
floor_divide,
10891087
minimum,
10901088
maximum,

tests/tensor/rewriting/test_elemwise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
dot,
2929
eq,
3030
exp,
31-
int_div,
31+
floor_divide,
3232
invert,
3333
iround,
3434
log,
@@ -627,7 +627,7 @@ def my_init(dtype="float64", num=0):
627627
"float32",
628628
),
629629
(
630-
fx - int_div(ix * 100, iy * 1000),
630+
fx - floor_divide(ix * 100, iy * 1000),
631631
(fx, ix, iy),
632632
(fxv, ixv, iyv),
633633
1,

tests/tensor/rewriting/test_math.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
floor_divide,
5959
ge,
6060
gt,
61-
int_div,
6261
invert,
6362
iround,
6463
le,
@@ -1447,7 +1446,7 @@ def my_init(shp, dtype="float64", num=0):
14471446
"float32",
14481447
),
14491448
(
1450-
fx - int_div(ix * 100, iy * 1000),
1449+
fx - floor_divide(ix * 100, iy * 1000),
14511450
(fx, ix, iy),
14521451
(fxv, ixv, iyv),
14531452
1,
@@ -3133,7 +3132,6 @@ def test_elemwise(self):
31333132
sub,
31343133
mul,
31353134
true_divide,
3136-
int_div,
31373135
floor_divide,
31383136
minimum,
31393137
maximum,
@@ -3951,7 +3949,7 @@ def test3(self):
39513949

39523950

39533951
@pytest.mark.parametrize("t", [scalar, ivector, ftensor4])
3954-
@pytest.mark.parametrize("op", [int_div, true_divide])
3952+
@pytest.mark.parametrize("op", [floor_divide, true_divide])
39553953
def test_local_zero_div(t, op):
39563954
"""Test the canonicalization ``0/x -> 0``."""
39573955
x = t("x")

0 commit comments

Comments
 (0)