Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
755f385a
提交
755f385a
authored
12月 06, 2020
作者:
Michael Osthege
提交者:
Brandon T. Willard
12月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get rid of most global variables in configparser
上级
8e3e8399
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
20 行增加
和
24 行删除
+20
-24
test_config.py
tests/test_config.py
+14
-13
configdefaults.py
theano/configdefaults.py
+3
-5
configparser.py
theano/configparser.py
+0
-0
cc.py
theano/gof/cc.py
+1
-2
vm.py
theano/gof/vm.py
+2
-4
没有找到文件。
tests/test_config.py
浏览文件 @
755f385a
...
@@ -6,13 +6,15 @@ import pytest
...
@@ -6,13 +6,15 @@ import pytest
from
theano
import
configdefaults
,
configparser
from
theano
import
configdefaults
,
configparser
from
theano.configdefaults
import
default_blas_ldflags
from
theano.configdefaults
import
default_blas_ldflags
from
theano.configparser
import
THEANO_FLAGS_DICT
,
AddConfigVar
,
ConfigParam
from
theano.configparser
import
ConfigParam
def
test_invalid_default
():
def
test_invalid_default
():
# Ensure an invalid default value found in the Theano code only causes
# Ensure an invalid default value found in the Theano code only causes
# a crash if it is not overridden by the user.
# a crash if it is not overridden by the user.
root
=
configdefaults
.
config
def
validate
(
val
):
def
validate
(
val
):
if
val
==
"invalid"
:
if
val
==
"invalid"
:
raise
ValueError
(
"Test-triggered"
)
raise
ValueError
(
"Test-triggered"
)
...
@@ -20,17 +22,17 @@ def test_invalid_default():
...
@@ -20,17 +22,17 @@ def test_invalid_default():
with
pytest
.
raises
(
ValueError
,
match
=
"Test-triggered"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Test-triggered"
):
# This should raise a ValueError because the default value is
# This should raise a ValueError because the default value is
# invalid.
# invalid.
AddConfigVar
(
root
.
add
(
"T_config__test_invalid_default_a"
,
"T_config__test_invalid_default_a"
,
doc
=
"unittest"
,
doc
=
"unittest"
,
configparam
=
ConfigParam
(
"invalid"
,
validate
=
validate
),
configparam
=
ConfigParam
(
"invalid"
,
validate
=
validate
),
in_c_key
=
False
,
in_c_key
=
False
,
)
)
THEANO_FLAGS_DICT
[
"T_config__test_invalid_default_b"
]
=
"ok"
root
.
_flags_dict
[
"T_config__test_invalid_default_b"
]
=
"ok"
# This should succeed since we defined a proper value, even
# This should succeed since we defined a proper value, even
# though the default was invalid.
# though the default was invalid.
AddConfigVar
(
root
.
add
(
"T_config__test_invalid_default_b"
,
"T_config__test_invalid_default_b"
,
doc
=
"unittest"
,
doc
=
"unittest"
,
configparam
=
ConfigParam
(
"invalid"
,
validate
=
validate
),
configparam
=
ConfigParam
(
"invalid"
,
validate
=
validate
),
...
@@ -39,7 +41,7 @@ def test_invalid_default():
...
@@ -39,7 +41,7 @@ def test_invalid_default():
# TODO We should remove these dummy options on test exit.
# TODO We should remove these dummy options on test exit.
# Check that the flag has been removed
# Check that the flag has been removed
assert
"T_config__test_invalid_default_b"
not
in
THEANO_FLAGS_DICT
assert
"T_config__test_invalid_default_b"
not
in
root
.
_flags_dict
@patch
(
"theano.configdefaults.try_blas_flag"
,
return_value
=
None
)
@patch
(
"theano.configdefaults.try_blas_flag"
,
return_value
=
None
)
...
@@ -84,20 +86,19 @@ def test_config_param_apply_and_validation():
...
@@ -84,20 +86,19 @@ def test_config_param_apply_and_validation():
def
test_config_hash
():
def
test_config_hash
():
# TODO: use custom config instance for the test
# TODO: use custom config instance for the test
root
=
configparser
.
config
root
=
configparser
.
config
configparser
.
AddConfigVar
(
root
.
add
(
"test_config_hash"
,
"test_config_hash"
,
"A config var from a test case."
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
configparser
.
StrParam
(
"test_default"
),
root
=
root
,
)
)
h0
=
configparser
.
get_config_hash
()
h0
=
root
.
get_config_hash
()
with
configparser
.
change_flags
(
test_config_hash
=
"new_value"
):
with
configparser
.
change_flags
(
test_config_hash
=
"new_value"
):
assert
root
.
test_config_hash
==
"new_value"
assert
root
.
test_config_hash
==
"new_value"
h1
=
configparser
.
get_config_hash
()
h1
=
root
.
get_config_hash
()
h2
=
configparser
.
get_config_hash
()
h2
=
root
.
get_config_hash
()
assert
h1
!=
h0
assert
h1
!=
h0
assert
h2
==
h0
assert
h2
==
h0
...
@@ -141,11 +142,10 @@ class TestConfigTypes:
...
@@ -141,11 +142,10 @@ class TestConfigTypes:
def
test_config_context
():
def
test_config_context
():
# TODO: use custom config instance for the test
# TODO: use custom config instance for the test
root
=
configparser
.
config
root
=
configparser
.
config
configparser
.
AddConfigVar
(
root
.
add
(
"test_config_context"
,
"test_config_context"
,
"A config var from a test case."
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
configparser
.
StrParam
(
"test_default"
),
root
=
root
,
)
)
assert
hasattr
(
root
,
"test_config_context"
)
assert
hasattr
(
root
,
"test_config_context"
)
assert
root
.
test_config_context
==
"test_default"
assert
root
.
test_config_context
==
"test_default"
...
@@ -156,8 +156,9 @@ def test_config_context():
...
@@ -156,8 +156,9 @@ def test_config_context():
def
test_no_more_dotting
():
def
test_no_more_dotting
():
root
=
configparser
.
config
with
pytest
.
raises
(
ValueError
,
match
=
"Dot-based"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Dot-based"
):
AddConfigVar
(
root
.
add
(
"T_config.something"
,
"T_config.something"
,
doc
=
"unittest"
,
doc
=
"unittest"
,
configparam
=
ConfigParam
(
"invalid"
),
configparam
=
ConfigParam
(
"invalid"
),
...
...
theano/configdefaults.py
浏览文件 @
755f385a
...
@@ -12,8 +12,8 @@ import warnings
...
@@ -12,8 +12,8 @@ import warnings
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
import
theano.configparser
from
theano.configparser
import
(
from
theano.configparser
import
(
THEANO_FLAGS_DICT
,
AddConfigVar
,
AddConfigVar
,
BoolParam
,
BoolParam
,
ConfigParam
,
ConfigParam
,
...
@@ -23,7 +23,6 @@ from theano.configparser import (
...
@@ -23,7 +23,6 @@ from theano.configparser import (
FloatParam
,
FloatParam
,
IntParam
,
IntParam
,
StrParam
,
StrParam
,
TheanoConfigParser
,
)
)
from
theano.misc.windows
import
call_subprocess_Popen
,
output_subprocess_Popen
from
theano.misc.windows
import
call_subprocess_Popen
,
output_subprocess_Popen
from
theano.utils
import
maybe_add_to_os_environ_pathlist
from
theano.utils
import
maybe_add_to_os_environ_pathlist
...
@@ -2236,7 +2235,7 @@ SUPPORTED_DNN_CONV_PRECISION = (
...
@@ -2236,7 +2235,7 @@ SUPPORTED_DNN_CONV_PRECISION = (
# TODO: we should add the configs explicitly to an instance of the TheanoConfigParser
# TODO: we should add the configs explicitly to an instance of the TheanoConfigParser
# Even if we treat it as a singleton, we should implement as if it wasn't, so we can
# Even if we treat it as a singleton, we should implement as if it wasn't, so we can
# test it independently.
# test it independently.
config
=
TheanoConfigParser
()
config
=
theano
.
configparser
.
config
add_basic_configvars
()
add_basic_configvars
()
add_dnn_configvars
()
add_dnn_configvars
()
add_magma_configvars
()
add_magma_configvars
()
...
@@ -2272,6 +2271,5 @@ except OSError:
...
@@ -2272,6 +2271,5 @@ except OSError:
add_caching_dir_configvars
()
add_caching_dir_configvars
()
# Check if there are remaining flags provided by the user through THEANO_FLAGS.
# Check if there are remaining flags provided by the user through THEANO_FLAGS.
# TODO: the global variable THEANO_FLAGS_DICT should probably become an attribute on the `config` singleton
for
key
in
config
.
_flags_dict
.
keys
():
for
key
in
THEANO_FLAGS_DICT
.
keys
():
warnings
.
warn
(
f
"Theano does not recognise this flag: {key}"
)
warnings
.
warn
(
f
"Theano does not recognise this flag: {key}"
)
theano/configparser.py
浏览文件 @
755f385a
差异被折叠。
点击展开。
theano/gof/cc.py
浏览文件 @
755f385a
...
@@ -11,7 +11,6 @@ from io import StringIO
...
@@ -11,7 +11,6 @@ from io import StringIO
import
numpy
as
np
import
numpy
as
np
import
theano
from
theano
import
config
from
theano
import
config
from
theano.gof
import
cmodule
,
graph
,
link
,
utils
from
theano.gof
import
cmodule
,
graph
,
link
,
utils
from
theano.gof.callcache
import
CallCache
from
theano.gof.callcache
import
CallCache
...
@@ -1472,7 +1471,7 @@ class CLinker(link.Linker):
...
@@ -1472,7 +1471,7 @@ class CLinker(link.Linker):
# NOTE: config md5 is not using md5 hash, but sha256 instead. Function
# NOTE: config md5 is not using md5 hash, but sha256 instead. Function
# string instances of md5 will be updated at a later release.
# string instances of md5 will be updated at a later release.
if
insert_config_hash
:
if
insert_config_hash
:
sig
.
append
(
"md5:"
+
theano
.
configparser
.
get_config_hash
())
sig
.
append
(
"md5:"
+
config
.
get_config_hash
())
else
:
else
:
sig
.
append
(
"md5: <omitted>"
)
sig
.
append
(
"md5: <omitted>"
)
...
...
theano/gof/vm.py
浏览文件 @
755f385a
...
@@ -13,7 +13,7 @@ import warnings
...
@@ -13,7 +13,7 @@ import warnings
from
collections
import
defaultdict
from
collections
import
defaultdict
import
theano.gof.cmodule
import
theano.gof.cmodule
from
theano.configparser
import
_config_var_list
,
config
from
theano.configparser
import
config
from
.
import
link
from
.
import
link
...
@@ -715,9 +715,7 @@ except (OSError, theano.gof.cmodule.MissingGXX) as e:
...
@@ -715,9 +715,7 @@ except (OSError, theano.gof.cmodule.MissingGXX) as e:
# already changed the default linker to something else then CVM.
# already changed the default linker to something else then CVM.
# Currently this is the py linker.
# Currently this is the py linker.
# Here we assert that the default linker is not cvm.
# Here we assert that the default linker is not cvm.
assert
not
[
x
for
x
in
_config_var_list
if
x
.
fullname
==
"linker"
][
assert
not
config
.
_config_var_dict
[
"linker"
]
.
default
.
startswith
(
"cvm"
),
e
0
]
.
default
.
startswith
(
"cvm"
),
e
class
VM_Linker
(
link
.
LocalLinker
):
class
VM_Linker
(
link
.
LocalLinker
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论