Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
45a2f784
提交
45a2f784
authored
7月 13, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
7月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make `take` return a Subtensor
上级
0dbd512b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
36 行删除
+20
-36
subtensor.py
aesara/tensor/subtensor.py
+19
-35
test_subtensor.py
tests/tensor/test_subtensor.py
+1
-1
没有找到文件。
aesara/tensor/subtensor.py
浏览文件 @
45a2f784
...
@@ -2717,41 +2717,25 @@ def take(a, indices, axis=None, mode="raise"):
...
@@ -2717,41 +2717,25 @@ def take(a, indices, axis=None, mode="raise"):
"""
"""
a
=
aesara
.
tensor
.
as_tensor_variable
(
a
)
a
=
aesara
.
tensor
.
as_tensor_variable
(
a
)
indices
=
aesara
.
tensor
.
as_tensor_variable
(
indices
)
indices
=
aesara
.
tensor
.
as_tensor_variable
(
indices
)
# Reuse advanced_subtensor1 if indices is a vector
if
indices
.
ndim
==
1
:
if
not
isinstance
(
axis
,
(
int
,
type
(
None
))):
if
mode
==
"clip"
:
raise
TypeError
(
"`axis` must be an integer or None"
)
indices
=
clip
(
indices
,
0
,
a
.
shape
[
axis
]
-
1
)
elif
mode
==
"wrap"
:
if
axis
is
None
and
indices
.
ndim
==
1
:
indices
=
indices
%
a
.
shape
[
axis
]
return
advanced_subtensor1
(
a
.
flatten
(),
indices
)
if
axis
is
None
:
elif
axis
==
0
and
indices
.
ndim
==
1
:
return
advanced_subtensor1
(
a
.
flatten
(),
indices
)
return
advanced_subtensor1
(
a
,
indices
)
elif
axis
==
0
:
elif
axis
<
0
:
return
advanced_subtensor1
(
a
,
indices
)
axis
+=
a
.
ndim
else
:
if
axis
<
0
:
if
mode
==
"clip"
:
axis
+=
a
.
ndim
indices
=
clip
(
indices
,
0
,
a
.
shape
[
axis
]
-
1
)
assert
axis
>=
0
elif
mode
==
"wrap"
:
shuffle
=
list
(
range
(
a
.
ndim
))
indices
=
indices
%
a
.
shape
[
axis
]
shuffle
[
0
]
=
axis
shuffle
[
axis
]
=
0
full_indices
=
(
slice
(
None
),)
*
axis
+
(
indices
,)
return
advanced_subtensor1
(
a
.
dimshuffle
(
shuffle
),
indices
)
.
dimshuffle
(
shuffle
return
a
[
full_indices
]
)
if
axis
is
None
:
shape
=
indices
.
shape
ndim
=
indices
.
ndim
else
:
# If axis is 0, don't generate a useless concatenation.
if
axis
==
0
:
shape
=
aesara
.
tensor
.
concatenate
([
indices
.
shape
,
a
.
shape
[
axis
+
1
:]])
else
:
if
axis
<
0
:
axis
+=
a
.
ndim
shape
=
aesara
.
tensor
.
concatenate
(
[
a
.
shape
[:
axis
],
indices
.
shape
,
a
.
shape
[
axis
+
1
:]]
)
ndim
=
a
.
ndim
+
indices
.
ndim
-
1
return
take
(
a
,
indices
.
flatten
(),
axis
,
mode
)
.
reshape
(
shape
,
ndim
)
__all__
=
[
__all__
=
[
...
...
tests/tensor/test_subtensor.py
浏览文件 @
45a2f784
...
@@ -1449,7 +1449,7 @@ def test_take_cases(a, index, axis, mode):
...
@@ -1449,7 +1449,7 @@ def test_take_cases(a, index, axis, mode):
fn_mode
=
aesara
.
compile
.
mode
.
get_default_mode
()
fn_mode
=
aesara
.
compile
.
mode
.
get_default_mode
()
fn_mode
=
fn_mode
.
including
(
fn_mode
=
fn_mode
.
including
(
"local_useless_subtensor"
,
"local_useless_subtensor"
,
#
"local_replace_AdvancedSubtensor",
"local_replace_AdvancedSubtensor"
,
)
)
f
=
aesara
.
function
([
a
,
index
],
a
.
take
(
index
,
axis
=
axis
,
mode
=
mode
),
mode
=
fn_mode
)
f
=
aesara
.
function
([
a
,
index
],
a
.
take
(
index
,
axis
=
axis
,
mode
=
mode
),
mode
=
fn_mode
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论