Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
40d0a283
提交
40d0a283
authored
1月 14, 2021
作者:
Brandon T. Willard
提交者:
Thomas Wiecki
1月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use direct imports for theano.compile.io and theano.compile.mode objects
上级
54c106b7
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
32 个修改的文件
包含
133 行增加
和
130 行删除
+133
-130
advanced_theano.txt
doc/cifarSC2011/advanced_theano.txt
+2
-2
aliasing.txt
doc/tutorial/aliasing.txt
+5
-3
conditions.txt
doc/tutorial/conditions.txt
+2
-2
modes.txt
doc/tutorial/modes.txt
+1
-1
test_types.py
tests/compile/function/test_types.py
+10
-13
test_mode.py
tests/compile/test_mode.py
+1
-1
test_modes.py
tests/compile/test_modes.py
+1
-1
test_basic.py
tests/link/c/test_basic.py
+3
-2
test_link.py
tests/link/test_link.py
+6
-5
test_vm.py
tests/link/test_vm.py
+6
-5
record.py
tests/record.py
+1
-1
test_basic.py
tests/scalar/test_basic.py
+2
-1
test_basic.py
tests/scan/test_basic.py
+27
-27
test_basic.py
tests/sparse/test_basic.py
+5
-8
test_opt.py
tests/sparse/test_opt.py
+9
-8
test_abstract_conv.py
tests/tensor/nnet/test_abstract_conv.py
+8
-7
test_conv.py
tests/tensor/nnet/test_conv.py
+2
-1
test_basic.py
tests/tensor/test_basic.py
+3
-2
test_blas.py
tests/tensor/test_blas.py
+8
-7
test_casting.py
tests/tensor/test_casting.py
+1
-1
test_elemwise.py
tests/tensor/test_elemwise.py
+1
-3
test_gc.py
tests/tensor/test_gc.py
+3
-6
test_keepdims.py
tests/tensor/test_keepdims.py
+3
-2
test_mpi.py
tests/tensor/test_mpi.py
+2
-1
test_opt.py
tests/tensor/test_opt.py
+0
-0
test_sort.py
tests/tensor/test_sort.py
+2
-1
test_subtensor.py
tests/tensor/test_subtensor.py
+2
-1
test_config.py
tests/test_config.py
+1
-1
pfunc.py
theano/compile/function/pfunc.py
+2
-3
configdefaults.py
theano/configdefaults.py
+3
-3
dnn.py
theano/gpuarray/dnn.py
+9
-9
printing.py
theano/printing.py
+2
-2
没有找到文件。
doc/cifarSC2011/advanced_theano.txt
浏览文件 @
40d0a283
...
@@ -29,9 +29,9 @@ Conditions
...
@@ -29,9 +29,9 @@ Conditions
z_lazy = ifelse(tt.lt(a,b), tt.mean(x), tt.mean(y))
z_lazy = ifelse(tt.lt(a,b), tt.mean(x), tt.mean(y))
f_switch = theano.function([a,b,x,y], z_switch,
f_switch = theano.function([a,b,x,y], z_switch,
mode=theano.Mode(linker='vm'))
mode=theano.
compile.mode.
Mode(linker='vm'))
f_lazyifelse = theano.function([a,b,x,y], z_lazy,
f_lazyifelse = theano.function([a,b,x,y], z_lazy,
mode=theano.Mode(linker='vm'))
mode=theano.
compile.mode.
Mode(linker='vm'))
val1 = 0.
val1 = 0.
val2 = 1.
val2 = 1.
...
...
doc/tutorial/aliasing.txt
浏览文件 @
40d0a283
...
@@ -232,11 +232,13 @@ that control how ``theano.function`` handles its argument[s] and return value[s]
...
@@ -232,11 +232,13 @@ that control how ``theano.function`` handles its argument[s] and return value[s]
.. testcode::
.. testcode::
import theano, theano.tensor
import theano
import theano.tensor as tt
from theano.compile.io import In, Out
x = t
heano.tensor
.matrix()
x = t
t
.matrix()
y = 2 * x
y = 2 * x
f = theano.function([
theano.In(x, borrow=True)], theano.
Out(y, borrow=True))
f = theano.function([
In(x, borrow=True)],
Out(y, borrow=True))
Borrowing an input means that Theano will treat the argument you provide as if
Borrowing an input means that Theano will treat the argument you provide as if
it were part of Theano's pool of temporaries. Consequently, your input
it were part of Theano's pool of temporaries. Consequently, your input
...
...
doc/tutorial/conditions.txt
浏览文件 @
40d0a283
...
@@ -31,9 +31,9 @@ IfElse vs Switch
...
@@ -31,9 +31,9 @@ IfElse vs Switch
z_lazy = ifelse(tt.lt(a, b), tt.mean(x), tt.mean(y))
z_lazy = ifelse(tt.lt(a, b), tt.mean(x), tt.mean(y))
f_switch = theano.function([a, b, x, y], z_switch,
f_switch = theano.function([a, b, x, y], z_switch,
mode=theano.Mode(linker='vm'))
mode=theano.
compile.mode.
Mode(linker='vm'))
f_lazyifelse = theano.function([a, b, x, y], z_lazy,
f_lazyifelse = theano.function([a, b, x, y], z_lazy,
mode=theano.Mode(linker='vm'))
mode=theano.
compile.mode.
Mode(linker='vm'))
val1 = 0.
val1 = 0.
val2 = 1.
val2 = 1.
...
...
doc/tutorial/modes.txt
浏览文件 @
40d0a283
...
@@ -210,7 +210,7 @@ The optimizers Theano provides are summarized below to indicate the trade-offs
...
@@ -210,7 +210,7 @@ The optimizers Theano provides are summarized below to indicate the trade-offs
one might make between compilation time and execution time.
one might make between compilation time and execution time.
These optimizers can be enabled globally with the Theano flag: ``optimizer=name``
These optimizers can be enabled globally with the Theano flag: ``optimizer=name``
or per call to theano functions with ``
theano.function(...mode=theano.
Mode(optimizer="name"))``.
or per call to theano functions with ``
function(...mode=
Mode(optimizer="name"))``.
================= ============ ============== ==================================================
================= ============ ============== ==================================================
optimizer Compile time Execution time Description
optimizer Compile time Execution time Description
...
...
tests/compile/function/test_types.py
浏览文件 @
40d0a283
...
@@ -11,6 +11,7 @@ import theano.tensor as tt
...
@@ -11,6 +11,7 @@ import theano.tensor as tt
from
theano.compile.function
import
function
from
theano.compile.function
import
function
from
theano.compile.function.types
import
UnusedInputError
from
theano.compile.function.types
import
UnusedInputError
from
theano.compile.io
import
In
,
Out
from
theano.compile.io
import
In
,
Out
from
theano.compile.mode
import
Mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.basic
import
Constant
from
theano.graph.basic
import
Constant
from
theano.graph.fg
import
MissingInputError
from
theano.graph.fg
import
MissingInputError
...
@@ -627,14 +628,12 @@ class TestFunction:
...
@@ -627,14 +628,12 @@ class TestFunction:
f
(
o
+
0.1
)
# should not clobber the memory used to store four
f
(
o
+
0.1
)
# should not clobber the memory used to store four
assert
np
.
all
(
four
==
4
)
assert
np
.
all
(
four
==
4
)
f
=
function
(
f
=
function
([
a
],
Out
(
a
*
4
,
borrow
=
True
),
mode
=
Mode
(
"c|py_nogc"
,
"fast_run"
))
[
a
],
Out
(
a
*
4
,
borrow
=
True
),
mode
=
theano
.
Mode
(
"c|py_nogc"
,
"fast_run"
)
)
o
=
np
.
ones
((
3
,
3
))
o
=
np
.
ones
((
3
,
3
))
four
=
f
(
o
)
four
=
f
(
o
)
assert
np
.
all
(
four
==
4
)
assert
np
.
all
(
four
==
4
)
f
(
o
+
0.1
)
# should clobber the memory used to store four
f
(
o
+
0.1
)
# should clobber the memory used to store four
if
theano
.
config
.
cxx
:
if
config
.
cxx
:
assert
not
np
.
all
(
four
==
4
)
assert
not
np
.
all
(
four
==
4
)
else
:
else
:
# The Elemwise.perform method don't reuse memory
# The Elemwise.perform method don't reuse memory
...
@@ -691,9 +690,7 @@ class TestFunction:
...
@@ -691,9 +690,7 @@ class TestFunction:
a
,
b
=
dscalars
(
"a"
,
"b"
)
a
,
b
=
dscalars
(
"a"
,
"b"
)
c
=
a
+
b
c
=
a
+
b
func
=
theano
.
function
(
func
=
theano
.
function
([
In
(
a
,
name
=
"first"
),
In
(
b
,
value
=
1
,
name
=
"second"
)],
c
)
[
theano
.
In
(
a
,
name
=
"first"
),
theano
.
In
(
b
,
value
=
1
,
name
=
"second"
)],
c
)
x
=
func
(
first
=
1
)
x
=
func
(
first
=
1
)
try
:
try
:
func
(
second
=
2
)
func
(
second
=
2
)
...
@@ -721,17 +718,17 @@ class TestFunction:
...
@@ -721,17 +718,17 @@ class TestFunction:
# Assert cases we should check for aliased inputs
# Assert cases we should check for aliased inputs
for
d
in
[
for
d
in
[
dict
(
dict
(
inputs
=
[
theano
.
In
(
x1
,
borrow
=
True
)],
inputs
=
[
In
(
x1
,
borrow
=
True
)],
outputs
=
[
x1
+
1
],
outputs
=
[
x1
+
1
],
updates
=
[(
s2
,
s2
+
3
)],
updates
=
[(
s2
,
s2
+
3
)],
),
),
dict
(
dict
(
inputs
=
[
theano
.
In
(
x1
,
borrow
=
True
,
mutable
=
True
)],
inputs
=
[
In
(
x1
,
borrow
=
True
,
mutable
=
True
)],
outputs
=
[
x1
+
1
],
outputs
=
[
x1
+
1
],
updates
=
[(
s2
,
s2
+
3
)],
updates
=
[(
s2
,
s2
+
3
)],
),
),
dict
(
dict
(
inputs
=
[
theano
.
In
(
x1
,
mutable
=
True
)],
inputs
=
[
In
(
x1
,
mutable
=
True
)],
outputs
=
[
x1
+
1
],
outputs
=
[
x1
+
1
],
updates
=
[(
s2
,
s2
+
3
)],
updates
=
[(
s2
,
s2
+
3
)],
),
),
...
@@ -1146,12 +1143,12 @@ def test_empty_givens_updates():
...
@@ -1146,12 +1143,12 @@ def test_empty_givens_updates():
# triggering useless crashes at compile time.
# triggering useless crashes at compile time.
x
=
scalar
()
x
=
scalar
()
y
=
x
*
2
y
=
x
*
2
function
([
theano
.
In
(
x
)],
y
,
givens
=
{})
function
([
In
(
x
)],
y
,
givens
=
{})
function
([
theano
.
In
(
x
)],
y
,
updates
=
{})
function
([
In
(
x
)],
y
,
updates
=
{})
@pytest.mark.skipif
(
@pytest.mark.skipif
(
not
theano
.
gpuarray
.
pygpu_activated
or
theano
.
config
.
mode
==
"DEBUG_MODE"
,
not
theano
.
gpuarray
.
pygpu_activated
or
config
.
mode
==
"DEBUG_MODE"
,
reason
=
"DEBUG_MODE forces synchronous behaviour which breaks this test"
,
reason
=
"DEBUG_MODE forces synchronous behaviour which breaks this test"
,
)
)
def
test_sync_update
():
def
test_sync_update
():
...
...
tests/compile/test_mode.py
浏览文件 @
40d0a283
...
@@ -33,5 +33,5 @@ def test_no_output_from_implace():
...
@@ -33,5 +33,5 @@ def test_no_output_from_implace():
def
test_including
():
def
test_including
():
mode
=
theano
.
Mode
(
optimizer
=
"merge"
)
mode
=
Mode
(
optimizer
=
"merge"
)
mode
.
including
(
"fast_compile"
)
mode
.
including
(
"fast_compile"
)
tests/compile/test_modes.py
浏览文件 @
40d0a283
...
@@ -5,7 +5,7 @@ Test compilation modes
...
@@ -5,7 +5,7 @@ Test compilation modes
import
copy
import
copy
import
theano
import
theano
from
theano.compile
import
Mode
from
theano.compile
.mode
import
Mode
from
theano.tensor.type
import
matrix
,
vector
from
theano.tensor.type
import
matrix
,
vector
...
...
tests/link/c/test_basic.py
浏览文件 @
40d0a283
...
@@ -2,6 +2,7 @@ import numpy as np
...
@@ -2,6 +2,7 @@ import numpy as np
import
pytest
import
pytest
import
theano
import
theano
from
theano.compile.mode
import
Mode
from
theano.graph
import
fg
from
theano.graph
import
fg
from
theano.graph.basic
import
Apply
,
Constant
,
Variable
from
theano.graph.basic
import
Apply
,
Constant
,
Variable
from
theano.graph.op
import
COp
from
theano.graph.op
import
COp
...
@@ -220,7 +221,7 @@ def test_clinker_literal_inlining():
...
@@ -220,7 +221,7 @@ def test_clinker_literal_inlining():
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_clinker_literal_cache
():
def
test_clinker_literal_cache
():
mode
=
theano
.
Mode
(
linker
=
"c"
)
mode
=
Mode
(
linker
=
"c"
)
A
=
matrix
()
A
=
matrix
()
input1
=
vector
()
input1
=
vector
()
...
@@ -415,7 +416,7 @@ def test_shared_input_output():
...
@@ -415,7 +416,7 @@ def test_shared_input_output():
state
=
theano
.
shared
(
0
)
state
=
theano
.
shared
(
0
)
state
.
name
=
"state"
state
.
name
=
"state"
linker
=
CLinker
()
linker
=
CLinker
()
mode
=
theano
.
Mode
(
linker
=
linker
)
mode
=
Mode
(
linker
=
linker
)
f
=
theano
.
function
([
inc
],
state
,
updates
=
[(
state
,
state
+
inc
)],
mode
=
mode
)
f
=
theano
.
function
([
inc
],
state
,
updates
=
[(
state
,
state
+
inc
)],
mode
=
mode
)
g
=
theano
.
function
([
inc
],
state
,
updates
=
[(
state
,
state
+
inc
)])
g
=
theano
.
function
([
inc
],
state
,
updates
=
[(
state
,
state
+
inc
)])
...
...
tests/link/test_link.py
浏览文件 @
40d0a283
...
@@ -3,8 +3,9 @@ from copy import deepcopy
...
@@ -3,8 +3,9 @@ from copy import deepcopy
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
from
theano.graph
import
basic
,
fg
from
theano.compile.mode
import
Mode
from
theano.graph.basic
import
Apply
,
Constant
,
Variable
from
theano.graph
import
fg
from
theano.graph.basic
import
Apply
,
Constant
,
Variable
,
clone
from
theano.graph.op
import
Op
from
theano.graph.op
import
Op
from
theano.graph.type
import
Type
from
theano.graph.type
import
Type
from
theano.link.basic
import
Container
,
PerformLinker
,
WrapLinker
from
theano.link.basic
import
Container
,
PerformLinker
,
WrapLinker
...
@@ -121,7 +122,7 @@ class TestPerformLinker:
...
@@ -121,7 +122,7 @@ class TestPerformLinker:
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
a
,
d
=
add
(
x
,
y
),
div
(
x
,
y
)
a
,
d
=
add
(
x
,
y
),
div
(
x
,
y
)
e
=
mul
(
a
,
d
)
e
=
mul
(
a
,
d
)
fn
=
perform_linker
(
FunctionGraph
(
*
basic
.
clone
([
x
,
y
,
a
],
[
e
])))
.
make_function
()
fn
=
perform_linker
(
FunctionGraph
(
*
clone
([
x
,
y
,
a
],
[
e
])))
.
make_function
()
assert
fn
(
1.0
,
2.0
,
9.0
)
==
4.5
assert
fn
(
1.0
,
2.0
,
9.0
)
==
4.5
def
test_skiphole
(
self
):
def
test_skiphole
(
self
):
...
@@ -129,7 +130,7 @@ class TestPerformLinker:
...
@@ -129,7 +130,7 @@ class TestPerformLinker:
a
=
add
(
x
,
y
)
a
=
add
(
x
,
y
)
r
=
raise_err
(
a
)
r
=
raise_err
(
a
)
e
=
add
(
r
,
a
)
e
=
add
(
r
,
a
)
fn
=
perform_linker
(
FunctionGraph
(
*
basic
.
clone
([
x
,
y
,
r
],
[
e
])))
.
make_function
()
fn
=
perform_linker
(
FunctionGraph
(
*
clone
([
x
,
y
,
r
],
[
e
])))
.
make_function
()
assert
fn
(
1.0
,
2.0
,
4.5
)
==
7.5
assert
fn
(
1.0
,
2.0
,
4.5
)
==
7.5
...
@@ -186,7 +187,7 @@ def test_sort_schedule_fn():
...
@@ -186,7 +187,7 @@ def test_sort_schedule_fn():
return
cmp
(
str
(
a
),
str
(
b
))
# lexicographical sort
return
cmp
(
str
(
a
),
str
(
b
))
# lexicographical sort
linker
=
OpWiseCLinker
(
schedule
=
sort_schedule_fn
(
str_cmp
))
linker
=
OpWiseCLinker
(
schedule
=
sort_schedule_fn
(
str_cmp
))
mode
=
theano
.
Mode
(
linker
=
linker
)
mode
=
Mode
(
linker
=
linker
)
f
=
theano
.
function
((
x
,),
(
y
,),
mode
=
mode
)
f
=
theano
.
function
((
x
,),
(
y
,),
mode
=
mode
)
nodes
=
f
.
maker
.
linker
.
make_all
()[
-
1
]
nodes
=
f
.
maker
.
linker
.
make_all
()[
-
1
]
...
...
tests/link/test_vm.py
浏览文件 @
40d0a283
...
@@ -8,7 +8,8 @@ import pytest
...
@@ -8,7 +8,8 @@ import pytest
import
theano
import
theano
from
theano
import
function
from
theano
import
function
from
theano
import
tensor
as
tt
from
theano
import
tensor
as
tt
from
theano.compile
import
Mode
from
theano.compile.io
import
In
from
theano.compile.mode
import
Mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.basic
import
Apply
from
theano.graph.basic
import
Apply
from
theano.graph.op
import
Op
from
theano.graph.op
import
Op
...
@@ -389,8 +390,8 @@ def test_vm_gc():
...
@@ -389,8 +390,8 @@ def test_vm_gc():
x
=
vector
()
x
=
vector
()
p
=
RunOnce
()(
x
)
p
=
RunOnce
()(
x
)
mode
=
theano
.
Mode
(
linker
=
VMLinker
(
lazy
=
True
))
mode
=
Mode
(
linker
=
VMLinker
(
lazy
=
True
))
f
=
theano
.
function
([
theano
.
In
(
x
,
mutable
=
True
)],
[
p
+
1
,
p
+
2
],
mode
=
mode
)
f
=
theano
.
function
([
In
(
x
,
mutable
=
True
)],
[
p
+
1
,
p
+
2
],
mode
=
mode
)
f
([
1
,
2
,
3
])
f
([
1
,
2
,
3
])
p
=
RunOnce
()(
x
)
p
=
RunOnce
()(
x
)
...
@@ -408,7 +409,7 @@ def test_reallocation():
...
@@ -408,7 +409,7 @@ def test_reallocation():
VMLinker
(
allow_gc
=
False
,
lazy
=
False
,
use_cloop
=
False
),
VMLinker
(
allow_gc
=
False
,
lazy
=
False
,
use_cloop
=
False
),
VMLinker
(
allow_gc
=
True
,
lazy
=
False
,
use_cloop
=
False
),
VMLinker
(
allow_gc
=
True
,
lazy
=
False
,
use_cloop
=
False
),
]:
]:
m
=
theano
.
compile
.
get_mode
(
theano
.
Mode
(
linker
=
linker
))
m
=
theano
.
compile
.
get_mode
(
Mode
(
linker
=
linker
))
m
=
m
.
excluding
(
"fusion"
,
"inplace"
)
m
=
m
.
excluding
(
"fusion"
,
"inplace"
)
f
=
theano
.
function
([
x
,
y
],
z
,
name
=
"test_reduce_memory"
,
mode
=
m
)
f
=
theano
.
function
([
x
,
y
],
z
,
name
=
"test_reduce_memory"
,
mode
=
m
)
...
@@ -444,7 +445,7 @@ def test_no_recycling():
...
@@ -444,7 +445,7 @@ def test_no_recycling():
VMLinker
(
use_cloop
=
False
,
lazy
=
False
,
allow_gc
=
False
),
VMLinker
(
use_cloop
=
False
,
lazy
=
False
,
allow_gc
=
False
),
]:
]:
mode
=
theano
.
Mode
(
optimizer
=
"fast_compile"
,
linker
=
lnk
)
mode
=
Mode
(
optimizer
=
"fast_compile"
,
linker
=
lnk
)
f
=
theano
.
function
([
x
],
x
+
1
,
mode
=
mode
)
f
=
theano
.
function
([
x
],
x
+
1
,
mode
=
mode
)
f2
=
theano
.
function
([
x
],
(
x
+
1
)
*
2
,
mode
=
mode
)
f2
=
theano
.
function
([
x
],
(
x
+
1
)
*
2
,
mode
=
mode
)
m1
=
f
.
fn
.
thunks
[
0
]
.
thunk
.
module
m1
=
f
.
fn
.
thunks
[
0
]
.
thunk
.
module
...
...
tests/record.py
浏览文件 @
40d0a283
from
theano.compile
import
Mode
from
theano.compile
.mode
import
Mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.link.basic
import
WrapLinkerMany
from
theano.link.basic
import
WrapLinkerMany
from
theano.link.vm
import
VMLinker
from
theano.link.vm
import
VMLinker
...
...
tests/scalar/test_basic.py
浏览文件 @
40d0a283
...
@@ -13,6 +13,7 @@ import pytest
...
@@ -13,6 +13,7 @@ import pytest
import
tests.unittest_tools
as
utt
import
tests.unittest_tools
as
utt
import
theano
import
theano
from
theano.compile.mode
import
Mode
from
theano.graph.fg
import
FunctionGraph
from
theano.graph.fg
import
FunctionGraph
from
theano.link.c.basic
import
DualLinker
from
theano.link.c.basic
import
DualLinker
from
theano.scalar.basic
import
(
from
theano.scalar.basic
import
(
...
@@ -453,7 +454,7 @@ def test_grad_abs():
...
@@ -453,7 +454,7 @@ def test_grad_abs():
a
=
fscalar
(
"a"
)
a
=
fscalar
(
"a"
)
b
=
theano
.
tensor
.
nnet
.
relu
(
a
)
b
=
theano
.
tensor
.
nnet
.
relu
(
a
)
c
=
theano
.
grad
(
b
,
a
)
c
=
theano
.
grad
(
b
,
a
)
f
=
theano
.
function
([
a
],
c
,
mode
=
theano
.
Mode
(
optimizer
=
None
))
f
=
theano
.
function
([
a
],
c
,
mode
=
Mode
(
optimizer
=
None
))
# Currently Theano return 0.5, but it isn't sure it won't change
# Currently Theano return 0.5, but it isn't sure it won't change
# in the futur.
# in the futur.
ret
=
f
(
0.0
)
ret
=
f
(
0.0
)
...
...
tests/scan/test_basic.py
浏览文件 @
40d0a283
...
@@ -26,6 +26,8 @@ import theano.scalar.sharedvar
...
@@ -26,6 +26,8 @@ import theano.scalar.sharedvar
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano
import
tensor
as
tt
from
theano
import
tensor
as
tt
from
theano.compile.function.pfunc
import
rebuild_collect_shared
from
theano.compile.function.pfunc
import
rebuild_collect_shared
from
theano.compile.io
import
In
from
theano.compile.mode
import
FAST_RUN
,
Mode
,
get_default_mode
,
get_mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.misc.safe_asarray
import
_asarray
from
theano.misc.safe_asarray
import
_asarray
from
theano.scan.basic
import
scan
from
theano.scan.basic
import
scan
...
@@ -54,11 +56,11 @@ from theano.tensor.type import (
...
@@ -54,11 +56,11 @@ from theano.tensor.type import (
if
config
.
mode
==
"FAST_COMPILE"
:
if
config
.
mode
==
"FAST_COMPILE"
:
mode_with_opt
=
theano
.
compile
.
mode
.
get_mode
(
"FAST_RUN"
)
mode_with_opt
=
get_mode
(
"FAST_RUN"
)
else
:
else
:
mode_with_opt
=
theano
.
compile
.
mode
.
get_default_mode
()
mode_with_opt
=
get_default_mode
()
if
config
.
mode
in
(
"DEBUG_MODE"
,
"DebugMode"
):
if
config
.
mode
in
(
"DEBUG_MODE"
,
"DebugMode"
):
mode_nodebug
=
theano
.
compile
.
mode
.
get_mode
(
"FAST_RUN"
)
mode_nodebug
=
get_mode
(
"FAST_RUN"
)
else
:
else
:
mode_nodebug
=
mode_with_opt
mode_nodebug
=
mode_with_opt
...
@@ -234,9 +236,7 @@ class TestScan:
...
@@ -234,9 +236,7 @@ class TestScan:
# generator network, only one output , type scalar ; no sequence or
# generator network, only one output , type scalar ; no sequence or
# non sequence arguments
# non sequence arguments
@pytest.mark.skipif
(
@pytest.mark.skipif
(
isinstance
(
isinstance
(
get_default_mode
(),
theano
.
compile
.
debugmode
.
DebugMode
),
theano
.
compile
.
mode
.
get_default_mode
(),
theano
.
compile
.
debugmode
.
DebugMode
),
reason
=
"This test fails in DebugMode, because it is not yet picklable."
,
reason
=
"This test fails in DebugMode, because it is not yet picklable."
,
)
)
def
test_pickling
(
self
):
def
test_pickling
(
self
):
...
@@ -920,14 +920,14 @@ class TestScan:
...
@@ -920,14 +920,14 @@ class TestScan:
u0
=
vector
(
"u0"
)
u0
=
vector
(
"u0"
)
u1
=
vector
(
"u1"
)
u1
=
vector
(
"u1"
)
u2
=
vector
(
"u2"
)
u2
=
vector
(
"u2"
)
mu0
=
theano
.
In
(
u0
,
mutable
=
False
)
mu0
=
In
(
u0
,
mutable
=
False
)
mu1
=
theano
.
In
(
u1
,
mutable
=
True
)
mu1
=
In
(
u1
,
mutable
=
True
)
mu2
=
theano
.
In
(
u2
,
mutable
=
True
)
mu2
=
In
(
u2
,
mutable
=
True
)
x0
=
scalar
(
"x0"
)
x0
=
scalar
(
"x0"
)
x1
=
scalar
(
"y0"
)
x1
=
scalar
(
"y0"
)
W_in
=
theano
.
shared
(
vW_in
,
"Win"
)
W_in
=
theano
.
shared
(
vW_in
,
"Win"
)
W
=
theano
.
shared
(
vW
,
"W"
)
W
=
theano
.
shared
(
vW
,
"W"
)
mode
=
theano
.
compile
.
mode
.
get_mode
(
None
)
.
including
(
"inplace"
)
mode
=
get_mode
(
None
)
.
including
(
"inplace"
)
def
f_rnn_shared
(
u0_t
,
u1_t
,
u2_t
,
x0_tm1
,
x1_tm1
):
def
f_rnn_shared
(
u0_t
,
u1_t
,
u2_t
,
x0_tm1
,
x1_tm1
):
return
[
return
[
...
@@ -987,14 +987,14 @@ class TestScan:
...
@@ -987,14 +987,14 @@ class TestScan:
u0
=
vector
(
"u0"
)
u0
=
vector
(
"u0"
)
u1
=
vector
(
"u1"
)
u1
=
vector
(
"u1"
)
u2
=
vector
(
"u2"
)
u2
=
vector
(
"u2"
)
mu0
=
theano
.
In
(
u0
,
mutable
=
True
)
mu0
=
In
(
u0
,
mutable
=
True
)
mu1
=
theano
.
In
(
u1
,
mutable
=
True
)
mu1
=
In
(
u1
,
mutable
=
True
)
mu2
=
theano
.
In
(
u2
,
mutable
=
True
)
mu2
=
In
(
u2
,
mutable
=
True
)
x0
=
scalar
(
"x0"
)
x0
=
scalar
(
"x0"
)
x1
=
scalar
(
"y0"
)
x1
=
scalar
(
"y0"
)
W_in
=
theano
.
shared
(
vW_in
,
"Win"
)
W_in
=
theano
.
shared
(
vW_in
,
"Win"
)
W
=
theano
.
shared
(
vW
,
"W"
)
W
=
theano
.
shared
(
vW
,
"W"
)
mode
=
theano
.
compile
.
mode
.
get_mode
(
None
)
.
including
(
"inplace"
)
mode
=
get_mode
(
None
)
.
including
(
"inplace"
)
def
f_rnn_shared
(
u0_t
,
u1_t
,
u1_tp1
,
u2_tm1
,
u2_t
,
u2_tp1
,
x0_tm1
,
x1_tm1
):
def
f_rnn_shared
(
u0_t
,
u1_t
,
u1_tp1
,
u2_tm1
,
u2_t
,
u2_tp1
,
x0_tm1
,
x1_tm1
):
return
[
return
[
...
@@ -1057,7 +1057,7 @@ class TestScan:
...
@@ -1057,7 +1057,7 @@ class TestScan:
x0
=
tt
.
constant
(
x0
)
x0
=
tt
.
constant
(
x0
)
to_replace
=
outputs
[
0
]
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
1
]
to_replace
=
outputs
[
0
]
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
1
]
outputs
=
theano
.
clone
(
outputs
,
replace
=
[(
to_replace
,
x0
)])
outputs
=
theano
.
clone
(
outputs
,
replace
=
[(
to_replace
,
x0
)])
mode
=
theano
.
compile
.
mode
.
get_mode
(
None
)
.
including
(
"inplace"
)
mode
=
get_mode
(
None
)
.
including
(
"inplace"
)
f9
=
theano
.
function
([],
outputs
,
updates
=
updates
,
mode
=
mode
)
f9
=
theano
.
function
([],
outputs
,
updates
=
updates
,
mode
=
mode
)
scan_node
=
[
x
for
x
in
f9
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
x
.
op
,
Scan
)]
scan_node
=
[
x
for
x
in
f9
.
maker
.
fgraph
.
toposort
()
if
isinstance
(
x
.
op
,
Scan
)]
assert
0
not
in
scan_node
[
0
]
.
op
.
destroy_map
.
keys
()
assert
0
not
in
scan_node
[
0
]
.
op
.
destroy_map
.
keys
()
...
@@ -2783,7 +2783,7 @@ class TestScan:
...
@@ -2783,7 +2783,7 @@ class TestScan:
x
,
x
,
tt
.
constant
(
np
.
asarray
(
0.0
,
dtype
=
config
.
floatX
)),
tt
.
constant
(
np
.
asarray
(
0.0
,
dtype
=
config
.
floatX
)),
)
)
mode
=
theano
.
compile
.
mode
.
FAST_RUN
mode
=
FAST_RUN
mode
=
mode
.
excluding
(
"inplace"
)
mode
=
mode
.
excluding
(
"inplace"
)
f1
=
theano
.
function
([],
o
,
mode
=
mode
)
f1
=
theano
.
function
([],
o
,
mode
=
mode
)
inputs
,
outputs
=
clone_optimized_graph
(
f1
)
inputs
,
outputs
=
clone_optimized_graph
(
f1
)
...
@@ -2817,7 +2817,7 @@ class TestScan:
...
@@ -2817,7 +2817,7 @@ class TestScan:
tt
.
constant
(
np
.
asarray
(
0.0
,
dtype
=
config
.
floatX
)),
tt
.
constant
(
np
.
asarray
(
0.0
,
dtype
=
config
.
floatX
)),
)
)
mode
=
theano
.
compile
.
mode
.
FAST_RUN
mode
=
FAST_RUN
mode
=
mode
.
excluding
(
"inplace"
)
mode
=
mode
.
excluding
(
"inplace"
)
f0
=
theano
.
function
([],
o
,
mode
=
mode
)
f0
=
theano
.
function
([],
o
,
mode
=
mode
)
inputs
,
outputs
=
clone_optimized_graph
(
f0
)
inputs
,
outputs
=
clone_optimized_graph
(
f0
)
...
@@ -2852,7 +2852,7 @@ class TestScan:
...
@@ -2852,7 +2852,7 @@ class TestScan:
tt
.
constant
(
np
.
asarray
(
0.0
,
dtype
=
config
.
floatX
)),
tt
.
constant
(
np
.
asarray
(
0.0
,
dtype
=
config
.
floatX
)),
)
)
mode
=
theano
.
compile
.
mode
.
FAST_RUN
mode
=
FAST_RUN
mode
=
mode
.
excluding
(
"inplace"
)
mode
=
mode
.
excluding
(
"inplace"
)
f1
=
theano
.
function
([],
o
,
mode
=
mode
)
f1
=
theano
.
function
([],
o
,
mode
=
mode
)
inputs
,
outputs
=
clone_optimized_graph
(
f1
)
inputs
,
outputs
=
clone_optimized_graph
(
f1
)
...
@@ -4186,7 +4186,7 @@ class TestScan:
...
@@ -4186,7 +4186,7 @@ class TestScan:
[
U
,
x1
,
x2
],
[
U
,
x1
,
x2
],
[
X1
,
X2
,
X3
],
[
X1
,
X2
,
X3
],
updates
=
updates
,
updates
=
updates
,
mode
=
theano
.
Mode
(
linker
=
"py"
),
mode
=
Mode
(
linker
=
"py"
),
allow_input_downcast
=
True
,
allow_input_downcast
=
True
,
)
)
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -4223,7 +4223,7 @@ class TestScan:
...
@@ -4223,7 +4223,7 @@ class TestScan:
[
W
,
x1
,
x2
],
[
W
,
x1
,
x2
],
[
X1
,
X2
,
X3
],
[
X1
,
X2
,
X3
],
updates
=
updates
,
updates
=
updates
,
mode
=
theano
.
Mode
(
linker
=
"py"
),
mode
=
Mode
(
linker
=
"py"
),
allow_input_downcast
=
True
,
allow_input_downcast
=
True
,
)
)
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -4594,7 +4594,7 @@ def test_speed():
...
@@ -4594,7 +4594,7 @@ def test_speed():
# fn=lambda ri, rii: ri + rii,
# fn=lambda ri, rii: ri + rii,
# sequences=[s_r[1:]],
# sequences=[s_r[1:]],
# outputs_info=tt.constant(r[0]),
# outputs_info=tt.constant(r[0]),
# mode=
theano.
Mode(linker="cvm"),
# mode=Mode(linker="cvm"),
# )
# )
# assert not updates
# assert not updates
#
#
...
@@ -4616,7 +4616,7 @@ def test_speed():
...
@@ -4616,7 +4616,7 @@ def test_speed():
[],
[],
[],
[],
updates
=
OrderedDict
([(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)]),
updates
=
OrderedDict
([(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)]),
mode
=
theano
.
Mode
(
linker
=
"cvm"
),
mode
=
Mode
(
linker
=
"cvm"
),
)
)
f_cvm_shared
.
_check_for_aliased_inputs
=
False
f_cvm_shared
.
_check_for_aliased_inputs
=
False
...
@@ -4652,11 +4652,11 @@ def test_speed_rnn():
...
@@ -4652,11 +4652,11 @@ def test_speed_rnn():
# fn=lambda ri, rii: tt.tanh(tt.dot(rii, w)),
# fn=lambda ri, rii: tt.tanh(tt.dot(rii, w)),
# sequences=[s_r[1:]],
# sequences=[s_r[1:]],
# outputs_info=tt.constant(r[0]),
# outputs_info=tt.constant(r[0]),
# mode=
theano.
Mode(linker="cvm"),
# mode=Mode(linker="cvm"),
# )
# )
# assert not updates
# assert not updates
#
#
# f_cvm = theano.function([s_r], s_y, mode=
theano.
Mode(linker="cvm"))
# f_cvm = theano.function([s_r], s_y, mode=Mode(linker="cvm"))
#
#
# cvm_duration = timeit(lambda: f_cvm(r), number=n_timeit)
# cvm_duration = timeit(lambda: f_cvm(r), number=n_timeit)
...
@@ -4675,7 +4675,7 @@ def test_speed_rnn():
...
@@ -4675,7 +4675,7 @@ def test_speed_rnn():
[],
[],
[],
[],
updates
=
OrderedDict
([(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)]),
updates
=
OrderedDict
([(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)]),
mode
=
theano
.
Mode
(
linker
=
"cvm"
),
mode
=
Mode
(
linker
=
"cvm"
),
)
)
cvm_shared_duration
=
timeit
(
lambda
:
f_cvm_shared
(),
number
=
n_timeit
)
cvm_shared_duration
=
timeit
(
lambda
:
f_cvm_shared
(),
number
=
n_timeit
)
...
@@ -4691,7 +4691,7 @@ def test_speed_batchrnn():
...
@@ -4691,7 +4691,7 @@ def test_speed_batchrnn():
This function prints out the speed of recurrent neural network
This function prints out the speed of recurrent neural network
calculations implemented in various ways.
calculations implemented in various ways.
We force the mode to
theano.
Mode(linker='cvm'). If you manually
We force the mode to Mode(linker='cvm'). If you manually
change this code to use DebugMode this will test the correctness
change this code to use DebugMode this will test the correctness
of the optimizations applied, but generally correctness-testing
of the optimizations applied, but generally correctness-testing
is not the goal of this test.
is not the goal of this test.
...
@@ -4725,7 +4725,7 @@ def test_speed_batchrnn():
...
@@ -4725,7 +4725,7 @@ def test_speed_batchrnn():
[],
[],
[],
[],
updates
=
[(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)],
updates
=
[(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)],
mode
=
theano
.
Mode
(
linker
=
"cvm"
),
mode
=
Mode
(
linker
=
"cvm"
),
)
)
f_fn
=
f
.
fn
f_fn
=
f
.
fn
t2
=
time
.
time
()
t2
=
time
.
time
()
...
...
tests/sparse/test_basic.py
浏览文件 @
40d0a283
...
@@ -11,6 +11,7 @@ from tests import unittest_tools as utt
...
@@ -11,6 +11,7 @@ from tests import unittest_tools as utt
from
tests.tensor.test_sharedvar
import
makeSharedTester
from
tests.tensor.test_sharedvar
import
makeSharedTester
from
theano
import
sparse
from
theano
import
sparse
from
theano.compile.function
import
function
from
theano.compile.function
import
function
from
theano.compile.io
import
In
,
Out
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.gradient
import
GradientError
from
theano.gradient
import
GradientError
from
theano.graph.basic
import
Apply
,
Constant
from
theano.graph.basic
import
Apply
,
Constant
...
@@ -1357,7 +1358,7 @@ class TestStructuredDot:
...
@@ -1357,7 +1358,7 @@ class TestStructuredDot:
a
=
SparseType
(
sparse_format_a
,
dtype
=
sparse_dtype
)()
a
=
SparseType
(
sparse_format_a
,
dtype
=
sparse_dtype
)()
b
=
SparseType
(
sparse_format_b
,
dtype
=
sparse_dtype
)()
b
=
SparseType
(
sparse_format_b
,
dtype
=
sparse_dtype
)()
d
=
tt
.
dot
(
a
,
b
)
d
=
tt
.
dot
(
a
,
b
)
f
=
theano
.
function
([
a
,
b
],
theano
.
Out
(
d
,
borrow
=
True
))
f
=
theano
.
function
([
a
,
b
],
Out
(
d
,
borrow
=
True
))
for
M
,
N
,
K
,
nnz
in
[
for
M
,
N
,
K
,
nnz
in
[
(
4
,
3
,
2
,
3
),
(
4
,
3
,
2
,
3
),
(
40
,
30
,
20
,
3
),
(
40
,
30
,
20
,
3
),
...
@@ -1379,7 +1380,7 @@ class TestStructuredDot:
...
@@ -1379,7 +1380,7 @@ class TestStructuredDot:
a
=
SparseType
(
"csc"
,
dtype
=
sparse_dtype
)()
a
=
SparseType
(
"csc"
,
dtype
=
sparse_dtype
)()
b
=
matrix
(
dtype
=
dense_dtype
)
b
=
matrix
(
dtype
=
dense_dtype
)
d
=
tt
.
dot
(
a
,
b
)
d
=
tt
.
dot
(
a
,
b
)
f
=
theano
.
function
([
a
,
b
],
theano
.
Out
(
d
,
borrow
=
True
))
f
=
theano
.
function
([
a
,
b
],
Out
(
d
,
borrow
=
True
))
for
M
,
N
,
K
,
nnz
in
[
for
M
,
N
,
K
,
nnz
in
[
(
4
,
3
,
2
,
3
),
(
4
,
3
,
2
,
3
),
...
@@ -1928,9 +1929,7 @@ def test_sparse_shared_memory():
...
@@ -1928,9 +1929,7 @@ def test_sparse_shared_memory():
sdot
=
sparse
.
structured_dot
sdot
=
sparse
.
structured_dot
z
=
sdot
(
x
*
3
,
m1
)
+
sdot
(
y
*
2
,
m2
)
z
=
sdot
(
x
*
3
,
m1
)
+
sdot
(
y
*
2
,
m2
)
f
=
theano
.
function
(
f
=
theano
.
function
([
In
(
x
,
mutable
=
True
),
In
(
y
,
mutable
=
True
)],
z
,
mode
=
"FAST_RUN"
)
[
theano
.
In
(
x
,
mutable
=
True
),
theano
.
In
(
y
,
mutable
=
True
)],
z
,
mode
=
"FAST_RUN"
)
def
f_
(
x
,
y
,
m1
=
m1
,
m2
=
m2
):
def
f_
(
x
,
y
,
m1
=
m1
,
m2
=
m2
):
return
((
x
*
3
)
*
m1
)
+
((
y
*
2
)
*
m2
)
return
((
x
*
3
)
*
m1
)
+
((
y
*
2
)
*
m2
)
...
@@ -2243,9 +2242,7 @@ class TestRemove0(utt.InferShapeTester):
...
@@ -2243,9 +2242,7 @@ class TestRemove0(utt.InferShapeTester):
# the In thingy has to be there because theano has as rule not
# the In thingy has to be there because theano has as rule not
# to optimize inputs
# to optimize inputs
f
=
theano
.
function
(
f
=
theano
.
function
([
In
(
x
,
borrow
=
True
,
mutable
=
True
)],
Remove0
()(
x
))
[
theano
.
In
(
x
,
borrow
=
True
,
mutable
=
True
)],
Remove0
()(
x
)
)
# assert optimization local_inplace_remove0 is applied in
# assert optimization local_inplace_remove0 is applied in
# modes with optimization
# modes with optimization
...
...
tests/sparse/test_opt.py
浏览文件 @
40d0a283
...
@@ -10,6 +10,7 @@ import theano.tensor as tt
...
@@ -10,6 +10,7 @@ import theano.tensor as tt
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
tests.sparse.test_basic
import
random_lil
from
tests.sparse.test_basic
import
random_lil
from
theano
import
sparse
from
theano
import
sparse
from
theano.compile.mode
import
Mode
,
get_default_mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.tensor.type
import
ivector
,
matrix
,
vector
from
theano.tensor.type
import
ivector
,
matrix
,
vector
...
@@ -17,7 +18,7 @@ from theano.tensor.type import ivector, matrix, vector
...
@@ -17,7 +18,7 @@ from theano.tensor.type import ivector, matrix, vector
def
test_local_csm_properties_csm
():
def
test_local_csm_properties_csm
():
data
=
vector
()
data
=
vector
()
indices
,
indptr
,
shape
=
(
ivector
(),
ivector
(),
ivector
())
indices
,
indptr
,
shape
=
(
ivector
(),
ivector
(),
ivector
())
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
mode
=
mode
.
including
(
"specialize"
,
"local_csm_properties_csm"
)
mode
=
mode
.
including
(
"specialize"
,
"local_csm_properties_csm"
)
for
CS
,
cast
in
[
for
CS
,
cast
in
[
(
sparse
.
CSC
,
sp
.
sparse
.
csc_matrix
),
(
sparse
.
CSC
,
sp
.
sparse
.
csc_matrix
),
...
@@ -43,10 +44,10 @@ def test_local_csm_properties_csm():
...
@@ -43,10 +44,10 @@ def test_local_csm_properties_csm():
def
test_local_csm_grad_c
():
def
test_local_csm_grad_c
():
data
=
vector
()
data
=
vector
()
indices
,
indptr
,
shape
=
(
ivector
(),
ivector
(),
ivector
())
indices
,
indptr
,
shape
=
(
ivector
(),
ivector
(),
ivector
())
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
if
theano
.
config
.
mode
==
"FAST_COMPILE"
:
mode
=
theano
.
compile
.
Mode
(
linker
=
"c|py"
,
optimizer
=
"fast_compile"
)
mode
=
Mode
(
linker
=
"c|py"
,
optimizer
=
"fast_compile"
)
mode
=
mode
.
including
(
"specialize"
,
"local_csm_grad_c"
)
mode
=
mode
.
including
(
"specialize"
,
"local_csm_grad_c"
)
for
CS
,
cast
in
[
for
CS
,
cast
in
[
...
@@ -68,7 +69,7 @@ def test_local_csm_grad_c():
...
@@ -68,7 +69,7 @@ def test_local_csm_grad_c():
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_local_mul_s_d
():
def
test_local_mul_s_d
():
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
mode
=
mode
.
including
(
"specialize"
,
"local_mul_s_d"
)
mode
=
mode
.
including
(
"specialize"
,
"local_mul_s_d"
)
for
sp_format
in
sparse
.
sparse_formats
:
for
sp_format
in
sparse
.
sparse_formats
:
...
@@ -85,7 +86,7 @@ def test_local_mul_s_d():
...
@@ -85,7 +86,7 @@ def test_local_mul_s_d():
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_local_mul_s_v
():
def
test_local_mul_s_v
():
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
mode
=
mode
.
including
(
"specialize"
,
"local_mul_s_v"
)
mode
=
mode
.
including
(
"specialize"
,
"local_mul_s_v"
)
for
sp_format
in
[
"csr"
]:
# Not implemented for other format
for
sp_format
in
[
"csr"
]:
# Not implemented for other format
...
@@ -102,7 +103,7 @@ def test_local_mul_s_v():
...
@@ -102,7 +103,7 @@ def test_local_mul_s_v():
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_local_structured_add_s_v
():
def
test_local_structured_add_s_v
():
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
mode
=
mode
.
including
(
"specialize"
,
"local_structured_add_s_v"
)
mode
=
mode
.
including
(
"specialize"
,
"local_structured_add_s_v"
)
for
sp_format
in
[
"csr"
]:
# Not implemented for other format
for
sp_format
in
[
"csr"
]:
# Not implemented for other format
...
@@ -120,7 +121,7 @@ def test_local_structured_add_s_v():
...
@@ -120,7 +121,7 @@ def test_local_structured_add_s_v():
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
theano
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_local_sampling_dot_csr
():
def
test_local_sampling_dot_csr
():
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
mode
=
mode
.
including
(
"specialize"
,
"local_sampling_dot_csr"
)
mode
=
mode
.
including
(
"specialize"
,
"local_sampling_dot_csr"
)
for
sp_format
in
[
"csr"
]:
# Not implemented for other format
for
sp_format
in
[
"csr"
]:
# Not implemented for other format
...
@@ -147,7 +148,7 @@ def test_local_sampling_dot_csr():
...
@@ -147,7 +148,7 @@ def test_local_sampling_dot_csr():
def
test_local_dense_from_sparse_sparse_from_dense
():
def
test_local_dense_from_sparse_sparse_from_dense
():
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
mode
=
get_default_mode
()
mode
=
mode
.
including
(
"local_dense_from_sparse_sparse_from_dense"
)
mode
=
mode
.
including
(
"local_dense_from_sparse_sparse_from_dense"
)
m
=
matrix
()
m
=
matrix
()
...
...
tests/tensor/nnet/test_abstract_conv.py
浏览文件 @
40d0a283
...
@@ -4,6 +4,7 @@ import pytest
...
@@ -4,6 +4,7 @@ import pytest
import
theano
import
theano
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
theano.compile.mode
import
Mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.opt
import
check_stack_trace
from
theano.graph.opt
import
check_stack_trace
from
theano.tensor.nnet
import
abstract_conv
as
conv
from
theano.tensor.nnet
import
abstract_conv
as
conv
...
@@ -1047,7 +1048,7 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
...
@@ -1047,7 +1048,7 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
def
run_test_case
(
self
,
i
,
f
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
run_test_case
(
self
,
i
,
f
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
o
=
self
.
get_output_shape
(
i
,
f
,
s
,
b
,
fd
)
o
=
self
.
get_output_shape
(
i
,
f
,
s
,
b
,
fd
)
mode
=
theano
.
Mode
(
optimizer
=
None
)
mode
=
Mode
(
optimizer
=
None
)
self
.
run_fwd
(
self
.
run_fwd
(
inputs_shape
=
i
,
inputs_shape
=
i
,
filters_shape
=
f
,
filters_shape
=
f
,
...
@@ -1093,7 +1094,7 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
...
@@ -1093,7 +1094,7 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
def
run_test_case_gi
(
def
run_test_case_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
),
expect_error
=
False
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
),
expect_error
=
False
):
):
mode
=
theano
.
Mode
(
optimizer
=
None
)
mode
=
Mode
(
optimizer
=
None
)
if
not
expect_error
:
if
not
expect_error
:
self
.
run_gradinput
(
self
.
run_gradinput
(
inputs_shape
=
i
,
inputs_shape
=
i
,
...
@@ -2059,7 +2060,7 @@ class TestGroupedConvNoOptim:
...
@@ -2059,7 +2060,7 @@ class TestGroupedConvNoOptim:
conv_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d
conv_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d
conv_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
conv_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
conv_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
conv_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
mode
=
theano
.
Mode
(
optimizer
=
None
)
mode
=
Mode
(
optimizer
=
None
)
is_dnn
=
False
is_dnn
=
False
def
setup_method
(
self
):
def
setup_method
(
self
):
...
@@ -2269,7 +2270,7 @@ class TestGroupedConv3dNoOptim(TestGroupedConvNoOptim):
...
@@ -2269,7 +2270,7 @@ class TestGroupedConv3dNoOptim(TestGroupedConvNoOptim):
conv_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv3d
conv_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv3d
conv_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv3d_gradWeights
conv_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv3d_gradWeights
conv_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv3d_gradInputs
conv_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv3d_gradInputs
mode
=
theano
.
Mode
(
optimizer
=
None
)
mode
=
Mode
(
optimizer
=
None
)
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
num_groups
=
[
3
,
2
,
4
,
4
]
self
.
num_groups
=
[
3
,
2
,
4
,
4
]
...
@@ -2509,7 +2510,7 @@ class TestUnsharedConv:
...
@@ -2509,7 +2510,7 @@ class TestUnsharedConv:
conv2d_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
conv2d_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
conv2d_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
conv2d_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
mode
=
theano
.
compile
.
mode
.
Mode
(
optimizer
=
"None"
)
mode
=
Mode
(
optimizer
=
"None"
)
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
img_shape
=
[(
2
,
2
,
4
,
4
),
(
3
,
2
,
4
,
2
),
(
3
,
3
,
5
,
3
),
(
3
,
4
,
4
,
4
)]
self
.
img_shape
=
[(
2
,
2
,
4
,
4
),
(
3
,
2
,
4
,
2
),
(
3
,
3
,
5
,
3
),
(
3
,
4
,
4
,
4
)]
...
@@ -2741,7 +2742,7 @@ class TestAsymmetricPadding:
...
@@ -2741,7 +2742,7 @@ class TestAsymmetricPadding:
conv2d_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
conv2d_gradw_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
conv2d_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
conv2d_gradi_op
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
mode
=
theano
.
compile
.
mode
.
Mode
(
optimizer
=
"None"
)
mode
=
Mode
(
optimizer
=
"None"
)
img_shape
=
[(
2
,
2
,
4
,
4
),
(
3
,
2
,
4
,
2
),
(
3
,
3
,
5
,
3
)]
img_shape
=
[(
2
,
2
,
4
,
4
),
(
3
,
2
,
4
,
2
),
(
3
,
3
,
5
,
3
)]
kern_shape
=
[(
4
,
2
,
2
,
2
),
(
2
,
2
,
4
,
2
),
(
2
,
3
,
3
,
3
)]
kern_shape
=
[(
4
,
2
,
2
,
2
),
(
2
,
2
,
4
,
2
),
(
2
,
3
,
3
,
3
)]
...
@@ -2911,7 +2912,7 @@ class TestAsymmetricPadding:
...
@@ -2911,7 +2912,7 @@ class TestAsymmetricPadding:
class
TestCausalConv
:
class
TestCausalConv
:
mode
=
theano
.
compile
.
mode
.
Mode
(
optimizer
=
"None"
)
mode
=
Mode
(
optimizer
=
"None"
)
img
=
np
.
array
(
img
=
np
.
array
(
[
[
...
...
tests/tensor/nnet/test_conv.py
浏览文件 @
40d0a283
...
@@ -6,6 +6,7 @@ import pytest
...
@@ -6,6 +6,7 @@ import pytest
import
theano
import
theano
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
theano.compile.mode
import
Mode
from
theano.tensor.basic
import
NotScalarConstantError
,
_allclose
from
theano.tensor.basic
import
NotScalarConstantError
,
_allclose
from
theano.tensor.nnet
import
conv
,
conv2d
from
theano.tensor.nnet
import
conv
,
conv2d
from
theano.tensor.type
import
dmatrix
,
dtensor3
,
dtensor4
,
dvector
,
scalar
,
tensor4
from
theano.tensor.type
import
dmatrix
,
dtensor3
,
dtensor4
,
dvector
,
scalar
,
tensor4
...
@@ -607,7 +608,7 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -607,7 +608,7 @@ class TestConv2D(utt.InferShapeTester):
unroll_patch
=
True
,
unroll_patch
=
True
,
openmp
=
openmp
,
openmp
=
openmp
,
)
)
mode
=
theano
.
Mode
(
mode
=
Mode
(
linker
=
theano
.
link
.
vm
.
VMLinker
(
linker
=
theano
.
link
.
vm
.
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
allow_gc
=
False
,
use_cloop
=
True
)
)
...
...
tests/tensor/test_basic.py
浏览文件 @
40d0a283
...
@@ -13,7 +13,6 @@ from numpy.testing import assert_allclose, assert_almost_equal, assert_array_equ
...
@@ -13,7 +13,6 @@ from numpy.testing import assert_allclose, assert_almost_equal, assert_array_equ
import
theano
import
theano
import
theano.scalar
as
ts
import
theano.scalar
as
ts
import
theano.tensor
as
tt
import
theano.tensor
as
tt
import
theano.tensor.var
as
var
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
tests.tensor.utils
import
(
from
tests.tensor.utils
import
(
ALL_DTYPES
,
ALL_DTYPES
,
...
@@ -73,6 +72,7 @@ from tests.tensor.utils import (
...
@@ -73,6 +72,7 @@ from tests.tensor.utils import (
from
theano
import
compile
,
config
,
function
,
shared
from
theano
import
compile
,
config
,
function
,
shared
from
theano.assert_op
import
Assert
from
theano.assert_op
import
Assert
from
theano.compile
import
DeepCopyOp
from
theano.compile
import
DeepCopyOp
from
theano.compile.io
import
In
,
Out
from
theano.compile.mode
import
get_default_mode
from
theano.compile.mode
import
get_default_mode
from
theano.gradient
import
grad
,
hessian
,
numeric_grad
from
theano.gradient
import
grad
,
hessian
,
numeric_grad
from
theano.graph.basic
import
Apply
,
Variable
from
theano.graph.basic
import
Apply
,
Variable
...
@@ -170,6 +170,7 @@ from theano.tensor import (
...
@@ -170,6 +170,7 @@ from theano.tensor import (
triu
,
triu
,
true_div
,
true_div
,
unbroadcast
,
unbroadcast
,
var
,
vertical_stack
,
vertical_stack
,
)
)
from
theano.tensor.elemwise
import
DimShuffle
,
Elemwise
from
theano.tensor.elemwise
import
DimShuffle
,
Elemwise
...
@@ -3224,7 +3225,7 @@ def test_join_inplace():
...
@@ -3224,7 +3225,7 @@ def test_join_inplace():
join
=
Join
(
view
=
0
)
join
=
Join
(
view
=
0
)
c
=
join
(
0
,
x
,
z
,
z
)
c
=
join
(
0
,
x
,
z
,
z
)
f
=
theano
.
function
([
theano
.
In
(
x
,
borrow
=
True
),
s
],
theano
.
Out
(
c
,
borrow
=
True
))
f
=
theano
.
function
([
In
(
x
,
borrow
=
True
),
s
],
Out
(
c
,
borrow
=
True
))
data
=
np
.
array
([
3
,
4
,
5
],
dtype
=
config
.
floatX
)
data
=
np
.
array
([
3
,
4
,
5
],
dtype
=
config
.
floatX
)
print
(
f
(
data
,
0
))
print
(
f
(
data
,
0
))
...
...
tests/tensor/test_blas.py
浏览文件 @
40d0a283
...
@@ -25,6 +25,7 @@ from tests import unittest_tools
...
@@ -25,6 +25,7 @@ from tests import unittest_tools
from
tests.tensor.utils
import
inplace_func
from
tests.tensor.utils
import
inplace_func
from
theano
import
shared
from
theano
import
shared
from
theano.compile.io
import
In
from
theano.compile.io
import
In
from
theano.compile.mode
import
Mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.fg
import
FunctionGraph
from
theano.graph.fg
import
FunctionGraph
from
theano.misc.safe_asarray
import
_asarray
from
theano.misc.safe_asarray
import
_asarray
...
@@ -139,7 +140,7 @@ class TestGemm:
...
@@ -139,7 +140,7 @@ class TestGemm:
f
=
inplace_func
(
f
=
inplace_func
(
[
tz
,
ta
,
tx
,
ty
,
tb
],
[
tz
,
ta
,
tx
,
ty
,
tb
],
gemm_inplace
(
tz
,
ta
,
tx
,
ty
,
tb
),
gemm_inplace
(
tz
,
ta
,
tx
,
ty
,
tb
),
mode
=
theano
.
compile
.
Mode
(
optimizer
=
None
,
linker
=
l
),
mode
=
Mode
(
optimizer
=
None
,
linker
=
l
),
)
)
f
(
z
,
a
,
x
,
y
,
b
)
f
(
z
,
a
,
x
,
y
,
b
)
z_after
=
self
.
_gemm
(
z_orig
,
a
,
x
,
y
,
b
)
z_after
=
self
.
_gemm
(
z_orig
,
a
,
x
,
y
,
b
)
...
@@ -304,12 +305,12 @@ class TestGemm:
...
@@ -304,12 +305,12 @@ class TestGemm:
tz
,
ta
,
tx
,
ty
,
tb
=
[
shared
(
p
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
tz
,
ta
,
tx
,
ty
,
tb
=
[
shared
(
p
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
# f = inplace_func([tz,ta,tx,ty,tb], gemm_inplace(tz,ta,tx,ty,tb),
# f = inplace_func([tz,ta,tx,ty,tb], gemm_inplace(tz,ta,tx,ty,tb),
# mode =
theano.compile.
Mode(optimizer = None, linker=l))
# mode = Mode(optimizer = None, linker=l))
# f(z, a, x, y, b)
# f(z, a, x, y, b)
f
=
inplace_func
(
f
=
inplace_func
(
[],
[],
gemm_inplace
(
tz
,
ta
,
tx
,
ty
,
tb
),
gemm_inplace
(
tz
,
ta
,
tx
,
ty
,
tb
),
mode
=
theano
.
compile
.
Mode
(
optimizer
=
None
,
linker
=
l
),
mode
=
Mode
(
optimizer
=
None
,
linker
=
l
),
)
)
f
()
f
()
unittest_tools
.
assert_allclose
(
z_after
,
tz
.
get_value
(
borrow
=
True
))
unittest_tools
.
assert_allclose
(
z_after
,
tz
.
get_value
(
borrow
=
True
))
...
@@ -366,7 +367,7 @@ class TestGemm:
...
@@ -366,7 +367,7 @@ class TestGemm:
f_i
=
inplace_func
(
f_i
=
inplace_func
(
[],
[],
gemm_inplace
(
tz
[:,
:,
i
],
ta
,
tx
[:,
:,
i
],
ty
[:,
:,
i
],
tb
),
gemm_inplace
(
tz
[:,
:,
i
],
ta
,
tx
[:,
:,
i
],
ty
[:,
:,
i
],
tb
),
mode
=
theano
.
compile
.
Mode
(
optimizer
=
None
,
linker
=
l
),
mode
=
Mode
(
optimizer
=
None
,
linker
=
l
),
)
)
for
j
in
range
(
3
):
for
j
in
range
(
3
):
# tz will not _always_ be overwritten,
# tz will not _always_ be overwritten,
...
@@ -385,7 +386,7 @@ class TestGemm:
...
@@ -385,7 +386,7 @@ class TestGemm:
[],
[],
tz_i
,
tz_i
,
updates
=
[(
tz
,
tt
.
set_subtensor
(
tz
[:,
:,
i
],
tz_i
))],
updates
=
[(
tz
,
tt
.
set_subtensor
(
tz
[:,
:,
i
],
tz_i
))],
mode
=
theano
.
compile
.
Mode
(
optimizer
=
None
,
linker
=
l
),
mode
=
Mode
(
optimizer
=
None
,
linker
=
l
),
)
)
for
j
in
range
(
3
):
for
j
in
range
(
3
):
g_i
()
g_i
()
...
@@ -645,7 +646,7 @@ def just_gemm(i, o, ishapes=None, max_graphlen=0, expected_nb_gemm=1):
...
@@ -645,7 +646,7 @@ def just_gemm(i, o, ishapes=None, max_graphlen=0, expected_nb_gemm=1):
g
=
inplace_func
(
g
=
inplace_func
(
i
,
i
,
o
,
o
,
mode
=
theano
.
compile
.
Mode
(
linker
=
"py"
,
optimizer
=
None
),
mode
=
Mode
(
linker
=
"py"
,
optimizer
=
None
),
allow_input_downcast
=
True
,
allow_input_downcast
=
True
,
on_unused_input
=
"ignore"
,
on_unused_input
=
"ignore"
,
)
)
...
@@ -734,7 +735,7 @@ def test_gemm_opt_double_gemm():
...
@@ -734,7 +735,7 @@ def test_gemm_opt_double_gemm():
g
=
inplace_func
(
g
=
inplace_func
(
i
,
i
,
o
,
o
,
mode
=
theano
.
compile
.
Mode
(
linker
=
"py"
,
optimizer
=
None
),
mode
=
Mode
(
linker
=
"py"
,
optimizer
=
None
),
on_unused_input
=
"ignore"
,
on_unused_input
=
"ignore"
,
)
)
...
...
tests/tensor/test_casting.py
浏览文件 @
40d0a283
...
@@ -3,7 +3,7 @@ import numpy as np
...
@@ -3,7 +3,7 @@ import numpy as np
import
theano
import
theano
import
theano.tensor.basic
as
basic
import
theano.tensor.basic
as
basic
from
theano
import
function
from
theano
import
function
from
theano.compile
import
In
from
theano.compile
.io
import
In
from
theano.misc.safe_asarray
import
_asarray
from
theano.misc.safe_asarray
import
_asarray
from
theano.tensor.basic
import
(
from
theano.tensor.basic
import
(
_convert_to_float32
,
_convert_to_float32
,
...
...
tests/tensor/test_elemwise.py
浏览文件 @
40d0a283
...
@@ -1284,9 +1284,7 @@ class TestElemwise(unittest_tools.InferShapeTester):
...
@@ -1284,9 +1284,7 @@ class TestElemwise(unittest_tools.InferShapeTester):
# it overflowed in this case.
# it overflowed in this case.
a
,
b
,
c
,
d
,
e
,
f
=
vectors
(
"abcdef"
)
a
,
b
,
c
,
d
,
e
,
f
=
vectors
(
"abcdef"
)
s
=
a
+
b
+
c
+
d
+
e
+
f
s
=
a
+
b
+
c
+
d
+
e
+
f
g
=
theano
.
function
(
g
=
theano
.
function
([
a
,
b
,
c
,
d
,
e
,
f
],
s
,
mode
=
Mode
(
linker
=
"py"
))
[
a
,
b
,
c
,
d
,
e
,
f
],
s
,
mode
=
theano
.
compile
.
Mode
(
linker
=
"py"
)
)
g
(
*
[
np
.
zeros
(
2
**
11
,
config
.
floatX
)
for
i
in
range
(
6
)])
g
(
*
[
np
.
zeros
(
2
**
11
,
config
.
floatX
)
for
i
in
range
(
6
)])
...
...
tests/tensor/test_gc.py
浏览文件 @
40d0a283
...
@@ -4,6 +4,7 @@ import time
...
@@ -4,6 +4,7 @@ import time
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
from
theano.compile.mode
import
Mode
from
theano.link.basic
import
PerformLinker
from
theano.link.basic
import
PerformLinker
from
theano.link.c.basic
import
OpWiseCLinker
from
theano.link.c.basic
import
OpWiseCLinker
from
theano.tensor.type
import
dvector
,
lvector
from
theano.tensor.type
import
dvector
,
lvector
...
@@ -42,12 +43,8 @@ def test_gc_never_pickles_temporaries():
...
@@ -42,12 +43,8 @@ def test_gc_never_pickles_temporaries():
# g_linker has no garbage collection
# g_linker has no garbage collection
f
=
theano
.
function
(
f
=
theano
.
function
([
x
],
r
,
mode
=
Mode
(
optimizer
=
optimizer
,
linker
=
f_linker
))
[
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
f_linker
)
g
=
theano
.
function
([
x
],
r
,
mode
=
Mode
(
optimizer
=
optimizer
,
linker
=
g_linker
))
)
g
=
theano
.
function
(
[
x
],
r
,
mode
=
theano
.
Mode
(
optimizer
=
optimizer
,
linker
=
g_linker
)
)
pre_f
=
pickle
.
dumps
(
f
)
pre_f
=
pickle
.
dumps
(
f
)
# pre_g = pickle.dumps(g)
# pre_g = pickle.dumps(g)
...
...
tests/tensor/test_keepdims.py
浏览文件 @
40d0a283
...
@@ -4,6 +4,7 @@ import pytest
...
@@ -4,6 +4,7 @@ import pytest
import
theano
import
theano
import
theano.tensor
as
tt
import
theano.tensor
as
tt
from
theano
import
function
from
theano
import
function
from
theano.compile.mode
import
Mode
from
theano.tensor.elemwise
import
DimShuffle
from
theano.tensor.elemwise
import
DimShuffle
from
theano.tensor.type
import
dtensor3
from
theano.tensor.type
import
dtensor3
...
@@ -43,7 +44,7 @@ class TestKeepDims:
...
@@ -43,7 +44,7 @@ class TestKeepDims:
a
=
np
.
random
.
rand
(
3
,
2
,
4
)
a
=
np
.
random
.
rand
(
3
,
2
,
4
)
# We don't need to test all opt and C code, as this is tested
# We don't need to test all opt and C code, as this is tested
# by the ops tests.
# by the ops tests.
mode
=
theano
.
compile
.
Mode
(
optimizer
=
"fast_compile"
,
linker
=
"py"
)
mode
=
Mode
(
optimizer
=
"fast_compile"
,
linker
=
"py"
)
# 'max_and_argmax' has two outputs and can be specified with either
# 'max_and_argmax' has two outputs and can be specified with either
# a single or every axis:
# a single or every axis:
...
@@ -177,7 +178,7 @@ class TestKeepDims:
...
@@ -177,7 +178,7 @@ class TestKeepDims:
x
=
dtensor3
()
x
=
dtensor3
()
a
=
np
.
random
.
rand
(
3
,
2
,
4
)
.
astype
(
theano
.
config
.
floatX
)
a
=
np
.
random
.
rand
(
3
,
2
,
4
)
.
astype
(
theano
.
config
.
floatX
)
mode
=
theano
.
compile
.
Mode
(
optimizer
=
"fast_compile"
,
linker
=
"py"
)
mode
=
Mode
(
optimizer
=
"fast_compile"
,
linker
=
"py"
)
for
axis
in
[
for
axis
in
[
0
,
0
,
...
...
tests/tensor/test_mpi.py
浏览文件 @
40d0a283
...
@@ -4,6 +4,7 @@ import subprocess
...
@@ -4,6 +4,7 @@ import subprocess
import
pytest
import
pytest
import
theano
import
theano
from
theano.compile.mode
import
Mode
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.sched
import
sort_schedule_fn
from
theano.graph.sched
import
sort_schedule_fn
from
theano.link.c.basic
import
OpWiseCLinker
from
theano.link.c.basic
import
OpWiseCLinker
...
@@ -21,7 +22,7 @@ from theano.tensor.type import matrix
...
@@ -21,7 +22,7 @@ from theano.tensor.type import matrix
mpi_scheduler
=
sort_schedule_fn
(
*
mpi_cmps
)
mpi_scheduler
=
sort_schedule_fn
(
*
mpi_cmps
)
mpi_linker
=
OpWiseCLinker
(
schedule
=
mpi_scheduler
)
mpi_linker
=
OpWiseCLinker
(
schedule
=
mpi_scheduler
)
mpi_mode
=
theano
.
Mode
(
linker
=
mpi_linker
)
mpi_mode
=
Mode
(
linker
=
mpi_linker
)
@config.change_flags
(
compute_test_value
=
"off"
)
@config.change_flags
(
compute_test_value
=
"off"
)
...
...
tests/tensor/test_opt.py
浏览文件 @
40d0a283
差异被折叠。
点击展开。
tests/tensor/test_sort.py
浏览文件 @
40d0a283
...
@@ -6,6 +6,7 @@ import pytest
...
@@ -6,6 +6,7 @@ import pytest
import
theano
import
theano
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano.compile.mode
import
Mode
from
theano.tensor.sort
import
(
from
theano.tensor.sort
import
(
ArgSortOp
,
ArgSortOp
,
SortOp
,
SortOp
,
...
@@ -428,7 +429,7 @@ class TestTopK:
...
@@ -428,7 +429,7 @@ class TestTopK:
# So don't use DebugMode here.
# So don't use DebugMode here.
mode
=
self
.
mode
mode
=
self
.
mode
if
isinstance
(
self
.
mode
,
theano
.
compile
.
debugmode
.
DebugMode
):
if
isinstance
(
self
.
mode
,
theano
.
compile
.
debugmode
.
DebugMode
):
mode
=
theano
.
Mode
(
optimizer
=
mode
.
optimizer
)
mode
=
Mode
(
optimizer
=
mode
.
optimizer
)
fn
=
theano
.
function
([
x
],
y
,
mode
=
mode
)
fn
=
theano
.
function
([
x
],
y
,
mode
=
mode
)
assert
any
(
assert
any
(
[
isinstance
(
n
.
op
,
self
.
op_class
)
for
n
in
fn
.
maker
.
fgraph
.
apply_nodes
]
[
isinstance
(
n
.
op
,
self
.
op_class
)
for
n
in
fn
.
maker
.
fgraph
.
apply_nodes
]
...
...
tests/tensor/test_subtensor.py
浏览文件 @
40d0a283
...
@@ -12,6 +12,7 @@ import theano.tensor as tt
...
@@ -12,6 +12,7 @@ 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.compile
import
DeepCopyOp
,
shared
from
theano.compile
import
DeepCopyOp
,
shared
from
theano.compile.io
import
In
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.op
import
get_test_value
from
theano.graph.op
import
get_test_value
from
theano.graph.toolbox
import
is_same_graph
from
theano.graph.toolbox
import
is_same_graph
...
@@ -1265,7 +1266,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
...
@@ -1265,7 +1266,7 @@ class TestSubtensor(utt.OptimizationTestMixin):
data_copy
[
idx
]
=
inc_num
data_copy
[
idx
]
=
inc_num
else
:
else
:
data_copy
[
idx
]
+=
inc_num
data_copy
[
idx
]
+=
inc_num
data_var
=
theano
.
In
(
data_var
,
mutable
=
True
)
data_var
=
In
(
data_var
,
mutable
=
True
)
# Remember data for the Theano function (see below).
# Remember data for the Theano function (see below).
all_inputs_var
+=
[
data_var
,
idx_var
,
inc_var
]
all_inputs_var
+=
[
data_var
,
idx_var
,
inc_var
]
...
...
tests/test_config.py
浏览文件 @
40d0a283
...
@@ -249,7 +249,7 @@ def test_mode_apply():
...
@@ -249,7 +249,7 @@ def test_mode_apply():
with
pytest
.
raises
(
ValueError
,
match
=
"Expected one of"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Expected one of"
):
configdefaults
.
_filter_mode
(
"not_a_mode"
)
configdefaults
.
_filter_mode
(
"not_a_mode"
)
# test with
theano.
Mode instance
# test with Mode instance
import
theano.compile.mode
import
theano.compile.mode
assert
(
assert
(
...
...
theano/compile/function/pfunc.py
浏览文件 @
40d0a283
...
@@ -282,8 +282,7 @@ class Param(In):
...
@@ -282,8 +282,7 @@ class Param(In):
borrow
=
None
,
borrow
=
None
,
):
):
warnings
.
warn
(
warnings
.
warn
(
"The Param class is deprecated. Replace Param(default=N)"
"The Param class is deprecated. Replace Param(default=N)"
" by In(value=N)"
,
" by theano.In(value=N)"
,
stacklevel
=
2
,
stacklevel
=
2
,
)
)
super
()
.
__init__
(
super
()
.
__init__
(
...
@@ -322,7 +321,7 @@ def pfunc(
...
@@ -322,7 +321,7 @@ def pfunc(
Function parameters, these are not allowed to be shared variables.
Function parameters, these are not allowed to be shared variables.
outputs : list of Variables or Out instances
outputs : list of Variables or Out instances
Expressions to compute.
Expressions to compute.
mode : string or `theano.compile.Mode` instance
mode : string or `theano.compile.
mode.
Mode` instance
Compilation mode.
Compilation mode.
updates : iterable over pairs (shared_variable, new_expression). List, tuple or dict.
updates : iterable over pairs (shared_variable, new_expression). List, tuple or dict.
Update the values for SharedVariable inputs according to these
Update the values for SharedVariable inputs according to these
...
...
theano/configdefaults.py
浏览文件 @
40d0a283
...
@@ -111,14 +111,14 @@ def _filter_mode(val):
...
@@ -111,14 +111,14 @@ def _filter_mode(val):
if
val
in
str_options
:
if
val
in
str_options
:
return
val
return
val
# This can be executed before Theano is completly imported, so
# This can be executed before Theano is completly imported, so
# theano.Mode is not always available.
# theano.
compile.mode.
Mode is not always available.
# Instead of isinstance(val, theano.Mode),
# Instead of isinstance(val, theano.
compile.mode.
Mode),
# we can inspect the __mro__ of the object!
# we can inspect the __mro__ of the object!
for
type_
in
type
(
val
)
.
__mro__
:
for
type_
in
type
(
val
)
.
__mro__
:
if
"theano.compile.mode.Mode"
in
str
(
type_
):
if
"theano.compile.mode.Mode"
in
str
(
type_
):
return
val
return
val
raise
ValueError
(
raise
ValueError
(
f
"Expected one of {str_options}, or an instance of theano.Mode. "
f
"Expected one of {str_options}, or an instance of theano.
compile.mode.
Mode. "
f
"Instead got: {val}."
f
"Instead got: {val}."
)
)
...
...
theano/gpuarray/dnn.py
浏览文件 @
40d0a283
...
@@ -10,6 +10,8 @@ import theano
...
@@ -10,6 +10,8 @@ import theano
import
theano.pathparse
import
theano.pathparse
import
theano.tensor
as
tt
import
theano.tensor
as
tt
from
theano.assert_op
import
Assert
from
theano.assert_op
import
Assert
from
theano.compile.io
import
Out
from
theano.compile.mode
import
Mode
from
theano.compile.ops
import
shape_i
,
shape_i_op
from
theano.compile.ops
import
shape_i
,
shape_i_op
from
theano.configdefaults
import
SUPPORTED_DNN_CONV_ALGO_RUNTIME
,
config
from
theano.configdefaults
import
SUPPORTED_DNN_CONV_ALGO_RUNTIME
,
config
from
theano.gpuarray
import
cudnn_defs
,
pygpu
from
theano.gpuarray
import
cudnn_defs
,
pygpu
...
@@ -285,7 +287,7 @@ class MakerCDataType(CDataType):
...
@@ -285,7 +287,7 @@ class MakerCDataType(CDataType):
self
.
_fn
=
theano
.
function
(
self
.
_fn
=
theano
.
function
(
[
v
],
[
v
],
CDataMaker
(
self
)(
v
),
CDataMaker
(
self
)(
v
),
mode
=
theano
.
Mode
(
optimizer
=
None
),
mode
=
Mode
(
optimizer
=
None
),
profile
=
False
,
profile
=
False
,
)
)
return
self
.
_fn
return
self
.
_fn
...
@@ -421,9 +423,7 @@ def version(raises=True):
...
@@ -421,9 +423,7 @@ def version(raises=True):
return
-
1
return
-
1
if
version
.
v
is
None
:
if
version
.
v
is
None
:
f
=
theano
.
function
(
f
=
theano
.
function
([],
DnnVersion
()(),
Mode
(
optimizer
=
None
),
profile
=
False
)
[],
DnnVersion
()(),
theano
.
Mode
(
optimizer
=
None
),
profile
=
False
)
v
=
f
()
v
=
f
()
if
v
[
0
]
!=
v
[
1
]:
if
v
[
0
]
!=
v
[
1
]:
raise
RuntimeError
(
raise
RuntimeError
(
...
@@ -2632,7 +2632,7 @@ def _make_dropout_desc(dropout, seed, context_name):
...
@@ -2632,7 +2632,7 @@ def _make_dropout_desc(dropout, seed, context_name):
desc
,
states
=
theano
.
function
(
desc
,
states
=
theano
.
function
(
[],
[],
_DropoutDescriptor
(
context_name
)(
dropout
,
seed
,
context_name
),
_DropoutDescriptor
(
context_name
)(
dropout
,
seed
,
context_name
),
theano
.
Mode
(
optimizer
=
None
),
Mode
(
optimizer
=
None
),
profile
=
False
,
profile
=
False
,
)()
)()
return
desc
,
states
return
desc
,
states
...
@@ -2740,7 +2740,7 @@ def _make_rnn_desc(
...
@@ -2740,7 +2740,7 @@ def _make_rnn_desc(
_RNNDescriptor
(
context_name
)(
_RNNDescriptor
(
context_name
)(
hidden_size
,
num_layers
,
ddesc
,
input_mode
,
direction_mode
,
rnn_mode
,
dtype
hidden_size
,
num_layers
,
ddesc
,
input_mode
,
direction_mode
,
rnn_mode
,
dtype
),
),
theano
.
Mode
(
optimizer
=
None
),
Mode
(
optimizer
=
None
),
profile
=
False
,
profile
=
False
,
)()
)()
return
desc
return
desc
...
@@ -2774,7 +2774,7 @@ def _get_param_size(desc, input_size, dtype, context_name):
...
@@ -2774,7 +2774,7 @@ def _get_param_size(desc, input_size, dtype, context_name):
return
theano
.
function
(
return
theano
.
function
(
[],
[],
_RNNParamSize
(
context_name
)(
desc
,
input_size
,
typecode
),
_RNNParamSize
(
context_name
)(
desc
,
input_size
,
typecode
),
theano
.
Mode
(
optimizer
=
None
),
Mode
(
optimizer
=
None
),
profile
=
False
,
profile
=
False
,
)()
)()
...
@@ -3016,8 +3016,8 @@ class _RNNSplitParams(DnnBase):
...
@@ -3016,8 +3016,8 @@ class _RNNSplitParams(DnnBase):
def
_split_rnn_params
(
w
,
desc
,
layer
,
input_size
,
dtype
,
rnn_mode
):
def
_split_rnn_params
(
w
,
desc
,
layer
,
input_size
,
dtype
,
rnn_mode
):
typecode
=
gpuarray
.
dtype_to_typecode
(
dtype
)
typecode
=
gpuarray
.
dtype_to_typecode
(
dtype
)
outs
=
_RNNSplitParams
(
rnn_mode
)(
w
,
desc
,
layer
,
input_size
,
typecode
)
outs
=
_RNNSplitParams
(
rnn_mode
)(
w
,
desc
,
layer
,
input_size
,
typecode
)
outs
=
[
theano
.
Out
(
o
,
borrow
=
True
)
for
o
in
outs
]
outs
=
[
Out
(
o
,
borrow
=
True
)
for
o
in
outs
]
return
theano
.
function
([],
outs
,
theano
.
Mode
(
optimizer
=
None
),
profile
=
False
)()
return
theano
.
function
([],
outs
,
Mode
(
optimizer
=
None
),
profile
=
False
)()
class
GpuDnnRNNOp
(
DnnBase
):
class
GpuDnnRNNOp
(
DnnBase
):
...
...
theano/printing.py
浏览文件 @
40d0a283
...
@@ -14,8 +14,8 @@ from io import StringIO
...
@@ -14,8 +14,8 @@ from io import StringIO
import
numpy
as
np
import
numpy
as
np
import
theano
from
theano.compile
import
Function
,
SharedVariable
,
debugmode
from
theano.compile
import
Function
,
SharedVariable
,
debugmode
from
theano.compile.io
import
In
,
Out
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.graph.basic
import
(
from
theano.graph.basic
import
(
Apply
,
Apply
,
...
@@ -176,7 +176,7 @@ def debugprint(
...
@@ -176,7 +176,7 @@ def debugprint(
order
.
extend
([
topo
for
item
in
obj
.
outputs
])
order
.
extend
([
topo
for
item
in
obj
.
outputs
])
elif
isinstance
(
obj
,
(
int
,
float
,
np
.
ndarray
)):
elif
isinstance
(
obj
,
(
int
,
float
,
np
.
ndarray
)):
print
(
obj
,
file
=
_file
)
print
(
obj
,
file
=
_file
)
elif
isinstance
(
obj
,
(
theano
.
In
,
theano
.
Out
)):
elif
isinstance
(
obj
,
(
In
,
Out
)):
results_to_print
.
append
(
obj
.
variable
)
results_to_print
.
append
(
obj
.
variable
)
profile_list
.
append
(
None
)
profile_list
.
append
(
None
)
smap
.
append
(
None
)
smap
.
append
(
None
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论