提交 bd168a56 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3127 from harlouci/flake8_scalar

Flake8 scalar
差异被折叠。
......@@ -296,51 +296,51 @@ 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){
/*taken from
Bernardo, J. M. (1976). Algorithm AS 103:
Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317.
http://www.uv.es/~bernardo/1976AppStatist.pdf */
double y, R, psi_ = 0;
double S = 1.0e-5;
double C = 8.5;
double S3 = 8.333333333e-2;
double S4 = 8.333333333e-3;
double S5 = 3.968253968e-3;
double D1 = -0.5772156649;
y = x;
if (y <= 0.0)
return psi_;
if (y <= S )
return D1 - 1.0/y;
while (y < C){
psi_ = psi_ - 1.0 / y;
y = y + 1;}
R = 1.0 / y;
psi_ = psi_ + log(y) - .5 * R ;
R= R*R;
psi_ = psi_ - R * (S3 - R * (S4 - R * S5));
return psi_;}
#endif
""" )
"""
// 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:
Psi (Digamma) Function. Applied Statistics. 25 (3), 315-317.
http://www.uv.es/~bernardo/1976AppStatist.pdf */
double y, R, psi_ = 0;
double S = 1.0e-5;
double C = 8.5;
double S3 = 8.333333333e-2;
double S4 = 8.333333333e-3;
double S5 = 3.968253968e-3;
double D1 = -0.5772156649;
y = x;
if (y <= 0.0)
return psi_;
if (y <= S )
return D1 - 1.0/y;
while (y < C){
psi_ = psi_ - 1.0 / y;
y = y + 1;}
R = 1.0 / y;
psi_ = psi_ + log(y) - .5 * R ;
R= R*R;
psi_ = psi_ - R * (S3 - R * (S4 - R * S5));
return psi_;}
#endif
""")
def c_code(self, node, name, inp, out, sub):
x, = inp
......
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):
......@@ -53,8 +51,8 @@ class SymPyCCode(ScalarOp):
def _sympy_c_code(self):
[(c_name, c_code), (h_name, c_header)] = codegen(
(self.name, self.expr), 'C', 'project_name',
header=False, argument_sequence=self.inputs)
(self.name, self.expr), 'C', 'project_name',
header=False, argument_sequence=self.inputs)
return c_code
def c_support_code(self):
......@@ -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):
......
......@@ -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.
"""
__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
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"
__contact__ = "theano-dev <theano-dev@googlegroups.com>"
__docformat__ = "restructuredtext en"
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
......@@ -52,7 +53,9 @@ def shared(value, name=None, strict=False, allow_downcast=None):
value = getattr(numpy, dtype)(value)
scalar_type = Scalar(dtype=dtype)
rval = ScalarSharedVariable(
type=scalar_type,
value=value,
name=name, strict=strict, allow_downcast=allow_downcast)
type=scalar_type,
value=value,
name=name,
strict=strict,
allow_downcast=allow_downcast)
return rval
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论