提交 969cf83c authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Apply isort to theano.scalar sub-package modules

上级 7029d8c0
from .basic import * from .basic import *
from .basic_scipy import * from .basic_scipy import *
...@@ -19,13 +19,16 @@ from textwrap import dedent ...@@ -19,13 +19,16 @@ from textwrap import dedent
import numpy as np import numpy as np
import six import six
import theano import theano
from theano import config, gof, printing from theano import config, gof, printing
from theano.compat import Callable from theano.compat import Callable
from theano.gof import Apply, Constant, FunctionGraph, Op, Type, Variable, utils from theano.gof import Apply, Constant, FunctionGraph, Op, Type, Variable, utils
from theano.gradient import DisconnectedType, grad_undefined from theano.gradient import DisconnectedType, grad_undefined
from theano.misc.safe_asarray import _asarray
from theano.printing import pprint from theano.printing import pprint
builtin_bool = bool builtin_bool = bool
builtin_complex = complex builtin_complex = complex
builtin_int = int builtin_int = int
...@@ -181,7 +184,7 @@ class NumpyAutocaster(object): ...@@ -181,7 +184,7 @@ class NumpyAutocaster(object):
and rval.dtype in ("float64", "float32") and rval.dtype in ("float64", "float32")
and rval.dtype != config.floatX and rval.dtype != config.floatX
): ):
rval = theano._asarray(rval, dtype=config.floatX) rval = _asarray(rval, dtype=config.floatX)
return rval return rval
# The following is the original code, corresponding to the 'custom' # The following is the original code, corresponding to the 'custom'
...@@ -207,7 +210,7 @@ class NumpyAutocaster(object): ...@@ -207,7 +210,7 @@ class NumpyAutocaster(object):
and config.floatX in self.dtypes and config.floatX in self.dtypes
and config.floatX != "float64" and config.floatX != "float64"
): ):
return theano._asarray(x, dtype=config.floatX) return _asarray(x, dtype=config.floatX)
# Don't autocast to float16 unless config.floatX is float16 # Don't autocast to float16 unless config.floatX is float16
try_dtypes = [ try_dtypes = [
...@@ -215,7 +218,7 @@ class NumpyAutocaster(object): ...@@ -215,7 +218,7 @@ class NumpyAutocaster(object):
] ]
for dtype in try_dtypes: for dtype in try_dtypes:
x_ = theano._asarray(x, dtype=dtype) x_ = _asarray(x, dtype=dtype)
if np.all(x == x_): if np.all(x == x_):
break break
# returns either an exact x_==x, or the last cast x_ # returns either an exact x_==x, or the last cast x_
...@@ -272,7 +275,7 @@ def convert(x, dtype=None): ...@@ -272,7 +275,7 @@ def convert(x, dtype=None):
""" """
if dtype is not None: if dtype is not None:
# in this case, the semantics are that the caller is forcing the dtype # in this case, the semantics are that the caller is forcing the dtype
x_ = theano._asarray(x, dtype=dtype) x_ = _asarray(x, dtype=dtype)
else: else:
# In this case, this function should infer the dtype according to the # In this case, this function should infer the dtype according to the
# autocasting rules. See autocasting above. # autocasting rules. See autocasting above.
...@@ -283,7 +286,7 @@ def convert(x, dtype=None): ...@@ -283,7 +286,7 @@ def convert(x, dtype=None):
except OverflowError: except OverflowError:
# This is to imitate numpy behavior which tries to fit # This is to imitate numpy behavior which tries to fit
# bigger numbers into a uint64. # bigger numbers into a uint64.
x_ = theano._asarray(x, dtype="uint64") x_ = _asarray(x, dtype="uint64")
elif isinstance(x, builtin_float): elif isinstance(x, builtin_float):
x_ = autocast_float(x) x_ = autocast_float(x)
elif isinstance(x, np.ndarray): elif isinstance(x, np.ndarray):
......
# Definitions of theano.scalar ops that have their python implementation taken # Definitions of theano.scalar ops that have their python implementation taken
# from SciPy. As SciPy is not always available, we treat them separately. # from SciPy. As SciPy is not always available, we treat them separately.
import numpy as np
import os import os
import numpy as np
import theano import theano
from theano.gradient import grad_not_implemented from theano.gradient import grad_not_implemented
from theano.scalar.basic import ( from theano.scalar.basic import (
UnaryScalarOp,
BinaryScalarOp, BinaryScalarOp,
UnaryScalarOp,
complex_types,
discrete_types,
exp, exp,
float_types,
upcast,
upgrade_to_float, upgrade_to_float,
upgrade_to_float64, upgrade_to_float64,
float_types,
)
from theano.scalar.basic import (
upgrade_to_float_no_complex, upgrade_to_float_no_complex,
complex_types,
discrete_types,
upcast,
) )
imported_scipy_special = False imported_scipy_special = False
try: try:
import scipy.special import scipy.special
......
import itertools as it import itertools as it
from theano.scalar.basic import Apply, ScalarOp, as_scalar, float64, float32, int64
from theano.gof.utils import remove from theano.gof.utils import remove
from theano.scalar.basic import Apply, ScalarOp, as_scalar, float32, float64, int64
imported_sympy = False imported_sympy = False
try: try:
from sympy.utilities.codegen import get_default_datatype, codegen from sympy.utilities.codegen import codegen, get_default_datatype
imported_sympy = True imported_sympy = True
except ImportError: except ImportError:
......
...@@ -20,8 +20,10 @@ import numpy as np ...@@ -20,8 +20,10 @@ import numpy as np
from six import integer_types from six import integer_types
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" __authors__ = "James Bergstra"
__copyright__ = "(c) 2010, Universite de Montreal" __copyright__ = "(c) 2010, Universite de Montreal"
__license__ = "3-clause BSD License" __license__ = "3-clause BSD License"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论