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 个修改的文件
包含
65 行增加
和
68 行删除
+65
-68
basic.py
theano/scalar/basic.py
+0
-0
basic_scipy.py
theano/scalar/basic_scipy.py
+45
-45
basic_sympy.py
theano/scalar/basic_sympy.py
+7
-9
sharedvar.py
theano/scalar/sharedvar.py
+13
-10
test_flake8.py
theano/tests/test_flake8.py
+0
-4
没有找到文件。
theano/scalar/basic.py
浏览文件 @
bd168a56
差异被折叠。
点击展开。
theano/scalar/basic_scipy.py
浏览文件 @
bd168a56
...
@@ -296,51 +296,51 @@ class Psi(UnaryScalarOp):
...
@@ -296,51 +296,51 @@ class Psi(UnaryScalarOp):
def
c_support_code
(
self
):
def
c_support_code
(
self
):
return
(
return
(
"""
"""
// For GPU support
// For GPU support
#ifdef __CUDACC__
#ifdef __CUDACC__
#define DEVICE __device__
#define DEVICE __device__
#else
#else
#define DEVICE
#define DEVICE
#endif
#endif
#ifndef _PSIFUNCDEFINED
#ifndef _PSIFUNCDEFINED
#define _PSIFUNCDEFINED
#define _PSIFUNCDEFINED
DEVICE double _psi(double x){
DEVICE double _psi(double x){
/*taken from
/*taken from
Bernardo, J. M. (1976). Algorithm AS 103:
Bernardo, J. M. (1976). Algorithm AS 103:
Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317.
Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317.
http://www.uv.es/~bernardo/1976AppStatist.pdf */
http://www.uv.es/~bernardo/1976AppStatist.pdf */
double y, R, psi_ = 0;
double y, R, psi_ = 0;
double S = 1.0e-5;
double S = 1.0e-5;
double C = 8.5;
double C = 8.5;
double S3 = 8.333333333e-2;
double S3 = 8.333333333e-2;
double S4 = 8.333333333e-3;
double S4 = 8.333333333e-3;
double S5 = 3.968253968e-3;
double S5 = 3.968253968e-3;
double D1 = -0.5772156649;
double D1 = -0.5772156649;
y = x;
y = x;
if (y <= 0.0)
if (y <= 0.0)
return psi_;
return psi_;
if (y <= S )
if (y <= S )
return D1 - 1.0/y;
return D1 - 1.0/y;
while (y < C){
while (y < C){
psi_ = psi_ - 1.0 / y;
psi_ = psi_ - 1.0 / y;
y = y + 1;}
y = y + 1;}
R = 1.0 / y;
R = 1.0 / y;
psi_ = psi_ + log(y) - .5 * R ;
psi_ = psi_ + log(y) - .5 * R ;
R= R*R;
R= R*R;
psi_ = psi_ - R * (S3 - R * (S4 - R * S5));
psi_ = psi_ - R * (S3 - R * (S4 - R * S5));
return psi_;}
return psi_;}
#endif
#endif
"""
)
"""
)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x
,
=
inp
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.scalar.basic
import
Apply
,
ScalarOp
,
as_scalar
,
float64
,
float32
,
int64
from
theano.gof.utils
import
remove
from
theano.gof.utils
import
remove
imported_sympy
=
False
imported_sympy
=
False
try
:
try
:
import
sympy
from
sympy.utilities.codegen
import
get_default_datatype
,
codegen
from
sympy.utilities.codegen
import
get_default_datatype
,
codegen
imported_sympy
=
True
imported_sympy
=
True
except
ImportError
:
except
ImportError
:
pass
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
):
def
include_line
(
line
):
...
@@ -53,8 +51,8 @@ class SymPyCCode(ScalarOp):
...
@@ -53,8 +51,8 @@ class SymPyCCode(ScalarOp):
def
_sympy_c_code
(
self
):
def
_sympy_c_code
(
self
):
[(
c_name
,
c_code
),
(
h_name
,
c_header
)]
=
codegen
(
[(
c_name
,
c_code
),
(
h_name
,
c_header
)]
=
codegen
(
(
self
.
name
,
self
.
expr
),
'C'
,
'project_name'
,
(
self
.
name
,
self
.
expr
),
'C'
,
'project_name'
,
header
=
False
,
argument_sequence
=
self
.
inputs
)
header
=
False
,
argument_sequence
=
self
.
inputs
)
return
c_code
return
c_code
def
c_support_code
(
self
):
def
c_support_code
(
self
):
...
@@ -64,8 +62,8 @@ class SymPyCCode(ScalarOp):
...
@@ -64,8 +62,8 @@ class SymPyCCode(ScalarOp):
def
c_headers
(
self
):
def
c_headers
(
self
):
c_code
=
self
.
_sympy_c_code
()
c_code
=
self
.
_sympy_c_code
()
return
[
line
.
replace
(
"#include"
,
""
)
.
strip
()
for
line
in
return
[
line
.
replace
(
"#include"
,
""
)
.
strip
()
for
line
in
c_code
.
split
(
'
\n
'
)
if
include_line
(
line
)
c_code
.
split
(
'
\n
'
)
if
include_line
(
line
)
and
and
not
'project_name'
in
line
]
'project_name'
not
in
line
]
def
c_code
(
self
,
node
,
name
,
input_names
,
output_names
,
sub
):
def
c_code
(
self
,
node
,
name
,
input_names
,
output_names
,
sub
):
y
,
=
output_names
y
,
=
output_names
...
@@ -92,7 +90,7 @@ class SymPyCCode(ScalarOp):
...
@@ -92,7 +90,7 @@ class SymPyCCode(ScalarOp):
def
grad
(
self
,
inputs
,
output_grads
):
def
grad
(
self
,
inputs
,
output_grads
):
return
[
SymPyCCode
(
self
.
inputs
,
return
[
SymPyCCode
(
self
.
inputs
,
self
.
expr
.
diff
(
inp
),
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
)]
for
i
,
inp
in
enumerate
(
self
.
inputs
)]
def
_info
(
self
):
def
_info
(
self
):
...
...
theano/scalar/sharedvar.py
浏览文件 @
bd168a56
...
@@ -14,17 +14,18 @@ default when calling theano.shared(value) then users must really go out of their
...
@@ -14,17 +14,18 @@ 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.
way (as scan does) to create a shared variable of this kind.
"""
"""
__authors__
=
"James Bergstra"
__copyright__
=
"(c) 2010, Universite de Montreal"
__license__
=
"3-clause BSD License"
__contact__
=
"theano-dev <theano-dev@googlegroups.com>"
__docformat__
=
"restructuredtext en"
import
numpy
import
numpy
from
theano.compile
import
SharedVariable
from
theano.compile
import
SharedVariable
from
.basic
import
Scalar
,
_scalar_py_operators
from
.basic
import
Scalar
,
_scalar_py_operators
__authors__
=
"James Bergstra"
__copyright__
=
"(c) 2010, Universite de Montreal"
__license__
=
"3-clause BSD License"
__contact__
=
"theano-dev <theano-dev@googlegroups.com>"
__docformat__
=
"restructuredtext en"
class
ScalarSharedVariable
(
_scalar_py_operators
,
SharedVariable
):
class
ScalarSharedVariable
(
_scalar_py_operators
,
SharedVariable
):
pass
pass
...
@@ -41,7 +42,7 @@ def shared(value, name=None, strict=False, allow_downcast=None):
...
@@ -41,7 +42,7 @@ def shared(value, name=None, strict=False, allow_downcast=None):
:note: We implement this using 0-d tensors for now.
: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
()
raise
TypeError
()
try
:
try
:
dtype
=
value
.
dtype
dtype
=
value
.
dtype
...
@@ -52,7 +53,9 @@ def shared(value, name=None, strict=False, allow_downcast=None):
...
@@ -52,7 +53,9 @@ def shared(value, name=None, strict=False, allow_downcast=None):
value
=
getattr
(
numpy
,
dtype
)(
value
)
value
=
getattr
(
numpy
,
dtype
)(
value
)
scalar_type
=
Scalar
(
dtype
=
dtype
)
scalar_type
=
Scalar
(
dtype
=
dtype
)
rval
=
ScalarSharedVariable
(
rval
=
ScalarSharedVariable
(
type
=
scalar_type
,
type
=
scalar_type
,
value
=
value
,
value
=
value
,
name
=
name
,
strict
=
strict
,
allow_downcast
=
allow_downcast
)
name
=
name
,
strict
=
strict
,
allow_downcast
=
allow_downcast
)
return
rval
return
rval
theano/tests/test_flake8.py
浏览文件 @
bd168a56
...
@@ -114,11 +114,7 @@ whitelist_flake8 = [
...
@@ -114,11 +114,7 @@ whitelist_flake8 = [
"tensor/nnet/tests/test_conv3d.py"
,
"tensor/nnet/tests/test_conv3d.py"
,
"tensor/nnet/tests/speed_test_conv.py"
,
"tensor/nnet/tests/speed_test_conv.py"
,
"tensor/nnet/tests/test_sigm.py"
,
"tensor/nnet/tests/test_sigm.py"
,
"scalar/sharedvar.py"
,
"scalar/basic_scipy.py"
,
"scalar/basic_sympy.py"
,
"scalar/__init__.py"
,
"scalar/__init__.py"
,
"scalar/basic.py"
,
"scalar/tests/test_basic.py"
,
"scalar/tests/test_basic.py"
,
"sandbox/test_theano_object.py"
,
"sandbox/test_theano_object.py"
,
"sandbox/test_scan.py"
,
"sandbox/test_scan.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论