Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0d0cc128
提交
0d0cc128
authored
9月 14, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
renamed FunctionGraph.nodes -> FunctionGraph.apply_nodes
上级
e5a29ece
显示空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
97 行增加
和
88 行删除
+97
-88
debugmode.py
theano/compile/debugmode.py
+1
-1
function_module.py
theano/compile/function_module.py
+1
-1
profilemode.py
theano/compile/profilemode.py
+1
-1
profiling.py
theano/compile/profiling.py
+1
-1
destroyhandler.py
theano/gof/destroyhandler.py
+1
-0
fg.py
theano/gof/fg.py
+41
-33
opt.py
theano/gof/opt.py
+4
-4
equilibrium.py
theano/gof/sandbox/equilibrium.py
+2
-2
toolbox.py
theano/gof/toolbox.py
+1
-1
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+2
-2
basic.py
theano/scalar/basic.py
+1
-1
blas.py
theano/tensor/blas.py
+1
-1
opt.py
theano/tensor/opt.py
+2
-2
test_blas.py
theano/tensor/tests/test_blas.py
+10
-10
test_naacl09.py
theano/tensor/tests/test_naacl09.py
+1
-1
test_opt.py
theano/tensor/tests/test_opt.py
+27
-27
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
0d0cc128
...
@@ -675,7 +675,7 @@ def _optcheck_fgraph(input_specs, output_specs, accept_inplace=False):
...
@@ -675,7 +675,7 @@ def _optcheck_fgraph(input_specs, output_specs, accept_inplace=False):
features
=
[
equivalence_tracker
])
features
=
[
equivalence_tracker
])
if
not
accept_inplace
:
if
not
accept_inplace
:
for
node
in
fgraph
.
nodes
:
for
node
in
fgraph
.
apply_
nodes
:
if
getattr
(
node
.
op
,
'destroy_map'
,
None
):
if
getattr
(
node
.
op
,
'destroy_map'
,
None
):
raise
TypeError
(
"Graph must not contain inplace operations"
,
raise
TypeError
(
"Graph must not contain inplace operations"
,
node
)
node
)
...
...
theano/compile/function_module.py
浏览文件 @
0d0cc128
...
@@ -131,7 +131,7 @@ def std_fgraph(input_specs, output_specs, accept_inplace = False):
...
@@ -131,7 +131,7 @@ def std_fgraph(input_specs, output_specs, accept_inplace = False):
inputs
,
outputs
=
gof
.
graph
.
clone
(
orig_inputs
,
orig_outputs
)
inputs
,
outputs
=
gof
.
graph
.
clone
(
orig_inputs
,
orig_outputs
)
fgraph
=
gof
.
fg
.
FunctionGraph
(
inputs
,
outputs
)
fgraph
=
gof
.
fg
.
FunctionGraph
(
inputs
,
outputs
)
for
node
in
fgraph
.
nodes
:
for
node
in
fgraph
.
apply_
nodes
:
if
getattr
(
node
.
op
,
'destroy_map'
,
None
):
if
getattr
(
node
.
op
,
'destroy_map'
,
None
):
if
not
accept_inplace
:
if
not
accept_inplace
:
raise
TypeError
(
"Graph must not contain inplace operations"
,
node
,
node
.
op
)
raise
TypeError
(
"Graph must not contain inplace operations"
,
node
,
node
.
op
)
...
...
theano/compile/profilemode.py
浏览文件 @
0d0cc128
...
@@ -520,7 +520,7 @@ class ProfileMode(Mode):
...
@@ -520,7 +520,7 @@ class ProfileMode(Mode):
print
"Profile of Theano functions memory:"
print
"Profile of Theano functions memory:"
print
"(This check only the output of each apply node. It don't check the temporary memory used by the op in the apply node.)"
print
"(This check only the output of each apply node. It don't check the temporary memory used by the op in the apply node.)"
nb_skipped
=
0
nb_skipped
=
0
for
fgraph
,
nodes_mem
in
fct_memory
.
iteritems
():
for
fgraph
,
nodes_mem
in
fct_memory
.
iteritems
():
size_sum
=
sum
([
sum
(
val
)
for
key
,
val
in
nodes_mem
.
iteritems
()])
size_sum
=
sum
([
sum
(
val
)
for
key
,
val
in
nodes_mem
.
iteritems
()])
if
size_sum
<
min_memory_size
:
if
size_sum
<
min_memory_size
:
nb_skipped
+=
1
nb_skipped
+=
1
...
...
theano/compile/profiling.py
浏览文件 @
0d0cc128
...
@@ -711,7 +711,7 @@ if 0: # old code still to be ported from ProfileMode
...
@@ -711,7 +711,7 @@ if 0: # old code still to be ported from ProfileMode
var_mem
[
out
]
=
v
var_mem
[
out
]
=
v
print
print
print
"Profile of Theano functions memory:"
print
"Profile of Theano functions memory:"
for
fgraph
,
nodes_mem
in
fct_memory
.
iteritems
():
for
fgraph
,
nodes_mem
in
fct_memory
.
iteritems
():
print
"Theano fct:"
,
[
fct
for
fct
in
fct_call
.
keys
()
if
fct
.
maker
.
fgraph
is
fgraph
][
0
]
.
name
print
"Theano fct:"
,
[
fct
for
fct
in
fct_call
.
keys
()
if
fct
.
maker
.
fgraph
is
fgraph
][
0
]
.
name
size_sum
=
sum
([
sum
(
val
)
for
key
,
val
in
nodes_mem
.
iteritems
()])
size_sum
=
sum
([
sum
(
val
)
for
key
,
val
in
nodes_mem
.
iteritems
()])
print
" Max without gc, inplace and view (KB)"
,
size_sum
/
1024
print
" Max without gc, inplace and view (KB)"
,
size_sum
/
1024
...
...
theano/gof/destroyhandler.py
浏览文件 @
0d0cc128
...
@@ -133,6 +133,7 @@ def _contains_cycle(inputs, outputs, orderings):
...
@@ -133,6 +133,7 @@ def _contains_cycle(inputs, outputs, orderings):
# into fifo_queue
# into fifo_queue
# TODO: does the order of the roots in the fifo_queue matter?
# TODO: does the order of the roots in the fifo_queue matter?
while
lifo_queue
:
while
lifo_queue
:
# using pop rather than pop_left makes this queue LIFO
# using pop rather than pop_left makes this queue LIFO
# using a LIFO queue makes the search DFS
# using a LIFO queue makes the search DFS
...
...
theano/gof/fg.py
浏览文件 @
0d0cc128
...
@@ -79,10 +79,10 @@ class FunctionGraph(utils.object2):
...
@@ -79,10 +79,10 @@ class FunctionGraph(utils.object2):
# so I probably am) this should be a set.
# so I probably am) this should be a set.
self
.
_features
=
[]
self
.
_features
=
[]
# All
nodes in the subgraph defined by inputs and outputs are cached in nodes
# All
apply nodes in the subgraph defined by inputs and outputs are cached in this field
self
.
nodes
=
set
()
self
.
apply_
nodes
=
set
()
# Ditto for variables
# Ditto for variable
node
s
self
.
variables
=
set
()
self
.
variables
=
set
()
self
.
inputs
=
list
(
inputs
)
self
.
inputs
=
list
(
inputs
)
...
@@ -151,13 +151,13 @@ class FunctionGraph(utils.object2):
...
@@ -151,13 +151,13 @@ class FunctionGraph(utils.object2):
nodes and variables. If there are no features, this should set
nodes and variables. If there are no features, this should set
them back to what they were originally.
them back to what they were originally.
"""
"""
for
node
in
self
.
nodes
:
for
apply_node
in
self
.
apply_
nodes
:
del
node
.
fgraph
del
apply_
node
.
fgraph
del
node
.
deps
del
apply_
node
.
deps
for
variable
in
self
.
variables
:
for
variable
in
self
.
variables
:
del
variable
.
fgraph
del
variable
.
fgraph
del
variable
.
clients
del
variable
.
clients
self
.
nodes
=
set
()
self
.
apply_
nodes
=
set
()
self
.
variables
=
set
()
self
.
variables
=
set
()
self
.
inputs
=
None
self
.
inputs
=
None
self
.
outputs
=
None
self
.
outputs
=
None
...
@@ -215,11 +215,11 @@ class FunctionGraph(utils.object2):
...
@@ -215,11 +215,11 @@ class FunctionGraph(utils.object2):
if
NullType
is
None
:
if
NullType
is
None
:
from
null_type
import
NullType
from
null_type
import
NullType
# Imports the owners of the variables
# Imports the owners of the variables
r_owner_done
=
set
(
self
.
nodes
)
r_owner_done
=
set
(
self
.
apply_
nodes
)
for
node
in
[
r
.
owner
for
r
in
variables
if
r
.
owner
is
not
None
]:
for
apply_
node
in
[
r
.
owner
for
r
in
variables
if
r
.
owner
is
not
None
]:
if
node
not
in
r_owner_done
:
if
apply_
node
not
in
r_owner_done
:
r_owner_done
.
add
(
node
)
r_owner_done
.
add
(
apply_
node
)
self
.
__import__
(
node
)
self
.
__import__
(
apply_
node
)
for
r
in
variables
:
for
r
in
variables
:
if
r
.
owner
is
None
and
not
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
:
if
r
.
owner
is
None
and
not
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
:
if
isinstance
(
r
.
type
,
NullType
):
if
isinstance
(
r
.
type
,
NullType
):
...
@@ -229,7 +229,9 @@ class FunctionGraph(utils.object2):
...
@@ -229,7 +229,9 @@ class FunctionGraph(utils.object2):
self
.
__setup_r__
(
r
)
self
.
__setup_r__
(
r
)
self
.
variables
.
add
(
r
)
self
.
variables
.
add
(
r
)
def
__import__
(
self
,
node
,
check
=
True
):
def
__import__
(
self
,
apply_node
,
check
=
True
):
node
=
apply_node
# We import the nodes in topological order. We only are interested
# We import the nodes in topological order. We only are interested
# in new nodes, so we use all variables we know of as if they were the input set.
# in new nodes, so we use all variables we know of as if they were the input set.
# (the functions in the graph module only use the input set to
# (the functions in the graph module only use the input set to
...
@@ -311,9 +313,9 @@ class FunctionGraph(utils.object2):
...
@@ -311,9 +313,9 @@ class FunctionGraph(utils.object2):
r
)
r
)
for
node
in
new_nodes
:
for
node
in
new_nodes
:
assert
node
not
in
self
.
nodes
assert
node
not
in
self
.
apply_
nodes
self
.
__setup_node__
(
node
)
self
.
__setup_node__
(
node
)
self
.
nodes
.
add
(
node
)
self
.
apply_
nodes
.
add
(
node
)
for
output
in
node
.
outputs
:
for
output
in
node
.
outputs
:
self
.
__setup_r__
(
output
)
self
.
__setup_r__
(
output
)
self
.
variables
.
add
(
output
)
self
.
variables
.
add
(
output
)
...
@@ -336,8 +338,9 @@ class FunctionGraph(utils.object2):
...
@@ -336,8 +338,9 @@ class FunctionGraph(utils.object2):
if
not
r
.
clients
and
r
in
self
.
variables
:
if
not
r
.
clients
and
r
in
self
.
variables
:
self
.
variables
.
remove
(
r
)
self
.
variables
.
remove
(
r
)
def
__prune__
(
self
,
node
):
def
__prune__
(
self
,
apply_node
):
if
node
not
in
self
.
nodes
:
node
=
apply_node
if
node
not
in
self
.
apply_nodes
:
raise
Exception
(
"
%
s does not belong to this FunctionGraph and cannot be pruned."
%
node
)
raise
Exception
(
"
%
s does not belong to this FunctionGraph and cannot be pruned."
%
node
)
assert
node
.
fgraph
is
self
assert
node
.
fgraph
is
self
# If node's outputs have no clients, removes it from the graph
# If node's outputs have no clients, removes it from the graph
...
@@ -348,7 +351,7 @@ class FunctionGraph(utils.object2):
...
@@ -348,7 +351,7 @@ class FunctionGraph(utils.object2):
# Cannot prune an op which is an output or used somewhere
# Cannot prune an op which is an output or used somewhere
if
self
.
clients
(
output
)
or
output
in
self
.
outputs
:
#output in self.outputs or self.clients(output):
if
self
.
clients
(
output
)
or
output
in
self
.
outputs
:
#output in self.outputs or self.clients(output):
return
return
self
.
nodes
.
remove
(
node
)
self
.
apply_
nodes
.
remove
(
node
)
self
.
variables
.
difference_update
(
node
.
outputs
)
self
.
variables
.
difference_update
(
node
.
outputs
)
self
.
execute_callbacks
(
'on_prune'
,
node
)
self
.
execute_callbacks
(
'on_prune'
,
node
)
...
@@ -532,12 +535,12 @@ class FunctionGraph(utils.object2):
...
@@ -532,12 +535,12 @@ class FunctionGraph(utils.object2):
{node: predecessors} where predecessors is a list of nodes
{node: predecessors} where predecessors is a list of nodes
that should be computed before the key node.
that should be computed before the key node.
"""
"""
if
len
(
self
.
nodes
)
<
2
:
if
len
(
self
.
apply_
nodes
)
<
2
:
# optimization
# optimization
# when there are 0 or 1 nodes, no sorting is necessary
# when there are 0 or 1 nodes, no sorting is necessary
# This special case happens a lot because the OpWiseCLinker produces
# This special case happens a lot because the OpWiseCLinker produces
# 1-element graphs.
# 1-element graphs.
return
list
(
self
.
nodes
)
return
list
(
self
.
apply_
nodes
)
fg
=
self
fg
=
self
ords
=
self
.
orderings
()
ords
=
self
.
orderings
()
order
=
graph
.
io_toposort
(
fg
.
inputs
,
fg
.
outputs
,
ords
)
order
=
graph
.
io_toposort
(
fg
.
inputs
,
fg
.
outputs
,
ords
)
...
@@ -569,26 +572,31 @@ class FunctionGraph(utils.object2):
...
@@ -569,26 +572,31 @@ class FunctionGraph(utils.object2):
"""WRITEME Same as len(self.clients(r))."""
"""WRITEME Same as len(self.clients(r))."""
return
len
(
self
.
clients
(
r
))
return
len
(
self
.
clients
(
r
))
# def edge(self, r):
def
nodes_getter
(
self
):
# return r in self.inputs or r in self.orphans
warnings
.
warn
(
"FunctionGraph.nodes is deprecated, it has been renamed 'apply_nodes'"
,
stacklevel
=
2
)
return
self
.
apply_nodes
def
nodes_setter
(
self
,
value
):
warnings
.
warn
(
"FunctionGraph.nodes is deprecated, it has been renamed 'apply_nodes'"
,
stacklevel
=
2
)
self
.
apply_nodes
=
value
def
nodes_deleter
(
self
):
warnings
.
warn
(
"FunctionGraph.nodes is deprecated, it has been renamed 'apply_nodes'"
,
stacklevel
=
2
)
del
self
.
apply_nodes
# def follow(self, r):
nodes
=
property
(
nodes_getter
,
nodes_setter
,
nodes_deleter
)
# node = r.owner
# if self.edge(r):
# return None
# else:
# if node is None:
# raise Exception("what the fuck")
# return node.inputs
def
check_integrity
(
self
):
def
check_integrity
(
self
):
"""WRITEME
"""WRITEME
Call this for a diagnosis if things go awry.
Call this for a diagnosis if things go awry.
"""
"""
nodes
=
graph
.
ops
(
self
.
inputs
,
self
.
outputs
)
nodes
=
graph
.
ops
(
self
.
inputs
,
self
.
outputs
)
if
self
.
nodes
!=
nodes
:
if
self
.
apply_
nodes
!=
nodes
:
missing
=
nodes
.
difference
(
self
.
nodes
)
missing
=
nodes
.
difference
(
self
.
apply_
nodes
)
excess
=
self
.
nodes
.
difference
(
nodes
)
excess
=
self
.
apply_
nodes
.
difference
(
nodes
)
raise
Exception
(
"The nodes are inappropriately cached. missing, in excess: "
,
missing
,
excess
)
raise
Exception
(
"The nodes are inappropriately cached. missing, in excess: "
,
missing
,
excess
)
for
node
in
nodes
:
for
node
in
nodes
:
if
node
.
fgraph
is
not
self
:
if
node
.
fgraph
is
not
self
:
...
...
theano/gof/opt.py
浏览文件 @
0d0cc128
...
@@ -162,7 +162,7 @@ class SeqOptimizer(Optimizer, list):
...
@@ -162,7 +162,7 @@ class SeqOptimizer(Optimizer, list):
l
=
[]
l
=
[]
if
fgraph
.
profile
:
if
fgraph
.
profile
:
validate_before
=
fgraph
.
profile
.
validate_time
validate_before
=
fgraph
.
profile
.
validate_time
nb_node_before
=
len
(
fgraph
.
nodes
)
nb_node_before
=
len
(
fgraph
.
apply_
nodes
)
sub_profs
=
[]
sub_profs
=
[]
for
optimizer
in
self
:
for
optimizer
in
self
:
try
:
try
:
...
@@ -184,7 +184,7 @@ class SeqOptimizer(Optimizer, list):
...
@@ -184,7 +184,7 @@ class SeqOptimizer(Optimizer, list):
print
"SeqOptimizer"
,
print
"SeqOptimizer"
,
if
hasattr
(
self
,
"name"
):
print
self
.
name
,
if
hasattr
(
self
,
"name"
):
print
self
.
name
,
elif
hasattr
(
self
,
"__name__"
):
print
self
.
__name__
,
elif
hasattr
(
self
,
"__name__"
):
print
self
.
__name__
,
print
" time
%.3
fs for
%
d/
%
d nodes before/after optimization"
%
(
sum
(
l
),
nb_node_before
,
len
(
fgraph
.
nodes
))
print
" time
%.3
fs for
%
d/
%
d nodes before/after optimization"
%
(
sum
(
l
),
nb_node_before
,
len
(
fgraph
.
apply_
nodes
))
print
" time
%.3
fs for validate "
%
(
print
" time
%.3
fs for validate "
%
(
fgraph
.
profile
.
validate_time
-
validate_before
)
fgraph
.
profile
.
validate_time
-
validate_before
)
ll
=
[]
ll
=
[]
...
@@ -208,7 +208,7 @@ class SeqOptimizer(Optimizer, list):
...
@@ -208,7 +208,7 @@ class SeqOptimizer(Optimizer, list):
else
:
else
:
validate_time
=
None
validate_time
=
None
return
(
self
,
l
,
validate_time
,
nb_node_before
,
return
(
self
,
l
,
validate_time
,
nb_node_before
,
len
(
fgraph
.
nodes
),
sub_profs
)
len
(
fgraph
.
apply_
nodes
),
sub_profs
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
#added to override the list's __eq__ implementation
#added to override the list's __eq__ implementation
...
@@ -1503,7 +1503,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
...
@@ -1503,7 +1503,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
max_use_abort
=
True
max_use_abort
=
True
opt_name
=
(
getattr
(
lopt
,
"name"
,
None
)
opt_name
=
(
getattr
(
lopt
,
"name"
,
None
)
or
getattr
(
lopt
,
"__name__"
,
""
))
or
getattr
(
lopt
,
"__name__"
,
""
))
if
node
not
in
fgraph
.
nodes
:
if
node
not
in
fgraph
.
apply_
nodes
:
# go to next node
# go to next node
break
break
finally
:
finally
:
...
...
theano/gof/sandbox/equilibrium.py
浏览文件 @
0d0cc128
...
@@ -73,7 +73,7 @@ if 0:
...
@@ -73,7 +73,7 @@ if 0:
tasks
=
defaultdict
(
list
)
tasks
=
defaultdict
(
list
)
if
self
.
max_use_ratio
is
not
None
:
if
self
.
max_use_ratio
is
not
None
:
max_uses
=
self
.
max_use_ratio
*
len
(
fgraph
.
nodes
)
max_uses
=
self
.
max_use_ratio
*
len
(
fgraph
.
apply_
nodes
)
runs
=
defaultdict
(
int
)
runs
=
defaultdict
(
int
)
else
:
else
:
runs
=
None
runs
=
None
...
@@ -91,7 +91,7 @@ if 0:
...
@@ -91,7 +91,7 @@ if 0:
self
.
backtrack
(
new_r
.
owner
,
tasks
)
self
.
backtrack
(
new_r
.
owner
,
tasks
)
# # == NOT IDEAL == #
# # == NOT IDEAL == #
# for node in fgraph.nodes:
# for node in fgraph.
apply_
nodes:
# importer(node)
# importer(node)
...
...
theano/gof/toolbox.py
浏览文件 @
0d0cc128
...
@@ -219,7 +219,7 @@ class ReplaceValidate(History, Validator):
...
@@ -219,7 +219,7 @@ class ReplaceValidate(History, Validator):
"""
"""
chk
=
fgraph
.
replace_all_validate
(
replacements
,
reason
)
chk
=
fgraph
.
replace_all_validate
(
replacements
,
reason
)
for
rm
in
remove
:
for
rm
in
remove
:
if
rm
in
fgraph
.
nodes
or
rm
in
fgraph
.
variables
:
if
rm
in
fgraph
.
apply_
nodes
or
rm
in
fgraph
.
variables
:
fgraph
.
revert
(
chk
)
fgraph
.
revert
(
chk
)
if
warn
:
if
warn
:
out
=
sys
.
stderr
out
=
sys
.
stderr
...
...
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
0d0cc128
...
@@ -1002,7 +1002,7 @@ def test_many_arg_elemwise():
...
@@ -1002,7 +1002,7 @@ def test_many_arg_elemwise():
#assert that the test was done on the gpu.
#assert that the test was done on the gpu.
if
mode
is
mode_with_gpu
:
if
mode
is
mode_with_gpu
:
assert
any
([
isinstance
(
node
.
op
,
cuda
.
GpuElemwise
)
assert
any
([
isinstance
(
node
.
op
,
cuda
.
GpuElemwise
)
for
node
in
f
.
maker
.
fgraph
.
nodes
])
for
node
in
f
.
maker
.
fgraph
.
apply_
nodes
])
#test the optijmization local_gpu_elemwise_1
#test the optijmization local_gpu_elemwise_1
f
=
theano
.
function
(
f
=
theano
.
function
(
...
@@ -1013,7 +1013,7 @@ def test_many_arg_elemwise():
...
@@ -1013,7 +1013,7 @@ def test_many_arg_elemwise():
#assert that the test was done on the gpu.
#assert that the test was done on the gpu.
if
mode
is
mode_with_gpu
:
if
mode
is
mode_with_gpu
:
assert
any
([
isinstance
(
node
.
op
,
cuda
.
GpuElemwise
)
assert
any
([
isinstance
(
node
.
op
,
cuda
.
GpuElemwise
)
for
node
in
f
.
maker
.
fgraph
.
nodes
])
for
node
in
f
.
maker
.
fgraph
.
apply_
nodes
])
assert
numpy
.
allclose
(
out
,
outputs
[
-
1
])
assert
numpy
.
allclose
(
out
,
outputs
[
-
1
])
results_gpu
,
results_cpu
=
outputs
results_gpu
,
results_cpu
=
outputs
...
...
theano/scalar/basic.py
浏览文件 @
0d0cc128
...
@@ -2667,7 +2667,7 @@ class Composite(ScalarOp):
...
@@ -2667,7 +2667,7 @@ class Composite(ScalarOp):
def
init_fgraph
(
self
):
def
init_fgraph
(
self
):
fgraph
=
FunctionGraph
(
*
gof
.
graph
.
clone
(
self
.
inputs
,
self
.
outputs
))
fgraph
=
FunctionGraph
(
*
gof
.
graph
.
clone
(
self
.
inputs
,
self
.
outputs
))
gof
.
MergeOptimizer
()
.
optimize
(
fgraph
)
gof
.
MergeOptimizer
()
.
optimize
(
fgraph
)
for
node
in
fgraph
.
nodes
:
for
node
in
fgraph
.
apply_
nodes
:
if
not
isinstance
(
node
.
op
,
ScalarOp
):
if
not
isinstance
(
node
.
op
,
ScalarOp
):
raise
ValueError
(
"The fgraph to Composite must be exclusively"
raise
ValueError
(
"The fgraph to Composite must be exclusively"
" composed of ScalarOp instances."
)
" composed of ScalarOp instances."
)
...
...
theano/tensor/blas.py
浏览文件 @
0d0cc128
...
@@ -1382,7 +1382,7 @@ class GemmOptimizer(Optimizer):
...
@@ -1382,7 +1382,7 @@ class GemmOptimizer(Optimizer):
(
theano
.
scalar
.
Add
,
theano
.
scalar
.
Sub
,
(
theano
.
scalar
.
Add
,
theano
.
scalar
.
Sub
,
theano
.
scalar
.
Neg
,
theano
.
scalar
.
Mul
))):
theano
.
scalar
.
Neg
,
theano
.
scalar
.
Mul
))):
continue
continue
if
not
node
in
fgraph
.
nodes
:
if
not
node
in
fgraph
.
apply_
nodes
:
# This mean that we already removed this node from
# This mean that we already removed this node from
# the graph
# the graph
continue
continue
...
...
theano/tensor/opt.py
浏览文件 @
0d0cc128
...
@@ -176,7 +176,7 @@ def inplace_elemwise_optimizer_op(OP):
...
@@ -176,7 +176,7 @@ def inplace_elemwise_optimizer_op(OP):
# We execute `validate` after this number of change.
# We execute `validate` after this number of change.
check_each_change
=
config
.
tensor
.
insert_inplace_optimizer_validate_nb
check_each_change
=
config
.
tensor
.
insert_inplace_optimizer_validate_nb
if
check_each_change
==
-
1
:
if
check_each_change
==
-
1
:
if
len
(
fgraph
.
nodes
)
>
500
:
if
len
(
fgraph
.
apply_
nodes
)
>
500
:
check_each_change
=
10
check_each_change
=
10
else
:
else
:
check_each_change
=
1
check_each_change
=
1
...
@@ -4596,7 +4596,7 @@ class FusionOptimizer(Optimizer):
...
@@ -4596,7 +4596,7 @@ class FusionOptimizer(Optimizer):
did_something
=
False
did_something
=
False
for
node
in
nodelist
:
for
node
in
nodelist
:
# Don't try to fuse node that have already been fused.
# Don't try to fuse node that have already been fused.
if
node
in
fgraph
.
nodes
:
if
node
in
fgraph
.
apply_
nodes
:
new_outputs
=
self
.
optimizer
(
node
)
new_outputs
=
self
.
optimizer
(
node
)
if
new_outputs
:
if
new_outputs
:
assert
len
(
new_outputs
)
==
len
(
node
.
outputs
)
assert
len
(
new_outputs
)
==
len
(
node
.
outputs
)
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
0d0cc128
...
@@ -478,7 +478,7 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
...
@@ -478,7 +478,7 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
mode
=
'FAST_RUN'
,
mode
=
'FAST_RUN'
,
on_unused_input
=
'ignore'
)
on_unused_input
=
'ignore'
)
nb_gemm
=
0
nb_gemm
=
0
for
node
in
f
.
maker
.
fgraph
.
nodes
:
for
node
in
f
.
maker
.
fgraph
.
apply_
nodes
:
if
node
.
op
==
T
.
dot
:
if
node
.
op
==
T
.
dot
:
raise
Failure
(
'dot not changed to gemm_inplace in graph'
)
raise
Failure
(
'dot not changed to gemm_inplace in graph'
)
if
node
.
op
==
_dot22
:
if
node
.
op
==
_dot22
:
...
@@ -488,7 +488,7 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
...
@@ -488,7 +488,7 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
assert
nb_gemm
==
expected_nb_gemm
,
(
nb_gemm
,
expected_nb_gemm
)
assert
nb_gemm
==
expected_nb_gemm
,
(
nb_gemm
,
expected_nb_gemm
)
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
),
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
),
allow_input_downcast
=
True
,
on_unused_input
=
'ignore'
)
allow_input_downcast
=
True
,
on_unused_input
=
'ignore'
)
for
node
in
g
.
maker
.
fgraph
.
nodes
:
for
node
in
g
.
maker
.
fgraph
.
apply_
nodes
:
if
node
.
op
==
gemm_inplace
:
if
node
.
op
==
gemm_inplace
:
raise
Exception
(
'gemm_inplace in original graph'
)
raise
Exception
(
'gemm_inplace in original graph'
)
...
@@ -561,14 +561,14 @@ def test_gemm_opt_double_gemm():
...
@@ -561,14 +561,14 @@ def test_gemm_opt_double_gemm():
try
:
try
:
f
=
inplace_func
([
Param
(
ii
,
mutable
=
True
)
for
ii
in
i
],
o
,
f
=
inplace_func
([
Param
(
ii
,
mutable
=
True
)
for
ii
in
i
],
o
,
mode
=
'FAST_RUN'
,
on_unused_input
=
'ignore'
)
mode
=
'FAST_RUN'
,
on_unused_input
=
'ignore'
)
for
node
in
f
.
maker
.
fgraph
.
nodes
:
for
node
in
f
.
maker
.
fgraph
.
apply_
nodes
:
if
node
.
op
==
T
.
dot
:
if
node
.
op
==
T
.
dot
:
raise
Failure
(
'dot in graph'
)
raise
Failure
(
'dot in graph'
)
if
node
.
op
==
_dot22
:
if
node
.
op
==
_dot22
:
raise
Failure
(
'_dot22 in graph'
)
raise
Failure
(
'_dot22 in graph'
)
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
),
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
),
on_unused_input
=
'ignore'
)
on_unused_input
=
'ignore'
)
#for node in g.maker.fgraph.nodes:
#for node in g.maker.fgraph.
apply_
nodes:
# if node.op == gemm_inplace: raise Failure('gemm_inplace in graph')
# if node.op == gemm_inplace: raise Failure('gemm_inplace in graph')
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
...
@@ -760,11 +760,11 @@ def test_gemm_opt_vector_stuff():
...
@@ -760,11 +760,11 @@ def test_gemm_opt_vector_stuff():
u
,
v
=
T
.
vector
(),
T
.
vector
()
u
,
v
=
T
.
vector
(),
T
.
vector
()
f
=
inplace_func
([
a
,
u
,
v
],
a
+
T
.
dot
(
u
,
v
),
mode
=
'FAST_RUN'
)
f
=
inplace_func
([
a
,
u
,
v
],
a
+
T
.
dot
(
u
,
v
),
mode
=
'FAST_RUN'
)
if
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
nodes
]:
if
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
apply_
nodes
]:
raise
Failure
(
'gemm_inplace in graph'
)
raise
Failure
(
'gemm_inplace in graph'
)
f
=
inplace_func
([
a
,
u
,
X
,
Y
],
a
*
u
+
T
.
dot
(
X
,
Y
),
mode
=
'FAST_RUN'
)
f
=
inplace_func
([
a
,
u
,
X
,
Y
],
a
*
u
+
T
.
dot
(
X
,
Y
),
mode
=
'FAST_RUN'
)
if
(
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
nodes
]):
if
(
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
apply_
nodes
]):
raise
Failure
(
'gemm_inplace in graph'
)
raise
Failure
(
'gemm_inplace in graph'
)
...
@@ -823,16 +823,16 @@ def test_inplace0():
...
@@ -823,16 +823,16 @@ def test_inplace0():
f
=
inplace_func
([
Z
,
b
,
R
,
S
],
f
=
inplace_func
([
Z
,
b
,
R
,
S
],
[
Z
*
(
Z
+
b
*
T
.
dot
(
R
,
S
)
.
T
)],
mode
=
'FAST_RUN'
)
[
Z
*
(
Z
+
b
*
T
.
dot
(
R
,
S
)
.
T
)],
mode
=
'FAST_RUN'
)
if
(
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
nodes
]):
if
(
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
apply_
nodes
]):
print
pp
(
f
.
maker
.
fgraph
.
outputs
[
0
])
print
pp
(
f
.
maker
.
fgraph
.
outputs
[
0
])
raise
Failure
(
'gemm_inplace in graph'
)
raise
Failure
(
'gemm_inplace in graph'
)
assert
gemm_no_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
nodes
]
assert
gemm_no_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
apply_
nodes
]
# gemm_inplace should be inserted here, to work in-place on Z*c
# gemm_inplace should be inserted here, to work in-place on Z*c
f
=
inplace_func
([
X
,
Y
,
Z
,
a
,
b
,
R
,
S
,
c
],
f
=
inplace_func
([
X
,
Y
,
Z
,
a
,
b
,
R
,
S
,
c
],
[
Z
*
(
c
*
Z
+
a
*
T
.
dot
(
X
,
Y
)
+
b
*
T
.
dot
(
R
,
S
)
.
T
)],
[
Z
*
(
c
*
Z
+
a
*
T
.
dot
(
X
,
Y
)
+
b
*
T
.
dot
(
R
,
S
)
.
T
)],
mode
=
'FAST_RUN'
)
mode
=
'FAST_RUN'
)
if
(
not
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
nodes
]):
if
(
not
gemm_inplace
in
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
apply_
nodes
]):
theano
.
printing
.
debugprint
(
f
)
theano
.
printing
.
debugprint
(
f
)
raise
Failure
(
'no gemm_inplace in graph'
)
raise
Failure
(
'no gemm_inplace in graph'
)
...
@@ -844,7 +844,7 @@ def test_inplace1():
...
@@ -844,7 +844,7 @@ def test_inplace1():
[
Z
+
Z
+
T
.
dot
(
X
,
Y
)],
mode
=
'FAST_RUN'
)
[
Z
+
Z
+
T
.
dot
(
X
,
Y
)],
mode
=
'FAST_RUN'
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
# it doesn't work inplace because we didn't mark Z as mutable input
# it doesn't work inplace because we didn't mark Z as mutable input
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
nodes
]
==
[
gemm_no_inplace
]
assert
[
n
.
op
for
n
in
f
.
maker
.
fgraph
.
apply_
nodes
]
==
[
gemm_no_inplace
]
def
test_dot22
():
def
test_dot22
():
...
...
theano/tensor/tests/test_naacl09.py
浏览文件 @
0d0cc128
...
@@ -590,7 +590,7 @@ def test_naacl_model(iters_per_unsup=3, iters_per_sup=3,
...
@@ -590,7 +590,7 @@ def test_naacl_model(iters_per_unsup=3, iters_per_sup=3,
#print input_pretraining_gradients[4].owner.inputs[1].owner.inputs
#print input_pretraining_gradients[4].owner.inputs[1].owner.inputs
#sys.exit()
#sys.exit()
#print "PROGRAM LEN %i HASH %i"% (len(m.pretraining_update.maker.fgraph.nodes), reduce(lambda a, b: hash(a) ^ hash(b),prog_str))
#print "PROGRAM LEN %i HASH %i"% (len(m.pretraining_update.maker.fgraph.
apply_
nodes), reduce(lambda a, b: hash(a) ^ hash(b),prog_str))
rng
=
N
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
23904
))
rng
=
N
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
23904
))
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
0d0cc128
...
@@ -2791,14 +2791,14 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
...
@@ -2791,14 +2791,14 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
f
=
function
([
v
],
v
**
(
15
),
mode
=
mode
)
f
=
function
([
v
],
v
**
(
15
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
len
(
nodes
)
==
1
assert
len
(
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
nodes
)
==
6
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_
nodes
)
==
6
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
numpy
.
allclose
(
f
(
val
),
val
**
15
)
assert
numpy
.
allclose
(
f
(
val
),
val
**
15
)
f
=
function
([
v
],
v
**
(
-
15
),
mode
=
mode
)
f
=
function
([
v
],
v
**
(
-
15
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
len
(
nodes
)
==
2
assert
len
(
nodes
)
==
2
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
nodes
)
==
6
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_
nodes
)
==
6
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
-
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
isinstance
(
nodes
[
-
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
15
))
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
15
))
...
@@ -2806,14 +2806,14 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
...
@@ -2806,14 +2806,14 @@ def test_local_pow_specialize_device_more_aggressive_on_cpu():
f
=
function
([
v
],
v
**
(
16
),
mode
=
mode
)
f
=
function
([
v
],
v
**
(
16
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
len
(
nodes
)
==
1
assert
len
(
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
nodes
)
==
4
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_
nodes
)
==
4
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
numpy
.
allclose
(
f
(
val
),
val
**
16
)
assert
numpy
.
allclose
(
f
(
val
),
val
**
16
)
f
=
function
([
v
],
v
**
(
-
16
),
mode
=
mode
)
f
=
function
([
v
],
v
**
(
-
16
),
mode
=
mode
)
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
nodes
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
len
(
nodes
)
==
2
assert
len
(
nodes
)
==
2
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
nodes
)
==
4
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_
nodes
)
==
4
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
0
]
.
scalar_op
,
theano
.
scalar
.
Composite
)
assert
isinstance
(
nodes
[
-
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
isinstance
(
nodes
[
-
1
]
.
scalar_op
,
theano
.
scalar
.
basic
.
Inv
)
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
16
))
assert
numpy
.
allclose
(
f
(
val_no0
),
val_no0
**
(
-
16
))
...
@@ -3204,21 +3204,21 @@ class T_local_erfc(unittest.TestCase):
...
@@ -3204,21 +3204,21 @@ class T_local_erfc(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
log
(
T
.
erfc
(
x
)),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
log
(
T
.
erfc
(
x
)),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
f
=
theano
.
function
([
x
],
T
.
log
(
T
.
erfc
(
-
x
)),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
log
(
T
.
erfc
(
-
x
)),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
24
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
24
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
all
(
numpy
.
isfinite
(
f
(
-
val
)))
assert
all
(
numpy
.
isfinite
(
f
(
-
val
)))
f
=
theano
.
function
([
x
],
T
.
log
(
T
.
erfc
(
x
)),
mode
=
mode_fusion
)
f
=
theano
.
function
([
x
],
T
.
log
(
T
.
erfc
(
x
)),
mode
=
mode_fusion
)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
fgraph
.
toposort
()[
assert
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
nodes
)
==
2
,
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
nodes
)
0
]
.
op
.
scalar_op
.
fgraph
.
apply_nodes
)
==
2
,
len
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
fgraph
.
toposort
()[
0
]
.
op
.
scalar_op
.
fgraph
.
apply_
nodes
)
#TODO: fix this problem
#TODO: fix this problem
if
theano
.
config
.
floatX
==
"float32"
and
theano
.
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
]:
if
theano
.
config
.
floatX
==
"float32"
and
theano
.
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
]:
raise
KnownFailureTest
(
raise
KnownFailureTest
(
...
@@ -3247,7 +3247,7 @@ class T_local_erfc(unittest.TestCase):
...
@@ -3247,7 +3247,7 @@ class T_local_erfc(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
grad
(
T
.
log
(
T
.
erfc
(
x
))
.
sum
(),
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
grad
(
T
.
log
(
T
.
erfc
(
x
))
.
sum
(),
x
),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
...
@@ -3255,14 +3255,14 @@ class T_local_erfc(unittest.TestCase):
...
@@ -3255,14 +3255,14 @@ class T_local_erfc(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
mul
(
T
.
exp
(
T
.
neg
(
T
.
sqr
(
x
))),
-
f
=
theano
.
function
([
x
],
T
.
mul
(
T
.
exp
(
T
.
neg
(
T
.
sqr
(
x
))),
-
10.12837917
)
/
T
.
erfc
(
x
),
mode
=
mode
)
10.12837917
)
/
T
.
erfc
(
x
),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
#test that we work without the mul
#test that we work without the mul
f
=
theano
.
function
([
x
],
T
.
exp
(
T
.
neg
(
T
.
sqr
(
x
)))
/
T
.
erfc
(
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
exp
(
T
.
neg
(
T
.
sqr
(
x
)))
/
T
.
erfc
(
x
),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
...
@@ -3270,14 +3270,14 @@ class T_local_erfc(unittest.TestCase):
...
@@ -3270,14 +3270,14 @@ class T_local_erfc(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
],
T
.
exp
(
T
.
neg
(
T
.
sqr
(
x
)))
/
T
.
erfc
(
f
=
theano
.
function
([
x
,
y
],
T
.
exp
(
T
.
neg
(
T
.
sqr
(
x
)))
/
T
.
erfc
(
y
),
mode
=
mode
)
y
),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
5
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
5
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
f
(
val
,
val
-
3
)
f
(
val
,
val
-
3
)
#test that we work without the sqr and neg
#test that we work without the sqr and neg
f
=
theano
.
function
([
x
],
T
.
exp
(
T
.
mul
(
-
1
,
x
,
x
))
/
T
.
erfc
(
x
),
mode
=
mode
)
f
=
theano
.
function
([
x
],
T
.
exp
(
T
.
mul
(
-
1
,
x
,
x
))
/
T
.
erfc
(
x
),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
22
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
22
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
assert
all
(
numpy
.
isfinite
(
f
(
val
)))
...
@@ -3285,13 +3285,13 @@ class T_local_erfc(unittest.TestCase):
...
@@ -3285,13 +3285,13 @@ class T_local_erfc(unittest.TestCase):
f
=
theano
.
function
([
x
],
T
.
grad
(
T
.
log
(
T
.
erfc
(
2
*
x
))
.
sum
(),
f
=
theano
.
function
([
x
],
T
.
grad
(
T
.
log
(
T
.
erfc
(
2
*
x
))
.
sum
(),
x
),
mode
=
mode
)
x
),
mode
=
mode
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
23
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
numpy
.
isfinite
(
f
(
val
))
.
all
()
assert
numpy
.
isfinite
(
f
(
val
))
.
all
()
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
f
=
theano
.
function
([
x
],
T
.
grad
(
T
.
log
(
T
.
erfc
(
x
))
.
sum
(),
x
),
f
=
theano
.
function
([
x
],
T
.
grad
(
T
.
log
(
T
.
erfc
(
x
))
.
sum
(),
x
),
mode
=
mode_fusion
)
mode
=
mode_fusion
)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
,
len
(
f
.
maker
.
fgraph
.
nodes
)
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
,
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
assert
f
.
maker
.
fgraph
.
outputs
[
0
]
.
dtype
==
theano
.
config
.
floatX
#TODO: fix this problem
#TODO: fix this problem
...
@@ -3413,18 +3413,18 @@ class T_local_sum(unittest.TestCase):
...
@@ -3413,18 +3413,18 @@ class T_local_sum(unittest.TestCase):
a
=
T
.
tensor3
()
a
=
T
.
tensor3
()
input
=
numpy
.
arange
(
3
*
3
*
3
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
3
,
3
)
input
=
numpy
.
arange
(
3
*
3
*
3
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
3
,
3
)
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
f
=
theano
.
function
([
a
],
a
.
sum
([
0
,
1
,
2
]),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
([
0
,
1
,
2
]),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
backup
=
config
.
warn
.
sum_sum_bug
backup
=
config
.
warn
.
sum_sum_bug
config
.
warn
.
sum_sum_bug
=
False
config
.
warn
.
sum_sum_bug
=
False
try
:
try
:
f
=
theano
.
function
([
a
],
a
.
sum
(
0
)
.
sum
(
0
)
.
sum
(
0
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
0
)
.
sum
(
0
)
.
sum
(
0
),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
finally
:
finally
:
config
.
warn
.
sum_sum_bug
=
backup
config
.
warn
.
sum_sum_bug
=
backup
...
@@ -3440,20 +3440,20 @@ class T_local_sum(unittest.TestCase):
...
@@ -3440,20 +3440,20 @@ class T_local_sum(unittest.TestCase):
for
d
,
dd
in
dims
:
for
d
,
dd
in
dims
:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
))
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
))
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
for
d
,
dd
in
dims
:
for
d
,
dd
in
dims
:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
)
.
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
),
mode
=
self
.
mode
)
sum
(
0
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
))
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
(
dd
)
.
sum
(
0
))
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
for
d
in
[
0
,
1
,
2
]:
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
None
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
d
)
.
sum
(
None
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
(
d
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
for
d
in
[
0
,
1
,
2
]:
for
d
in
[
0
,
1
,
2
]:
f
=
theano
.
function
([
a
],
a
.
sum
(
None
)
.
sum
(),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(
None
)
.
sum
(),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
1
finally
:
finally
:
config
.
warn
.
sum_sum_bug
=
backup
config
.
warn
.
sum_sum_bug
=
backup
...
@@ -3468,23 +3468,23 @@ class T_local_sum(unittest.TestCase):
...
@@ -3468,23 +3468,23 @@ class T_local_sum(unittest.TestCase):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
None
),
mode
=
mode
)
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
None
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
nb_nodes
[
0
]
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
nb_nodes
[
0
]
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
([
0
,
1
,
2
]),
mode
=
mode
)
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
([
0
,
1
,
2
]),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
nb_nodes
[
0
]
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
nb_nodes
[
0
]
for
d
in
range
(
3
):
for
d
in
range
(
3
):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
d
),
mode
=
mode
)
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
d
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
))
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
))
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
nb_nodes
[
1
]
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
nb_nodes
[
1
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
not
any
([
isinstance
(
node
.
op
,
T
.
Sum
)
for
node
in
topo
])
assert
not
any
([
isinstance
(
node
.
op
,
T
.
Sum
)
for
node
in
topo
])
for
i
in
range
(
3
):
for
i
in
range
(
3
):
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
i
),
mode
=
mode
)
f
=
theano
.
function
([
a
],
t_like
(
a
)
.
sum
(
i
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
i
))
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
i
))
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
nb_nodes
[
2
]
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
nb_nodes
[
2
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
not
any
([
isinstance
(
node
.
op
,
T
.
Sum
)
for
node
in
topo
])
assert
not
any
([
isinstance
(
node
.
op
,
T
.
Sum
)
for
node
in
topo
])
...
@@ -3497,7 +3497,7 @@ class T_local_sum(unittest.TestCase):
...
@@ -3497,7 +3497,7 @@ class T_local_sum(unittest.TestCase):
sum
(
d
)
.
sum
(
dd
),
mode
=
mode
)
sum
(
d
)
.
sum
(
dd
),
mode
=
mode
)
assert
numpy
.
allclose
(
f
(
input
),
assert
numpy
.
allclose
(
f
(
input
),
n_like
(
input
)
.
sum
(
d
)
.
sum
(
dd
))
n_like
(
input
)
.
sum
(
d
)
.
sum
(
dd
))
assert
len
(
f
.
maker
.
fgraph
.
nodes
)
==
nb_nodes
[
3
]
assert
len
(
f
.
maker
.
fgraph
.
apply_
nodes
)
==
nb_nodes
[
3
]
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
topo
[
-
1
]
.
op
==
T
.
alloc
assert
not
any
([
isinstance
(
node
.
op
,
assert
not
any
([
isinstance
(
node
.
op
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论