Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b0b34b59
Unverified
提交
b0b34b59
authored
12月 09, 2020
作者:
Brandon T. Willard
提交者:
GitHub
12月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #214 from michaelosthege/objectify-config
Get rid of singleton design and most module-level variables
上级
8e3e8399
505988e5
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
49 个修改的文件
包含
299 行增加
和
231 行删除
+299
-231
test.yml
.github/workflows/test.yml
+1
-1
test_builders.py
tests/compile/test_builders.py
+1
-1
test_debugmode.py
tests/compile/test_debugmode.py
+9
-9
test_ops.py
tests/compile/test_ops.py
+3
-3
test_compute_test_value.py
tests/gof/test_compute_test_value.py
+8
-15
test_destroyhandler.py
tests/gof/test_destroyhandler.py
+2
-2
test_fg.py
tests/gof/test_fg.py
+2
-2
test_op.py
tests/gof/test_op.py
+8
-9
test_opt.py
tests/gof/test_opt.py
+3
-7
test_types.py
tests/gof/test_types.py
+1
-1
test_opt.py
tests/gpuarray/test_opt.py
+0
-0
test_rng_mrg.py
tests/gpuarray/test_rng_mrg.py
+2
-2
test_subtensor.py
tests/gpuarray/test_subtensor.py
+1
-1
test_jax.py
tests/sandbox/test_jax.py
+3
-3
test_rng_mrg.py
tests/sandbox/test_rng_mrg.py
+3
-8
test_type.py
tests/scalar/test_type.py
+3
-3
test_basic.py
tests/scan/test_basic.py
+0
-0
_test_mpi_roundtrip.py
tests/tensor/_test_mpi_roundtrip.py
+2
-2
test_abstract_conv.py
tests/tensor/nnet/test_abstract_conv.py
+0
-0
test_neighbours.py
tests/tensor/nnet/test_neighbours.py
+3
-3
test_nnet.py
tests/tensor/nnet/test_nnet.py
+0
-0
test_basic.py
tests/tensor/test_basic.py
+0
-0
test_blas.py
tests/tensor/test_blas.py
+4
-8
test_blas_c.py
tests/tensor/test_blas_c.py
+1
-1
test_extra_ops.py
tests/tensor/test_extra_ops.py
+14
-14
test_mpi.py
tests/tensor/test_mpi.py
+4
-4
test_nlinalg.py
tests/tensor/test_nlinalg.py
+26
-27
test_opt.py
tests/tensor/test_opt.py
+0
-0
test_subtensor.py
tests/tensor/test_subtensor.py
+13
-17
test_type.py
tests/tensor/test_type.py
+3
-3
utils.py
tests/tensor/utils.py
+3
-3
test_config.py
tests/test_config.py
+121
-31
test_gradient.py
tests/test_gradient.py
+6
-6
__init__.py
theano/__init__.py
+6
-1
builders.py
theano/compile/builders.py
+2
-2
debugmode.py
theano/compile/debugmode.py
+6
-4
types.py
theano/compile/function/types.py
+35
-38
configdefaults.py
theano/configdefaults.py
+0
-0
configparser.py
theano/configparser.py
+0
-0
cc.py
theano/gof/cc.py
+0
-0
type.py
theano/gof/type.py
+0
-0
vm.py
theano/gof/vm.py
+0
-0
rng_mrg.py
theano/sandbox/rng_mrg.py
+0
-0
basic.py
theano/scalar/basic.py
+0
-0
basic.py
theano/tensor/basic.py
+0
-0
elemwise.py
theano/tensor/elemwise.py
+0
-0
bn.py
theano/tensor/nnet/bn.py
+0
-0
subtensor.py
theano/tensor/subtensor.py
+0
-0
utils.py
theano/utils.py
+0
-0
没有找到文件。
.github/workflows/test.yml
浏览文件 @
b0b34b59
...
@@ -130,7 +130,7 @@ jobs:
...
@@ -130,7 +130,7 @@ jobs:
run
:
|
run
:
|
if [[ $FAST_COMPILE == "1" ]]; then export THEANO_FLAGS=$THEANO_FLAGS,mode=FAST_COMPILE; fi
if [[ $FAST_COMPILE == "1" ]]; then export THEANO_FLAGS=$THEANO_FLAGS,mode=FAST_COMPILE; fi
if [[ $FLOAT32 == "1" ]]; then export THEANO_FLAGS=$THEANO_FLAGS,floatX=float32; fi
if [[ $FLOAT32 == "1" ]]; then export THEANO_FLAGS=$THEANO_FLAGS,floatX=float32; fi
export THEANO_FLAGS=$THEANO_FLAGS,warn
.ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc.
cxxflags=-pipe
export THEANO_FLAGS=$THEANO_FLAGS,warn
__ignore_bug_before=all,on_opt_error=raise,on_shape_error=raise,gcc__
cxxflags=-pipe
python -m pytest -x -r A --verbose --runslow --cov=theano/ --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail $PART
python -m pytest -x -r A --verbose --runslow --cov=theano/ --cov-report=xml:coverage/coverage-${MATRIX_ID}.xml --no-cov-on-fail $PART
env
:
env
:
MATRIX_ID
:
${{ steps.matrix-id.outputs.id }}
MATRIX_ID
:
${{ steps.matrix-id.outputs.id }}
...
...
tests/compile/test_builders.py
浏览文件 @
b0b34b59
...
@@ -396,7 +396,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
...
@@ -396,7 +396,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
OpFromGraph
,
OpFromGraph
,
)
)
@
theano
.change_flags
(
compute_test_value
=
"raise"
)
@
config
.change_flags
(
compute_test_value
=
"raise"
)
def
test_compute_test_value
(
self
):
def
test_compute_test_value
(
self
):
x
=
tt
.
scalar
(
"x"
)
x
=
tt
.
scalar
(
"x"
)
x
.
tag
.
test_value
=
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)
x
.
tag
.
test_value
=
np
.
array
(
1.0
,
dtype
=
config
.
floatX
)
...
...
tests/compile/test_debugmode.py
浏览文件 @
b0b34b59
...
@@ -190,7 +190,7 @@ wb1 = WeirdBrokenOp("times1")
...
@@ -190,7 +190,7 @@ wb1 = WeirdBrokenOp("times1")
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_badthunkoutput
():
def
test_badthunkoutput
():
# Check if the c and python code is consistent.
# Check if the c and python code is consistent.
...
@@ -200,12 +200,12 @@ def test_badthunkoutput():
...
@@ -200,12 +200,12 @@ def test_badthunkoutput():
f_good
=
theano
.
function
(
f_good
=
theano
.
function
(
[
a
,
b
],
[
a
,
b
],
off_by_half
(
a
,
b
),
off_by_half
(
a
,
b
),
mode
=
debugmode
.
DebugMode
(
check_c_code
=
theano
.
config
.
cxx
),
mode
=
debugmode
.
DebugMode
(
check_c_code
=
config
.
cxx
),
)
)
f_inconsistent
=
theano
.
function
(
f_inconsistent
=
theano
.
function
(
[
a
,
b
],
[
a
,
b
],
inconsistent
(
a
,
b
),
inconsistent
(
a
,
b
),
mode
=
debugmode
.
DebugMode
(
check_c_code
=
theano
.
config
.
cxx
),
mode
=
debugmode
.
DebugMode
(
check_c_code
=
config
.
cxx
),
)
)
# this should evaluate with no error
# this should evaluate with no error
...
@@ -283,7 +283,7 @@ def test_badoptimization_opt_err():
...
@@ -283,7 +283,7 @@ def test_badoptimization_opt_err():
with
pytest
.
raises
(
with
pytest
.
raises
(
theano
.
gof
.
toolbox
.
BadOptimization
,
match
=
r"insert_bad_dtype"
theano
.
gof
.
toolbox
.
BadOptimization
,
match
=
r"insert_bad_dtype"
)
as
einfo
:
)
as
einfo
:
with
theano
.
change_flags
(
on_opt_error
=
"raise"
):
with
config
.
change_flags
(
on_opt_error
=
"raise"
):
f2
=
theano
.
function
(
f2
=
theano
.
function
(
[
a
,
b
],
[
a
,
b
],
a
+
b
,
a
+
b
,
...
@@ -337,7 +337,7 @@ def test_stochasticoptimization():
...
@@ -337,7 +337,7 @@ def test_stochasticoptimization():
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_just_c_code
():
def
test_just_c_code
():
x
=
theano
.
tensor
.
dvector
()
x
=
theano
.
tensor
.
dvector
()
...
@@ -366,7 +366,7 @@ def test_baddestroymap():
...
@@ -366,7 +366,7 @@ def test_baddestroymap():
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_baddestroymap_c
():
def
test_baddestroymap_c
():
x
=
theano
.
tensor
.
dvector
()
x
=
theano
.
tensor
.
dvector
()
...
@@ -420,7 +420,7 @@ class TestViewMap:
...
@@ -420,7 +420,7 @@ class TestViewMap:
f
([
1
,
5
,
1
],
[
3
,
4
,
2
,
1
,
4
])
f
([
1
,
5
,
1
],
[
3
,
4
,
2
,
1
,
4
])
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_badviewmap_c
(
self
):
def
test_badviewmap_c
(
self
):
x
=
theano
.
tensor
.
dvector
()
x
=
theano
.
tensor
.
dvector
()
...
@@ -748,7 +748,7 @@ class TestPreallocatedOutput:
...
@@ -748,7 +748,7 @@ class TestPreallocatedOutput:
f
=
theano
.
function
([
a
,
b
],
out
,
mode
=
mode
)
f
=
theano
.
function
([
a
,
b
],
out
,
mode
=
mode
)
if
theano
.
config
.
cxx
:
if
config
.
cxx
:
with
pytest
.
raises
(
debugmode
.
BadThunkOutput
):
with
pytest
.
raises
(
debugmode
.
BadThunkOutput
):
f
(
a_val
,
b_val
)
f
(
a_val
,
b_val
)
else
:
else
:
...
@@ -779,7 +779,7 @@ class TestPreallocatedOutput:
...
@@ -779,7 +779,7 @@ class TestPreallocatedOutput:
f
=
theano
.
function
([
a
,
b
],
out
,
mode
=
mode
)
f
=
theano
.
function
([
a
,
b
],
out
,
mode
=
mode
)
if
theano
.
config
.
cxx
:
if
config
.
cxx
:
with
pytest
.
raises
(
debugmode
.
BadThunkOutput
):
with
pytest
.
raises
(
debugmode
.
BadThunkOutput
):
f
(
a_val
,
b_val
)
f
(
a_val
,
b_val
)
else
:
else
:
...
...
tests/compile/test_ops.py
浏览文件 @
b0b34b59
...
@@ -5,7 +5,7 @@ import pytest
...
@@ -5,7 +5,7 @@ import pytest
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
c
hange_flags
,
c
onfig
,
function
from
theano
import
config
,
function
from
theano.compile.ops
import
Rebroadcast
,
SpecifyShape
,
as_op
,
shape
,
shape_i
from
theano.compile.ops
import
Rebroadcast
,
SpecifyShape
,
as_op
,
shape
,
shape_i
from
theano.gof.fg
import
FunctionGraph
from
theano.gof.fg
import
FunctionGraph
from
theano.tensor.basic
import
(
from
theano.tensor.basic
import
(
...
@@ -228,11 +228,11 @@ class TestRebroadcast(utt.InferShapeTester):
...
@@ -228,11 +228,11 @@ class TestRebroadcast(utt.InferShapeTester):
)
)
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_nonstandard_shapes
():
def
test_nonstandard_shapes
():
a
=
tensor3
(
config
.
floatX
)
a
=
tensor3
(
config
.
floatX
)
a
.
tag
.
test_value
=
np
.
random
.
random
((
2
,
3
,
4
))
.
astype
(
config
.
floatX
)
a
.
tag
.
test_value
=
np
.
random
.
random
((
2
,
3
,
4
))
.
astype
(
config
.
floatX
)
b
=
tensor3
(
theano
.
config
.
floatX
)
b
=
tensor3
(
config
.
floatX
)
b
.
tag
.
test_value
=
np
.
random
.
random
((
2
,
3
,
4
))
.
astype
(
config
.
floatX
)
b
.
tag
.
test_value
=
np
.
random
.
random
((
2
,
3
,
4
))
.
astype
(
config
.
floatX
)
tl
=
make_list
([
a
,
b
])
tl
=
make_list
([
a
,
b
])
...
...
tests/gof/test_compute_test_value.py
浏览文件 @
b0b34b59
...
@@ -12,7 +12,7 @@ from theano.tensor.basic import _allclose
...
@@ -12,7 +12,7 @@ from theano.tensor.basic import _allclose
@pytest.fixture
(
scope
=
"module"
,
autouse
=
True
)
@pytest.fixture
(
scope
=
"module"
,
autouse
=
True
)
def
set_theano_flags
():
def
set_theano_flags
():
with
theano
.
change_flags
(
compute_test_value
=
"raise"
):
with
config
.
change_flags
(
compute_test_value
=
"raise"
):
yield
yield
...
@@ -92,26 +92,19 @@ class TestComputeTestValue:
...
@@ -92,26 +92,19 @@ class TestComputeTestValue:
y
.
tag
.
test_value
=
np
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
y
.
tag
.
test_value
=
np
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
# should skip computation of test value
# should skip computation of test value
theano
.
config
.
compute_test_value
=
"off"
with
config
.
change_flags
(
compute_test_value
=
"off"
):
z
=
tt
.
dot
(
x
,
y
)
z
=
tt
.
dot
(
x
,
y
)
assert
not
hasattr
(
z
.
tag
,
"test_value"
)
assert
not
hasattr
(
z
.
tag
,
"test_value"
)
# should fail when asked by user
# should fail when asked by user
theano
.
config
.
compute_test_value
=
"raise"
with
pytest
.
raises
(
ValueError
),
config
.
change_flags
(
compute_test_value
=
"raise"
):
with
pytest
.
raises
(
ValueError
):
tt
.
dot
(
x
,
y
)
tt
.
dot
(
x
,
y
)
# test that a warning is raised if required
# test that a warning is raised if required
theano
.
config
.
compute_test_value
=
"warn"
with
warnings
.
catch_warnings
(),
config
.
change_flags
(
compute_test_value
=
"warn"
):
warnings
.
simplefilter
(
"error"
,
UserWarning
)
warnings
.
simplefilter
(
"error"
,
UserWarning
)
try
:
with
pytest
.
raises
(
UserWarning
):
with
pytest
.
raises
(
UserWarning
):
tt
.
dot
(
x
,
y
)
tt
.
dot
(
x
,
y
)
finally
:
# Restore the default behavior.
# TODO There is a cleaner way to do this in Python 2.6, once
# Theano drops support of Python 2.4 and 2.5.
warnings
.
simplefilter
(
"default"
,
UserWarning
)
def
test_string_var
(
self
):
def
test_string_var
(
self
):
x
=
tt
.
matrix
(
"x"
)
x
=
tt
.
matrix
(
"x"
)
...
@@ -302,7 +295,7 @@ class TestComputeTestValue:
...
@@ -302,7 +295,7 @@ class TestComputeTestValue:
assert
o
.
tag
.
test_value
==
4
assert
o
.
tag
.
test_value
==
4
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_no_perform
(
self
):
def
test_no_perform
(
self
):
i
=
scalar
.
int32
(
"i"
)
i
=
scalar
.
int32
(
"i"
)
...
...
tests/gof/test_destroyhandler.py
浏览文件 @
b0b34b59
...
@@ -3,7 +3,7 @@ from copy import copy
...
@@ -3,7 +3,7 @@ from copy import copy
import
pytest
import
pytest
from
tests.unittest_tools
import
assertFailure_fast
from
tests.unittest_tools
import
assertFailure_fast
from
theano
import
c
hange_flags
from
theano
import
c
onfig
from
theano.gof
import
destroyhandler
,
graph
from
theano.gof
import
destroyhandler
,
graph
from
theano.gof.fg
import
FunctionGraph
,
InconsistencyError
from
theano.gof.fg
import
FunctionGraph
,
InconsistencyError
from
theano.gof.graph
import
Apply
,
Variable
from
theano.gof.graph
import
Apply
,
Variable
...
@@ -417,7 +417,7 @@ def test_value_repl():
...
@@ -417,7 +417,7 @@ def test_value_repl():
assert
g
.
consistent
()
assert
g
.
consistent
()
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_value_repl_2
():
def
test_value_repl_2
():
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
sy
=
sigmoid
(
y
)
sy
=
sigmoid
(
y
)
...
...
tests/gof/test_fg.py
浏览文件 @
b0b34b59
...
@@ -4,7 +4,7 @@ import numpy as np
...
@@ -4,7 +4,7 @@ import numpy as np
import
pytest
import
pytest
from
tests.gof.utils
import
MyVariable
,
MyVariable2
,
op1
,
op2
,
op3
from
tests.gof.utils
import
MyVariable
,
MyVariable2
,
op1
,
op2
,
op3
from
theano
import
c
hange_flags
from
theano
import
c
onfig
from
theano.gof.fg
import
FunctionGraph
,
MissingInputError
from
theano.gof.fg
import
FunctionGraph
,
MissingInputError
from
theano.gof.toolbox
import
BadOptimization
from
theano.gof.toolbox
import
BadOptimization
...
@@ -186,7 +186,7 @@ class TestFunctionGraph:
...
@@ -186,7 +186,7 @@ class TestFunctionGraph:
assert
var5
.
owner
.
inputs
[
1
]
is
var1
assert
var5
.
owner
.
inputs
[
1
]
is
var1
assert
(
var5
.
owner
,
1
)
not
in
fg
.
get_clients
(
var2
)
assert
(
var5
.
owner
,
1
)
not
in
fg
.
get_clients
(
var2
)
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_replace_test_value
(
self
):
def
test_replace_test_value
(
self
):
var1
=
MyVariable
(
"var1"
)
var1
=
MyVariable
(
"var1"
)
...
...
tests/gof/test_op.py
浏览文件 @
b0b34b59
...
@@ -5,7 +5,6 @@ import theano
...
@@ -5,7 +5,6 @@ import theano
import
theano.gof.op
as
op
import
theano.gof.op
as
op
import
theano.tensor
as
tt
import
theano.tensor
as
tt
from
theano
import
config
,
scalar
,
shared
from
theano
import
config
,
scalar
,
shared
from
theano.configparser
import
change_flags
from
theano.gof.graph
import
Apply
,
Variable
from
theano.gof.graph
import
Apply
,
Variable
from
theano.gof.op
import
Op
from
theano.gof.op
import
Op
from
theano.gof.type
import
Generic
,
Type
from
theano.gof.type
import
Generic
,
Type
...
@@ -133,13 +132,13 @@ class TestOp:
...
@@ -133,13 +132,13 @@ class TestOp:
assert
rval
==
"test Op no input"
assert
rval
==
"test Op no input"
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_op_struct
(
self
):
def
test_op_struct
(
self
):
sop
=
StructOp
()
sop
=
StructOp
()
c
=
sop
(
theano
.
tensor
.
constant
(
0
))
c
=
sop
(
theano
.
tensor
.
constant
(
0
))
mode
=
None
mode
=
None
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
if
config
.
mode
==
"FAST_COMPILE"
:
mode
=
"FAST_RUN"
mode
=
"FAST_RUN"
f
=
theano
.
function
([],
c
,
mode
=
mode
)
f
=
theano
.
function
([],
c
,
mode
=
mode
)
rval
=
f
()
rval
=
f
()
...
@@ -219,7 +218,7 @@ class TestMakeThunk:
...
@@ -219,7 +218,7 @@ class TestMakeThunk:
thunk
=
o
.
owner
.
op
.
make_thunk
(
thunk
=
o
.
owner
.
op
.
make_thunk
(
o
.
owner
,
storage_map
,
compute_map
,
no_recycling
=
[]
o
.
owner
,
storage_map
,
compute_map
,
no_recycling
=
[]
)
)
if
theano
.
config
.
cxx
:
if
config
.
cxx
:
required
=
thunk
()
required
=
thunk
()
# Check everything went OK
# Check everything went OK
assert
not
required
# We provided all inputs
assert
not
required
# We provided all inputs
...
@@ -275,7 +274,7 @@ def test_test_value_shared():
...
@@ -275,7 +274,7 @@ def test_test_value_shared():
assert
np
.
all
(
v
==
np
.
zeros
((
5
,
5
)))
assert
np
.
all
(
v
==
np
.
zeros
((
5
,
5
)))
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_test_value_op
():
def
test_test_value_op
():
x
=
tt
.
log
(
np
.
ones
((
5
,
5
)))
x
=
tt
.
log
(
np
.
ones
((
5
,
5
)))
...
@@ -284,7 +283,7 @@ def test_test_value_op():
...
@@ -284,7 +283,7 @@ def test_test_value_op():
assert
np
.
allclose
(
v
,
np
.
zeros
((
5
,
5
)))
assert
np
.
allclose
(
v
,
np
.
zeros
((
5
,
5
)))
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_get_test_values_no_debugger
():
def
test_get_test_values_no_debugger
():
"""Tests that `get_test_values` returns `[]` when debugger is off."""
"""Tests that `get_test_values` returns `[]` when debugger is off."""
...
@@ -292,7 +291,7 @@ def test_get_test_values_no_debugger():
...
@@ -292,7 +291,7 @@ def test_get_test_values_no_debugger():
assert
op
.
get_test_values
(
x
)
==
[]
assert
op
.
get_test_values
(
x
)
==
[]
@change_flags
(
compute_test_value
=
"ignore"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"ignore"
)
def
test_get_test_values_ignore
():
def
test_get_test_values_ignore
():
"""Tests that `get_test_values` returns `[]` when debugger is set to "ignore" and some values are missing."""
"""Tests that `get_test_values` returns `[]` when debugger is set to "ignore" and some values are missing."""
...
@@ -304,7 +303,7 @@ def test_get_test_values_success():
...
@@ -304,7 +303,7 @@ def test_get_test_values_success():
"""Tests that `get_test_values` returns values when available (and the debugger is on)."""
"""Tests that `get_test_values` returns values when available (and the debugger is on)."""
for
mode
in
[
"ignore"
,
"warn"
,
"raise"
]:
for
mode
in
[
"ignore"
,
"warn"
,
"raise"
]:
with
change_flags
(
compute_test_value
=
mode
):
with
c
onfig
.
c
hange_flags
(
compute_test_value
=
mode
):
x
=
tt
.
vector
()
x
=
tt
.
vector
()
x
.
tag
.
test_value
=
np
.
zeros
((
4
,),
dtype
=
config
.
floatX
)
x
.
tag
.
test_value
=
np
.
zeros
((
4
,),
dtype
=
config
.
floatX
)
y
=
np
.
zeros
((
5
,
5
))
y
=
np
.
zeros
((
5
,
5
))
...
@@ -321,7 +320,7 @@ def test_get_test_values_success():
...
@@ -321,7 +320,7 @@ def test_get_test_values_success():
assert
iters
==
1
assert
iters
==
1
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_get_test_values_exc
():
def
test_get_test_values_exc
():
"""Tests that `get_test_values` raises an exception when debugger is set to raise and a value is missing."""
"""Tests that `get_test_values` raises an exception when debugger is set to raise and a value is missing."""
...
...
tests/gof/test_opt.py
浏览文件 @
b0b34b59
import
theano.tensor
as
tt
import
theano.tensor
as
tt
from
tests.gof.utils
import
MyType
,
MyVariable
,
op1
,
op2
,
op3
,
op4
,
op5
,
op6
,
op_y
,
op_z
from
tests.gof.utils
import
MyType
,
MyVariable
,
op1
,
op2
,
op3
,
op4
,
op5
,
op6
,
op_y
,
op_z
from
theano
import
config
from
theano.gof.fg
import
FunctionGraph
from
theano.gof.fg
import
FunctionGraph
from
theano.gof.graph
import
Apply
,
Constant
from
theano.gof.graph
import
Apply
,
Constant
from
theano.gof.op
import
Op
from
theano.gof.op
import
Op
...
@@ -10,7 +11,6 @@ from theano.gof.opt import (
...
@@ -10,7 +11,6 @@ from theano.gof.opt import (
OpSub
,
OpSub
,
PatternSub
,
PatternSub
,
TopoOptimizer
,
TopoOptimizer
,
config
,
logging
,
logging
,
pre_constant_merge
,
pre_constant_merge
,
pre_greedy_local_optimizer
,
pre_greedy_local_optimizer
,
...
@@ -305,12 +305,8 @@ class TestMergeOptimizer:
...
@@ -305,12 +305,8 @@ class TestMergeOptimizer:
x
=
MyVariable
(
"x"
)
x
=
MyVariable
(
"x"
)
y
=
Constant
(
MyType
(),
2
,
name
=
"y"
)
y
=
Constant
(
MyType
(),
2
,
name
=
"y"
)
z
=
Constant
(
MyType
(),
2
,
name
=
"z"
)
z
=
Constant
(
MyType
(),
2
,
name
=
"z"
)
ctv_backup
=
config
.
compute_test_value
with
config
.
change_flags
(
compute_test_value
=
"off"
):
config
.
compute_test_value
=
"off"
try
:
e1
=
op1
(
y
,
z
)
e1
=
op1
(
y
,
z
)
finally
:
config
.
compute_test_value
=
ctv_backup
g
=
FunctionGraph
([
x
,
y
,
z
],
[
e1
])
g
=
FunctionGraph
([
x
,
y
,
z
],
[
e1
])
MergeOptimizer
()
.
optimize
(
g
)
MergeOptimizer
()
.
optimize
(
g
)
strg
=
str
(
g
)
strg
=
str
(
g
)
...
@@ -515,7 +511,7 @@ class TestEquilibrium:
...
@@ -515,7 +511,7 @@ class TestEquilibrium:
opt
.
optimize
(
g
)
opt
.
optimize
(
g
)
assert
str
(
g
)
==
"FunctionGraph(Op2(x, y))"
assert
str
(
g
)
==
"FunctionGraph(Op2(x, y))"
@
theano
.change_flags
(
on_opt_error
=
"ignore"
)
@
config
.change_flags
(
on_opt_error
=
"ignore"
)
def
test_low_use_ratio
(
self
):
def
test_low_use_ratio
(
self
):
x
,
y
,
z
=
map
(
MyVariable
,
"xyz"
)
x
,
y
,
z
=
map
(
MyVariable
,
"xyz"
)
e
=
op3
(
op4
(
x
,
y
))
e
=
op3
(
op4
(
x
,
y
))
...
...
tests/gof/test_types.py
浏览文件 @
b0b34b59
...
@@ -284,6 +284,6 @@ class TestEnumTypes:
...
@@ -284,6 +284,6 @@ class TestEnumTypes:
assert
val_billion
==
val_million
*
1000
assert
val_billion
==
val_million
*
1000
assert
val_two_billions
==
val_billion
*
2
assert
val_two_billions
==
val_billion
*
2
@theano.change_flags
(
**
{
"cmodule__debug"
:
True
})
@theano.c
onfig.c
hange_flags
(
**
{
"cmodule__debug"
:
True
})
def
test_op_with_cenumtype_debug
(
self
):
def
test_op_with_cenumtype_debug
(
self
):
self
.
test_op_with_cenumtype
()
self
.
test_op_with_cenumtype
()
tests/gpuarray/test_opt.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
tests/gpuarray/test_rng_mrg.py
浏览文件 @
b0b34b59
...
@@ -7,7 +7,7 @@ from tests import unittest_tools as utt
...
@@ -7,7 +7,7 @@ from tests import unittest_tools as utt
from
tests.gpuarray.config
import
mode_with_gpu
as
mode
from
tests.gpuarray.config
import
mode_with_gpu
as
mode
from
tests.sandbox.test_rng_mrg
import
java_samples
,
rng_mrg_overflow
from
tests.sandbox.test_rng_mrg
import
java_samples
,
rng_mrg_overflow
from
tests.sandbox.test_rng_mrg
import
test_f16_nonzero
as
cpu_f16_nonzero
from
tests.sandbox.test_rng_mrg
import
test_f16_nonzero
as
cpu_f16_nonzero
from
theano
import
c
hange_flags
,
tensor
from
theano
import
c
onfig
,
tensor
from
theano.gpuarray.rng_mrg
import
GPUA_mrg_uniform
from
theano.gpuarray.rng_mrg
import
GPUA_mrg_uniform
from
theano.gpuarray.type
import
gpuarray_shared_constructor
from
theano.gpuarray.type
import
gpuarray_shared_constructor
from
theano.sandbox
import
rng_mrg
from
theano.sandbox
import
rng_mrg
...
@@ -161,7 +161,7 @@ def test_overflow_gpu_new_backend():
...
@@ -161,7 +161,7 @@ def test_overflow_gpu_new_backend():
def
test_validate_input_types_gpuarray_backend
():
def
test_validate_input_types_gpuarray_backend
():
with
change_flags
(
compute_test_value
=
"raise"
):
with
c
onfig
.
c
hange_flags
(
compute_test_value
=
"raise"
):
rstate
=
np
.
zeros
((
7
,
6
),
dtype
=
"int32"
)
rstate
=
np
.
zeros
((
7
,
6
),
dtype
=
"int32"
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
rng_mrg
.
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
"float32"
,
size
=
(
3
,))
rng_mrg
.
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
"float32"
,
size
=
(
3
,))
...
...
tests/gpuarray/test_subtensor.py
浏览文件 @
b0b34b59
...
@@ -130,7 +130,7 @@ def test_advinc_subtensor1_dtype():
...
@@ -130,7 +130,7 @@ def test_advinc_subtensor1_dtype():
assert
np
.
allclose
(
rval
,
rep
)
assert
np
.
allclose
(
rval
,
rep
)
@theano.change_flags
(
deterministic
=
"more"
)
@theano.c
onfig.c
hange_flags
(
deterministic
=
"more"
)
def
test_deterministic_flag
():
def
test_deterministic_flag
():
shp
=
(
3
,
4
)
shp
=
(
3
,
4
)
for
dtype1
,
dtype2
in
[(
"float32"
,
"int8"
)]:
for
dtype1
,
dtype2
in
[(
"float32"
,
"int8"
)]:
...
...
tests/sandbox/test_jax.py
浏览文件 @
b0b34b59
...
@@ -14,7 +14,7 @@ from theano.gof.op import get_test_value # noqa: E402
...
@@ -14,7 +14,7 @@ from theano.gof.op import get_test_value # noqa: E402
@pytest.fixture
(
scope
=
"module"
,
autouse
=
True
)
@pytest.fixture
(
scope
=
"module"
,
autouse
=
True
)
def
set_theano_flags
():
def
set_theano_flags
():
with
theano
.
change_flags
(
cxx
=
""
,
compute_test_value
=
"ignore"
):
with
theano
.
c
onfig
.
c
hange_flags
(
cxx
=
""
,
compute_test_value
=
"ignore"
):
yield
yield
...
@@ -136,7 +136,7 @@ def test_jax_compile_ops():
...
@@ -136,7 +136,7 @@ def test_jax_compile_ops():
compare_jax_and_py
(
x_fg
,
[])
compare_jax_and_py
(
x_fg
,
[])
with
theano
.
change_flags
(
compute_test_value
=
"off"
):
with
theano
.
c
onfig
.
c
hange_flags
(
compute_test_value
=
"off"
):
x
=
theano
.
compile
.
ops
.
SpecifyShape
()(
tt
.
as_tensor_variable
(
x_np
),
(
2
,
3
))
x
=
theano
.
compile
.
ops
.
SpecifyShape
()(
tt
.
as_tensor_variable
(
x_np
),
(
2
,
3
))
x_fg
=
theano
.
gof
.
FunctionGraph
([],
[
x
])
x_fg
=
theano
.
gof
.
FunctionGraph
([],
[
x
])
...
@@ -151,7 +151,7 @@ def test_jax_compile_ops():
...
@@ -151,7 +151,7 @@ def test_jax_compile_ops():
compare_jax_and_py
(
x_fg
,
[])
compare_jax_and_py
(
x_fg
,
[])
with
theano
.
change_flags
(
compute_test_value
=
"off"
):
with
theano
.
c
onfig
.
c
hange_flags
(
compute_test_value
=
"off"
):
x
=
theano
.
compile
.
ops
.
Rebroadcast
((
0
,
True
),
(
1
,
False
),
(
2
,
False
))(
x
=
theano
.
compile
.
ops
.
Rebroadcast
((
0
,
True
),
(
1
,
False
),
(
2
,
False
))(
tt
.
as_tensor_variable
(
x_np
)
tt
.
as_tensor_variable
(
x_np
)
)
)
...
...
tests/sandbox/test_rng_mrg.py
浏览文件 @
b0b34b59
...
@@ -7,7 +7,7 @@ import pytest
...
@@ -7,7 +7,7 @@ import pytest
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
c
hange_flags
,
c
onfig
,
tensor
from
theano
import
config
,
tensor
from
theano.sandbox
import
rng_mrg
from
theano.sandbox
import
rng_mrg
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
...
@@ -78,9 +78,7 @@ def test_consistency_randomstreams():
...
@@ -78,9 +78,7 @@ def test_consistency_randomstreams():
def
test_get_substream_rstates
():
def
test_get_substream_rstates
():
try
:
with
config
.
change_flags
(
compute_test_value
=
"raise"
):
orig
=
theano
.
config
.
compute_test_value
theano
.
config
.
compute_test_value
=
"raise"
n_streams
=
100
n_streams
=
100
dtype
=
"float32"
dtype
=
"float32"
...
@@ -88,9 +86,6 @@ def test_get_substream_rstates():
...
@@ -88,9 +86,6 @@ def test_get_substream_rstates():
rng
.
get_substream_rstates
(
n_streams
,
dtype
)
rng
.
get_substream_rstates
(
n_streams
,
dtype
)
finally
:
theano
.
config
.
compute_test_value
=
orig
def
test_consistency_cpu_serial
():
def
test_consistency_cpu_serial
():
# Verify that the random numbers generated by mrg_uniform, serially,
# Verify that the random numbers generated by mrg_uniform, serially,
...
@@ -949,7 +944,7 @@ def test_overflow_cpu():
...
@@ -949,7 +944,7 @@ def test_overflow_cpu():
# run with THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32
# run with THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32
rng
=
MRG_RandomStreams
(
np
.
random
.
randint
(
1234
))
rng
=
MRG_RandomStreams
(
np
.
random
.
randint
(
1234
))
fct
=
rng
.
uniform
fct
=
rng
.
uniform
with
change_flags
(
compute_test_value
=
"off"
):
with
c
onfig
.
c
hange_flags
(
compute_test_value
=
"off"
):
# should raise error as the size overflows
# should raise error as the size overflows
sizes
=
[
sizes
=
[
(
2
**
31
,),
(
2
**
31
,),
...
...
tests/scalar/test_type.py
浏览文件 @
b0b34b59
import
numpy
as
np
import
numpy
as
np
from
theano
import
c
hange_flags
from
theano
import
c
onfig
from
theano.scalar.basic
import
(
from
theano.scalar.basic
import
(
IntDiv
,
IntDiv
,
Scalar
,
Scalar
,
...
@@ -33,7 +33,7 @@ def test_div_types():
...
@@ -33,7 +33,7 @@ def test_div_types():
def
test_filter_float_subclass
():
def
test_filter_float_subclass
():
"""Make sure `Scalar.filter` can handle `float` subclasses."""
"""Make sure `Scalar.filter` can handle `float` subclasses."""
with
change_flags
(
floatX
=
"float64"
):
with
c
onfig
.
c
hange_flags
(
floatX
=
"float64"
):
test_type
=
Scalar
(
"float64"
)
test_type
=
Scalar
(
"float64"
)
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float64"
)[
0
]
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float64"
)[
0
]
...
@@ -42,7 +42,7 @@ def test_filter_float_subclass():
...
@@ -42,7 +42,7 @@ def test_filter_float_subclass():
filtered_nan
=
test_type
.
filter
(
nan
)
filtered_nan
=
test_type
.
filter
(
nan
)
assert
isinstance
(
filtered_nan
,
float
)
assert
isinstance
(
filtered_nan
,
float
)
with
change_flags
(
floatX
=
"float32"
):
with
c
onfig
.
c
hange_flags
(
floatX
=
"float32"
):
# Try again, except this time `nan` isn't a `float`
# Try again, except this time `nan` isn't a `float`
test_type
=
Scalar
(
"float32"
)
test_type
=
Scalar
(
"float32"
)
...
...
tests/scan/test_basic.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
tests/tensor/_test_mpi_roundtrip.py
浏览文件 @
b0b34b59
...
@@ -7,7 +7,7 @@ import numpy as np
...
@@ -7,7 +7,7 @@ import numpy as np
from
mpi4py
import
MPI
from
mpi4py
import
MPI
import
theano
import
theano
from
theano
.configparser
import
change_flags
from
theano
import
config
from
theano.gof.sched
import
sort_schedule_fn
from
theano.gof.sched
import
sort_schedule_fn
from
theano.tensor.io
import
mpi_cmps
,
recv
,
send
from
theano.tensor.io
import
mpi_cmps
,
recv
,
send
...
@@ -31,7 +31,7 @@ dtype = "float32"
...
@@ -31,7 +31,7 @@ dtype = "float32"
scheduler
=
sort_schedule_fn
(
*
mpi_cmps
)
scheduler
=
sort_schedule_fn
(
*
mpi_cmps
)
mode
=
theano
.
Mode
(
optimizer
=
None
,
linker
=
theano
.
OpWiseCLinker
(
schedule
=
scheduler
))
mode
=
theano
.
Mode
(
optimizer
=
None
,
linker
=
theano
.
OpWiseCLinker
(
schedule
=
scheduler
))
with
change_flags
(
compute_test_value
=
"off"
):
with
c
onfig
.
c
hange_flags
(
compute_test_value
=
"off"
):
if
rank
==
0
:
if
rank
==
0
:
x
=
theano
.
tensor
.
matrix
(
"x"
,
dtype
=
dtype
)
x
=
theano
.
tensor
.
matrix
(
"x"
,
dtype
=
dtype
)
y
=
x
+
1
y
=
x
+
1
...
...
tests/tensor/nnet/test_abstract_conv.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
tests/tensor/nnet/test_neighbours.py
浏览文件 @
b0b34b59
...
@@ -4,7 +4,7 @@ import pytest
...
@@ -4,7 +4,7 @@ import pytest
import
theano
import
theano
import
theano.tensor
as
tt
import
theano.tensor
as
tt
from
tests
import
unittest_tools
from
tests
import
unittest_tools
from
theano
import
c
hange_flags
,
function
,
shared
from
theano
import
c
onfig
,
function
,
shared
from
theano.tensor.nnet.neighbours
import
Images2Neibs
,
images2neibs
,
neibs2images
from
theano.tensor.nnet.neighbours
import
Images2Neibs
,
images2neibs
,
neibs2images
...
@@ -161,7 +161,7 @@ class TestImages2Neibs(unittest_tools.InferShapeTester):
...
@@ -161,7 +161,7 @@ class TestImages2Neibs(unittest_tools.InferShapeTester):
# print g()
# print g()
# assert numpy.allclose(images.get_value(borrow=True), g())
# assert numpy.allclose(images.get_value(borrow=True), g())
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_neibs_bad_shape
(
self
):
def
test_neibs_bad_shape
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
shape
=
(
2
,
3
,
10
,
10
)
for
dtype
in
self
.
dtypes
:
for
dtype
in
self
.
dtypes
:
...
@@ -351,7 +351,7 @@ class TestImages2Neibs(unittest_tools.InferShapeTester):
...
@@ -351,7 +351,7 @@ class TestImages2Neibs(unittest_tools.InferShapeTester):
f_full
=
theano
.
function
([],
x_using_full
,
mode
=
self
.
mode
)
f_full
=
theano
.
function
([],
x_using_full
,
mode
=
self
.
mode
)
unittest_tools
.
assert_allclose
(
f_valid
(),
f_full
())
unittest_tools
.
assert_allclose
(
f_valid
(),
f_full
())
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_neibs_bad_shape_wrap_centered
(
self
):
def
test_neibs_bad_shape_wrap_centered
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
shape
=
(
2
,
3
,
10
,
10
)
...
...
tests/tensor/nnet/test_nnet.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
tests/tensor/test_basic.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
tests/tensor/test_blas.py
浏览文件 @
b0b34b59
...
@@ -128,8 +128,8 @@ class TestGemm:
...
@@ -128,8 +128,8 @@ class TestGemm:
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
"c|py"
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
"c|py"
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
"py"
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
"py"
)
if
not
dtype
.
startswith
(
"complex"
)
and
theano
.
config
.
cxx
:
if
not
dtype
.
startswith
(
"complex"
)
and
config
.
cxx
:
# If
theano.
config.blas__ldflags is empty, Theano will use
# If config.blas__ldflags is empty, Theano will use
# a NumPy C implementation of [sd]gemm_.
# a NumPy C implementation of [sd]gemm_.
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
"c"
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
"c"
)
...
@@ -477,7 +477,7 @@ class TestGemmNoFlags:
...
@@ -477,7 +477,7 @@ class TestGemmNoFlags:
C
=
self
.
get_value
(
C
,
transpose_C
,
slice_C
)
C
=
self
.
get_value
(
C
,
transpose_C
,
slice_C
)
return
alpha
*
np
.
dot
(
A
,
B
)
+
beta
*
C
return
alpha
*
np
.
dot
(
A
,
B
)
+
beta
*
C
@
theano
.change_flags
({
"blas__ldflags"
:
""
})
@
config
.change_flags
({
"blas__ldflags"
:
""
})
def
run_gemm
(
def
run_gemm
(
self
,
self
,
dtype
,
dtype
,
...
@@ -819,13 +819,9 @@ def test_upcasting_scalar_nogemm():
...
@@ -819,13 +819,9 @@ def test_upcasting_scalar_nogemm():
t
=
tt
.
fmatrix
(
"t"
)
t
=
tt
.
fmatrix
(
"t"
)
alpha
=
tt
.
cscalar
(
"a"
)
alpha
=
tt
.
cscalar
(
"a"
)
on_opt_error
=
config
.
on_opt_error
with
config
.
change_flags
(
on_opt_error
=
"raise"
):
try
:
config
.
on_opt_error
=
"raise"
rval
=
tt
.
dot
(
w
,
v
)
*
alpha
+
t
rval
=
tt
.
dot
(
w
,
v
)
*
alpha
+
t
f
=
theano
.
function
([
w
,
v
,
t
,
alpha
],
rval
)
f
=
theano
.
function
([
w
,
v
,
t
,
alpha
],
rval
)
finally
:
config
.
on_opt_error
=
on_opt_error
t
=
f
.
maker
.
fgraph
.
toposort
()
t
=
f
.
maker
.
fgraph
.
toposort
()
assert
np
.
sum
([
isinstance
(
n
.
op
,
Gemm
)
for
n
in
t
])
==
0
assert
np
.
sum
([
isinstance
(
n
.
op
,
Gemm
)
for
n
in
t
])
==
0
...
...
tests/tensor/test_blas_c.py
浏览文件 @
b0b34b59
...
@@ -387,7 +387,7 @@ class TestCGemvNoFlags:
...
@@ -387,7 +387,7 @@ class TestCGemvNoFlags:
ref_val
+=
beta
*
y
ref_val
+=
beta
*
y
return
ref_val
return
ref_val
@theano.c
hange_flags
({
"blas__ldflags"
:
""
}
)
@theano.c
onfig.change_flags
(
blas__ldflags
=
""
)
def
run_cgemv
(
self
,
dtype
,
ALPHA
,
BETA
,
transpose_A
,
slice_tensors
):
def
run_cgemv
(
self
,
dtype
,
ALPHA
,
BETA
,
transpose_A
,
slice_tensors
):
f
=
self
.
get_function
(
f
=
self
.
get_function
(
dtype
,
transpose_A
=
transpose_A
,
slice_tensors
=
slice_tensors
dtype
,
transpose_A
=
transpose_A
,
slice_tensors
=
slice_tensors
...
...
tests/tensor/test_extra_ops.py
浏览文件 @
b0b34b59
...
@@ -3,7 +3,7 @@ import pytest
...
@@ -3,7 +3,7 @@ import pytest
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
c
hange_flags
,
c
onfig
,
function
from
theano
import
config
,
function
from
theano
import
tensor
as
tt
from
theano
import
tensor
as
tt
from
theano.tensor.extra_ops
import
(
from
theano.tensor.extra_ops
import
(
Bartlett
,
Bartlett
,
...
@@ -320,8 +320,8 @@ class TestSqueeze(utt.InferShapeTester):
...
@@ -320,8 +320,8 @@ class TestSqueeze(utt.InferShapeTester):
def
test_op
(
self
):
def
test_op
(
self
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
theano
.
config
.
floatX
)
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
config
.
floatX
)
variable
=
tt
.
TensorType
(
theano
.
config
.
floatX
,
broadcast
)()
variable
=
tt
.
TensorType
(
config
.
floatX
,
broadcast
)()
f
=
theano
.
function
([
variable
],
self
.
op
(
variable
))
f
=
theano
.
function
([
variable
],
self
.
op
(
variable
))
...
@@ -333,8 +333,8 @@ class TestSqueeze(utt.InferShapeTester):
...
@@ -333,8 +333,8 @@ class TestSqueeze(utt.InferShapeTester):
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
theano
.
config
.
floatX
)
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
config
.
floatX
)
variable
=
tt
.
TensorType
(
theano
.
config
.
floatX
,
broadcast
)()
variable
=
tt
.
TensorType
(
config
.
floatX
,
broadcast
)()
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
variable
],
[
self
.
op
(
variable
)],
[
data
],
tt
.
DimShuffle
,
warn
=
False
[
variable
],
[
self
.
op
(
variable
)],
[
data
],
tt
.
DimShuffle
,
warn
=
False
...
@@ -342,15 +342,15 @@ class TestSqueeze(utt.InferShapeTester):
...
@@ -342,15 +342,15 @@ class TestSqueeze(utt.InferShapeTester):
def
test_grad
(
self
):
def
test_grad
(
self
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
theano
.
config
.
floatX
)
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
config
.
floatX
)
utt
.
verify_grad
(
self
.
op
,
[
data
])
utt
.
verify_grad
(
self
.
op
,
[
data
])
def
test_var_interface
(
self
):
def
test_var_interface
(
self
):
# same as test_op, but use a_theano_var.squeeze.
# same as test_op, but use a_theano_var.squeeze.
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
for
shape
,
broadcast
in
zip
(
self
.
shape_list
,
self
.
broadcast_list
):
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
theano
.
config
.
floatX
)
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
config
.
floatX
)
variable
=
tt
.
TensorType
(
theano
.
config
.
floatX
,
broadcast
)()
variable
=
tt
.
TensorType
(
config
.
floatX
,
broadcast
)()
f
=
theano
.
function
([
variable
],
variable
.
squeeze
())
f
=
theano
.
function
([
variable
],
variable
.
squeeze
())
...
@@ -361,17 +361,17 @@ class TestSqueeze(utt.InferShapeTester):
...
@@ -361,17 +361,17 @@ class TestSqueeze(utt.InferShapeTester):
assert
np
.
allclose
(
tested
,
expected
)
assert
np
.
allclose
(
tested
,
expected
)
def
test_axis
(
self
):
def
test_axis
(
self
):
variable
=
tt
.
TensorType
(
theano
.
config
.
floatX
,
[
False
,
True
,
False
])()
variable
=
tt
.
TensorType
(
config
.
floatX
,
[
False
,
True
,
False
])()
res
=
squeeze
(
variable
,
axis
=
1
)
res
=
squeeze
(
variable
,
axis
=
1
)
assert
res
.
broadcastable
==
(
False
,
False
)
assert
res
.
broadcastable
==
(
False
,
False
)
variable
=
tt
.
TensorType
(
theano
.
config
.
floatX
,
[
False
,
True
,
False
])()
variable
=
tt
.
TensorType
(
config
.
floatX
,
[
False
,
True
,
False
])()
res
=
squeeze
(
variable
,
axis
=
(
1
,))
res
=
squeeze
(
variable
,
axis
=
(
1
,))
assert
res
.
broadcastable
==
(
False
,
False
)
assert
res
.
broadcastable
==
(
False
,
False
)
variable
=
tt
.
TensorType
(
theano
.
config
.
floatX
,
[
False
,
True
,
False
,
True
])()
variable
=
tt
.
TensorType
(
config
.
floatX
,
[
False
,
True
,
False
,
True
])()
res
=
squeeze
(
variable
,
axis
=
(
1
,
3
))
res
=
squeeze
(
variable
,
axis
=
(
1
,
3
))
assert
res
.
broadcastable
==
(
False
,
False
)
assert
res
.
broadcastable
==
(
False
,
False
)
...
@@ -396,7 +396,7 @@ class TestCompress(utt.InferShapeTester):
...
@@ -396,7 +396,7 @@ class TestCompress(utt.InferShapeTester):
def
test_op
(
self
):
def
test_op
(
self
):
for
axis
,
cond
,
shape
in
zip
(
self
.
axis_list
,
self
.
cond_list
,
self
.
shape_list
):
for
axis
,
cond
,
shape
in
zip
(
self
.
axis_list
,
self
.
cond_list
,
self
.
shape_list
):
cond_var
=
theano
.
tensor
.
ivector
()
cond_var
=
theano
.
tensor
.
ivector
()
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
theano
.
config
.
floatX
)
data
=
np
.
random
.
random
(
size
=
shape
)
.
astype
(
config
.
floatX
)
data_var
=
theano
.
tensor
.
matrix
()
data_var
=
theano
.
tensor
.
matrix
()
f
=
theano
.
function
(
f
=
theano
.
function
(
...
@@ -713,7 +713,7 @@ def test_to_one_hot():
...
@@ -713,7 +713,7 @@ def test_to_one_hot():
o
=
to_one_hot
(
v
,
10
)
o
=
to_one_hot
(
v
,
10
)
f
=
theano
.
function
([
v
],
o
)
f
=
theano
.
function
([
v
],
o
)
out
=
f
([
1
,
2
,
3
,
5
,
6
])
out
=
f
([
1
,
2
,
3
,
5
,
6
])
assert
out
.
dtype
==
theano
.
config
.
floatX
assert
out
.
dtype
==
config
.
floatX
assert
np
.
allclose
(
assert
np
.
allclose
(
out
,
out
,
[
[
...
@@ -1318,7 +1318,7 @@ class TestBroadcastTo(utt.InferShapeTester):
...
@@ -1318,7 +1318,7 @@ class TestBroadcastTo(utt.InferShapeTester):
self
.
op_class
=
BroadcastTo
self
.
op_class
=
BroadcastTo
self
.
op
=
broadcast_to
self
.
op
=
broadcast_to
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_perform
(
self
):
def
test_perform
(
self
):
a
=
tt
.
scalar
()
a
=
tt
.
scalar
()
a
.
tag
.
test_value
=
5
a
.
tag
.
test_value
=
5
...
...
tests/tensor/test_mpi.py
浏览文件 @
b0b34b59
...
@@ -4,7 +4,7 @@ import subprocess
...
@@ -4,7 +4,7 @@ import subprocess
import
pytest
import
pytest
import
theano
import
theano
from
theano
import
c
hange_flags
from
theano
import
c
onfig
from
theano.gof.sched
import
sort_schedule_fn
from
theano.gof.sched
import
sort_schedule_fn
from
theano.tensor.io
import
(
from
theano.tensor.io
import
(
MPISend
,
MPISend
,
...
@@ -22,7 +22,7 @@ mpi_linker = theano.OpWiseCLinker(schedule=mpi_scheduler)
...
@@ -22,7 +22,7 @@ mpi_linker = theano.OpWiseCLinker(schedule=mpi_scheduler)
mpi_mode
=
theano
.
Mode
(
linker
=
mpi_linker
)
mpi_mode
=
theano
.
Mode
(
linker
=
mpi_linker
)
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_recv
():
def
test_recv
():
x
=
recv
((
10
,
10
),
"float64"
,
0
,
11
)
x
=
recv
((
10
,
10
),
"float64"
,
0
,
11
)
assert
x
.
dtype
==
"float64"
assert
x
.
dtype
==
"float64"
...
@@ -41,7 +41,7 @@ def test_send():
...
@@ -41,7 +41,7 @@ def test_send():
assert
sendnode
.
op
.
tag
==
11
assert
sendnode
.
op
.
tag
==
11
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_can_make_function
():
def
test_can_make_function
():
x
=
recv
((
5
,
5
),
"float32"
,
0
,
11
)
x
=
recv
((
5
,
5
),
"float32"
,
0
,
11
)
y
=
x
+
1
y
=
x
+
1
...
@@ -83,7 +83,7 @@ def test_mpi_send_wait_cmp():
...
@@ -83,7 +83,7 @@ def test_mpi_send_wait_cmp():
assert
mpi_send_wait_cmp
(
waitnode
,
addnode
)
>
0
# wait happens last
assert
mpi_send_wait_cmp
(
waitnode
,
addnode
)
>
0
# wait happens last
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_mpi_tag_ordering
():
def
test_mpi_tag_ordering
():
x
=
recv
((
2
,
2
),
"float32"
,
1
,
12
)
x
=
recv
((
2
,
2
),
"float32"
,
1
,
12
)
y
=
recv
((
2
,
2
),
"float32"
,
1
,
11
)
y
=
recv
((
2
,
2
),
"float32"
,
1
,
11
)
...
...
tests/tensor/test_nlinalg.py
浏览文件 @
b0b34b59
...
@@ -7,7 +7,6 @@ from numpy.testing import assert_array_almost_equal
...
@@ -7,7 +7,6 @@ from numpy.testing import assert_array_almost_equal
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
config
,
function
,
tensor
from
theano
import
config
,
function
,
tensor
from
theano.configparser
import
change_flags
from
theano.tensor.basic
import
_allclose
from
theano.tensor.basic
import
_allclose
from
theano.tensor.nlinalg
import
(
from
theano.tensor.nlinalg
import
(
SVD
,
SVD
,
...
@@ -39,7 +38,7 @@ def test_pseudoinverse_correctness():
...
@@ -39,7 +38,7 @@ def test_pseudoinverse_correctness():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
d1
=
rng
.
randint
(
4
)
+
2
d1
=
rng
.
randint
(
4
)
+
2
d2
=
rng
.
randint
(
4
)
+
2
d2
=
rng
.
randint
(
4
)
+
2
r
=
rng
.
randn
(
d1
,
d2
)
.
astype
(
theano
.
config
.
floatX
)
r
=
rng
.
randn
(
d1
,
d2
)
.
astype
(
config
.
floatX
)
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
xi
=
pinv
(
x
)
xi
=
pinv
(
x
)
...
@@ -57,7 +56,7 @@ def test_pseudoinverse_grad():
...
@@ -57,7 +56,7 @@ def test_pseudoinverse_grad():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
d1
=
rng
.
randint
(
4
)
+
2
d1
=
rng
.
randint
(
4
)
+
2
d2
=
rng
.
randint
(
4
)
+
2
d2
=
rng
.
randint
(
4
)
+
2
r
=
rng
.
randn
(
d1
,
d2
)
.
astype
(
theano
.
config
.
floatX
)
r
=
rng
.
randn
(
d1
,
d2
)
.
astype
(
config
.
floatX
)
utt
.
verify_grad
(
pinv
,
[
r
])
utt
.
verify_grad
(
pinv
,
[
r
])
...
@@ -71,7 +70,7 @@ class TestMatrixInverse(utt.InferShapeTester):
...
@@ -71,7 +70,7 @@ class TestMatrixInverse(utt.InferShapeTester):
def
test_inverse_correctness
(
self
):
def
test_inverse_correctness
(
self
):
r
=
self
.
rng
.
randn
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
r
=
self
.
rng
.
randn
(
4
,
4
)
.
astype
(
config
.
floatX
)
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
xi
=
self
.
op
(
x
)
xi
=
self
.
op
(
x
)
...
@@ -88,7 +87,7 @@ class TestMatrixInverse(utt.InferShapeTester):
...
@@ -88,7 +87,7 @@ class TestMatrixInverse(utt.InferShapeTester):
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
r
=
self
.
rng
.
randn
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
r
=
self
.
rng
.
randn
(
4
,
4
)
.
astype
(
config
.
floatX
)
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
xi
=
self
.
op
(
x
)
xi
=
self
.
op
(
x
)
...
@@ -102,7 +101,7 @@ def test_matrix_dot():
...
@@ -102,7 +101,7 @@ def test_matrix_dot():
rs
=
[]
rs
=
[]
xs
=
[]
xs
=
[]
for
k
in
range
(
n
):
for
k
in
range
(
n
):
rs
+=
[
rng
.
randn
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)]
rs
+=
[
rng
.
randn
(
4
,
4
)
.
astype
(
config
.
floatX
)]
xs
+=
[
tensor
.
matrix
()]
xs
+=
[
tensor
.
matrix
()]
sol
=
matrix_dot
(
*
xs
)
sol
=
matrix_dot
(
*
xs
)
...
@@ -117,8 +116,8 @@ def test_matrix_dot():
...
@@ -117,8 +116,8 @@ def test_matrix_dot():
def
test_qr_modes
():
def
test_qr_modes
():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
A
=
tensor
.
matrix
(
"A"
,
dtype
=
config
.
floatX
)
a
=
rng
.
rand
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
a
=
rng
.
rand
(
4
,
4
)
.
astype
(
config
.
floatX
)
f
=
function
([
A
],
qr
(
A
))
f
=
function
([
A
],
qr
(
A
))
t_qr
=
f
(
a
)
t_qr
=
f
(
a
)
...
@@ -189,15 +188,15 @@ class TestSvd(utt.InferShapeTester):
...
@@ -189,15 +188,15 @@ class TestSvd(utt.InferShapeTester):
def
test_tensorsolve
():
def
test_tensorsolve
():
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
A
=
tensor
.
tensor4
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
A
=
tensor
.
tensor4
(
"A"
,
dtype
=
config
.
floatX
)
B
=
tensor
.
matrix
(
"B"
,
dtype
=
theano
.
config
.
floatX
)
B
=
tensor
.
matrix
(
"B"
,
dtype
=
config
.
floatX
)
X
=
tensorsolve
(
A
,
B
)
X
=
tensorsolve
(
A
,
B
)
fn
=
function
([
A
,
B
],
[
X
])
fn
=
function
([
A
,
B
],
[
X
])
# slightly modified example from np.linalg.tensorsolve docstring
# slightly modified example from np.linalg.tensorsolve docstring
a
=
np
.
eye
(
2
*
3
*
4
)
.
astype
(
theano
.
config
.
floatX
)
a
=
np
.
eye
(
2
*
3
*
4
)
.
astype
(
config
.
floatX
)
a
.
shape
=
(
2
*
3
,
4
,
2
,
3
*
4
)
a
.
shape
=
(
2
*
3
,
4
,
2
,
3
*
4
)
b
=
rng
.
rand
(
2
*
3
,
4
)
.
astype
(
theano
.
config
.
floatX
)
b
=
rng
.
rand
(
2
*
3
,
4
)
.
astype
(
config
.
floatX
)
n_x
=
np
.
linalg
.
tensorsolve
(
a
,
b
)
n_x
=
np
.
linalg
.
tensorsolve
(
a
,
b
)
t_x
=
fn
(
a
,
b
)
t_x
=
fn
(
a
,
b
)
...
@@ -233,7 +232,7 @@ def test_tensorsolve():
...
@@ -233,7 +232,7 @@ def test_tensorsolve():
def
test_inverse_singular
():
def
test_inverse_singular
():
singular
=
np
.
array
([[
1
,
0
,
0
]]
+
[[
0
,
1
,
0
]]
*
2
,
dtype
=
theano
.
config
.
floatX
)
singular
=
np
.
array
([[
1
,
0
,
0
]]
+
[[
0
,
1
,
0
]]
*
2
,
dtype
=
config
.
floatX
)
a
=
tensor
.
matrix
()
a
=
tensor
.
matrix
()
f
=
function
([
a
],
matrix_inverse
(
a
))
f
=
function
([
a
],
matrix_inverse
(
a
))
with
pytest
.
raises
(
np
.
linalg
.
LinAlgError
):
with
pytest
.
raises
(
np
.
linalg
.
LinAlgError
):
...
@@ -527,20 +526,20 @@ class TestLstsq:
...
@@ -527,20 +526,20 @@ class TestLstsq:
class
TestMatrixPower
:
class
TestMatrixPower
:
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
@pytest.mark.parametrize
(
"n"
,
[
-
1
,
0
,
1
,
2
,
3
,
4
,
5
,
11
])
@pytest.mark.parametrize
(
"n"
,
[
-
1
,
0
,
1
,
2
,
3
,
4
,
5
,
11
])
def
test_numpy_compare
(
self
,
n
):
def
test_numpy_compare
(
self
,
n
):
a
=
np
.
array
([[
0.1231101
,
0.72381381
],
[
0.28748201
,
0.43036511
]])
.
astype
(
a
=
np
.
array
([[
0.1231101
,
0.72381381
],
[
0.28748201
,
0.43036511
]])
.
astype
(
theano
.
config
.
floatX
config
.
floatX
)
)
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
A
=
tensor
.
matrix
(
"A"
,
dtype
=
config
.
floatX
)
A
.
tag
.
test_value
=
a
A
.
tag
.
test_value
=
a
Q
=
matrix_power
(
A
,
n
)
Q
=
matrix_power
(
A
,
n
)
n_p
=
np
.
linalg
.
matrix_power
(
a
,
n
)
n_p
=
np
.
linalg
.
matrix_power
(
a
,
n
)
assert
np
.
allclose
(
n_p
,
Q
.
get_test_value
())
assert
np
.
allclose
(
n_p
,
Q
.
get_test_value
())
def
test_non_square_matrix
(
self
):
def
test_non_square_matrix
(
self
):
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
A
=
tensor
.
matrix
(
"A"
,
dtype
=
config
.
floatX
)
Q
=
matrix_power
(
A
,
3
)
Q
=
matrix_power
(
A
,
3
)
f
=
function
([
A
],
[
Q
])
f
=
function
([
A
],
[
Q
])
a
=
np
.
array
(
a
=
np
.
array
(
...
@@ -549,7 +548,7 @@ class TestMatrixPower:
...
@@ -549,7 +548,7 @@ class TestMatrixPower:
[
0.74387558
,
0.31780172
],
[
0.74387558
,
0.31780172
],
[
0.54381007
,
0.28153101
],
[
0.54381007
,
0.28153101
],
]
]
)
.
astype
(
theano
.
config
.
floatX
)
)
.
astype
(
config
.
floatX
)
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
f
(
a
)
f
(
a
)
...
@@ -574,11 +573,11 @@ class TestNormTests:
...
@@ -574,11 +573,11 @@ class TestNormTests:
def
test_numpy_compare
(
self
):
def
test_numpy_compare
(
self
):
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
M
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
M
=
tensor
.
matrix
(
"A"
,
dtype
=
config
.
floatX
)
V
=
tensor
.
vector
(
"V"
,
dtype
=
theano
.
config
.
floatX
)
V
=
tensor
.
vector
(
"V"
,
dtype
=
config
.
floatX
)
a
=
rng
.
rand
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
a
=
rng
.
rand
(
4
,
4
)
.
astype
(
config
.
floatX
)
b
=
rng
.
rand
(
4
)
.
astype
(
theano
.
config
.
floatX
)
b
=
rng
.
rand
(
4
)
.
astype
(
config
.
floatX
)
A
=
(
A
=
(
[
None
,
"fro"
,
"inf"
,
"-inf"
,
1
,
-
1
,
None
,
"inf"
,
"-inf"
,
0
,
1
,
-
1
,
2
,
-
2
],
[
None
,
"fro"
,
"inf"
,
"-inf"
,
1
,
-
1
,
None
,
"inf"
,
"-inf"
,
0
,
1
,
-
1
,
2
,
-
2
],
...
@@ -597,12 +596,12 @@ class TestNormTests:
...
@@ -597,12 +596,12 @@ class TestNormTests:
class
TestTensorInv
(
utt
.
InferShapeTester
):
class
TestTensorInv
(
utt
.
InferShapeTester
):
def
setup_method
(
self
):
def
setup_method
(
self
):
super
()
.
setup_method
()
super
()
.
setup_method
()
self
.
A
=
tensor
.
tensor4
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
self
.
A
=
tensor
.
tensor4
(
"A"
,
dtype
=
config
.
floatX
)
self
.
B
=
tensor
.
tensor3
(
"B"
,
dtype
=
theano
.
config
.
floatX
)
self
.
B
=
tensor
.
tensor3
(
"B"
,
dtype
=
config
.
floatX
)
self
.
a
=
np
.
random
.
rand
(
4
,
6
,
8
,
3
)
.
astype
(
theano
.
config
.
floatX
)
self
.
a
=
np
.
random
.
rand
(
4
,
6
,
8
,
3
)
.
astype
(
config
.
floatX
)
self
.
b
=
np
.
random
.
rand
(
2
,
15
,
30
)
.
astype
(
theano
.
config
.
floatX
)
self
.
b
=
np
.
random
.
rand
(
2
,
15
,
30
)
.
astype
(
config
.
floatX
)
self
.
b1
=
np
.
random
.
rand
(
30
,
2
,
15
)
.
astype
(
self
.
b1
=
np
.
random
.
rand
(
30
,
2
,
15
)
.
astype
(
theano
.
config
.
floatX
config
.
floatX
)
# for ind=1 since we need prod(b1.shape[:ind]) == prod(b1.shape[ind:])
)
# for ind=1 since we need prod(b1.shape[:ind]) == prod(b1.shape[ind:])
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
...
...
tests/tensor/test_opt.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
tests/tensor/test_subtensor.py
浏览文件 @
b0b34b59
...
@@ -11,7 +11,7 @@ import theano.scalar as scal
...
@@ -11,7 +11,7 @@ import theano.scalar as scal
import
theano.tensor
as
tt
import
theano.tensor
as
tt
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
tests.tensor.utils
import
inplace_func
,
rand
,
randint_ranged
from
tests.tensor.utils
import
inplace_func
,
rand
,
randint_ranged
from
theano
import
c
hange_flags
,
c
onfig
from
theano
import
config
from
theano.compile
import
DeepCopyOp
from
theano.compile
import
DeepCopyOp
from
theano.gof.op
import
get_test_value
from
theano.gof.op
import
get_test_value
from
theano.gof.toolbox
import
is_same_graph
from
theano.gof.toolbox
import
is_same_graph
...
@@ -70,10 +70,10 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -70,10 +70,10 @@ class TestSubtensor(utt.OptimizationTestMixin):
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
shared
=
_shared
self
.
shared
=
_shared
self
.
dtype
=
theano
.
config
.
floatX
self
.
dtype
=
config
.
floatX
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
self
.
mode
=
mode
.
including
(
"local_useless_subtensor"
)
self
.
mode
=
mode
.
including
(
"local_useless_subtensor"
)
self
.
fast_compile
=
theano
.
config
.
mode
==
"FAST_COMPILE"
self
.
fast_compile
=
config
.
mode
==
"FAST_COMPILE"
utt
.
seed_rng
()
utt
.
seed_rng
()
def
function
(
def
function
(
...
@@ -124,7 +124,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -124,7 +124,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
with
pytest
.
raises
(
IndexError
):
with
pytest
.
raises
(
IndexError
):
n
.
__getitem__
(
0
)
n
.
__getitem__
(
0
)
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_err_bounds
(
self
):
def
test_err_bounds
(
self
):
n
=
self
.
shared
(
np
.
ones
(
3
,
dtype
=
self
.
dtype
))
n
=
self
.
shared
(
np
.
ones
(
3
,
dtype
=
self
.
dtype
))
t
=
n
[
7
]
t
=
n
[
7
]
...
@@ -204,7 +204,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -204,7 +204,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
assert
tval
.
shape
==
(
2
,)
assert
tval
.
shape
==
(
2
,)
assert
(
tval
==
[
0.0
,
2.0
])
.
all
()
assert
(
tval
==
[
0.0
,
2.0
])
.
all
()
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_err_bounds0
(
self
):
def
test_err_bounds0
(
self
):
n
=
self
.
shared
(
np
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
n
=
self
.
shared
(
np
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
for
idx
in
[(
0
,
4
),
(
0
,
-
4
)]:
for
idx
in
[(
0
,
4
),
(
0
,
-
4
)]:
...
@@ -220,7 +220,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -220,7 +220,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
finally
:
finally
:
_logger
.
setLevel
(
oldlevel
)
_logger
.
setLevel
(
oldlevel
)
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_err_bounds1
(
self
):
def
test_err_bounds1
(
self
):
n
=
self
.
shared
(
np
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
n
=
self
.
shared
(
np
.
ones
((
2
,
3
),
dtype
=
self
.
dtype
)
*
5
)
t
=
n
[
4
:
5
,
3
]
t
=
n
[
4
:
5
,
3
]
...
@@ -449,7 +449,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -449,7 +449,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
inc_subtensor
(
n4
[
test_array
>
2
,
...
,
0
,
1
],
1
)
.
eval
(),
inc_subtensor
(
n4
[
test_array
>
2
,
...
,
0
,
1
],
1
)
.
eval
(),
)
)
with
change_flags
(
compute_test_value
=
"off"
):
with
c
onfig
.
c
hange_flags
(
compute_test_value
=
"off"
):
# the boolean mask should have the correct shape
# the boolean mask should have the correct shape
# - too large, padded with True
# - too large, padded with True
mask
=
np
.
array
([
True
,
False
,
True
])
mask
=
np
.
array
([
True
,
False
,
True
])
...
@@ -783,7 +783,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -783,7 +783,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
g
=
tt
.
grad
(
h
.
sum
(),
W
)
g
=
tt
.
grad
(
h
.
sum
(),
W
)
N
=
2
N
=
2
if
(
if
(
theano
.
config
.
mode
==
"FAST_COMPILE"
config
.
mode
==
"FAST_COMPILE"
and
AdvancedIncSubtensor1
is
AdvancedIncSubtensor1
and
AdvancedIncSubtensor1
is
AdvancedIncSubtensor1
):
):
N
=
3
N
=
3
...
@@ -1273,9 +1273,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -1273,9 +1273,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
)
)
# Actual test (we compile a single Theano function to make it faster).
# Actual test (we compile a single Theano function to make it faster).
orig_warn
=
theano
.
config
.
warn__gpu_set_subtensor1
with
config
.
change_flags
(
warn__gpu_set_subtensor1
=
False
):
try
:
theano
.
config
.
warn__gpu_set_subtensor1
=
False
f
=
self
.
function
(
f
=
self
.
function
(
all_inputs_var
,
all_inputs_var
,
all_outputs_var
,
all_outputs_var
,
...
@@ -1283,8 +1281,6 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -1283,8 +1281,6 @@ class TestSubtensor(utt.OptimizationTestMixin):
op
=
AdvancedIncSubtensor1
,
op
=
AdvancedIncSubtensor1
,
N
=
len
(
all_outputs_var
),
N
=
len
(
all_outputs_var
),
)
)
finally
:
theano
.
config
.
warn__gpu_set_subtensor1
=
orig_warn
f_outs
=
f
(
*
all_inputs_num
)
f_outs
=
f
(
*
all_inputs_num
)
assert
len
(
f_outs
)
==
len
(
all_outputs_num
)
assert
len
(
f_outs
)
==
len
(
all_outputs_num
)
...
@@ -1528,7 +1524,7 @@ class TestAdvancedSubtensor:
...
@@ -1528,7 +1524,7 @@ class TestAdvancedSubtensor:
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
shared
=
_shared
self
.
shared
=
_shared
self
.
dtype
=
theano
.
config
.
floatX
self
.
dtype
=
config
.
floatX
self
.
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
self
.
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
self
.
s
=
iscalar
()
self
.
s
=
iscalar
()
...
@@ -2183,7 +2179,7 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2183,7 +2179,7 @@ class TestInferShape(utt.InferShapeTester):
bivec
.
tag
.
test_value
=
bivec_val
bivec
.
tag
.
test_value
=
bivec_val
# Make sure it doesn't complain about test values
# Make sure it doesn't complain about test values
with
theano
.
change_flags
(
compute_test_value
=
"raise"
):
with
config
.
change_flags
(
compute_test_value
=
"raise"
):
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
admat
,
aivec
],
[
admat
,
aivec
],
[
admat
[
1
:
3
,
aivec
]],
[
admat
[
1
:
3
,
aivec
]],
...
@@ -2215,7 +2211,7 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -2215,7 +2211,7 @@ class TestInferShape(utt.InferShapeTester):
assert
abs_res
.
broadcastable
==
(
False
,)
assert
abs_res
.
broadcastable
==
(
False
,)
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_basic_shape
():
def
test_basic_shape
():
test_shape
=
(
5
,
4
)
test_shape
=
(
5
,
4
)
test_indices
=
(
make_slice
(
1
,
3
,
None
),)
test_indices
=
(
make_slice
(
1
,
3
,
None
),)
...
@@ -2223,7 +2219,7 @@ def test_basic_shape():
...
@@ -2223,7 +2219,7 @@ def test_basic_shape():
assert
get_test_value
(
res
)
==
(
2
,)
assert
get_test_value
(
res
)
==
(
2
,)
@change_flags
(
compute_test_value
=
"raise"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"raise"
)
def
test_indexed_result_shape
():
def
test_indexed_result_shape
():
_test_idx
=
np
.
ix_
(
np
.
array
([
True
,
True
]),
np
.
array
([
True
]),
np
.
array
([
True
,
True
]))
_test_idx
=
np
.
ix_
(
np
.
array
([
True
,
True
]),
np
.
array
([
True
]),
np
.
array
([
True
,
True
]))
...
...
tests/tensor/test_type.py
浏览文件 @
b0b34b59
...
@@ -4,7 +4,7 @@ from tempfile import mkdtemp
...
@@ -4,7 +4,7 @@ from tempfile import mkdtemp
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
from
theano
import
c
hange_flags
,
c
onfig
from
theano
import
config
from
theano.tensor.type
import
TensorType
from
theano.tensor.type
import
TensorType
...
@@ -42,7 +42,7 @@ def test_filter_ndarray_subclass():
...
@@ -42,7 +42,7 @@ def test_filter_ndarray_subclass():
def
test_filter_float_subclass
():
def
test_filter_float_subclass
():
"""Make sure `TensorType.filter` can handle `float` subclasses."""
"""Make sure `TensorType.filter` can handle `float` subclasses."""
with
change_flags
(
floatX
=
"float64"
):
with
c
onfig
.
c
hange_flags
(
floatX
=
"float64"
):
test_type
=
TensorType
(
"float64"
,
broadcastable
=
[])
test_type
=
TensorType
(
"float64"
,
broadcastable
=
[])
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float64"
)[
0
]
nan
=
np
.
array
([
np
.
nan
],
dtype
=
"float64"
)[
0
]
...
@@ -51,7 +51,7 @@ def test_filter_float_subclass():
...
@@ -51,7 +51,7 @@ def test_filter_float_subclass():
filtered_nan
=
test_type
.
filter
(
nan
)
filtered_nan
=
test_type
.
filter
(
nan
)
assert
isinstance
(
filtered_nan
,
np
.
ndarray
)
assert
isinstance
(
filtered_nan
,
np
.
ndarray
)
with
change_flags
(
floatX
=
"float32"
):
with
c
onfig
.
c
hange_flags
(
floatX
=
"float32"
):
# Try again, except this time `nan` isn't a `float`
# Try again, except this time `nan` isn't a `float`
test_type
=
TensorType
(
"float32"
,
broadcastable
=
[])
test_type
=
TensorType
(
"float32"
,
broadcastable
=
[])
...
...
tests/tensor/utils.py
浏览文件 @
b0b34b59
...
@@ -8,7 +8,7 @@ import pytest
...
@@ -8,7 +8,7 @@ import pytest
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
c
hange_flags
,
c
onfig
,
function
,
gof
,
shared
,
tensor
from
theano
import
config
,
function
,
gof
,
shared
,
tensor
from
theano.compile.mode
import
get_default_mode
from
theano.compile.mode
import
get_default_mode
from
theano.tensor.type
import
TensorType
from
theano.tensor.type
import
TensorType
...
@@ -16,7 +16,7 @@ from theano.tensor.type import TensorType
...
@@ -16,7 +16,7 @@ from theano.tensor.type import TensorType
# Used to exclude random numbers too close to certain values
# Used to exclude random numbers too close to certain values
_eps
=
1e-2
_eps
=
1e-2
if
theano
.
config
.
floatX
==
"float32"
:
if
config
.
floatX
==
"float32"
:
angle_eps
=
1e-4
angle_eps
=
1e-4
else
:
else
:
angle_eps
=
1e-10
angle_eps
=
1e-10
...
@@ -572,7 +572,7 @@ def makeTester(
...
@@ -572,7 +572,7 @@ def makeTester(
# instantiated on the following bad inputs: %s"
# instantiated on the following bad inputs: %s"
# % (self.op, testname, node, inputs))
# % (self.op, testname, node, inputs))
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
@pytest.mark.skipif
(
skip
,
reason
=
"Skipped"
)
@pytest.mark.skipif
(
skip
,
reason
=
"Skipped"
)
def
test_bad_runtime
(
self
):
def
test_bad_runtime
(
self
):
for
testname
,
inputs
in
self
.
bad_runtime
.
items
():
for
testname
,
inputs
in
self
.
bad_runtime
.
items
():
...
...
tests/test_config.py
浏览文件 @
b0b34b59
"""Test config options."""
"""Test config options."""
import
configparser
as
stdlib_configparser
import
logging
import
logging
from
unittest.mock
import
patch
from
unittest.mock
import
patch
...
@@ -6,13 +7,69 @@ import pytest
...
@@ -6,13 +7,69 @@ 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
_create_test_config
():
return
configparser
.
TheanoConfigParser
(
flags_dict
=
{},
theano_cfg
=
stdlib_configparser
.
ConfigParser
(),
theano_raw_cfg
=
stdlib_configparser
.
RawConfigParser
(),
)
def
test_api_deprecation_warning
():
# accessing through configdefaults.config is the new best practice
with
pytest
.
warns
(
None
):
root
=
configdefaults
.
config
assert
isinstance
(
str
(
root
),
str
)
# accessing through configparser.config is discouraged
root
=
configparser
.
config
with
pytest
.
warns
(
DeprecationWarning
,
match
=
"instead"
):
root
.
add
(
"test_deprecationwarning"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
)
with
pytest
.
warns
(
DeprecationWarning
,
match
=
"instead"
):
with
root
.
change_flags
(
test_deprecationwarning
=
"new_value"
):
pass
def
test_api_redirect
():
root
=
_create_test_config
()
# one section level
root
.
add
(
"test__section_redirect"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
)
assert
hasattr
(
root
,
"test__section_redirect"
)
assert
root
.
test__section_redirect
==
"test_default"
assert
hasattr
(
root
,
"test"
)
assert
isinstance
(
root
.
test
,
configparser
.
_SectionRedirect
)
with
pytest
.
warns
(
DeprecationWarning
):
assert
root
.
test
.
section_redirect
==
"test_default"
# two section levels
root
.
add
(
"test__subsection__redirect"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default2"
),
)
assert
hasattr
(
root
,
"test__subsection__redirect"
)
assert
root
.
test__subsection__redirect
==
"test_default2"
with
pytest
.
warns
(
DeprecationWarning
):
assert
root
.
test
.
subsection
.
redirect
==
"test_default2"
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
=
_create_test_config
()
def
validate
(
val
):
def
validate
(
val
):
if
val
==
"invalid"
:
if
val
==
"invalid"
:
raise
ValueError
(
"Test-triggered"
)
raise
ValueError
(
"Test-triggered"
)
...
@@ -20,26 +77,25 @@ def test_invalid_default():
...
@@ -20,26 +77,25 @@ 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"
,
"
test
__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
[
"test
__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"
,
"
test
__test_invalid_default_b"
,
doc
=
"unittest"
,
doc
=
"unittest"
,
configparam
=
ConfigParam
(
"invalid"
,
validate
=
validate
),
configparam
=
ConfigParam
(
"invalid"
,
validate
=
validate
),
in_c_key
=
False
,
in_c_key
=
False
,
)
)
# 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
"
test__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
)
...
@@ -82,26 +138,30 @@ def test_config_param_apply_and_validation():
...
@@ -82,26 +138,30 @@ def test_config_param_apply_and_validation():
def
test_config_hash
():
def
test_config_hash
():
# TODO: use custom config instance for the test
root
=
_create_test_config
()
root
=
configparser
.
config
root
.
add
(
configparser
.
AddConfigVar
(
"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
root
.
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
def
test_config_print
():
root
=
configdefaults
.
config
result
=
str
(
root
)
assert
isinstance
(
result
,
str
)
class
TestConfigTypes
:
class
TestConfigTypes
:
def
test_bool
(
self
):
def
test_bool
(
self
):
valids
=
{
valids
=
{
...
@@ -139,26 +199,56 @@ class TestConfigTypes:
...
@@ -139,26 +199,56 @@ class TestConfigTypes:
def
test_config_context
():
def
test_config_context
():
# TODO: use custom config instance for the test
root
=
_create_test_config
()
root
=
configparser
.
config
root
.
add
(
configparser
.
AddConfigVar
(
"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"
with
configparser
.
change_flags
(
test_config_context
=
"new_value"
):
with
root
.
change_flags
(
test__config_context
=
"new_value"
):
assert
root
.
test_config_context
==
"new_value"
assert
root
.
test__config_context
==
"new_value"
assert
root
.
test_config_context
==
"test_default"
with
root
.
change_flags
({
"test__config_context"
:
"new_value2"
}):
assert
root
.
test__config_context
==
"new_value2"
assert
root
.
test__config_context
==
"new_value"
assert
root
.
test__config_context
==
"test_default"
def
test_invalid_configvar_access
():
root
=
configdefaults
.
config
root_test
=
_create_test_config
()
# add a setting to the test instance
root_test
.
add
(
"test__on_test_instance"
,
"This config setting was added to the test instance."
,
configparser
.
IntParam
(
5
),
)
assert
hasattr
(
root_test
,
"test__on_test_instance"
)
# While the property _actually_ exists on all instances,
# accessing it through another instance raises an AttributeError.
assert
not
hasattr
(
root
,
"test__on_test_instance"
)
# But we can make sure that nothing crazy happens when we access it:
with
pytest
.
raises
(
configparser
.
ConfigAccessViolation
,
match
=
"different instance"
):
print
(
root
.
test__on_test_instance
)
# And also that we can't add two configs of the same name to different instances:
with
pytest
.
raises
(
AttributeError
,
match
=
"already registered"
):
root
.
add
(
"test__on_test_instance"
,
"This config setting was already added to another instance."
,
configparser
.
IntParam
(
5
),
)
def
test_no_more_dotting
():
def
test_no_more_dotting
():
root
=
configdefaults
.
config
with
pytest
.
raises
(
ValueError
,
match
=
"Dot-based"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Dot-based"
):
AddConfigVar
(
root
.
add
(
"
T_config
.something"
,
"
test
.something"
,
doc
=
"unittest"
,
doc
=
"unittest"
,
configparam
=
ConfigParam
(
"invalid"
),
configparam
=
ConfigParam
(
"invalid"
),
in_c_key
=
False
,
in_c_key
=
False
,
...
...
tests/test_gradient.py
浏览文件 @
b0b34b59
...
@@ -5,7 +5,7 @@ import pytest
...
@@ -5,7 +5,7 @@ import pytest
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
c
hange_flags
,
c
onfig
,
gof
,
gradient
from
theano
import
config
,
gof
,
gradient
from
theano.gof.null_type
import
NullType
from
theano.gof.null_type
import
NullType
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
as
RandomStreams
from
theano.sandbox.rng_mrg
import
MRG_RandomStreams
as
RandomStreams
...
@@ -521,7 +521,7 @@ def test_known_grads_integers():
...
@@ -521,7 +521,7 @@ def test_known_grads_integers():
f
=
theano
.
function
([
g_expected
],
g_grad
)
f
=
theano
.
function
([
g_expected
],
g_grad
)
x
=
-
3
x
=
-
3
gv
=
np
.
cast
[
theano
.
config
.
floatX
](
0.6
)
gv
=
np
.
cast
[
config
.
floatX
](
0.6
)
g_actual
=
f
(
gv
)
g_actual
=
f
(
gv
)
...
@@ -784,7 +784,7 @@ def test_grad_clip():
...
@@ -784,7 +784,7 @@ def test_grad_clip():
f
=
theano
.
function
([
x
],
outputs
=
[
z
,
z2
])
f
=
theano
.
function
([
x
],
outputs
=
[
z
,
z2
])
if
theano
.
config
.
mode
!=
"FAST_COMPILE"
:
if
config
.
mode
!=
"FAST_COMPILE"
:
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
any
([
isinstance
(
node
.
op
,
gradient
.
GradClip
)
for
node
in
topo
])
assert
not
any
([
isinstance
(
node
.
op
,
gradient
.
GradClip
)
for
node
in
topo
])
out
=
f
(
2.0
)
out
=
f
(
2.0
)
...
@@ -800,7 +800,7 @@ def test_grad_scale():
...
@@ -800,7 +800,7 @@ def test_grad_scale():
f
=
theano
.
function
([
x
],
outputs
=
[
z
,
z2
])
f
=
theano
.
function
([
x
],
outputs
=
[
z
,
z2
])
if
theano
.
config
.
mode
!=
"FAST_COMPILE"
:
if
config
.
mode
!=
"FAST_COMPILE"
:
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
not
any
([
isinstance
(
node
.
op
,
gradient
.
GradScale
)
for
node
in
topo
])
assert
not
any
([
isinstance
(
node
.
op
,
gradient
.
GradScale
)
for
node
in
topo
])
out
=
f
(
2.0
)
out
=
f
(
2.0
)
...
@@ -808,11 +808,11 @@ def test_grad_scale():
...
@@ -808,11 +808,11 @@ def test_grad_scale():
assert
np
.
allclose
(
out
,
(
8
,
4
))
assert
np
.
allclose
(
out
,
(
8
,
4
))
@change_flags
(
compute_test_value
=
"off"
)
@c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
test_undefined_grad_opt
():
def
test_undefined_grad_opt
():
# Make sure that undefined grad get removed in optimized graph.
# Make sure that undefined grad get removed in optimized graph.
random
=
RandomStreams
(
np
.
random
.
randint
(
1
,
2147462579
))
random
=
RandomStreams
(
np
.
random
.
randint
(
1
,
2147462579
))
pvals
=
theano
.
shared
(
np
.
random
.
rand
(
10
,
20
)
.
astype
(
theano
.
config
.
floatX
))
pvals
=
theano
.
shared
(
np
.
random
.
rand
(
10
,
20
)
.
astype
(
config
.
floatX
))
pvals
=
pvals
/
pvals
.
sum
(
axis
=
1
)
pvals
=
pvals
/
pvals
.
sum
(
axis
=
1
)
pvals
=
gradient
.
zero_grad
(
pvals
)
pvals
=
gradient
.
zero_grad
(
pvals
)
samples
=
random
.
multinomial
(
pvals
=
pvals
,
n
=
1
)
samples
=
random
.
multinomial
(
pvals
=
pvals
,
n
=
1
)
...
...
theano/__init__.py
浏览文件 @
b0b34b59
...
@@ -64,7 +64,12 @@ for p in sys.path:
...
@@ -64,7 +64,12 @@ for p in sys.path:
raise
RuntimeError
(
"You have the theano directory in your Python path."
)
raise
RuntimeError
(
"You have the theano directory in your Python path."
)
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.configparser
import
change_flags
from
theano.utils
import
deprecated
change_flags
=
deprecated
(
"Use theano.config.change_flags instead!"
)(
config
.
change_flags
)
# This is the api version for ops that generate C code. External ops
# This is the api version for ops that generate C code. External ops
...
...
theano/compile/builders.py
浏览文件 @
b0b34b59
...
@@ -401,7 +401,7 @@ class OpFromGraph(Op):
...
@@ -401,7 +401,7 @@ class OpFromGraph(Op):
is_inline
=
self
.
is_inline
is_inline
=
self
.
is_inline
return
"
%(name)
s{inline=
%(is_inline)
s}"
%
locals
()
return
"
%(name)
s{inline=
%(is_inline)
s}"
%
locals
()
@theano.change_flags
(
compute_test_value
=
"off"
)
@theano.c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
_recompute_lop_op
(
self
):
def
_recompute_lop_op
(
self
):
"""
"""
converts self._lop_op from user supplied form to type(self) instance
converts self._lop_op from user supplied form to type(self) instance
...
@@ -541,7 +541,7 @@ class OpFromGraph(Op):
...
@@ -541,7 +541,7 @@ class OpFromGraph(Op):
self
.
_lop_op_is_cached
=
True
self
.
_lop_op_is_cached
=
True
self
.
_lop_type
=
"lop"
self
.
_lop_type
=
"lop"
@theano.change_flags
(
compute_test_value
=
"off"
)
@theano.c
onfig.c
hange_flags
(
compute_test_value
=
"off"
)
def
_recompute_rop_op
(
self
):
def
_recompute_rop_op
(
self
):
"""
"""
converts self._rop_op from user supplied form to type(self) instance
converts self._rop_op from user supplied form to type(self) instance
...
...
theano/compile/debugmode.py
浏览文件 @
b0b34b59
...
@@ -18,7 +18,7 @@ from warnings import warn
...
@@ -18,7 +18,7 @@ from warnings import warn
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
from
theano
import
c
hange_flags
,
c
onfig
,
gof
from
theano
import
config
,
gof
from
theano.compile.function.types
import
(
from
theano.compile.function.types
import
(
Function
,
Function
,
FunctionMaker
,
FunctionMaker
,
...
@@ -2446,7 +2446,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
...
@@ -2446,7 +2446,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
)
)
fgraph
.
equivalence_tracker
=
equivalence_tracker
fgraph
.
equivalence_tracker
=
equivalence_tracker
with
change_flags
(
compute_test_value
=
config
.
compute_test_value_opt
):
with
c
onfig
.
c
hange_flags
(
compute_test_value
=
config
.
compute_test_value_opt
):
optimizer
(
fgraph
)
optimizer
(
fgraph
)
theano
.
compile
.
function
.
types
.
insert_deepcopy
(
theano
.
compile
.
function
.
types
.
insert_deepcopy
(
...
@@ -2506,7 +2506,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
...
@@ -2506,7 +2506,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
file
=
sys
.
stderr
,
file
=
sys
.
stderr
,
)
)
self
.
fgraph
=
fgraph
self
.
fgraph
=
fgraph
if
theano
.
config
.
cycle_detection
==
"regular"
:
if
config
.
cycle_detection
==
"regular"
:
destroy_handler_added
=
False
destroy_handler_added
=
False
for
feature
in
fgraph
.
_features
:
for
feature
in
fgraph
.
_features
:
if
isinstance
(
feature
,
gof
.
DestroyHandler
):
if
isinstance
(
feature
,
gof
.
DestroyHandler
):
...
@@ -2516,7 +2516,9 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
...
@@ -2516,7 +2516,9 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
fgraph
.
attach_feature
(
gof
.
DestroyHandler
())
fgraph
.
attach_feature
(
gof
.
DestroyHandler
())
for
o
in
fgraph
.
outputs
:
for
o
in
fgraph
.
outputs
:
try
:
try
:
with
change_flags
(
compute_test_value
=
config
.
compute_test_value_opt
):
with
config
.
change_flags
(
compute_test_value
=
config
.
compute_test_value_opt
):
fgraph
.
replace_validate
(
fgraph
.
replace_validate
(
o
,
_output_guard
(
o
),
reason
=
"output_guard"
o
,
_output_guard
(
o
),
reason
=
"output_guard"
)
)
...
...
theano/compile/function/types.py
浏览文件 @
b0b34b59
...
@@ -1153,7 +1153,7 @@ def _pickle_Function(f):
...
@@ -1153,7 +1153,7 @@ def _pickle_Function(f):
def
_constructor_Function
(
maker
,
input_storage
,
inputs_data
,
trust_input
=
False
):
def
_constructor_Function
(
maker
,
input_storage
,
inputs_data
,
trust_input
=
False
):
if
not
theano
.
config
.
unpickle_function
:
if
not
config
.
unpickle_function
:
return
None
return
None
f
=
maker
.
create
(
input_storage
,
trustme
=
True
)
f
=
maker
.
create
(
input_storage
,
trustme
=
True
)
...
@@ -1360,7 +1360,7 @@ class FunctionMaker:
...
@@ -1360,7 +1360,7 @@ class FunctionMaker:
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof.compilelock
import
get_lock
,
release_lock
graph_db_file
=
os
.
path
.
join
(
theano
.
config
.
compiledir
,
"optimized_graphs.pkl"
)
graph_db_file
=
os
.
path
.
join
(
config
.
compiledir
,
"optimized_graphs.pkl"
)
# the inputs, outputs, and size of the graph to be optimized
# the inputs, outputs, and size of the graph to be optimized
inputs_new
=
[
inp
.
variable
for
inp
in
inputs
]
inputs_new
=
[
inp
.
variable
for
inp
in
inputs
]
...
@@ -1379,12 +1379,12 @@ class FunctionMaker:
...
@@ -1379,12 +1379,12 @@ class FunctionMaker:
print
(
f
"create new graph_db in {graph_db_file}"
)
print
(
f
"create new graph_db in {graph_db_file}"
)
# load the graph_db dictionary
# load the graph_db dictionary
try
:
try
:
with
open
(
graph_db_file
,
"rb"
)
as
f
:
with
open
(
graph_db_file
,
"rb"
)
as
f
,
config
.
change_flags
(
unpickle_function
=
False
):
# Temporary hack to allow
# Temporary hack to allow
# tests.scan.test_scan.T_Scan to
# tests.scan.test_scan.T_Scan to
# finish. Should be changed in definitive version.
# finish. Should be changed in definitive version.
tmp
=
theano
.
config
.
unpickle_function
theano
.
config
.
unpickle_function
=
False
graph_db
=
pickle
.
load
(
f
)
graph_db
=
pickle
.
load
(
f
)
print
(
"graph_db loaded and it is not empty"
)
print
(
"graph_db loaded and it is not empty"
)
except
EOFError
as
e
:
except
EOFError
as
e
:
...
@@ -1392,8 +1392,6 @@ class FunctionMaker:
...
@@ -1392,8 +1392,6 @@ class FunctionMaker:
print
(
e
)
print
(
e
)
print
(
"graph_db loaded and it is empty"
)
print
(
"graph_db loaded and it is empty"
)
graph_db
=
{}
graph_db
=
{}
finally
:
theano
.
config
.
unpickle_function
=
tmp
return
graph_db
return
graph_db
...
@@ -1583,50 +1581,52 @@ class FunctionMaker:
...
@@ -1583,50 +1581,52 @@ class FunctionMaker:
# Fetch the optimizer and linker
# Fetch the optimizer and linker
optimizer
,
linker
=
mode
.
optimizer
,
copy
.
copy
(
mode
.
linker
)
optimizer
,
linker
=
mode
.
optimizer
,
copy
.
copy
(
mode
.
linker
)
if
need_opt
:
if
need_opt
:
compute_test_value_orig
=
theano
.
config
.
compute_test_value
limit_orig
=
theano
.
config
.
traceback__limit
# Why we add stack on node when it get done in output var?
# Why we add stack on node when it get done in output var?
try
:
try
:
# optimize the fgraph
theano
.
config
.
compute_test_value
=
theano
.
config
.
compute_test_value_opt
theano
.
config
.
traceback__limit
=
theano
.
config
.
traceback__compile_limit
start_optimizer
=
time
.
time
()
start_optimizer
=
time
.
time
()
# In case there is an error during optimization.
# In case there is an error during optimization.
optimizer_profile
=
None
optimizer_profile
=
None
opt_time
=
None
opt_time
=
None
# now optimize the graph
with
config
.
change_flags
(
if
theano
.
config
.
cache_optimizations
:
compute_test_value
=
config
.
compute_test_value_opt
,
optimizer_profile
=
self
.
optimize_graph_with_cache
(
traceback__limit
=
config
.
traceback__compile_limit
,
optimizer
,
inputs
,
outputs
):
)
# now optimize the graph
else
:
if
config
.
cache_optimizations
:
optimizer_profile
=
optimizer
(
fgraph
)
optimizer_profile
=
self
.
optimize_graph_with_cache
(
optimizer
,
inputs
,
outputs
)
else
:
optimizer_profile
=
optimizer
(
fgraph
)
end_optimizer
=
time
.
time
()
end_optimizer
=
time
.
time
()
opt_time
=
end_optimizer
-
start_optimizer
opt_time
=
end_optimizer
-
start_optimizer
_logger
.
debug
(
f
"Optimizing took {opt_time:f} seconds"
)
_logger
.
debug
(
f
"Optimizing took {opt_time:f} seconds"
)
# Add deep copy to respect the memory interface
# Add deep copy to respect the memory interface
insert_deepcopy
(
fgraph
,
inputs
,
outputs
+
additional_outputs
)
insert_deepcopy
(
fgraph
,
inputs
,
outputs
+
additional_outputs
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
compute_test_value_orig
theano
.
config
.
traceback__limit
=
limit_orig
# If the optimizer got interrupted
# If the optimizer got interrupted
if
opt_time
is
None
:
if
opt_time
is
None
:
end_optimizer
=
time
.
time
()
end_optimizer
=
time
.
time
()
opt_time
=
end_optimizer
-
start_optimizer
opt_time
=
end_optimizer
-
start_optimizer
theano
.
compile
.
profiling
.
total_graph_opt_time
+=
opt_time
theano
.
compile
.
profiling
.
total_graph_opt_time
+=
opt_time
if
profile
:
if
profile
:
if
optimizer_profile
is
None
and
hasattr
(
optimizer
,
"pre_profile"
):
if
optimizer_profile
is
None
and
hasattr
(
optimizer
,
"pre_profile"
):
optimizer_profile
=
optimizer
.
pre_profile
optimizer_profile
=
optimizer
.
pre_profile
profile
.
optimizer_time
+=
opt_time
profile
.
optimizer_time
+=
opt_time
if
theano
.
config
.
profile_optimizer
:
if
config
.
profile_optimizer
:
profile
.
optimizer_profile
=
(
optimizer
,
optimizer_profile
)
profile
.
optimizer_profile
=
(
optimizer
,
optimizer_profile
)
# IF False, if mean the profile for that function was explicitly disabled
# IF False, if mean the profile for that function was
elif
theano
.
config
.
profile_optimizer
and
profile
is
not
False
:
# explicitly disabled
elif
config
.
profile_optimizer
and
profile
is
not
False
:
warnings
.
warn
(
warnings
.
warn
(
(
(
"config.profile_optimizer requires config.profile to "
"config.profile_optimizer requires config.profile to "
...
@@ -1687,7 +1687,7 @@ class FunctionMaker:
...
@@ -1687,7 +1687,7 @@ class FunctionMaker:
def
_check_unused_inputs
(
self
,
inputs
,
outputs
,
on_unused_input
):
def
_check_unused_inputs
(
self
,
inputs
,
outputs
,
on_unused_input
):
if
on_unused_input
is
None
:
if
on_unused_input
is
None
:
on_unused_input
=
theano
.
config
.
on_unused_input
on_unused_input
=
config
.
on_unused_input
if
on_unused_input
==
"ignore"
:
if
on_unused_input
==
"ignore"
:
return
return
...
@@ -1816,14 +1816,11 @@ class FunctionMaker:
...
@@ -1816,14 +1816,11 @@ class FunctionMaker:
# Get a function instance
# Get a function instance
start_linker
=
time
.
time
()
start_linker
=
time
.
time
()
start_import_time
=
theano
.
gof
.
cmodule
.
import_time
start_import_time
=
theano
.
gof
.
cmodule
.
import_time
limit_orig
=
theano
.
config
.
traceback__limit
try
:
with
config
.
change_flags
(
traceback__limit
=
config
.
traceback__compile_limit
):
theano
.
config
.
traceback__limit
=
theano
.
config
.
traceback__compile_limit
_fn
,
_i
,
_o
=
self
.
linker
.
make_thunk
(
_fn
,
_i
,
_o
=
self
.
linker
.
make_thunk
(
input_storage
=
input_storage_lists
,
storage_map
=
storage_map
input_storage
=
input_storage_lists
,
storage_map
=
storage_map
)
)
finally
:
theano
.
config
.
traceback__limit
=
limit_orig
end_linker
=
time
.
time
()
end_linker
=
time
.
time
()
...
@@ -1857,8 +1854,8 @@ class FunctionMaker:
...
@@ -1857,8 +1854,8 @@ class FunctionMaker:
def
_constructor_FunctionMaker
(
kwargs
):
def
_constructor_FunctionMaker
(
kwargs
):
# Needed for old pickle
# Needed for old pickle
# Old pickle have at least the problem that output_keys where not saved.
# Old pickle have at least the problem that output_keys where not saved.
if
theano
.
config
.
unpickle_function
:
if
config
.
unpickle_function
:
if
theano
.
config
.
reoptimize_unpickled_function
:
if
config
.
reoptimize_unpickled_function
:
del
kwargs
[
"fgraph"
]
del
kwargs
[
"fgraph"
]
return
FunctionMaker
(
**
kwargs
)
return
FunctionMaker
(
**
kwargs
)
else
:
else
:
...
@@ -1965,7 +1962,7 @@ def orig_function(
...
@@ -1965,7 +1962,7 @@ def orig_function(
output_keys
=
output_keys
,
output_keys
=
output_keys
,
name
=
name
,
name
=
name
,
)
)
with
theano
.
change_flags
(
compute_test_value
=
"off"
):
with
config
.
change_flags
(
compute_test_value
=
"off"
):
fn
=
m
.
create
(
defaults
)
fn
=
m
.
create
(
defaults
)
finally
:
finally
:
t2
=
time
.
time
()
t2
=
time
.
time
()
...
...
theano/configdefaults.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/configparser.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/gof/cc.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/gof/type.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/gof/vm.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/sandbox/rng_mrg.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/scalar/basic.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/tensor/basic.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/tensor/elemwise.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/tensor/nnet/bn.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/tensor/subtensor.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
theano/utils.py
浏览文件 @
b0b34b59
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论