Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3db127e9
提交
3db127e9
authored
6月 20, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
6月 21, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid recreating Ops in `local_uint_constant_indices`
This prevents undoing the rewrite that introduces AdvancedSubtensor1
上级
a14cb2bd
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
17 行删除
+18
-17
subtensor.py
pytensor/tensor/rewriting/subtensor.py
+14
-16
subtensor.py
pytensor/tensor/subtensor.py
+4
-1
没有找到文件。
pytensor/tensor/rewriting/subtensor.py
浏览文件 @
3db127e9
...
@@ -1805,7 +1805,8 @@ def local_join_subtensors(fgraph, node):
...
@@ -1805,7 +1805,8 @@ def local_join_subtensors(fgraph, node):
def
local_uint_constant_indices
(
fgraph
,
node
):
def
local_uint_constant_indices
(
fgraph
,
node
):
"""Convert constant indices to unsigned dtypes."""
"""Convert constant indices to unsigned dtypes."""
if
isinstance
(
node
.
op
,
IncSubtensor
|
AdvancedIncSubtensor
|
AdvancedIncSubtensor1
):
op
=
node
.
op
if
isinstance
(
op
,
IncSubtensor
|
AdvancedIncSubtensor
|
AdvancedIncSubtensor1
):
x
,
y
,
*
indices
=
node
.
inputs
x
,
y
,
*
indices
=
node
.
inputs
else
:
else
:
x
,
*
indices
=
node
.
inputs
x
,
*
indices
=
node
.
inputs
...
@@ -1864,21 +1865,18 @@ def local_uint_constant_indices(fgraph, node):
...
@@ -1864,21 +1865,18 @@ def local_uint_constant_indices(fgraph, node):
if
not
has_new_index
:
if
not
has_new_index
:
return
False
return
False
new_out
=
x
[
tuple
(
new_indices
)]
if
isinstance
(
op
,
Subtensor
|
IncSubtensor
):
# Basic index Ops contain information about the dtype of the indices, so wee have to recreate them
if
y
is
not
None
:
props
=
op
.
_props_dict
()
new_out
=
inc_subtensor
(
props
[
"idx_list"
]
=
new_indices
new_out
,
op
=
type
(
op
)(
**
props
)
y
,
# Basic index Ops don't expect slices, but the respective start/step/stop
inplace
=
node
.
op
.
inplace
,
new_indices
=
get_slice_elements
(
new_indices
)
set_instead_of_inc
=
node
.
op
.
set_instead_of_inc
,
ignore_duplicates
=
getattr
(
node
.
op
,
"ignore_duplicates"
,
False
),
new_args
=
(
x
,
*
new_indices
)
if
y
is
None
else
(
x
,
y
,
*
new_indices
)
)
new_out
=
op
(
*
new_args
)
copy_stack_trace
(
node
.
outputs
[
0
],
new_out
)
new_outs
=
new_out
.
owner
.
outputs
return
[
new_out
]
copy_stack_trace
(
node
.
outputs
,
new_outs
)
return
new_outs
@register_canonicalize
(
"shape_unsafe"
)
@register_canonicalize
(
"shape_unsafe"
)
...
...
pytensor/tensor/subtensor.py
浏览文件 @
3db127e9
...
@@ -550,7 +550,10 @@ def indexed_result_shape(array_shape, indices, indices_are_shapes=False):
...
@@ -550,7 +550,10 @@ def indexed_result_shape(array_shape, indices, indices_are_shapes=False):
return
res_shape
return
res_shape
def
get_slice_elements
(
idxs
:
list
,
cond
:
Callable
)
->
list
:
def
get_slice_elements
(
idxs
:
list
,
cond
:
Callable
=
lambda
x
:
isinstance
(
x
,
Variable
),
)
->
list
:
"""Extract slice elements conditional on a given predicate function.
"""Extract slice elements conditional on a given predicate function.
Parameters
Parameters
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论