Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
935ce79a
提交
935ce79a
authored
10月 07, 2024
作者:
ricardoV94
提交者:
Ricardo Vieira
10月 08, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tune down TestMeandDtype.test_mean_custom_dtype
上级
3eea7d0e
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
36 行删除
+40
-36
test_math.py
tests/tensor/test_math.py
+40
-36
没有找到文件。
tests/tensor/test_math.py
浏览文件 @
935ce79a
...
@@ -3210,52 +3210,56 @@ class TestMeanDtype:
...
@@ -3210,52 +3210,56 @@ class TestMeanDtype:
# TODO FIXME: This is a bad test
# TODO FIXME: This is a bad test
f
(
data
)
f
(
data
)
@pytest.mark.slow
@pytest.mark.parametrize
(
def
test_mean_custom_dtype
(
self
):
"input_dtype"
,
(
"bool"
,
"uint16"
,
"int8"
,
"int64"
,
"float16"
,
"float32"
,
"float64"
,
"complex64"
,
"complex128"
,
),
)
@pytest.mark.parametrize
(
"sum_dtype"
,
(
"bool"
,
"uint16"
,
"int8"
,
"int64"
,
"float16"
,
"float32"
,
"float64"
,
"complex64"
,
"complex128"
,
),
)
@pytest.mark.parametrize
(
"axis"
,
[
None
,
()])
def
test_mean_custom_dtype
(
self
,
input_dtype
,
sum_dtype
,
axis
):
# Test the ability to provide your own output dtype for a mean.
# Test the ability to provide your own output dtype for a mean.
# We try multiple axis combinations even though axis should not matter.
axes
=
[
None
,
0
,
1
,
[],
[
0
],
[
1
],
[
0
,
1
]]
idx
=
0
for
input_dtype
in
map
(
str
,
ps
.
all_types
):
x
=
matrix
(
dtype
=
input_dtype
)
x
=
matrix
(
dtype
=
input_dtype
)
for
sum_dtype
in
map
(
str
,
ps
.
all_types
):
# If the inner sum cannot be created, it will raise a TypeError.
axis
=
axes
[
idx
%
len
(
axes
)]
# If the inner sum cannot be created, it will raise a
# TypeError.
try
:
mean_var
=
x
.
mean
(
dtype
=
sum_dtype
,
axis
=
axis
)
mean_var
=
x
.
mean
(
dtype
=
sum_dtype
,
axis
=
axis
)
except
TypeError
:
pass
else
:
# Executed if no TypeError was raised
if
sum_dtype
in
discrete_dtypes
:
if
sum_dtype
in
discrete_dtypes
:
assert
mean_var
.
dtype
==
"float64"
,
(
mean_var
.
dtype
,
sum_dtype
)
assert
mean_var
.
dtype
==
"float64"
,
(
mean_var
.
dtype
,
sum_dtype
)
else
:
else
:
assert
mean_var
.
dtype
==
sum_dtype
,
(
mean_var
.
dtype
,
sum_dtype
)
assert
mean_var
.
dtype
==
sum_dtype
,
(
mean_var
.
dtype
,
sum_dtype
)
if
(
"complex"
in
input_dtype
or
"complex"
in
sum_dtype
f
=
function
([
x
],
mean_var
,
mode
=
"FAST_COMPILE"
)
)
and
input_dtype
!=
sum_dtype
:
data
=
np
.
ones
((
2
,
1
))
.
astype
(
input_dtype
)
continue
if
axis
!=
():
f
=
function
([
x
],
mean_var
)
expected_res
=
np
.
array
(
2
)
.
astype
(
sum_dtype
)
/
2
data
=
np
.
random
.
random
((
3
,
4
))
*
10
data
=
data
.
astype
(
input_dtype
)
# TODO FIXME: This is a bad test
f
(
data
)
# Check that we can take the gradient, when implemented
if
"complex"
in
mean_var
.
dtype
:
continue
try
:
grad
(
mean_var
.
sum
(),
x
,
disconnected_inputs
=
"ignore"
)
except
NotImplementedError
:
# TrueDiv does not seem to have a gradient when
# the numerator is complex.
if
mean_var
.
dtype
in
complex_dtypes
:
pass
else
:
else
:
raise
expected_res
=
data
np
.
testing
.
assert_allclose
(
f
(
data
),
expected_res
)
idx
+=
1
if
"complex"
not
in
mean_var
.
dtype
:
grad
(
mean_var
.
sum
(),
x
,
disconnected_inputs
=
"ignore"
)
def
test_mean_precision
(
self
):
def
test_mean_precision
(
self
):
# Check that the default accumulator precision is sufficient
# Check that the default accumulator precision is sufficient
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论