Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7e351b93
提交
7e351b93
authored
2月 18, 2022
作者:
Ricardo
提交者:
Ricardo Vieira
2月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename `*shape_from_params` to `*supp_shape_from_params` for clarity
上级
e30d7b90
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
19 行删除
+24
-19
basic.py
aesara/tensor/random/basic.py
+4
-4
op.py
aesara/tensor/random/op.py
+8
-7
test_basic.py
tests/tensor/random/test_basic.py
+1
-1
test_op.py
tests/tensor/random/test_op.py
+11
-7
没有找到文件。
aesara/tensor/random/basic.py
浏览文件 @
7e351b93
...
...
@@ -6,7 +6,7 @@ import scipy.stats as stats
import
aesara
from
aesara.tensor.basic
import
as_tensor_variable
from
aesara.tensor.random.op
import
RandomVariable
,
default_shape_from_params
from
aesara.tensor.random.op
import
RandomVariable
,
default_s
upp_s
hape_from_params
from
aesara.tensor.random.type
import
RandomGeneratorType
,
RandomStateType
from
aesara.tensor.random.utils
import
broadcast_params
from
aesara.tensor.random.var
import
(
...
...
@@ -591,8 +591,8 @@ class MultinomialRV(RandomVariable):
dtype
=
"int64"
_print_name
=
(
"MN"
,
"
\\
operatorname{MN}"
)
def
_shape_from_params
(
self
,
dist_params
,
rep_param_idx
=
1
,
param_shapes
=
None
):
return
default_shape_from_params
(
def
_s
upp_s
hape_from_params
(
self
,
dist_params
,
rep_param_idx
=
1
,
param_shapes
=
None
):
return
default_s
upp_s
hape_from_params
(
self
.
ndim_supp
,
dist_params
,
rep_param_idx
,
param_shapes
)
...
...
@@ -713,7 +713,7 @@ class ChoiceRV(RandomVariable):
def
rng_fn
(
cls
,
rng
,
a
,
p
,
replace
,
size
):
return
rng
.
choice
(
a
,
size
,
replace
,
p
)
def
_shape_from_params
(
self
,
*
args
,
**
kwargs
):
def
_s
upp_s
hape_from_params
(
self
,
*
args
,
**
kwargs
):
raise
NotImplementedError
()
def
_infer_shape
(
self
,
size
,
dist_params
,
param_shapes
=
None
):
...
...
aesara/tensor/random/op.py
浏览文件 @
7e351b93
...
...
@@ -24,7 +24,7 @@ from aesara.tensor.type_other import NoneConst
from
aesara.tensor.var
import
TensorVariable
def
default_shape_from_params
(
def
default_s
upp_s
hape_from_params
(
ndim_supp
:
int
,
dist_params
:
Sequence
[
Variable
],
rep_param_idx
:
Optional
[
int
]
=
0
,
...
...
@@ -151,14 +151,15 @@ class RandomVariable(Op):
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
def
_shape_from_params
(
self
,
dist_params
,
**
kwargs
):
"""Determine the shape of a `RandomVariable`'s output given its parameters.
def
_s
upp_s
hape_from_params
(
self
,
dist_params
,
**
kwargs
):
"""Determine the s
upport s
hape of a `RandomVariable`'s output given its parameters.
This does *not* consider the extra dimensions added by the `size` parameter.
This does *not* consider the extra dimensions added by the `size` parameter
or independent (batched) parameters.
Defaults to `param_supp_shape_fn`.
"""
return
default_shape_from_params
(
self
.
ndim_supp
,
dist_params
,
**
kwargs
)
return
default_s
upp_s
hape_from_params
(
self
.
ndim_supp
,
dist_params
,
**
kwargs
)
def
rng_fn
(
self
,
rng
,
*
args
,
**
kwargs
):
"""Sample a numeric random variate."""
...
...
@@ -196,7 +197,7 @@ class RandomVariable(Op):
if
self
.
ndim_supp
==
0
:
return
size
else
:
supp_shape
=
self
.
_shape_from_params
(
supp_shape
=
self
.
_s
upp_s
hape_from_params
(
dist_params
,
param_shapes
=
param_shapes
)
return
tuple
(
size
)
+
tuple
(
supp_shape
)
...
...
@@ -256,7 +257,7 @@ class RandomVariable(Op):
ndim_reps
=
len
(
shape_reps
)
else
:
shape_supp
=
self
.
_shape_from_params
(
shape_supp
=
self
.
_s
upp_s
hape_from_params
(
dist_params
,
param_shapes
=
param_shapes
,
)
...
...
tests/tensor/random/test_basic.py
浏览文件 @
7e351b93
...
...
@@ -1227,7 +1227,7 @@ def test_integers_samples():
def
test_choice_samples
():
with
pytest
.
raises
(
NotImplementedError
):
choice
.
_shape_from_params
(
np
.
asarray
(
5
))
choice
.
_s
upp_s
hape_from_params
(
np
.
asarray
(
5
))
rv_numpy_tester
(
choice
,
np
.
asarray
([
5
]))
rv_numpy_tester
(
choice
,
np
.
array
([
1.0
,
5.0
],
dtype
=
config
.
floatX
))
...
...
tests/tensor/random/test_op.py
浏览文件 @
7e351b93
...
...
@@ -10,7 +10,7 @@ from aesara.tensor.random.op import (
RandomState
,
RandomVariable
,
default_rng
,
default_shape_from_params
,
default_s
upp_s
hape_from_params
,
)
from
aesara.tensor.shape
import
specify_shape
from
aesara.tensor.type
import
all_dtypes
,
iscalar
,
tensor
...
...
@@ -22,20 +22,24 @@ def set_aesara_flags():
yield
def
test_default_shape_from_params
():
def
test_default_s
upp_s
hape_from_params
():
with
pytest
.
raises
(
ValueError
,
match
=
"^ndim_supp*"
):
default_shape_from_params
(
0
,
(
np
.
array
([
1
,
2
]),
0
))
default_s
upp_s
hape_from_params
(
0
,
(
np
.
array
([
1
,
2
]),
0
))
res
=
default_shape_from_params
(
1
,
(
np
.
array
([
1
,
2
]),
np
.
eye
(
2
)),
rep_param_idx
=
0
)
res
=
default_supp_shape_from_params
(
1
,
(
np
.
array
([
1
,
2
]),
np
.
eye
(
2
)),
rep_param_idx
=
0
)
assert
res
==
(
2
,)
res
=
default_shape_from_params
(
1
,
(
np
.
array
([
1
,
2
]),
0
),
param_shapes
=
((
2
,),
()))
res
=
default_supp_shape_from_params
(
1
,
(
np
.
array
([
1
,
2
]),
0
),
param_shapes
=
((
2
,),
())
)
assert
res
==
(
2
,)
with
pytest
.
raises
(
ValueError
,
match
=
"^Reference parameter*"
):
default_shape_from_params
(
1
,
(
np
.
array
(
1
),),
rep_param_idx
=
0
)
default_s
upp_s
hape_from_params
(
1
,
(
np
.
array
(
1
),),
rep_param_idx
=
0
)
res
=
default_shape_from_params
(
res
=
default_s
upp_s
hape_from_params
(
2
,
(
np
.
array
([
1
,
2
]),
np
.
ones
((
2
,
3
,
4
))),
rep_param_idx
=
1
)
assert
res
==
(
3
,
4
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论