Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f8e7fe07
提交
f8e7fe07
authored
11月 15, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
11月 18, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use inferred shapes for RandomVariable size parameter
上级
a24cd432
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
10 行删除
+26
-10
op.py
aesara/tensor/random/op.py
+26
-10
没有找到文件。
aesara/tensor/random/op.py
浏览文件 @
f8e7fe07
from
collections.abc
import
Sequence
from
collections.abc
import
Sequence
from
copy
import
copy
from
copy
import
copy
from
typing
import
List
,
Optional
,
Tuple
import
numpy
as
np
import
numpy
as
np
...
@@ -10,12 +11,19 @@ from aesara.graph.fg import FunctionGraph
...
@@ -10,12 +11,19 @@ from aesara.graph.fg import FunctionGraph
from
aesara.graph.op
import
Op
from
aesara.graph.op
import
Op
from
aesara.graph.opt_utils
import
optimize_graph
from
aesara.graph.opt_utils
import
optimize_graph
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.misc.safe_asarray
import
_asarray
from
aesara.tensor.basic
import
as_tensor_variable
,
constant
,
get_vector_length
from
aesara.scalar
import
ScalarVariable
from
aesara.tensor.basic
import
(
as_tensor_variable
,
constant
,
get_scalar_constant_value
,
get_vector_length
,
)
from
aesara.tensor.basic_opt
import
ShapeFeature
,
topo_constant_folding
from
aesara.tensor.basic_opt
import
ShapeFeature
,
topo_constant_folding
from
aesara.tensor.random.type
import
RandomType
from
aesara.tensor.random.type
import
RandomType
from
aesara.tensor.random.utils
import
normalize_size_param
,
params_broadcast_shapes
from
aesara.tensor.random.utils
import
normalize_size_param
,
params_broadcast_shapes
from
aesara.tensor.shape
import
shape_tuple
from
aesara.tensor.shape
import
shape_tuple
from
aesara.tensor.type
import
TensorType
,
all_dtypes
from
aesara.tensor.type
import
TensorType
,
all_dtypes
from
aesara.tensor.var
import
TensorVariable
def
default_shape_from_params
(
def
default_shape_from_params
(
...
@@ -159,25 +167,26 @@ class RandomVariable(Op):
...
@@ -159,25 +167,26 @@ class RandomVariable(Op):
props_str
=
", "
.
join
((
f
"{getattr(self, prop)}"
for
prop
in
self
.
__props__
[
1
:]))
props_str
=
", "
.
join
((
f
"{getattr(self, prop)}"
for
prop
in
self
.
__props__
[
1
:]))
return
f
"{self.name}_rv{{{props_str}}}"
return
f
"{self.name}_rv{{{props_str}}}"
def
_infer_shape
(
self
,
size
,
dist_params
,
param_shapes
=
None
):
def
_infer_shape
(
self
,
size
:
Tuple
[
TensorVariable
],
dist_params
:
List
[
TensorVariable
],
param_shapes
:
Optional
[
List
[
Tuple
[
TensorVariable
]]]
=
None
,
)
->
Tuple
[
ScalarVariable
]:
"""Compute the output shape given the size and distribution parameters.
"""Compute the output shape given the size and distribution parameters.
Parameters
Parameters
----------
----------
size
: TensorVariable
size
The size parameter specified for this `RandomVariable`.
The size parameter specified for this `RandomVariable`.
dist_params
: list of TensorVariable
dist_params
The symbolic parameter for this `RandomVariable`'s distribution.
The symbolic parameter for this `RandomVariable`'s distribution.
param_shapes
: list of tuples of TensorVariable (optional)
param_shapes
The shapes of the `dist_params` as given by `ShapeFeature`'s
The shapes of the `dist_params` as given by `ShapeFeature`'s
via `Op.infer_shape`'s `input_shapes` argument. This parameter's
via `Op.infer_shape`'s `input_shapes` argument. This parameter's
values are essentially more accurate versions of ``[d.shape for d
values are essentially more accurate versions of ``[d.shape for d
in dist_params]``.
in dist_params]``.
Outputs
-------
shape : tuple of `ScalarVariable`
"""
"""
size_len
=
get_vector_length
(
size
)
size_len
=
get_vector_length
(
size
)
...
@@ -294,7 +303,14 @@ class RandomVariable(Op):
...
@@ -294,7 +303,14 @@ class RandomVariable(Op):
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
_
,
size
,
_
,
*
dist_params
=
node
.
inputs
_
,
size
,
_
,
*
dist_params
=
node
.
inputs
_
,
_
,
_
,
*
param_shapes
=
input_shapes
_
,
size_shape
,
_
,
*
param_shapes
=
input_shapes
try
:
size_len
=
get_vector_length
(
size
)
except
ValueError
:
size_len
=
get_scalar_constant_value
(
size_shape
[
0
])
size
=
tuple
(
size
[
n
]
for
n
in
range
(
size_len
))
shape
=
self
.
_infer_shape
(
size
,
dist_params
,
param_shapes
=
param_shapes
)
shape
=
self
.
_infer_shape
(
size
,
dist_params
,
param_shapes
=
param_shapes
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论