Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fd4c5d91
提交
fd4c5d91
authored
10月 31, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 15, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor get_canonical_form_slice so that it uses as_index_literal
上级
0cbf8557
全部展开
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
13 行删除
+16
-13
subtensor.py
aesara/tensor/subtensor.py
+16
-13
test_subtensor.py
tests/tensor/test_subtensor.py
+0
-0
没有找到文件。
aesara/tensor/subtensor.py
浏览文件 @
fd4c5d91
...
@@ -168,7 +168,9 @@ def get_idx_list(inputs, idx_list):
...
@@ -168,7 +168,9 @@ def get_idx_list(inputs, idx_list):
return
indices_from_subtensor
(
inputs
[
1
:],
idx_list
)
return
indices_from_subtensor
(
inputs
[
1
:],
idx_list
)
def
get_canonical_form_slice
(
theslice
,
length
):
def
get_canonical_form_slice
(
theslice
:
Union
[
slice
,
Variable
],
length
:
Variable
)
->
Tuple
[
Variable
,
int
]:
"""Convert slices to canonical form.
"""Convert slices to canonical form.
Given a slice [start:stop:step] transform it into a canonical form
Given a slice [start:stop:step] transform it into a canonical form
...
@@ -179,16 +181,24 @@ def get_canonical_form_slice(theslice, length):
...
@@ -179,16 +181,24 @@ def get_canonical_form_slice(theslice, length):
if the resulting set of numbers needs to be reversed or not.
if the resulting set of numbers needs to be reversed or not.
"""
"""
from
aesara.tensor
import
extract_constant
,
ge
,
lt
,
sgn
,
switch
from
aesara.tensor
import
ge
,
lt
,
sgn
,
switch
if
isinstance
(
theslice
,
slice
):
if
not
isinstance
(
theslice
,
slice
):
try
:
value
=
as_index_literal
(
theslice
)
except
NotScalarConstantError
:
value
=
theslice
value
=
switch
(
lt
(
value
,
0
),
(
value
+
length
),
value
)
return
value
,
1
def
analyze
(
x
):
def
analyze
(
x
):
try
:
try
:
x_constant
=
get_scalar_constant_value
(
x
)
x_constant
=
as_index_literal
(
x
)
is_constant
=
True
is_constant
=
True
except
NotScalarConstantError
:
except
NotScalarConstantError
:
x_constant
=
extract_constant
(
x
)
x_constant
=
x
is_constant
=
False
is_constant
=
False
return
x_constant
,
is_constant
return
x_constant
,
is_constant
...
@@ -298,9 +308,7 @@ def get_canonical_form_slice(theslice, length):
...
@@ -298,9 +308,7 @@ def get_canonical_form_slice(theslice, length):
else
:
else
:
start
=
switch
(
lt
(
start
,
0
),
start
+
length
,
start
)
start
=
switch
(
lt
(
start
,
0
),
start
+
length
,
start
)
start
=
switch
(
lt
(
start
,
0
),
switch_neg_step
(
-
1
,
0
),
start
)
start
=
switch
(
lt
(
start
,
0
),
switch_neg_step
(
-
1
,
0
),
start
)
start
=
switch
(
start
=
switch
(
ge
(
start
,
length
),
switch_neg_step
(
length
-
1
,
length
),
start
)
ge
(
start
,
length
),
switch_neg_step
(
length
-
1
,
length
),
start
)
if
stop
is
None
or
stop
==
sys
.
maxsize
:
if
stop
is
None
or
stop
==
sys
.
maxsize
:
# The special "maxsize" case is probably not needed here,
# The special "maxsize" case is probably not needed here,
# as slices containing maxsize are not generated by
# as slices containing maxsize are not generated by
...
@@ -328,11 +336,6 @@ def get_canonical_form_slice(theslice, length):
...
@@ -328,11 +336,6 @@ def get_canonical_form_slice(theslice, length):
return
slice
(
nw_start
,
nw_stop
,
nw_step
),
reverse
return
slice
(
nw_start
,
nw_stop
,
nw_step
),
reverse
else
:
else
:
return
slice
(
nw_start
,
nw_stop
,
nw_step
),
1
return
slice
(
nw_start
,
nw_stop
,
nw_step
),
1
else
:
value
=
extract_constant
(
theslice
)
value
=
switch
(
lt
(
value
,
0
),
(
value
+
length
),
value
)
return
value
,
1
def
range_len
(
slc
):
def
range_len
(
slc
):
...
...
tests/tensor/test_subtensor.py
浏览文件 @
fd4c5d91
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论