Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bd168a56
提交
bd168a56
authored
7月 14, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3127 from harlouci/flake8_scalar
Flake8 scalar
上级
36d1eca8
64b59c00
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
58 行增加
和
62 行删除
+58
-62
basic.py
theano/scalar/basic.py
+32
-33
basic_scipy.py
theano/scalar/basic_scipy.py
+12
-12
basic_sympy.py
theano/scalar/basic_sympy.py
+5
-7
sharedvar.py
theano/scalar/sharedvar.py
+9
-6
test_flake8.py
theano/tests/test_flake8.py
+0
-4
没有找到文件。
theano/scalar/basic.py
浏览文件 @
bd168a56
...
...
@@ -247,8 +247,7 @@ class Scalar(Type):
'float64'
:
(
numpy
.
float64
,
'npy_float64'
,
'Float64'
),
'complex128'
:
(
numpy
.
complex128
,
'theano_complex128'
,
'Complex128'
),
'complex64'
:
(
numpy
.
complex64
,
'theano_complex64'
,
'Complex64'
),
'complex64'
:
(
numpy
.
complex64
,
'theano_complex64'
,
'Complex64'
),
'uint8'
:
(
numpy
.
uint8
,
'npy_uint8'
,
'UInt8'
),
'int8'
:
(
numpy
.
int8
,
'npy_int8'
,
'Int8'
),
'uint16'
:
(
numpy
.
uint16
,
'npy_uint16'
,
'UInt16'
),
...
...
@@ -421,12 +420,12 @@ class Scalar(Type):
{ this->real=y.real; this->imag=y.imag; return *this; }
'''
%
dict
(
mytype
=
mytype
,
othertype
=
othertype
)
operator_eq
=
''
.
join
(
operator_eq_real
(
ctype
,
rtype
)
operator_eq
=
(
''
.
join
(
operator_eq_real
(
ctype
,
rtype
)
for
ctype
in
cplx_types
for
rtype
in
real_types
)
\
+
''
.
join
(
operator_eq_cplx
(
ctype1
,
ctype2
)
for
rtype
in
real_types
)
+
''
.
join
(
operator_eq_cplx
(
ctype1
,
ctype2
)
for
ctype1
in
cplx_types
for
ctype2
in
cplx_types
)
for
ctype2
in
cplx_types
)
)
# We are not using C++ generic templating here, because this would
# generate two different functions for adding a complex64 and a
...
...
@@ -473,12 +472,12 @@ class Scalar(Type):
for
ctype
in
cplx_types
for
rtype
in
real_types
)
return
template
%
dict
(
nbits
=
64
,
half_nbits
=
32
)
\
+
template
%
dict
(
nbits
=
128
,
half_nbits
=
64
)
\
+
operator_eq
\
+
operator_plus
\
+
operator_minus
\
+
operator_mul
return
(
template
%
dict
(
nbits
=
64
,
half_nbits
=
32
)
+
template
%
dict
(
nbits
=
128
,
half_nbits
=
64
)
+
operator_eq
+
operator_plus
+
operator_minus
+
operator_mul
)
else
:
return
""
...
...
@@ -544,9 +543,9 @@ class _scalar_py_operators:
return
neg
(
self
)
# CASTS
#def __int__(self): return AsInt(self).out
#def __float__(self): return AsDouble(self).out
#def __complex__(self): return AsComplex(self).out
#
def __int__(self): return AsInt(self).out
#
def __float__(self): return AsDouble(self).out
#
def __complex__(self): return AsComplex(self).out
# BITWISE
def
__invert__
(
self
):
...
...
@@ -583,7 +582,7 @@ class _scalar_py_operators:
def
__ge__
(
self
,
other
):
return
ge
(
self
,
other
)
#ARITHMETIC - NORMAL
#
ARITHMETIC - NORMAL
def
__add__
(
self
,
other
):
return
add
(
self
,
other
)
...
...
@@ -609,7 +608,7 @@ class _scalar_py_operators:
def
__pow__
(
self
,
other
):
return
pow
(
self
,
other
)
#ARITHMETIC - RIGHT-OPERAND
#
ARITHMETIC - RIGHT-OPERAND
def
__radd__
(
self
,
other
):
return
add
(
other
,
self
)
...
...
@@ -891,9 +890,9 @@ class ScalarOp(Op):
self
.
__class__
.
__name__
)
def
__eq__
(
self
,
other
):
test
=
type
(
self
)
==
type
(
other
)
\
and
getattr
(
self
,
'output_types_preference'
,
None
)
\
==
getattr
(
other
,
'output_types_preference'
,
None
)
test
=
(
type
(
self
)
==
type
(
other
)
and
getattr
(
self
,
'output_types_preference'
,
None
)
==
getattr
(
other
,
'output_types_preference'
,
None
)
)
return
test
def
__hash__
(
self
):
...
...
@@ -1176,7 +1175,7 @@ class InRange(LogicalComparison):
cmp1
=
'>='
# backport
#cmp1 = '>' if self.openlow else '>='
#
cmp1 = '>' if self.openlow else '>='
if
self
.
openhi
:
cmp2
=
'<'
...
...
@@ -1184,14 +1183,14 @@ class InRange(LogicalComparison):
cmp2
=
'<='
# backport
#cmp2 = '<' if self.openhi else '<='
#
cmp2 = '<' if self.openhi else '<='
return
(
"
%(z)
s =
%(x)
s
%(cmp1)
s
%(low)
s &&"
"
%(x)
s
%(cmp2)
s
%(hi)
s;"
%
locals
())
def
get_grad
(
self
,
elem
):
if
elem
.
type
in
complex_types
:
msg
=
"No gradient implemented for complex numbers in
\
class scalar.basic.InRange"
msg
=
(
"No gradient implemented for complex numbers in "
"class scalar.basic.InRange"
)
raise
NotImplementedError
(
msg
)
elif
elem
.
type
in
discrete_types
:
return
elem
.
zeros_like
()
.
astype
(
theano
.
config
.
floatX
)
...
...
@@ -1473,7 +1472,7 @@ class Mul(ScalarOp):
# output is complex. The rest of this function make this supposition.
output_type
=
self
.
output_types
([
i
.
type
for
i
in
inputs
])[
0
]
if
output_type
in
complex_types
:
if
not
gz
.
type
in
complex_types
:
if
gz
.
type
not
in
complex_types
:
raise
TypeError
(
'Mul with output_type '
+
str
(
output_type
)
+
' expected gz type to be complex, got gz with type '
+
...
...
@@ -2201,7 +2200,7 @@ class RoundHalfToEven(UnaryScalarOp):
(
x
,)
=
inputs
(
z
,)
=
outputs
typ
=
node
.
outputs
[
0
]
.
type
.
dtype
if
not
typ
in
[
'float32'
,
'float64'
]:
if
typ
not
in
[
'float32'
,
'float64'
]:
Exception
(
"The output should be float32 or float64"
)
return
dedent
(
"""
...
...
@@ -3326,12 +3325,12 @@ class Composite(ScalarOp):
subd
[
output
]
=
name
_c_code
+=
"
%
s
%
s;
\n
"
%
(
output
.
type
.
dtype_specs
()[
1
],
name
)
s
=
node
.
op
.
c_code
(
node
,
s
=
node
.
op
.
c_code
(
node
,
self
.
nodenames
[
j
],
[
subd
[
input
]
for
input
in
node
.
inputs
],
[
subd
[
output
]
for
output
in
node
.
outputs
],
dict
(
fail
=
"
%(fail)
s"
,
id
=
"
%%(id)
s_
%
i"
%
j
))
dict
(
fail
=
"
%(fail)
s"
,
id
=
"
%%(id)
s_
%
i"
%
j
))
_c_code
+=
s
_c_code
+=
"
\n
"
_c_code
+=
"}
\n
"
...
...
@@ -3489,7 +3488,7 @@ class Composite(ScalarOp):
izip
((
"o
%
i"
%
i
for
i
in
xrange
(
len
(
onames
))),
onames
)),
**
sub
)
d
[
'nodename'
]
=
nodename
if
not
'id'
in
sub
:
if
'id'
not
in
sub
:
# The use of a dummy id is safe as the code is in a separate block.
# It won't generate conflicting variable name.
d
[
'id'
]
=
'_DUMMY_ID_'
...
...
@@ -3536,9 +3535,9 @@ class Composite(ScalarOp):
def
__eq__
(
self
,
other
):
if
self
is
other
:
return
True
if
(
type
(
self
)
!=
type
(
other
)
or
self
.
nin
!=
other
.
nin
or
self
.
nout
!=
other
.
nout
):
if
(
type
(
self
)
!=
type
(
other
)
or
self
.
nin
!=
other
.
nin
or
self
.
nout
!=
other
.
nout
):
return
False
# see __hash__ for comment on why there is no mention of fgraph
# or module cache key here.
...
...
theano/scalar/basic_scipy.py
浏览文件 @
bd168a56
...
...
@@ -296,17 +296,17 @@ class Psi(UnaryScalarOp):
def
c_support_code
(
self
):
return
(
"""
// For GPU support
#ifdef __CUDACC__
#define DEVICE __device__
#else
#define DEVICE
#endif
#ifndef _PSIFUNCDEFINED
#define _PSIFUNCDEFINED
DEVICE double _psi(double x){
"""
// For GPU support
#ifdef __CUDACC__
#define DEVICE __device__
#else
#define DEVICE
#endif
#ifndef _PSIFUNCDEFINED
#define _PSIFUNCDEFINED
DEVICE double _psi(double x){
/*taken from
Bernardo, J. M. (1976). Algorithm AS 103:
...
...
@@ -340,7 +340,7 @@ DEVICE double _psi(double x){
return psi_;}
#endif
"""
)
"""
)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
=
inp
...
...
theano/scalar/basic_sympy.py
浏览文件 @
bd168a56
import
numpy
as
np
import
itertools
as
it
from
theano.scalar.basic
import
Apply
,
ScalarOp
,
as_scalar
,
float64
,
float32
,
int64
from
theano.gof.utils
import
remove
imported_sympy
=
False
try
:
import
sympy
from
sympy.utilities.codegen
import
get_default_datatype
,
codegen
imported_sympy
=
True
except
ImportError
:
pass
import
itertools
as
it
names
=
(
"sympy_func_
%
d"
%
i
for
i
in
it
.
count
(
0
))
names
=
(
"sympy_func_
%
d"
%
i
for
i
in
it
.
count
(
0
))
def
include_line
(
line
):
...
...
@@ -64,8 +62,8 @@ class SymPyCCode(ScalarOp):
def
c_headers
(
self
):
c_code
=
self
.
_sympy_c_code
()
return
[
line
.
replace
(
"#include"
,
""
)
.
strip
()
for
line
in
c_code
.
split
(
'
\n
'
)
if
include_line
(
line
)
and
not
'project_name'
in
line
]
c_code
.
split
(
'
\n
'
)
if
include_line
(
line
)
and
'project_name'
not
in
line
]
def
c_code
(
self
,
node
,
name
,
input_names
,
output_names
,
sub
):
y
,
=
output_names
...
...
@@ -92,7 +90,7 @@ class SymPyCCode(ScalarOp):
def
grad
(
self
,
inputs
,
output_grads
):
return
[
SymPyCCode
(
self
.
inputs
,
self
.
expr
.
diff
(
inp
),
name
=
self
.
name
+
"_grad_
%
d"
%
i
)(
*
inputs
)
name
=
self
.
name
+
"_grad_
%
d"
%
i
)(
*
inputs
)
for
i
,
inp
in
enumerate
(
self
.
inputs
)]
def
_info
(
self
):
...
...
theano/scalar/sharedvar.py
浏览文件 @
bd168a56
...
...
@@ -14,6 +14,11 @@ default when calling theano.shared(value) then users must really go out of their
way (as scan does) to create a shared variable of this kind.
"""
import
numpy
from
theano.compile
import
SharedVariable
from
.basic
import
Scalar
,
_scalar_py_operators
__authors__
=
"James Bergstra"
__copyright__
=
"(c) 2010, Universite de Montreal"
__license__
=
"3-clause BSD License"
...
...
@@ -21,10 +26,6 @@ __contact__ = "theano-dev <theano-dev@googlegroups.com>"
__docformat__
=
"restructuredtext en"
import
numpy
from
theano.compile
import
SharedVariable
from
.basic
import
Scalar
,
_scalar_py_operators
class
ScalarSharedVariable
(
_scalar_py_operators
,
SharedVariable
):
pass
...
...
@@ -41,7 +42,7 @@ def shared(value, name=None, strict=False, allow_downcast=None):
:note: We implement this using 0-d tensors for now.
"""
if
not
isinstance
(
value
,
(
numpy
.
number
,
float
,
int
,
complex
)):
if
not
isinstance
(
value
,
(
numpy
.
number
,
float
,
int
,
complex
)):
raise
TypeError
()
try
:
dtype
=
value
.
dtype
...
...
@@ -54,5 +55,7 @@ def shared(value, name=None, strict=False, allow_downcast=None):
rval
=
ScalarSharedVariable
(
type
=
scalar_type
,
value
=
value
,
name
=
name
,
strict
=
strict
,
allow_downcast
=
allow_downcast
)
name
=
name
,
strict
=
strict
,
allow_downcast
=
allow_downcast
)
return
rval
theano/tests/test_flake8.py
浏览文件 @
bd168a56
...
...
@@ -114,11 +114,7 @@ whitelist_flake8 = [
"tensor/nnet/tests/test_conv3d.py"
,
"tensor/nnet/tests/speed_test_conv.py"
,
"tensor/nnet/tests/test_sigm.py"
,
"scalar/sharedvar.py"
,
"scalar/basic_scipy.py"
,
"scalar/basic_sympy.py"
,
"scalar/__init__.py"
,
"scalar/basic.py"
,
"scalar/tests/test_basic.py"
,
"sandbox/test_theano_object.py"
,
"sandbox/test_scan.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论