Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9e46e6b4
提交
9e46e6b4
authored
1月 31, 2026
作者:
ricardoV94
提交者:
Ricardo Vieira
2月 05, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle constants in XTensorType.filter_variable
上级
cc4b77a0
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
2 行删除
+33
-2
type.py
pytensor/xtensor/type.py
+1
-1
test_type.py
tests/xtensor/test_type.py
+32
-1
没有找到文件。
pytensor/xtensor/type.py
浏览文件 @
9e46e6b4
...
@@ -103,7 +103,7 @@ class XTensorType(Type, HasDataType, HasShape):
...
@@ -103,7 +103,7 @@ class XTensorType(Type, HasDataType, HasShape):
if
not
isinstance
(
other
,
Variable
):
if
not
isinstance
(
other
,
Variable
):
# The value is not a Variable: we cast it into
# The value is not a Variable: we cast it into
# a Constant of the appropriate Type.
# a Constant of the appropriate Type.
other
=
xtensor_constant
(
other
)
other
=
XTensorConstant
(
type
=
self
,
data
=
other
)
if
self
.
is_super
(
other
.
type
):
if
self
.
is_super
(
other
.
type
):
return
other
return
other
...
...
tests/xtensor/test_type.py
浏览文件 @
9e46e6b4
...
@@ -10,7 +10,7 @@ from xarray import DataArray
...
@@ -10,7 +10,7 @@ from xarray import DataArray
from
pytensor.graph.basic
import
equal_computations
from
pytensor.graph.basic
import
equal_computations
from
pytensor.tensor
import
as_tensor
,
specify_shape
,
tensor
from
pytensor.tensor
import
as_tensor
,
specify_shape
,
tensor
from
pytensor.xtensor
import
xtensor
from
pytensor.xtensor
import
xtensor
from
pytensor.xtensor.type
import
XTensorType
,
as_xtensor
from
pytensor.xtensor.type
import
XTensor
Constant
,
XTensor
Type
,
as_xtensor
def
test_xtensortype
():
def
test_xtensortype
():
...
@@ -77,6 +77,37 @@ def test_xtensortype_filter_variable():
...
@@ -77,6 +77,37 @@ def test_xtensortype_filter_variable():
x
.
type
.
filter_variable
(
z4
)
x
.
type
.
filter_variable
(
z4
)
def
test_xtensortype_filter_variable_constant
():
x
=
xtensor
(
"x"
,
dims
=
(
"a"
,
"b"
),
shape
=
(
2
,
3
),
dtype
=
"float32"
)
valid_x
=
np
.
zeros
((
2
,
3
),
dtype
=
"float32"
)
res
=
x
.
type
.
filter_variable
(
valid_x
)
assert
isinstance
(
res
,
XTensorConstant
)
and
res
.
type
==
x
.
type
# Upcasting allowed
valid_x
=
np
.
zeros
((
2
,
3
),
dtype
=
"float16"
)
res
=
x
.
type
.
filter_variable
(
valid_x
)
assert
isinstance
(
res
,
XTensorConstant
)
and
res
.
type
==
x
.
type
valid_x
=
np
.
zeros
((
2
,
3
),
dtype
=
"int16"
)
res
=
x
.
type
.
filter_variable
(
valid_x
)
assert
isinstance
(
res
,
XTensorConstant
)
and
res
.
type
==
x
.
type
# Downcasting not allowed
invalid_x
=
np
.
zeros
((
2
,
3
),
dtype
=
"float64"
)
with
pytest
.
raises
(
TypeError
):
x
.
type
.
filter_variable
(
invalid_x
)
invalid_x
=
np
.
zeros
((
2
,
3
),
dtype
=
"int32"
)
with
pytest
.
raises
(
TypeError
):
x
.
type
.
filter_variable
(
invalid_x
)
# non_array types are fine
valid_x
=
[[
0
,
0
,
0
],
[
0
,
0
,
0
]]
res
=
x
.
type
.
filter_variable
(
valid_x
)
assert
isinstance
(
res
,
XTensorConstant
)
and
res
.
type
==
x
.
type
def
test_xtensor_constant
():
def
test_xtensor_constant
():
x
=
as_xtensor
(
DataArray
(
np
.
ones
((
2
,
3
)),
dims
=
(
"a"
,
"b"
)))
x
=
as_xtensor
(
DataArray
(
np
.
ones
((
2
,
3
)),
dims
=
(
"a"
,
"b"
)))
assert
x
.
type
==
XTensorType
(
dtype
=
"float64"
,
dims
=
(
"a"
,
"b"
),
shape
=
(
2
,
3
))
assert
x
.
type
==
XTensorType
(
dtype
=
"float64"
,
dims
=
(
"a"
,
"b"
),
shape
=
(
2
,
3
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论