Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e8273115
提交
e8273115
authored
3月 11, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
3月 13, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not autouse test_value flag fixture
上级
62cee002
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
13 行删除
+12
-13
test_op.py
tests/tensor/random/test_op.py
+12
-13
没有找到文件。
tests/tensor/random/test_op.py
浏览文件 @
e8273115
...
...
@@ -13,13 +13,13 @@ from pytensor.tensor.shape import specify_shape
from
pytensor.tensor.type
import
all_dtypes
,
iscalar
,
tensor
@pytest.fixture
(
scope
=
"
module"
,
autouse
=
Tru
e
)
def
s
et_pytensor
_flags
():
@pytest.fixture
(
scope
=
"
function"
,
autouse
=
Fals
e
)
def
s
trict_test_value
_flags
():
with
config
.
change_flags
(
cxx
=
""
,
compute_test_value
=
"raise"
):
yield
def
test_RandomVariable_basics
():
def
test_RandomVariable_basics
(
strict_test_value_flags
):
str_res
=
str
(
RandomVariable
(
"normal"
,
...
...
@@ -95,7 +95,7 @@ def test_RandomVariable_basics():
grad
(
rv_out
,
[
rv_node
.
inputs
[
0
]])
def
test_RandomVariable_bcast
():
def
test_RandomVariable_bcast
(
strict_test_value_flags
):
rv
=
RandomVariable
(
"normal"
,
0
,
[
0
,
0
],
config
.
floatX
,
inplace
=
True
)
mu
=
tensor
(
dtype
=
config
.
floatX
,
shape
=
(
1
,
None
,
None
))
...
...
@@ -125,7 +125,7 @@ def test_RandomVariable_bcast():
assert
res
.
broadcastable
==
(
True
,
False
)
def
test_RandomVariable_bcast_specify_shape
():
def
test_RandomVariable_bcast_specify_shape
(
strict_test_value_flags
):
rv
=
RandomVariable
(
"normal"
,
0
,
[
0
,
0
],
config
.
floatX
,
inplace
=
True
)
s1
=
pt
.
as_tensor
(
1
,
dtype
=
np
.
int64
)
...
...
@@ -146,7 +146,7 @@ def test_RandomVariable_bcast_specify_shape():
assert
res
.
type
.
shape
==
(
1
,
None
,
None
,
None
,
1
)
def
test_RandomVariable_floatX
():
def
test_RandomVariable_floatX
(
strict_test_value_flags
):
test_rv_op
=
RandomVariable
(
"normal"
,
0
,
...
...
@@ -172,14 +172,14 @@ def test_RandomVariable_floatX():
(
3
,
default_rng
,
np
.
random
.
default_rng
(
3
)),
],
)
def
test_random_maker_op
(
seed
,
maker_op
,
numpy_res
):
def
test_random_maker_op
(
s
trict_test_value_flags
,
s
eed
,
maker_op
,
numpy_res
):
seed
=
pt
.
as_tensor_variable
(
seed
)
z
=
function
(
inputs
=
[],
outputs
=
[
maker_op
(
seed
)])()
aes_res
=
z
[
0
]
assert
maker_op
.
random_type
.
values_eq
(
aes_res
,
numpy_res
)
def
test_random_maker_ops_no_seed
():
def
test_random_maker_ops_no_seed
(
strict_test_value_flags
):
# Testing the initialization when seed=None
# Since internal states randomly generated,
# we just check the output classes
...
...
@@ -192,7 +192,7 @@ def test_random_maker_ops_no_seed():
assert
isinstance
(
aes_res
,
np
.
random
.
Generator
)
def
test_RandomVariable_incompatible_size
():
def
test_RandomVariable_incompatible_size
(
strict_test_value_flags
):
rv_op
=
RandomVariable
(
"normal"
,
0
,
[
0
,
0
],
config
.
floatX
,
inplace
=
True
)
with
pytest
.
raises
(
ValueError
,
match
=
"Size length is incompatible with batched dimensions"
...
...
@@ -216,7 +216,6 @@ class MultivariateRandomVariable(RandomVariable):
return
[
dist_params
[
0
]
.
shape
[
-
1
]]
@config.change_flags
(
compute_test_value
=
"off"
)
def
test_multivariate_rv_infer_static_shape
():
"""Test that infer shape for multivariate random variable works when a parameter must be broadcasted."""
mv_op
=
MultivariateRandomVariable
()
...
...
@@ -244,9 +243,7 @@ def test_multivariate_rv_infer_static_shape():
def
test_vectorize_node
():
vec
=
tensor
(
shape
=
(
None
,))
vec
.
tag
.
test_value
=
[
0
,
0
,
0
]
mat
=
tensor
(
shape
=
(
None
,
None
))
mat
.
tag
.
test_value
=
[[
0
,
0
,
0
],
[
1
,
1
,
1
]]
# Test without size
node
=
normal
(
vec
)
.
owner
...
...
@@ -273,4 +270,6 @@ def test_vectorize_node():
vect_node
=
vectorize_node
(
node
,
*
new_inputs
)
assert
vect_node
.
op
is
normal
assert
vect_node
.
inputs
[
3
]
is
mat
assert
tuple
(
vect_node
.
inputs
[
1
]
.
eval
({
mat
:
mat
.
tag
.
test_value
}))
==
(
2
,
3
)
assert
tuple
(
vect_node
.
inputs
[
1
]
.
eval
({
mat
:
np
.
zeros
((
2
,
3
),
dtype
=
config
.
floatX
)})
)
==
(
2
,
3
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论