Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a64055dd
提交
a64055dd
authored
12月 02, 2022
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fail early in RandomVariable.make_node when size is incompatible with parameters dimensionality
上级
237f54f9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
0 行删除
+27
-0
op.py
pytensor/tensor/random/op.py
+13
-0
test_op.py
tests/tensor/random/test_op.py
+14
-0
没有找到文件。
pytensor/tensor/random/op.py
浏览文件 @
a64055dd
...
...
@@ -192,6 +192,19 @@ class RandomVariable(Op):
size_len
=
get_vector_length
(
size
)
if
size_len
>
0
:
# Fail early when size is incompatible with parameters
for
i
,
(
param
,
param_ndim_supp
)
in
enumerate
(
zip
(
dist_params
,
self
.
ndims_params
)
):
param_batched_dims
=
getattr
(
param
,
"ndim"
,
0
)
-
param_ndim_supp
if
param_batched_dims
>
size_len
:
raise
ValueError
(
f
"Size length is incompatible with batched dimensions of parameter {i} {param}:
\n
"
f
"len(size) = {size_len}, len(batched dims {param}) = {param_batched_dims}. "
f
"Size length must be 0 or >= {param_batched_dims}"
)
if
self
.
ndim_supp
==
0
:
return
size
else
:
...
...
tests/tensor/random/test_op.py
浏览文件 @
a64055dd
...
...
@@ -217,3 +217,17 @@ def test_random_maker_ops_no_seed():
z
=
function
(
inputs
=
[],
outputs
=
[
default_rng
()])()
aes_res
=
z
[
0
]
assert
isinstance
(
aes_res
,
np
.
random
.
Generator
)
def
test_RandomVariable_incompatible_size
():
rv_op
=
RandomVariable
(
"normal"
,
0
,
[
0
,
0
],
config
.
floatX
,
inplace
=
True
)
with
pytest
.
raises
(
ValueError
,
match
=
"Size length is incompatible with batched dimensions"
):
rv_op
(
np
.
zeros
((
1
,
3
)),
1
,
size
=
(
3
,))
rv_op
=
RandomVariable
(
"dirichlet"
,
0
,
[
1
],
config
.
floatX
,
inplace
=
True
)
with
pytest
.
raises
(
ValueError
,
match
=
"Size length is incompatible with batched dimensions"
):
rv_op
(
np
.
zeros
((
2
,
4
,
3
)),
1
,
size
=
(
4
,))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论