Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
248ce6d9
提交
248ce6d9
authored
5月 23, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ignore Cast in RandomVariable.compute_bcast
Closes #390
上级
6228d023
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
0 行删除
+15
-0
op.py
aesara/tensor/random/op.py
+9
-0
test_op.py
tests/tensor/random/test_op.py
+6
-0
没有找到文件。
aesara/tensor/random/op.py
浏览文件 @
248ce6d9
...
@@ -9,12 +9,14 @@ from aesara.configdefaults import config
...
@@ -9,12 +9,14 @@ from aesara.configdefaults import config
from
aesara.graph.basic
import
Apply
,
Variable
from
aesara.graph.basic
import
Apply
,
Variable
from
aesara.graph.op
import
Op
from
aesara.graph.op
import
Op
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.scalar.basic
import
Cast
from
aesara.tensor.basic
import
(
from
aesara.tensor.basic
import
(
as_tensor_variable
,
as_tensor_variable
,
constant
,
constant
,
get_scalar_constant_value
,
get_scalar_constant_value
,
get_vector_length
,
get_vector_length
,
)
)
from
aesara.tensor.elemwise
import
Elemwise
from
aesara.tensor.exceptions
import
NotScalarConstantError
from
aesara.tensor.exceptions
import
NotScalarConstantError
from
aesara.tensor.random.type
import
RandomStateType
from
aesara.tensor.random.type
import
RandomStateType
from
aesara.tensor.random.utils
import
normalize_size_param
,
params_broadcast_shapes
from
aesara.tensor.random.utils
import
normalize_size_param
,
params_broadcast_shapes
...
@@ -284,6 +286,13 @@ class RandomVariable(Op):
...
@@ -284,6 +286,13 @@ class RandomVariable(Op):
"""
"""
shape
=
self
.
_infer_shape
(
size
,
dist_params
)
shape
=
self
.
_infer_shape
(
size
,
dist_params
)
# Ignore `Cast`s, since they do not affect broadcastables
if
getattr
(
shape
,
"owner"
,
None
)
and
(
isinstance
(
shape
.
owner
.
op
,
Elemwise
)
and
isinstance
(
shape
.
owner
.
op
.
scalar_op
,
Cast
)
):
shape
=
shape
.
owner
.
inputs
[
0
]
# Let's try to do a better job than `_infer_ndim_bcast` when
# Let's try to do a better job than `_infer_ndim_bcast` when
# dimension sizes are symbolic.
# dimension sizes are symbolic.
bcast
=
[]
bcast
=
[]
...
...
tests/tensor/random/test_op.py
浏览文件 @
248ce6d9
...
@@ -111,6 +111,8 @@ def test_RandomVariable_basics():
...
@@ -111,6 +111,8 @@ def test_RandomVariable_basics():
with
raises
(
NullTypeGradError
):
with
raises
(
NullTypeGradError
):
grad
(
rv_out
,
[
rv_node
.
inputs
[
0
]])
grad
(
rv_out
,
[
rv_node
.
inputs
[
0
]])
def
test_RandomVariable_bcast
():
rv
=
RandomVariable
(
"normal"
,
0
,
[
0
,
0
],
config
.
floatX
,
inplace
=
True
)
rv
=
RandomVariable
(
"normal"
,
0
,
[
0
,
0
],
config
.
floatX
,
inplace
=
True
)
mu
=
tensor
(
config
.
floatX
,
[
True
,
False
,
False
])
mu
=
tensor
(
config
.
floatX
,
[
True
,
False
,
False
])
...
@@ -129,6 +131,10 @@ def test_RandomVariable_basics():
...
@@ -129,6 +131,10 @@ def test_RandomVariable_basics():
res
=
rv
.
compute_bcast
([
mu
,
sd
],
(
s1
,
s2
,
s3
))
res
=
rv
.
compute_bcast
([
mu
,
sd
],
(
s1
,
s2
,
s3
))
assert
res
==
[
False
]
*
3
assert
res
==
[
False
]
*
3
size
=
aet
.
as_tensor
((
1
,
2
,
3
),
dtype
=
np
.
int32
)
.
astype
(
np
.
int64
)
res
=
rv
.
compute_bcast
([
mu
,
sd
],
size
)
assert
res
==
[
True
,
False
,
False
]
def
test_RandomVariable_floatX
():
def
test_RandomVariable_floatX
():
test_rv_op
=
RandomVariable
(
test_rv_op
=
RandomVariable
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论