Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
26ad0835
提交
26ad0835
authored
7月 18, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #749 from nouiz/small
Small
上级
49add2d8
69354dd0
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
108 行增加
和
55 行删除
+108
-55
mode.py
theano/compile/mode.py
+1
-1
printing.py
theano/printing.py
+29
-6
test_scan.py
theano/scan_module/tests/test_scan.py
+5
-11
blas.py
theano/tensor/blas.py
+3
-3
test_casting.py
theano/tensor/tests/test_casting.py
+42
-34
test_printing.py
theano/tests/test_printing.py
+28
-0
没有找到文件。
theano/compile/mode.py
浏览文件 @
26ad0835
...
...
@@ -367,7 +367,7 @@ class Mode(object):
# FunctionMaker, the Mode will be taken from this dictionary using the
# string as the key
FAST_COMPILE
=
Mode
(
'py'
,
'fast_compile'
)
FAST_RUN
=
Mode
(
'c
|py
'
,
'fast_run'
)
FAST_RUN
=
Mode
(
'c
vm
'
,
'fast_run'
)
predefined_modes
=
{
'FAST_COMPILE'
:
FAST_COMPILE
,
'FAST_RUN'
:
FAST_RUN
,
...
...
theano/printing.py
浏览文件 @
26ad0835
...
...
@@ -479,10 +479,10 @@ def pydotprint(fct, outfile=None,
high_contrast
=
True
,
cond_highlight
=
None
,
colorCodes
=
None
,
max_label_size
=
50
,
scan_graphs
=
False
,
var_with_name_simple
=
False
,
print_output_file
=
True
print_output_file
=
True
,
assert_nb_all_strings
=-
1
):
"""
print to a file in png format the graph of op of a compile theano fct.
"""print to a file in png format the graph of op of a compile theano fct.
:param fct: the theano fct returned by theano.function.
:param outfile: the output file where to put the graph.
...
...
@@ -509,6 +509,10 @@ def pydotprint(fct, outfile=None,
:param var_with_name_simple: If true and a variable have a name,
we will print only the variable name.
Otherwise, we concatenate the type to the var name.
:param assert_nb_all_strings: Used for tests. This assert the
number of uniq string node in the dot graph. This is
used in tests to verify that dot won't merge Theano
node.
In the graph, ellipses are Apply Nodes (the execution of an op)
and boxes are variables. If variables have names they are used as
...
...
@@ -526,6 +530,7 @@ def pydotprint(fct, outfile=None,
grey boxes are variables that are not outputs and are not used
red ellipses are transfers from/to the gpu (ops with names GpuFromHost,
HostFromGpu)
"""
if
colorCodes
is
None
:
colorCodes
=
default_colorCodes
...
...
@@ -622,6 +627,13 @@ def pydotprint(fct, outfile=None,
varstr
=
varstr
+
idx
elif
len
(
varstr
)
>
max_label_size
:
varstr
=
varstr
[:
max_label_size
-
3
]
+
'...'
idx
=
1
while
varstr
in
all_strings
:
idx
+=
1
suffix
=
' id='
+
str
(
idx
)
varstr
=
(
varstr
[:
max_label_size
-
3
-
len
(
suffix
)]
+
'...'
+
suffix
)
var_str
[
var
]
=
varstr
all_strings
.
add
(
varstr
)
...
...
@@ -656,6 +668,13 @@ def pydotprint(fct, outfile=None,
applystr
=
applystr
+
idx
elif
len
(
applystr
)
>
max_label_size
:
applystr
=
applystr
[:
max_label_size
-
3
]
+
'...'
idx
=
1
while
applystr
in
all_strings
:
idx
+=
1
suffix
=
' id='
+
str
(
idx
)
applystr
=
(
applystr
[:
max_label_size
-
3
-
len
(
suffix
)]
+
'...'
+
suffix
)
all_strings
.
add
(
applystr
)
apply_name_cache
[
node
]
=
applystr
...
...
@@ -698,10 +717,10 @@ def pydotprint(fct, outfile=None,
for
id
,
var
in
enumerate
(
node
.
inputs
):
varstr
=
var_name
(
var
)
label
=
str
(
var
.
type
)
if
len
(
label
)
>
max_label_size
:
label
=
label
[:
max_label_size
-
3
]
+
'...'
if
len
(
node
.
inputs
)
>
1
:
label
=
str
(
id
)
+
' '
+
label
if
len
(
label
)
>
max_label_size
:
label
=
label
[:
max_label_size
-
3
]
+
'...'
if
var
.
owner
is
None
:
if
high_contrast
:
g
.
add_node
(
pd
.
Node
(
varstr
,
...
...
@@ -751,10 +770,14 @@ def pydotprint(fct, outfile=None,
if
not
outfile
.
endswith
(
'.'
+
format
):
outfile
+=
'.'
+
format
g
.
write
(
outfile
,
prog
=
'dot'
,
format
=
format
)
g
.
write
(
outfile
,
prog
=
'dot'
,
format
=
format
)
if
print_output_file
:
print
'The output file is available at'
,
outfile
if
assert_nb_all_strings
!=
-
1
:
assert
len
(
all_strings
)
==
assert_nb_all_strings
if
scan_graphs
:
scan_ops
=
[(
idx
,
x
)
for
idx
,
x
in
enumerate
(
fct_fgraph
.
toposort
())
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
26ad0835
...
...
@@ -3217,9 +3217,6 @@ def test_speed_rnn():
# multiplication - the heart of an ESN or RNN.
#
import
theano.scalar.sharedvar
print
"""Warning: the updates version runs slower than python because by
default the blas optimizations don't replace dot with dot22.
Why is that?"""
L
=
10000
N
=
50
...
...
@@ -3267,15 +3264,15 @@ def test_speed_rnn():
s_i
:
s_i
+
1
,
shared_r
:
s_rinc
},
mode
=
theano
.
Mode
(
linker
=
'cvm'
))
theano
.
printing
.
debugprint
(
f
)
#
theano.printing.debugprint(f)
f_fn
=
f
.
fn
print
f_fn
#
print f_fn
t2
=
time
.
time
()
f_fn
(
n_calls
=
L
-
2
)
f
()
# 999 to update the profiling timers
t3
=
time
.
time
()
print
'theano (updates, cvm)'
,
t3
-
t2
print
shared_r
.
get_value
()
#
print shared_r.get_value()
def
test_speed_batchrnn
():
...
...
@@ -3296,9 +3293,6 @@ def test_speed_batchrnn():
# multiplication - the heart of an ESN or RNN.
#
import
theano.scalar.sharedvar
print
"""Warning: the updates version runs slower than python because by
default the blas optimizations don't replace dot with dot22.
Why is that?"""
L
=
100
B
=
50
...
...
@@ -3333,9 +3327,9 @@ def test_speed_batchrnn():
s_i
:
s_i
+
1
,
shared_r
:
s_rinc
},
mode
=
theano
.
Mode
(
linker
=
'cvm'
))
theano
.
printing
.
debugprint
(
f
)
#
theano.printing.debugprint(f)
f_fn
=
f
.
fn
print
f_fn
#
print f_fn
t2
=
time
.
time
()
f_fn
(
n_calls
=
L
-
2
)
f
()
# 999 to update the profiling timers
...
...
theano/tensor/blas.py
浏览文件 @
26ad0835
...
...
@@ -1350,6 +1350,7 @@ class GemmOptimizer(Optimizer):
"""Graph optimizer for inserting Gemm operations"""
def
__init__
(
self
):
Optimizer
.
__init__
(
self
)
self
.
warned
=
False
def
add_requirements
(
self
,
fgraph
):
fgraph
.
extend
(
toolbox
.
ReplaceValidate
())
...
...
@@ -1398,7 +1399,7 @@ class GemmOptimizer(Optimizer):
zip
(
node
.
outputs
,
new_outputs
),
[
old_dot22
],
reason
=
'GemmOptimizer'
,
warn
=
n
b_replacement_didn_t_remove
==
0
warn
=
n
ot
self
.
warned
)
did_something
=
True
nb_replacement
+=
1
...
...
@@ -1406,10 +1407,9 @@ class GemmOptimizer(Optimizer):
# TODO: retry other applications of gemm (see comment
# in _gemm_from_node)
nb_inconsistency_replace
+=
1
pass
except
ReplacementDidntRemovedError
,
e
:
nb_replacement_didn_t_remove
+=
1
pass
self
.
warned
=
True
nb_iter
+=
1
return
(
self
,
nb_iter
,
nb_replacement
,
nb_replacement_didn_t_remove
,
nb_inconsistency_make
,
nb_inconsistency_replace
,
...
...
theano/tensor/tests/test_casting.py
浏览文件 @
26ad0835
import
unittest
from
theano
import
function
from
theano.tensor.basic
import
(
_convert_to_int32
,
_convert_to_int8
,
_convert_to_int16
,
_convert_to_int64
,
_convert_to_float32
,
_convert_to_float64
)
from
theano.tensor.basic
import
(
_convert_to_int32
,
_convert_to_int8
,
_convert_to_int16
,
_convert_to_int64
,
_convert_to_float32
,
_convert_to_float64
)
from
theano.tensor
import
*
class
test_casting
(
unittest
.
TestCase
):
def
test_0
(
self
):
for
op_fn
in
_convert_to_int32
,
_convert_to_float32
,
_convert_to_float64
:
for
op_fn
in
[
_convert_to_int32
,
_convert_to_float32
,
_convert_to_float64
]:
for
type_fn
in
bvector
,
ivector
,
fvector
,
dvector
:
x
=
type_fn
()
f
=
function
([
x
],
op_fn
(
x
))
xval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
10
)
*
10
,
dtype
=
type_fn
.
dtype
)
xval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
10
)
*
10
,
dtype
=
type_fn
.
dtype
)
yval
=
f
(
xval
)
assert
str
(
yval
.
dtype
)
==
op_fn
.
scalar_op
.
output_types_preference
.
spec
[
0
]
.
dtype
assert
(
str
(
yval
.
dtype
)
==
op_fn
.
scalar_op
.
output_types_preference
.
spec
[
0
]
.
dtype
)
def
test_illegal
(
self
):
try
:
x
=
zmatrix
()
function
([
x
],
cast
(
x
,
'float64'
))(
numpy
.
ones
((
2
,
3
),
dtype
=
'complex128'
))
function
([
x
],
cast
(
x
,
'float64'
))(
numpy
.
ones
((
2
,
3
),
dtype
=
'complex128'
))
except
TypeError
:
return
assert
0
def
test_basic
(
self
):
for
type1
in
[
'uint8'
,
'uint16'
,
'uint32'
,
'uint64'
,
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
]:
x
=
TensorType
(
dtype
=
type1
,
broadcastable
=
(
False
,
))
.
make_variable
()
for
type2
,
converter
in
zip
([
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
],
for
type1
in
[
'uint8'
,
'uint16'
,
'uint32'
,
'uint64'
,
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
]:
x
=
TensorType
(
dtype
=
type1
,
broadcastable
=
(
False
,
))
.
make_variable
()
for
type2
,
converter
in
zip
([
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
],
[
_convert_to_int8
,
_convert_to_int16
,
_convert_to_int32
,
_convert_to_int64
,
_convert_to_float32
,
_convert_to_float64
]):
_convert_to_int32
,
_convert_to_int64
,
_convert_to_float32
,
_convert_to_float64
]):
y
=
converter
(
x
)
f
=
function
([
compile
.
In
(
x
,
strict
=
True
)],
y
)
a
=
numpy
.
arange
(
10
,
dtype
=
type1
)
f
=
function
([
compile
.
In
(
x
,
strict
=
True
)],
y
)
a
=
numpy
.
arange
(
10
,
dtype
=
type1
)
b
=
f
(
a
)
self
.
assertTrue
(
numpy
.
all
(
b
==
numpy
.
arange
(
10
,
dtype
=
type2
)))
self
.
assertTrue
(
numpy
.
all
(
b
==
numpy
.
arange
(
10
,
dtype
=
type2
)))
def
test_convert_to_complex
(
self
):
val64
=
numpy
.
ones
(
3
,
dtype
=
'complex64'
)
+
0.5
j
val128
=
numpy
.
ones
(
3
,
dtype
=
'complex128'
)
+
0.5
j
vec64
=
TensorType
(
'complex64'
,
(
False
,
))()
vec128
=
TensorType
(
'complex128'
,
(
False
,
))()
vec64
=
TensorType
(
'complex64'
,
(
False
,
))()
vec128
=
TensorType
(
'complex128'
,
(
False
,
))()
f
=
function
([
vec64
],
basic
.
_convert_to_complex128
(
vec64
))
f
=
function
([
vec64
],
basic
.
_convert_to_complex128
(
vec64
))
#we need to compare with the same type.
assert
vec64
.
type
.
values_eq_approx
(
val128
,
f
(
val64
))
f
=
function
([
vec128
],
basic
.
_convert_to_complex128
(
vec128
))
f
=
function
([
vec128
],
basic
.
_convert_to_complex128
(
vec128
))
assert
vec64
.
type
.
values_eq_approx
(
val128
,
f
(
val128
))
f
=
function
([
vec64
],
basic
.
_convert_to_complex64
(
vec64
))
f
=
function
([
vec64
],
basic
.
_convert_to_complex64
(
vec64
))
assert
vec64
.
type
.
values_eq_approx
(
val64
,
f
(
val64
))
f
=
function
([
vec128
],
basic
.
_convert_to_complex64
(
vec128
))
f
=
function
([
vec128
],
basic
.
_convert_to_complex64
(
vec128
))
assert
vec128
.
type
.
values_eq_approx
(
val64
,
f
(
val128
))
# upcasting to complex128
for
t
in
[
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
]:
a
=
shared
(
numpy
.
ones
(
3
,
dtype
=
t
))
b
=
shared
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
f
=
function
([],
basic
.
_convert_to_complex128
(
a
))
for
t
in
[
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
,
'float64'
]:
a
=
theano
.
shared
(
numpy
.
ones
(
3
,
dtype
=
t
))
b
=
theano
.
shared
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
f
=
function
([],
basic
.
_convert_to_complex128
(
a
))
assert
a
.
type
.
values_eq_approx
(
b
.
get_value
(),
f
())
# upcasting to complex64
for
t
in
[
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
]:
a
=
shared
(
numpy
.
ones
(
3
,
dtype
=
t
))
b
=
shared
(
numpy
.
ones
(
3
,
dtype
=
'complex64'
))
f
=
function
([],
basic
.
_convert_to_complex64
(
a
))
for
t
in
[
'int8'
,
'int16'
,
'int32'
,
'int64'
,
'float32'
]:
a
=
theano
.
shared
(
numpy
.
ones
(
3
,
dtype
=
t
))
b
=
theano
.
shared
(
numpy
.
ones
(
3
,
dtype
=
'complex64'
))
f
=
function
([],
basic
.
_convert_to_complex64
(
a
))
assert
a
.
type
.
values_eq_approx
(
b
.
get_value
(),
f
())
# downcast to complex64
for
t
in
[
'float64'
]:
a
=
shared
(
numpy
.
ones
(
3
,
dtype
=
t
))
b
=
shared
(
numpy
.
ones
(
3
,
dtype
=
'complex64'
))
f
=
function
([],
basic
.
_convert_to_complex64
(
a
))
a
=
theano
.
shared
(
numpy
.
ones
(
3
,
dtype
=
t
))
b
=
theano
.
shared
(
numpy
.
ones
(
3
,
dtype
=
'complex64'
))
f
=
function
([],
basic
.
_convert_to_complex64
(
a
))
assert
a
.
type
.
values_eq_approx
(
b
.
get_value
(),
f
())
def
test_bug_complext_10_august_09
(
self
):
v0
=
dmatrix
()
v1
=
basic
.
_convert_to_complex128
(
v0
)
...
...
@@ -87,5 +95,5 @@ class test_casting(unittest.TestCase):
inputs
=
[
v0
]
outputs
=
[
v1
]
f
=
function
(
inputs
,
outputs
)
i
=
numpy
.
zeros
((
2
,
2
))
assert
(
f
(
i
)
==
numpy
.
zeros
((
2
,
2
)))
.
all
()
i
=
numpy
.
zeros
((
2
,
2
))
assert
(
f
(
i
)
==
numpy
.
zeros
((
2
,
2
)))
.
all
()
theano/tests/test_printing.py
浏览文件 @
26ad0835
...
...
@@ -47,6 +47,34 @@ def test_pydotprint_cond_highlight():
' is no IfElse node in the graph
\n
'
)
def
test_pydotprint_long_name
():
"""This is a REALLY PARTIAL TEST.
It print a graph where there is variable and apply node that
there too long name is different, but not the shortened name.
We should not merge those node in the dot graph.
"""
# Skip test if pydot is not available.
if
not
theano
.
printing
.
pydot_imported
:
raise
SkipTest
(
'pydot not available'
)
x
=
tensor
.
dvector
()
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
"fusion"
)
f
=
theano
.
function
([
x
],
[
x
*
2
,
x
+
x
],
mode
=
mode
)
f
([
1
,
2
,
3
,
4
])
s
=
StringIO
.
StringIO
()
new_handler
=
logging
.
StreamHandler
(
s
)
new_handler
.
setLevel
(
logging
.
DEBUG
)
orig_handler
=
theano
.
logging_default_handler
theano
.
printing
.
pydotprint
(
f
,
max_label_size
=
5
,
print_output_file
=
False
,
assert_nb_all_strings
=
6
)
def
test_pydotprint_profile
():
"""Just check that pydotprint does not crash with ProfileMode."""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论