Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d7fb9402
提交
d7fb9402
authored
8月 28, 2022
作者:
ltoniazzi
提交者:
Brandon T. Willard
8月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BUG: add tensor conversion to at.roll
上级
f4004b27
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
8 行删除
+20
-8
basic.py
aesara/tensor/basic.py
+11
-8
test_basic.py
tests/tensor/test_basic.py
+9
-0
没有找到文件。
aesara/tensor/basic.py
浏览文件 @
d7fb9402
...
...
@@ -2484,30 +2484,33 @@ def roll(x, shift, axis=None):
Output tensor, with the same shape as ``x``.
"""
_x
=
as_tensor_variable
(
x
)
if
axis
is
None
:
if
x
.
ndim
>
1
:
y
=
x
.
flatten
()
return
roll
(
y
,
shift
,
axis
=
0
)
.
reshape
(
x
.
shape
)
if
_
x
.
ndim
>
1
:
y
=
_
x
.
flatten
()
return
roll
(
y
,
shift
,
axis
=
0
)
.
reshape
(
_
x
.
shape
)
else
:
axis
=
0
if
axis
<
0
:
axis
+=
x
.
ndim
axis
+=
_
x
.
ndim
# Shift may be larger than the size of the axis. If so, since the
# roll operation is cyclic, we can take the shift modulo the size
# of the axis
shift
=
shift
%
x
.
shape
[
axis
]
shift
=
shift
%
_
x
.
shape
[
axis
]
# A slice of all elements in a dimension ':'
allslice
=
slice
(
None
)
# List of slices describing the front half [:, :, shift:, :]
front_slice
=
slice
(
-
shift
,
None
)
front_list
=
[
allslice
]
*
axis
+
[
front_slice
]
+
[
allslice
]
*
(
x
.
ndim
-
axis
-
1
)
front_list
=
[
allslice
]
*
axis
+
[
front_slice
]
+
[
allslice
]
*
(
_
x
.
ndim
-
axis
-
1
)
# List of slices describing the back half [:, :, :shift, :]
end_slice
=
slice
(
0
,
-
shift
)
end_list
=
[
allslice
]
*
axis
+
[
end_slice
]
+
[
allslice
]
*
(
x
.
ndim
-
axis
-
1
)
return
join
(
axis
,
x
.
__getitem__
(
tuple
(
front_list
)),
x
.
__getitem__
(
tuple
(
end_list
)))
end_list
=
[
allslice
]
*
axis
+
[
end_slice
]
+
[
allslice
]
*
(
_x
.
ndim
-
axis
-
1
)
return
join
(
axis
,
_x
.
__getitem__
(
tuple
(
front_list
)),
_x
.
__getitem__
(
tuple
(
end_list
))
)
def
stack
(
*
tensors
,
**
kwargs
):
...
...
tests/tensor/test_basic.py
浏览文件 @
d7fb9402
...
...
@@ -1449,6 +1449,15 @@ class TestJoinAndSplit:
assert
(
out
==
want
)
.
all
()
# Pass a list to make sure `a` is converted to a
# TensorVariable by roll
a
=
[
1
,
2
,
3
,
4
,
5
,
6
]
b
=
roll
(
a
,
get_shift
(
2
))
want
=
np
.
array
([
5
,
6
,
1
,
2
,
3
,
4
])
out
=
aesara
.
function
([],
b
)()
assert
(
out
==
want
)
.
all
()
def
test_stack_vector
(
self
):
a
=
self
.
shared
(
np
.
array
([
1
,
2
,
3
],
dtype
=
self
.
floatX
))
b
=
as_tensor_variable
(
np
.
array
([
7
,
8
,
9
],
dtype
=
self
.
floatX
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论