Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b39d1749
提交
b39d1749
authored
5月 22, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Flake8 for compile/ops.py
上级
9eced720
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
45 行删除
+57
-45
ops.py
theano/compile/ops.py
+57
-44
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/compile/ops.py
浏览文件 @
b39d1749
...
...
@@ -71,12 +71,13 @@ class ViewOp(gof.Op):
version
=
[]
# If any of the c code is unversionned, we have to return ()
# Else, we will return a list of (type name, version) pairs.
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
if
not
v
:
warnings
.
warn
(
"Type
%
s has C code for ViewOp, but it has "
"no version. You should add a 'version' keyword arg
"
"
when calling register_view_op_c_code."
%
t
,
stacklevel
=
2
)
warnings
.
warn
(
"Type
%
s has C code for ViewOp, but it has
no
"
"version. You should add a 'version' keyword
"
"arg
when calling register_view_op_c_code."
%
t
,
stacklevel
=
2
)
return
()
version
.
append
((
str
(
t
),
v
))
...
...
@@ -165,12 +166,14 @@ class DeepCopyOp(gof.Op):
version
=
[]
# If any of the c code is unversionned, we have to return ()
# Else, we will return a list of (type name, version) pairs.
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
if
not
v
:
warnings
.
warn
(
"Type
%
s has C code for DeepCopyOp, but it has "
"no version. You should add a 'version' keyword arg "
"when calling register_deep_copy_op_c_code."
%
t
,
stacklevel
=
2
)
"no version. You should add a 'version' keyword"
" arg when calling "
"register_deep_copy_op_c_code."
%
t
,
stacklevel
=
2
)
return
()
version
.
append
((
str
(
t
),
v
))
...
...
@@ -284,12 +287,13 @@ class Shape(gof.Op):
version
=
[]
# If any of the c code is unversionned, we have to return ()
# Else, we will return a list of (type name, version) pairs.
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
if
not
v
:
warnings
.
warn
(
"Type
%
s has C code for Shape, but it has "
"no version. You should add a 'version' keyword arg
"
"
when calling register_shape_c_code."
%
t
,
stacklevel
=
2
)
warnings
.
warn
(
"Type
%
s has C code for Shape, but it has
no
"
"version. You should add a 'version' keyword
"
"arg
when calling register_shape_c_code."
%
t
,
stacklevel
=
2
)
return
()
version
.
append
((
str
(
t
),
v
))
...
...
@@ -301,7 +305,6 @@ class Shape(gof.Op):
shape
=
Shape
()
_shape
=
shape
# was used in the past, now use shape directly.
#pprint.assign(_shape, printing.MemberPrinter('shape'))
class
Shape_i
(
gof
.
Op
):
...
...
@@ -389,8 +392,11 @@ class Shape_i(gof.Op):
return
[()]
def
grad
(
self
,
inp
,
grads
):
return
[
theano
.
gradient
.
grad_not_implemented
(
op
=
self
,
x_pos
=
0
,
x
=
inp
[
0
],
comment
=
"No gradient for the shape of a matrix is implemented."
)]
return
[
theano
.
gradient
.
grad_not_implemented
(
op
=
self
,
x_pos
=
0
,
x
=
inp
[
0
],
comment
=
(
"No gradient for the shape of a matrix "
"is implemented."
))]
def
shape_i
(
var
,
i
,
fgraph
=
None
):
"""Equivalent of var.shape[i], but apply if possible the shape
...
...
@@ -421,7 +427,7 @@ def shape_i(var, i, fgraph=None):
# If the output var isn't marked as being in the graph,
# we need to att it in the ShapeFeature.
shape_feature
.
on_import
(
fgraph
,
node
,
'gof.ops.shape_i'
)
'gof.ops.shape_i'
)
if
var
not
in
shape_of
:
recur
(
var
.
owner
)
return
shape_of
[
var
][
i
]
...
...
@@ -435,9 +441,10 @@ def shape_i(var, i, fgraph=None):
def
register_shape_i_c_code
(
typ
,
code
,
check_input
,
version
=
()):
""" Tell Shape_i how to generate C code for a Theano Type
:param typ: A Theano type. It must be the Theano class itself and not an
instance of the class.
:param code: C code that gets the shape of dimensions
%(i)
s for the Theano type 'typ'.
:param typ: A Theano type. It must be the Theano class itself and not
an instance of the class.
:param code: C code that gets the shape of dimensions
%(i)
s for the
Theano type 'typ'.
Use
%(iname)
s and
%(oname)
s for the input and output C
variable names respectively.
:param version: A number indicating the version of the code, for cache.
...
...
@@ -620,7 +627,8 @@ class Rebroadcast(gof.Op):
return
type
(
self
)
==
type
(
other
)
and
self
.
axis
==
other
.
axis
def
__hash__
(
self
):
items
=
sorted
(
self
.
axis
.
iteritems
())
# no ambiguity because each item key is unique
# no ambiguity because each item key is unique
items
=
sorted
(
self
.
axis
.
iteritems
())
return
hash
((
type
(
self
),
tuple
(
items
)))
def
__str__
(
self
):
...
...
@@ -637,9 +645,9 @@ class Rebroadcast(gof.Op):
def
make_node
(
self
,
x
):
if
self
.
axis
.
keys
()
and
(
x
.
ndim
<=
numpy
.
max
(
self
.
axis
.
keys
())):
raise
ValueError
(
'Trying to rebroadcast non-existent dimension'
)
t
=
x
.
type
.
clone
(
broadcastable
=
[
self
.
axis
.
get
(
i
,
b
)
for
i
,
b
in
enumerate
(
x
.
type
.
broadcastable
)])
t
=
x
.
type
.
clone
(
broadcastable
=
[
self
.
axis
.
get
(
i
,
b
)
for
i
,
b
in
enumerate
(
x
.
type
.
broadcastable
)])
return
gof
.
Apply
(
self
,
[
x
],
[
t
()])
def
perform
(
self
,
node
,
inp
,
out_
):
...
...
@@ -702,10 +710,11 @@ class Rebroadcast(gof.Op):
for
t
,
(
c
,
v
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
if
not
v
:
warnings
.
warn
(
"Type
%
s has C code for Rebroadcast, but it has "
"no version. You should add a 'version' keyword arg "
"when calling register_rebroadcast_c_code."
%
t
,
stacklevel
=
2
)
warnings
.
warn
(
"Type
%
s has C code for Rebroadcast, but it "
"has no version. You should add a 'version' "
"keyword arg when calling "
"register_rebroadcast_c_code."
%
t
,
stacklevel
=
2
)
return
()
version
.
append
((
str
(
t
),
v
))
...
...
@@ -718,17 +727,18 @@ def register_specify_shape_c_code(typ, code, version=(),
c_support_code_apply
=
None
):
""" Tell SpecifyShape how to generate C code for a Theano Type
:param typ: A Theano type. It must be the Theano class itself and
not an
instance of the class.
:param code: C code that checks the shape and returns a view for
the Theano type 'typ'.
Use
%(iname)
s and
%(oname)
s for the input and output C
variable names respectively.
%(shape)
s is the vector of shape of
%(iname)
s.
Check that its length is good.
:param typ: A Theano type. It must be the Theano class itself and
not an
instance of the class.
:param code: C code that checks the shape and returns a view for
the Theano type 'typ'. Use
%(iname)
s and
%(oname)
s
for the input and output C variable names
respectively.
%(shape)
s is the vector of shape of
%(iname)
s.
Check that its length is good.
:param version: A number indicating the version of the code, for cache.
:param c_support_code_apply: extra code.
"""
SpecifyShape
.
c_code_and_version
[
typ
]
=
(
code
,
version
,
c_support_code_apply
)
SpecifyShape
.
c_code_and_version
[
typ
]
=
(
code
,
version
,
c_support_code_apply
)
class
SpecifyShape
(
gof
.
Op
):
...
...
@@ -784,7 +794,8 @@ class SpecifyShape(gof.Op):
new_shape
=
[]
for
dim
in
xrange
(
node
.
inputs
[
0
]
.
ndim
):
try
:
s
=
theano
.
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
1
][
dim
])
s
=
theano
.
tensor
.
get_scalar_constant_value
(
node
.
inputs
[
1
][
dim
])
s
=
theano
.
tensor
.
as_tensor_variable
(
s
)
new_shape
.
append
(
s
)
except
theano
.
tensor
.
NotScalarConstantError
:
...
...
@@ -832,19 +843,21 @@ class SpecifyShape(gof.Op):
code
,
version
,
_
=
self
.
c_code_and_version
[
itype
]
return
code
%
locals
()
return
super
(
SpecifyShape
,
self
)
.
c_code
(
node
,
node
,
inames
,
onames
,
sub
)
return
super
(
SpecifyShape
,
self
)
.
c_code
(
node
,
node
,
inames
,
onames
,
sub
)
def
c_code_cache_version
(
self
):
version
=
[]
# If any of the c code is unversionned, we have to return ()
# Else, we will return a list of (type name, version) pairs.
for
t
,
(
c
,
v
,
_
)
in
sorted
(
self
.
c_code_and_version
.
items
(),
key
=
lambda
pair
:
str
(
pair
[
0
])):
key
=
lambda
pair
:
str
(
pair
[
0
])):
if
not
v
:
warnings
.
warn
(
"Type
%
s has C code for SpecifyShape, but it has "
"no version. You should add a 'version' keyword arg "
"when calling register_specify_shape_c_code."
%
t
,
stacklevel
=
2
)
warnings
.
warn
(
"Type
%
s has C code for SpecifyShape, but it "
"has no version. You should add a 'version' "
"keyword arg when calling "
"register_specify_shape_c_code."
%
t
,
stacklevel
=
2
)
return
()
version
.
append
((
str
(
t
),
v
))
...
...
theano/tests/test_flake8.py
浏览文件 @
b39d1749
...
...
@@ -38,7 +38,6 @@ whitelist_flake8 = [
"tests/test_tutorial.py"
,
"tests/disturb_mem.py"
,
"tests/unittest_tools.py"
,
"compile/ops.py"
,
"compile/debugmode.py"
,
"compile/function.py"
,
"compile/pfunc.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论