提交 c32c1d34 authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Include __props__ in RandomVariable.__str__

上级 f9a85474
...@@ -91,7 +91,6 @@ class RandomVariable(Op): ...@@ -91,7 +91,6 @@ class RandomVariable(Op):
__props__ = ("name", "ndim_supp", "ndims_params", "dtype", "inplace") __props__ = ("name", "ndim_supp", "ndims_params", "dtype", "inplace")
default_output = 1 default_output = 1
nondeterministic = True
def __init__( def __init__(
self, self,
...@@ -162,7 +161,8 @@ class RandomVariable(Op): ...@@ -162,7 +161,8 @@ class RandomVariable(Op):
return getattr(np.random.RandomState, self.name)(rng, *args, **kwargs) return getattr(np.random.RandomState, self.name)(rng, *args, **kwargs)
def __str__(self): def __str__(self):
return "{}_rv".format(self.name) props_str = ", ".join((f"{getattr(self, prop)}" for prop in self.__props__[1:]))
return f"{self.name}_rv{{{props_str}}}"
def _infer_shape(self, size, dist_params, param_shapes=None): def _infer_shape(self, size, dist_params, param_shapes=None):
"""Compute the output shape given the size and distribution parameters. """Compute the output shape given the size and distribution parameters.
......
...@@ -42,12 +42,12 @@ def test_RandomVariable_basics(): ...@@ -42,12 +42,12 @@ def test_RandomVariable_basics():
"normal", "normal",
0, 0,
[0, 0], [0, 0],
config.floatX, "float32",
inplace=True, inplace=True,
) )
) )
assert str_res == "normal_rv" assert str_res == "normal_rv{0, (0, 0), float32, True}"
# `ndims_params` should be a `Sequence` type # `ndims_params` should be a `Sequence` type
with raises(TypeError, match="^Parameter ndims_params*"): with raises(TypeError, match="^Parameter ndims_params*"):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论