Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7d07260b
提交
7d07260b
authored
7月 29, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
7月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove RandomType's get_shape_info and get_size methods
上级
d9fd640e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
56 行删除
+24
-56
type.py
aesara/tensor/random/type.py
+0
-15
test_type.py
tests/tensor/random/test_type.py
+24
-41
没有找到文件。
aesara/tensor/random/type.py
浏览文件 @
7d07260b
import
sys
import
numpy
as
np
import
numpy
as
np
import
aesara
import
aesara
...
@@ -30,10 +28,6 @@ class RandomType(Type):
...
@@ -30,10 +28,6 @@ class RandomType(Type):
else
:
else
:
raise
TypeError
()
raise
TypeError
()
@staticmethod
def
get_shape_info
(
obj
):
return
obj
.
get_value
(
borrow
=
True
)
@staticmethod
@staticmethod
def
may_share_memory
(
a
,
b
):
def
may_share_memory
(
a
,
b
):
return
a
.
_bit_generator
is
b
.
_bit_generator
return
a
.
_bit_generator
is
b
.
_bit_generator
...
@@ -99,10 +93,6 @@ class RandomStateType(RandomType):
...
@@ -99,10 +93,6 @@ class RandomStateType(RandomType):
return
_eq
(
sa
,
sb
)
return
_eq
(
sa
,
sb
)
@staticmethod
def
get_size
(
shape_info
):
return
sys
.
getsizeof
(
shape_info
.
get_state
(
legacy
=
False
))
# Register `RandomStateType`'s C code for `ViewOp`.
# Register `RandomStateType`'s C code for `ViewOp`.
aesara
.
compile
.
register_view_op_c_code
(
aesara
.
compile
.
register_view_op_c_code
(
...
@@ -184,11 +174,6 @@ class RandomGeneratorType(RandomType):
...
@@ -184,11 +174,6 @@ class RandomGeneratorType(RandomType):
return
_eq
(
sa
,
sb
)
return
_eq
(
sa
,
sb
)
@staticmethod
def
get_size
(
shape_info
):
state
=
shape_info
.
__getstate__
()
return
sys
.
getsizeof
(
state
)
# Register `RandomGeneratorType`'s C code for `ViewOp`.
# Register `RandomGeneratorType`'s C code for `ViewOp`.
aesara
.
compile
.
register_view_op_c_code
(
aesara
.
compile
.
register_view_op_c_code
(
...
...
tests/tensor/random/test_type.py
浏览文件 @
7d07260b
import
pickle
import
pickle
import
sys
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
...
@@ -95,21 +94,6 @@ class TestRandomStateType:
...
@@ -95,21 +94,6 @@ class TestRandomStateType:
assert
not
rng_type
.
values_eq
(
rng_g
,
rng_a
)
assert
not
rng_type
.
values_eq
(
rng_g
,
rng_a
)
assert
not
rng_type
.
values_eq
(
rng_e
,
rng_g
)
assert
not
rng_type
.
values_eq
(
rng_e
,
rng_g
)
def
test_get_shape_info
(
self
):
rng
=
np
.
random
.
RandomState
(
12
)
rng_a
=
shared
(
rng
)
assert
isinstance
(
random_state_type
.
get_shape_info
(
rng_a
),
np
.
random
.
RandomState
)
def
test_get_size
(
self
):
rng
=
np
.
random
.
RandomState
(
12
)
rng_a
=
shared
(
rng
)
shape_info
=
random_state_type
.
get_shape_info
(
rng_a
)
size
=
random_state_type
.
get_size
(
shape_info
)
assert
size
==
sys
.
getsizeof
(
rng
.
get_state
(
legacy
=
False
))
def
test_may_share_memory
(
self
):
def
test_may_share_memory
(
self
):
bg1
=
np
.
random
.
MT19937
()
bg1
=
np
.
random
.
MT19937
()
bg2
=
np
.
random
.
MT19937
()
bg2
=
np
.
random
.
MT19937
()
...
@@ -119,16 +103,23 @@ class TestRandomStateType:
...
@@ -119,16 +103,23 @@ class TestRandomStateType:
rng_var_a
=
shared
(
rng_a
,
borrow
=
True
)
rng_var_a
=
shared
(
rng_a
,
borrow
=
True
)
rng_var_b
=
shared
(
rng_b
,
borrow
=
True
)
rng_var_b
=
shared
(
rng_b
,
borrow
=
True
)
shape_info_a
=
random_state_type
.
get_shape_info
(
rng_var_a
)
shape_info_b
=
random_state_type
.
get_shape_info
(
rng_var_b
)
assert
random_state_type
.
may_share_memory
(
shape_info_a
,
shape_info_b
)
is
False
assert
(
random_state_type
.
may_share_memory
(
rng_var_a
.
get_value
(
borrow
=
True
),
rng_var_b
.
get_value
(
borrow
=
True
)
)
is
False
)
rng_c
=
np
.
random
.
RandomState
(
bg2
)
rng_c
=
np
.
random
.
RandomState
(
bg2
)
rng_var_c
=
shared
(
rng_c
,
borrow
=
True
)
rng_var_c
=
shared
(
rng_c
,
borrow
=
True
)
shape_info_c
=
random_state_type
.
get_shape_info
(
rng_var_c
)
assert
random_state_type
.
may_share_memory
(
shape_info_b
,
shape_info_c
)
is
True
assert
(
random_state_type
.
may_share_memory
(
rng_var_b
.
get_value
(
borrow
=
True
),
rng_var_c
.
get_value
(
borrow
=
True
)
)
is
True
)
class
TestRandomGeneratorType
:
class
TestRandomGeneratorType
:
...
@@ -197,21 +188,6 @@ class TestRandomGeneratorType:
...
@@ -197,21 +188,6 @@ class TestRandomGeneratorType:
assert
rng_type
.
is_valid_value
(
bitgen_g
,
strict
=
True
)
assert
rng_type
.
is_valid_value
(
bitgen_g
,
strict
=
True
)
assert
rng_type
.
is_valid_value
(
bitgen_h
.
__getstate__
(),
strict
=
False
)
assert
rng_type
.
is_valid_value
(
bitgen_h
.
__getstate__
(),
strict
=
False
)
def
test_get_shape_info
(
self
):
rng
=
np
.
random
.
default_rng
(
12
)
rng_a
=
shared
(
rng
)
assert
isinstance
(
random_generator_type
.
get_shape_info
(
rng_a
),
np
.
random
.
Generator
)
def
test_get_size
(
self
):
rng
=
np
.
random
.
Generator
(
np
.
random
.
PCG64
(
12
))
rng_a
=
shared
(
rng
)
shape_info
=
random_generator_type
.
get_shape_info
(
rng_a
)
size
=
random_generator_type
.
get_size
(
shape_info
)
assert
size
==
sys
.
getsizeof
(
rng
.
__getstate__
())
def
test_may_share_memory
(
self
):
def
test_may_share_memory
(
self
):
bg_a
=
np
.
random
.
PCG64
()
bg_a
=
np
.
random
.
PCG64
()
bg_b
=
np
.
random
.
PCG64
()
bg_b
=
np
.
random
.
PCG64
()
...
@@ -220,13 +196,20 @@ class TestRandomGeneratorType:
...
@@ -220,13 +196,20 @@ class TestRandomGeneratorType:
rng_var_a
=
shared
(
rng_a
,
borrow
=
True
)
rng_var_a
=
shared
(
rng_a
,
borrow
=
True
)
rng_var_b
=
shared
(
rng_b
,
borrow
=
True
)
rng_var_b
=
shared
(
rng_b
,
borrow
=
True
)
shape_info_a
=
random_state_type
.
get_shape_info
(
rng_var_a
)
shape_info_b
=
random_state_type
.
get_shape_info
(
rng_var_b
)
assert
random_state_type
.
may_share_memory
(
shape_info_a
,
shape_info_b
)
is
False
assert
(
random_state_type
.
may_share_memory
(
rng_var_a
.
get_value
(
borrow
=
True
),
rng_var_b
.
get_value
(
borrow
=
True
)
)
is
False
)
rng_c
=
np
.
random
.
Generator
(
bg_b
)
rng_c
=
np
.
random
.
Generator
(
bg_b
)
rng_var_c
=
shared
(
rng_c
,
borrow
=
True
)
rng_var_c
=
shared
(
rng_c
,
borrow
=
True
)
shape_info_c
=
random_state_type
.
get_shape_info
(
rng_var_c
)
assert
random_state_type
.
may_share_memory
(
shape_info_b
,
shape_info_c
)
is
True
assert
(
random_state_type
.
may_share_memory
(
rng_var_b
.
get_value
(
borrow
=
True
),
rng_var_c
.
get_value
(
borrow
=
True
)
)
is
True
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论