Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
05d376f3
提交
05d376f3
authored
7月 05, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
7月 06, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug in vectorize_random_variable when size is empty but not None
上级
85506229
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
5 行删除
+14
-5
op.py
pytensor/tensor/random/op.py
+4
-5
test_op.py
tests/tensor/random/test_op.py
+10
-0
没有找到文件。
pytensor/tensor/random/op.py
浏览文件 @
05d376f3
...
...
@@ -238,7 +238,7 @@ class RandomVariable(Op):
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}"
f
"Size
must be None or have length
>= {param_batched_dims}"
)
return
tuple
(
size
)
+
supp_shape
...
...
@@ -454,11 +454,10 @@ def vectorize_random_variable(
original_dist_params
=
op
.
dist_params
(
node
)
old_size
=
op
.
size_param
(
node
)
len_old_size
=
(
None
if
isinstance
(
old_size
.
type
,
NoneTypeT
)
else
get_vector_length
(
old_size
)
)
if
len_old_size
and
equal_computations
([
old_size
],
[
size
]):
if
not
isinstance
(
old_size
.
type
,
NoneTypeT
)
and
equal_computations
(
[
old_size
],
[
size
]
):
# If the original RV had a size variable and a new one has not been provided,
# we need to define a new size as the concatenation of the original size dimensions
# and the novel ones implied by new broadcasted batched parameters dimensions.
...
...
tests/tensor/random/test_op.py
浏览文件 @
05d376f3
...
...
@@ -296,6 +296,16 @@ def test_vectorize():
assert
vect_node
.
default_output
()
.
type
.
shape
==
(
10
,
2
,
5
)
def
test_vectorize_empty_size
():
scalar_mu
=
pt
.
scalar
(
"scalar_mu"
)
scalar_x
=
pt
.
random
.
normal
(
loc
=
scalar_mu
,
size
=
())
assert
scalar_x
.
type
.
shape
==
()
vector_mu
=
pt
.
vector
(
"vector_mu"
,
shape
=
(
5
,))
vector_x
=
vectorize_graph
(
scalar_x
,
{
scalar_mu
:
vector_mu
})
assert
vector_x
.
type
.
shape
==
(
5
,)
def
test_size_none_vs_empty
():
rv
=
RandomVariable
(
"normal"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论