Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f8a1d6b9
提交
f8a1d6b9
authored
5月 06, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 07, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename aesara.tensor.extra_ops.RepeatOp to Repeat
上级
67d7f140
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
18 行增加
和
18 行删除
+18
-18
dispatch.py
aesara/link/jax/dispatch.py
+3
-3
extra_ops.py
aesara/tensor/extra_ops.py
+2
-2
test_extra_ops.py
tests/tensor/test_extra_ops.py
+13
-13
没有找到文件。
aesara/link/jax/dispatch.py
浏览文件 @
f8a1d6b9
...
...
@@ -38,7 +38,7 @@ from aesara.tensor.extra_ops import (
FillDiagonal
,
FillDiagonalOffset
,
RavelMultiIndex
,
Repeat
Op
,
Repeat
,
Unique
,
UnravelIndex
,
)
...
...
@@ -877,8 +877,8 @@ def jax_funcify_DiffOp(op, **kwargs):
return
diffop
@jax_funcify.register
(
Repeat
Op
)
def
jax_funcify_Repeat
Op
(
op
,
**
kwargs
):
@jax_funcify.register
(
Repeat
)
def
jax_funcify_Repeat
(
op
,
**
kwargs
):
axis
=
op
.
axis
def
repeatop
(
x
,
repeats
,
axis
=
axis
):
...
...
aesara/tensor/extra_ops.py
浏览文件 @
f8a1d6b9
...
...
@@ -656,7 +656,7 @@ def compress(condition, x, axis=None):
return
x
.
take
(
indices
,
axis
=
axis
)
class
Repeat
Op
(
Op
):
class
Repeat
(
Op
):
# See the repeat function for docstring
__props__
=
(
"axis"
,)
...
...
@@ -800,7 +800,7 @@ def repeat(x, repeats, axis=None):
raise
ValueError
(
"The dimension of repeats should not exceed 1."
)
if
repeats
.
ndim
==
1
and
not
repeats
.
broadcastable
[
0
]:
return
Repeat
Op
(
axis
=
axis
)(
x
,
repeats
)
return
Repeat
(
axis
=
axis
)(
x
,
repeats
)
else
:
if
repeats
.
ndim
==
1
:
repeats
=
repeats
[
0
]
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
f8a1d6b9
...
...
@@ -20,7 +20,7 @@ from aesara.tensor.extra_ops import (
FillDiagonal
,
FillDiagonalOffset
,
RavelMultiIndex
,
Repeat
Op
,
Repeat
,
SearchsortedOp
,
Unique
,
UnravelIndex
,
...
...
@@ -437,14 +437,14 @@ class TestCompress(utt.InferShapeTester):
assert
np
.
allclose
(
tested
,
expected
)
class
TestRepeat
Op
(
utt
.
InferShapeTester
):
class
TestRepeat
(
utt
.
InferShapeTester
):
def
_possible_axis
(
self
,
ndim
):
return
[
None
]
+
list
(
range
(
ndim
))
+
[
-
i
for
i
in
range
(
ndim
)]
def
setup_method
(
self
):
super
()
.
setup_method
()
self
.
op_class
=
Repeat
Op
self
.
op
=
Repeat
Op
()
self
.
op_class
=
Repeat
self
.
op
=
Repeat
()
# uint64 always fails
# int64 and uint32 also fail if python int are 32-bit
if
LOCAL_BITWIDTH
==
64
:
...
...
@@ -452,7 +452,7 @@ class TestRepeatOp(utt.InferShapeTester):
if
LOCAL_BITWIDTH
==
32
:
self
.
numpy_unsupported_dtypes
=
(
"uint32"
,
"int64"
,
"uint64"
)
def
test_
repeatOp
(
self
):
def
test_
basic
(
self
):
for
ndim
in
[
1
,
3
]:
x
=
TensorType
(
config
.
floatX
,
[
False
]
*
ndim
)()
a
=
np
.
random
.
random
((
10
,)
*
ndim
)
.
astype
(
config
.
floatX
)
...
...
@@ -489,7 +489,7 @@ class TestRepeatOp(utt.InferShapeTester):
assert
np
.
allclose
(
np
.
repeat
(
a
,
r
,
axis
=
axis
),
f
(
a
))
assert
not
np
.
any
(
[
isinstance
(
n
.
op
,
Repeat
Op
)
isinstance
(
n
.
op
,
Repeat
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
]
)
...
...
@@ -501,7 +501,7 @@ class TestRepeatOp(utt.InferShapeTester):
assert
np
.
allclose
(
np
.
repeat
(
a
,
r
[
0
],
axis
=
axis
),
f
(
a
,
r
))
assert
not
np
.
any
(
[
isinstance
(
n
.
op
,
Repeat
Op
)
isinstance
(
n
.
op
,
Repeat
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
]
)
...
...
@@ -524,7 +524,7 @@ class TestRepeatOp(utt.InferShapeTester):
else
:
self
.
_compile_and_check
(
[
x
,
r_var
],
[
Repeat
Op
(
axis
=
axis
)(
x
,
r_var
)],
[
Repeat
(
axis
=
axis
)(
x
,
r_var
)],
[
a
,
r
],
self
.
op_class
,
)
...
...
@@ -541,7 +541,7 @@ class TestRepeatOp(utt.InferShapeTester):
self
.
_compile_and_check
(
[
x
,
r_var
],
[
Repeat
Op
(
axis
=
axis
)(
x
,
r_var
)],
[
Repeat
(
axis
=
axis
)(
x
,
r_var
)],
[
a
,
r
],
self
.
op_class
,
)
...
...
@@ -551,15 +551,15 @@ class TestRepeatOp(utt.InferShapeTester):
a
=
np
.
random
.
random
((
10
,)
*
ndim
)
.
astype
(
config
.
floatX
)
for
axis
in
self
.
_possible_axis
(
ndim
):
utt
.
verify_grad
(
lambda
x
:
Repeat
Op
(
axis
=
axis
)(
x
,
3
),
[
a
])
utt
.
verify_grad
(
lambda
x
:
Repeat
(
axis
=
axis
)(
x
,
3
),
[
a
])
def
test_broadcastable
(
self
):
x
=
TensorType
(
config
.
floatX
,
[
False
,
True
,
False
])()
r
=
Repeat
Op
(
axis
=
1
)(
x
,
2
)
r
=
Repeat
(
axis
=
1
)(
x
,
2
)
assert
r
.
broadcastable
==
(
False
,
False
,
False
)
r
=
Repeat
Op
(
axis
=
1
)(
x
,
1
)
r
=
Repeat
(
axis
=
1
)(
x
,
1
)
assert
r
.
broadcastable
==
(
False
,
True
,
False
)
r
=
Repeat
Op
(
axis
=
0
)(
x
,
2
)
r
=
Repeat
(
axis
=
0
)(
x
,
2
)
assert
r
.
broadcastable
==
(
False
,
True
,
False
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论