Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
968f6f9a
提交
968f6f9a
authored
6月 24, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
8505d9d3
099efddb
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
90 行增加
和
13 行删除
+90
-13
graph.py
theano/gof/graph.py
+2
-0
printing.py
theano/printing.py
+25
-11
basic.py
theano/scalar/basic.py
+1
-0
basic.py
theano/tensor/basic.py
+10
-0
blas.py
theano/tensor/blas.py
+3
-2
sigm.py
theano/tensor/nnet/sigm.py
+44
-0
opt.py
theano/tensor/opt.py
+5
-0
没有找到文件。
theano/gof/graph.py
浏览文件 @
968f6f9a
...
...
@@ -341,6 +341,8 @@ class Value(Variable):
if
value
is
not
None
:
raise
ValueError
(
"Value instances cannot have an owner."
)
owner
=
property
(
lambda
self
:
None
,
__set_owner
)
value
=
property
(
lambda
self
:
self
.
data
,
doc
=
'read-only data access method'
)
# index is not defined, because the `owner` attribute must necessarily be None
...
...
theano/printing.py
浏览文件 @
968f6f9a
...
...
@@ -359,7 +359,8 @@ pprint.assign(lambda pstate, r: hasattr(pstate, 'target') and pstate.target is n
pp
=
pprint
def
pydotprint
(
fct
,
outfile
=
os
.
path
.
join
(
config
.
compiledir
,
'theano.pydotprint.png'
),
compact
=
True
,
mode
=
None
,
format
=
'png'
):
def
pydotprint
(
fct
,
outfile
=
os
.
path
.
join
(
config
.
compiledir
,
'theano.pydotprint.png'
),
compact
=
True
,
mode
=
None
,
format
=
'png'
,
with_ids
=
False
):
"""
print to a file in png format the graph of op of a compile theano fct.
...
...
@@ -390,14 +391,15 @@ def pydotprint(fct, outfile=os.path.join(config.compiledir,'theano.pydotprint.pn
g
=
pd
.
Dot
()
var_str
=
{}
all_strings
=
set
()
def
var_name
(
var
):
if
var
in
var_str
:
return
var_str
[
var
]
if
var
.
name
is
not
None
:
varstr
=
var
.
name
+
" "
+
str
(
var
.
type
)
varstr
=
'name='
+
var
.
name
+
" "
+
str
(
var
.
type
)
elif
isinstance
(
var
,
gof
.
Constant
):
dstr
=
str
(
var
.
data
)
dstr
=
'val='
+
str
(
var
.
data
)
if
'
\n
'
in
dstr
:
dstr
=
dstr
[:
dstr
.
index
(
'
\n
'
)]
if
len
(
dstr
)
>
30
:
...
...
@@ -408,12 +410,17 @@ def pydotprint(fct, outfile=os.path.join(config.compiledir,'theano.pydotprint.pn
else
:
#a var id is needed as otherwise var with the same type will be merged in the graph.
varstr
=
str
(
var
.
type
)
varstr
+=
' '
+
str
(
len
(
var_str
))
if
(
varstr
in
all_strings
)
or
with_ids
:
varstr
+=
' id='
+
str
(
len
(
var_str
))
var_str
[
var
]
=
varstr
all_strings
.
add
(
varstr
)
return
varstr
topo
=
fct
.
maker
.
env
.
toposort
()
apply_name_cache
=
{}
def
apply_name
(
node
):
if
node
in
apply_name_cache
:
return
apply_name_cache
[
node
]
prof_str
=
''
if
mode
:
time
=
mode
.
apply_time
.
get
((
topo
.
index
(
node
),
node
),
0
)
...
...
@@ -425,7 +432,12 @@ def pydotprint(fct, outfile=os.path.join(config.compiledir,'theano.pydotprint.pn
pf
=
0
else
:
pf
=
time
*
100
/
mode
.
fct_call_time
[
fct
]
prof_str
=
' (
%.3
fs,
%.3
f
%%
,
%.3
f
%%
)'
%
(
time
,
pt
,
pf
)
return
str
(
node
.
op
)
.
replace
(
':'
,
'_'
)
+
' '
+
str
(
topo
.
index
(
node
))
+
prof_str
applystr
=
str
(
node
.
op
)
.
replace
(
':'
,
'_'
)
if
(
applystr
in
all_strings
)
or
with_ids
:
applystr
=
applystr
+
' id='
+
str
(
topo
.
index
(
node
))
+
prof_str
all_strings
.
add
(
applystr
)
apply_name_cache
[
node
]
=
applystr
return
applystr
# Update the inputs that have an update function
input_update
=
{}
...
...
@@ -434,16 +446,18 @@ def pydotprint(fct, outfile=os.path.join(config.compiledir,'theano.pydotprint.pn
if
i
.
update
is
not
None
:
input_update
[
outputs
.
pop
()]
=
i
apply_shape
=
'ellipse'
var_shape
=
'box'
for
node_idx
,
node
in
enumerate
(
topo
):
astr
=
apply_name
(
node
)
g
.
add_node
(
pd
.
Node
(
astr
,
shape
=
'box'
))
g
.
add_node
(
pd
.
Node
(
astr
,
shape
=
apply_shape
))
for
id
,
var
in
enumerate
(
node
.
inputs
):
varstr
=
var_name
(
var
)
label
=
''
if
len
(
node
.
inputs
)
>
1
:
label
=
str
(
id
)
if
var
.
owner
is
None
:
g
.
add_node
(
pd
.
Node
(
varstr
,
color
=
'green'
))
g
.
add_node
(
pd
.
Node
(
varstr
,
color
=
'green'
,
shape
=
var_shape
))
g
.
add_edge
(
pd
.
Edge
(
varstr
,
astr
,
label
=
label
))
elif
var
.
name
or
not
compact
:
g
.
add_edge
(
pd
.
Edge
(
varstr
,
astr
,
label
=
label
))
...
...
@@ -460,10 +474,10 @@ def pydotprint(fct, outfile=os.path.join(config.compiledir,'theano.pydotprint.pn
label
=
str
(
id
)
if
out
:
g
.
add_edge
(
pd
.
Edge
(
astr
,
varstr
,
label
=
label
))
g
.
add_node
(
pd
.
Node
(
varstr
,
color
=
'blue'
))
g
.
add_node
(
pd
.
Node
(
varstr
,
color
=
'blue'
,
shape
=
var_shape
))
elif
len
(
var
.
clients
)
==
0
:
g
.
add_edge
(
pd
.
Edge
(
astr
,
varstr
,
label
=
label
))
g
.
add_node
(
pd
.
Node
(
varstr
,
color
=
'grey'
))
g
.
add_node
(
pd
.
Node
(
varstr
,
color
=
'grey'
,
shape
=
var_shape
))
elif
var
.
name
or
not
compact
:
g
.
add_edge
(
pd
.
Edge
(
astr
,
varstr
,
label
=
label
))
# else:
...
...
@@ -495,9 +509,9 @@ def pydot_var(vars, outfile=os.path.join(config.compiledir,'theano.pydotprint.pn
return
var_str
[
var
]
if
var
.
name
is
not
None
:
varstr
=
var
.
name
varstr
=
'name='
+
var
.
name
elif
isinstance
(
var
,
gof
.
Constant
):
dstr
=
str
(
var
.
data
)
dstr
=
'val='
+
str
(
var
.
data
)
if
'
\n
'
in
dstr
:
dstr
=
dstr
[:
dstr
.
index
(
'
\n
'
)]
if
len
(
dstr
)
>
30
:
...
...
theano/scalar/basic.py
浏览文件 @
968f6f9a
...
...
@@ -932,6 +932,7 @@ class IntDiv(BinaryScalarOp):
return
[
None
]
*
len
(
inputs
)
int_div
=
IntDiv
(
upcast_out
,
name
=
'int_div'
)
floor_div
=
int_div
class
Mod
(
BinaryScalarOp
):
def
impl
(
self
,
x
,
y
):
...
...
theano/tensor/basic.py
浏览文件 @
968f6f9a
...
...
@@ -887,6 +887,11 @@ class _tensor_py_operators:
except
Exception
,
e
:
return
NotImplemented
def
__truediv__
(
self
,
other
):
return
true_div
(
self
,
other
)
def
__floordiv__
(
self
,
other
):
return
floor_div
(
self
,
other
)
def
__rtruediv__
(
self
,
other
):
return
true_div
(
other
,
self
)
def
__rfloordiv__
(
self
,
other
):
return
floor_div
(
other
,
self
)
# ##### DON"T USE THESE BECAUSE INPLACE OPS SHOULD BE INSERTED BY OPTIMIZATION ONLY
# #ARITHMETIC - INPLACE
# def __iadd__(self,other): return _add_inplace(self,other)
...
...
@@ -2066,6 +2071,11 @@ def true_div(a, b):
"""elementwise [true] division (inverse of multiplication)"""
# see decorator for function body
@_scal_elemwise
def
floor_div
(
a
,
b
):
"""elementwise [floor] division (inverse of multiplication)"""
# see decorator for function body
@_scal_elemwise
def
int_div
(
a
,
b
):
"""elementwise integer-division"""
...
...
theano/tensor/blas.py
浏览文件 @
968f6f9a
...
...
@@ -889,6 +889,7 @@ def _gemm_from_node2(node):
if
len
(
lst
)
>
1
:
lst
=
_factor_canonicalized
(
lst
)
rval
=
_gemm_from_factored_list
(
lst
)
#print "RVAL", rval
if
rval
:
assert
rval
[
0
]
.
type
==
node
.
outputs
[
0
]
.
type
,
(
rval
[
0
]
.
type
,
node
.
outputs
[
0
]
.
type
)
return
rval
...
...
@@ -909,7 +910,6 @@ class GemmOptimizer(Optimizer):
did_something
=
False
nodelist
.
reverse
()
for
node
in
nodelist
:
#new_outputs = _gemm_from_node(node)
try
:
new_outputs
=
_gemm_from_node2
(
node
)
except
InconsistencyError
,
e
:
...
...
@@ -1193,9 +1193,10 @@ blas_optdb.register('local_dot22_to_dot22scalar',
11
,
'fast_run'
)
from
opt
import
register_specialize
from
opt
import
register_specialize
,
register_canonicalize
#@register_specialize
@local_optimizer
([])
def
local_print_as_we_go_along
(
node
):
if
node
.
op
in
(
T
.
sub
,
T
.
add
):
debugprint
(
node
)
theano/tensor/nnet/sigm.py
浏览文件 @
968f6f9a
...
...
@@ -338,3 +338,47 @@ register_local_1msigmoid = False
if
register_local_1msigmoid
:
opt
.
register_canonicalize
(
local_1msigmoid
)
if
0
:
# This code is if'd out because it is not complete,
# and it isn't obviously a good idea anyway.
# The motivation here was to identify the last exp() node
# in the SciPy2010 article, which was not optimized away at the time of publication,
# so the example is actually not numerically stable, even though it should be.
@opt.register_stabilize
@gof.local_optimizer
([
tensor
.
mul
])
def
local_sigm_gest
(
node
):
print
"CANONICALIZE"
print
sigm_canonicalize
(
node
)
def
sigm_canonicalize
(
node
):
add
=
tensor
.
add
mul
=
tensor
.
mul
div
=
tensor
.
true_div
if
node
.
op
==
tensor
.
add
:
rval
=
[]
for
i
in
node
.
inputs
:
rval
+=
sigm_canonicalize
(
i
)
return
rval
if
node
.
op
==
tensor
.
mul
:
rval
=
sigm_canonicalize
(
node
.
inputs
[
0
])
for
i
in
node
.
inputs
[
1
:]:
old_rval
=
rval
rval
=
[]
for
t1
in
sigm_canonicalize
(
i
):
for
t0
in
old_rval
:
assert
t1
.
owner
.
op
==
div
assert
t0
.
owner
.
op
==
div
t0top
,
t0bot
=
t0
.
owner
.
inputs
t1top
,
t1bot
=
t1
.
owner
.
inputs
rval
.
append
(
div
(
mul
(
*
(
t0top
+
t1top
)),
mul
(
*
(
t0bot
+
t1bot
))))
if
len
(
rval
)
>
100
:
# This loop can be exponentially long.
# aborting
return
[]
elif
len
(
node
.
outputs
)
>
1
:
return
[]
else
:
return
[
node
.
outputs
[
0
]]
theano/tensor/opt.py
浏览文件 @
968f6f9a
...
...
@@ -194,6 +194,11 @@ def local_dimshuffle_lift(node):
register_canonicalize
(
local_dimshuffle_lift
)
register_specialize
(
local_dimshuffle_lift
)
@register_canonicalize
@local_optimizer
([])
def
local_dimshuffle_no_inplace_at_canonicalize
(
node
):
if
isinstance
(
node
.
op
,
T
.
DimShuffle
)
and
node
.
op
.
inplace
:
return
[
T
.
DimShuffle
(
node
.
op
.
input_broadcastable
,
node
.
op
.
new_order
,
inplace
=
False
)(
node
.
inputs
[
0
])]
#####################################
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论