Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f83c05ba
Unverified
提交
f83c05ba
authored
10月 28, 2025
作者:
Copilot
提交者:
GitHub
10月 28, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `__rtruediv__` and `__rfloordiv__` to Scalar variables (#1701)
Also remove legacy `__div__`
上级
112b3252
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
22 行删除
+24
-22
basic.py
pytensor/scalar/basic.py
+6
-0
variable.py
pytensor/tensor/variable.py
+0
-16
type.py
pytensor/xtensor/type.py
+0
-6
test_basic.py
tests/scalar/test_basic.py
+18
-0
没有找到文件。
pytensor/scalar/basic.py
浏览文件 @
f83c05ba
...
...
@@ -943,6 +943,12 @@ class _scalar_py_operators:
def
__rmul__
(
self
,
other
):
return
mul
(
other
,
self
)
def
__rtruediv__
(
self
,
other
):
return
true_div
(
other
,
self
)
def
__rfloordiv__
(
self
,
other
):
return
int_div
(
other
,
self
)
def
__rmod__
(
self
,
other
):
return
mod
(
other
,
self
)
...
...
pytensor/tensor/variable.py
浏览文件 @
f83c05ba
...
...
@@ -13,7 +13,6 @@ from pytensor.graph.basic import Constant, OptionalApplyType, Variable
from
pytensor.graph.utils
import
MetaType
from
pytensor.scalar
import
(
ComplexError
,
IntegerDivisionError
,
)
from
pytensor.tensor
import
_get_vector_length
from
pytensor.tensor.exceptions
import
AdvancedIndexingError
...
...
@@ -138,18 +137,6 @@ class _tensor_py_operators:
except
(
NotImplementedError
,
TypeError
):
return
NotImplemented
def
__div__
(
self
,
other
):
# See explanation in __add__ for the error caught
# and the return value in that case
try
:
return
pt
.
math
.
div_proxy
(
self
,
other
)
except
IntegerDivisionError
:
# This is to raise the exception that occurs when trying to divide
# two integer arrays (currently forbidden).
raise
except
(
NotImplementedError
,
TypeError
):
return
NotImplemented
def
__pow__
(
self
,
other
):
# See explanation in __add__ for the error caught
# and the return value in that case
...
...
@@ -210,9 +197,6 @@ class _tensor_py_operators:
def
__rmul__
(
self
,
other
):
return
pt
.
math
.
mul
(
other
,
self
)
def
__rdiv__
(
self
,
other
):
return
pt
.
math
.
div_proxy
(
other
,
self
)
def
__rmod__
(
self
,
other
):
return
pt
.
math
.
mod
(
other
,
self
)
...
...
pytensor/xtensor/type.py
浏览文件 @
f83c05ba
...
...
@@ -308,9 +308,6 @@ class XTensorVariable(Variable[_XTensorTypeType, OptionalApplyType]):
def
__mul__
(
self
,
other
):
return
px
.
math
.
mul
(
self
,
other
)
def
__div__
(
self
,
other
):
return
px
.
math
.
div
(
self
,
other
)
def
__pow__
(
self
,
other
):
return
px
.
math
.
pow
(
self
,
other
)
...
...
@@ -341,9 +338,6 @@ class XTensorVariable(Variable[_XTensorTypeType, OptionalApplyType]):
def
__rmul__
(
self
,
other
):
return
px
.
math
.
mul
(
other
,
self
)
def
__rdiv__
(
self
,
other
):
return
px
.
math
.
div_proxy
(
other
,
self
)
def
__rmod__
(
self
,
other
):
return
px
.
math
.
mod
(
other
,
self
)
...
...
tests/scalar/test_basic.py
浏览文件 @
f83c05ba
...
...
@@ -10,7 +10,9 @@ from pytensor.scalar.basic import (
EQ
,
ComplexError
,
Composite
,
IntDiv
,
ScalarType
,
TrueDiv
,
add
,
and_
,
arccos
,
...
...
@@ -531,3 +533,19 @@ def test_scalar_hash_default_output_type_preference():
del
old_eq
.
output_types_preference
# mimic old Op
assert
new_eq
==
old_eq
assert
hash
(
new_eq
)
==
hash
(
old_eq
)
def
test_rtruediv
():
x
=
ScalarType
(
dtype
=
"float64"
)()
y
=
1.0
/
x
assert
isinstance
(
y
.
owner
.
op
,
TrueDiv
)
assert
isinstance
(
y
.
type
,
ScalarType
)
assert
y
.
eval
({
x
:
2.0
})
==
0.5
def
test_rfloordiv
():
x
=
ScalarType
(
dtype
=
"float64"
)()
y
=
5.0
//
x
assert
isinstance
(
y
.
owner
.
op
,
IntDiv
)
assert
isinstance
(
y
.
type
,
ScalarType
)
assert
y
.
eval
({
x
:
2.0
})
==
2.0
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论