Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8e0b1560
提交
8e0b1560
authored
2月 26, 2021
作者:
kc611
提交者:
Thomas Wiecki
3月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make RandomStateType compatible with array-form state values
上级
b852bd24
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
5 行删除
+37
-5
type.py
aesara/tensor/random/type.py
+27
-5
test_type.py
tests/tensor/random/test_type.py
+10
-0
没有找到文件。
aesara/tensor/random/type.py
浏览文件 @
8e0b1560
...
...
@@ -14,6 +14,9 @@ class RandomStateType(Type):
with the `==` operator. This `Type` exists to provide an equals function
that is used by `DebugMode`.
Also works with a `dict` derived from RandomState.get_state() unless
the `strict` argument is explicitly set to `True`.
"""
def
__repr__
(
self
):
...
...
@@ -21,19 +24,38 @@ class RandomStateType(Type):
@classmethod
def
filter
(
cls
,
data
,
strict
=
False
,
allow_downcast
=
None
):
if
cls
.
is_valid_value
(
data
):
if
cls
.
is_valid_value
(
data
,
strict
):
return
data
else
:
raise
TypeError
()
@staticmethod
def
is_valid_value
(
a
):
return
isinstance
(
a
,
np
.
random
.
RandomState
)
def
is_valid_value
(
a
,
strict
):
if
isinstance
(
a
,
np
.
random
.
RandomState
):
return
True
if
not
strict
and
isinstance
(
a
,
dict
):
gen_keys
=
[
"bit_generator"
,
"gauss"
,
"has_gauss"
,
"state"
]
state_keys
=
[
"key"
,
"pos"
]
for
key
in
gen_keys
:
if
key
not
in
a
:
return
False
for
key
in
state_keys
:
if
key
not
in
a
[
"state"
]:
return
False
state_key
=
a
[
"state"
][
"key"
]
if
state_key
.
shape
==
(
624
,)
and
state_key
.
dtype
==
np
.
uint32
:
return
True
return
False
@staticmethod
def
values_eq
(
a
,
b
):
sa
=
a
.
get_state
(
legacy
=
False
)
sb
=
b
.
get_state
(
legacy
=
False
)
sa
=
a
if
isinstance
(
a
,
dict
)
else
a
.
get_state
(
legacy
=
False
)
sb
=
b
if
isinstance
(
b
,
dict
)
else
b
.
get_state
(
legacy
=
False
)
def
_eq
(
sa
,
sb
):
for
key
in
sa
:
...
...
tests/tensor/random/test_type.py
浏览文件 @
8e0b1560
...
...
@@ -51,6 +51,16 @@ class TestRandomStateType:
with
pytest
.
raises
(
TypeError
):
rng_type
.
filter
(
1
)
rng
=
rng
.
get_state
(
legacy
=
False
)
assert
rng_type
.
is_valid_value
(
rng
,
strict
=
False
)
rng
[
"state"
]
=
{}
assert
rng_type
.
is_valid_value
(
rng
,
strict
=
False
)
is
False
rng
=
{}
assert
rng_type
.
is_valid_value
(
rng
,
strict
=
False
)
is
False
def
test_values_eq
(
self
):
rng_type
=
random_state_type
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论