def _scal_inplace(symbol): """Replace a symbol definition with an elementwise version of the corresponding scalar Op""" symbolname = symbol.__name__ inplace = symbolname.endswith('_inplace') if inplace: scalar_op = getattr(scal, symbolname[:-len('_inplace')]) inplace_scalar_op = scalar_op.__class__(scal.transfer_type(0)) rval = elemwise.Elemwise(inplace_scalar_op, {0: 0}, name=symbolname) else: scalar_op = getattr(scal, symbolname) rval = elemwise.Elemwise(scalar_op, name=symbolname) if getattr(symbol, '__doc__', False): rval.__doc__ = symbol.__doc__ + '\n' + rval.__doc__ # for the meaning of this see the ./epydoc script # it makes epydoc display rval as if it were a function, not an object rval.__epydoc_asRoutine = symbol rval.__module__ = 'theano.tensor.inplace' def chk(pstate, r): if not r.owner: return False return r.owner.op == rval pprint.assign(chk, printing.FunctionPrinter(symbolname.replace('_inplace', '='))) return rval
def construct(symbol): symbolname = symbol.__name__ inplace = symbolname.endswith('_inplace') if inplace: msg = "inplace" else: msg = "no_inplace" n = "Elemwise{%s,%s}" % (symbolname, msg) if inplace: scalar_op = getattr(scal, symbolname[:-len('_inplace')]) inplace_scalar_op = scalar_op.__class__(scal.transfer_type(0)) rval = elemwise.Elemwise(inplace_scalar_op, {0: 0}, name=n, nfunc_spec=(nfunc and (nfunc, nin, nout))) else: scalar_op = getattr(scal, symbolname) rval = elemwise.Elemwise(scalar_op, name=n, nfunc_spec=(nfunc and (nfunc, nin, nout))) if getattr(symbol, '__doc__', False): rval.__doc__ = symbol.__doc__ + '\n' + rval.__doc__ # for the meaning of this see the ./epydoc script # it makes epydoc display rval as if it were a function, not an object rval.__epydoc_asRoutine = symbol rval.__module__ = 'tensor' pprint.assign(rval, printing.FunctionPrinter(symbolname)) return rval
def _scal_inplace(symbol): """Replace a symbol definition with an elementwise version of the corresponding scalar Op""" symbolname = symbol.__name__ inplace = symbolname.endswith('_inplace') if inplace: scalar_op = getattr(scal, symbolname[:-len('_inplace')]) inplace_scalar_op = scalar_op.__class__(scal.transfer_type(0)) rval = elemwise.Elemwise(inplace_scalar_op, {0: 0}, name=symbolname) else: scalar_op = getattr(scal, symbolname) rval = elemwise.Elemwise(scalar_op, name=symbolname) if getattr(symbol, '__doc__', False): rval.__doc__ = symbol.__doc__ + '\n' + rval.__doc__ # for the meaning of this see the ./epydoc script # it makes epydoc display rval as if it were a function, not an object rval.__epydoc_asRoutine = symbol rval.__module__ = 'theano.tensor.inplace' def chk(pstate, r): if not r.owner: return False return r.owner.op == rval pprint.assign( chk, printing.FunctionPrinter(symbolname.replace('_inplace', '='))) return rval
def construct(symbol): symbolname = symbol.__name__ msg = "no_inplace" n = "Elemwise{%s,%s}" % (symbolname, msg) rval = Elemwise(scalar_op, name=n, nfunc_spec=(nfunc and (nfunc, nin, nout))) if getattr(symbol, '__doc__', False): rval.__doc__ = symbol.__doc__ + '\n' + rval.__doc__ # for the meaning of this see the ./epydoc script # it makes epydoc display rval as if it were a function, not an object rval.__epydoc_asRoutine = symbol rval.__module__ = 'tensor' pprint.assign(rval, printing.FunctionPrinter(symbolname)) return rval
def _scal_inplace(symbol): """Replace a symbol definition with an elementwise version of the corresponding scalar Op""" symbolname = symbol.__name__ inplace = symbolname.endswith("_inplace") if inplace: scalar_op = getattr(scal, symbolname[: -len("_inplace")]) inplace_scalar_op = scalar_op.__class__(scal.transfer_type(0)) rval = elemwise.Elemwise(inplace_scalar_op, {0: 0}, name=symbolname) else: scalar_op = getattr(scal, symbolname) rval = elemwise.Elemwise(scalar_op, name=symbolname) if getattr(symbol, "__doc__", False): rval.__doc__ = symbol.__doc__ + "\n" + rval.__doc__ # for the meaning of this see the ./epydoc script # it makes epydoc display rval as if it were a function, not an object rval.__epydoc_asRoutine = symbol rval.__module__ = "theano.tensor.inplace" pprint.assign(rval, printing.FunctionPrinter(symbolname.replace("_inplace", "="))) return rval
@_scal_inplace def j0_inplace(a): """Bessel function of the 0'th kind""" @_scal_inplace def j1_inplace(a): """Bessel function of the 0'th kind""" @_scal_inplace def second_inplace(a): """Fill `a` with `b`""" fill_inplace = second_inplace pprint.assign(fill_inplace, printing.FunctionPrinter('fill=')) @_scal_inplace def maximum_inplace(a, b): """elementwise addition (inplace on `a`)""" @_scal_inplace def minimum_inplace(a, b): """elementwise addition (inplace on `a`)""" @_scal_inplace def add_inplace(a, b): """elementwise addition (inplace on `a`)"""
plt.savefig(fname) print("New picture saved at", fname) print(val_ultra.max()) print(val_ultra.min()) scalar_sigmoid = ScalarSigmoid(scalar.upgrade_to_float, name="scalar_sigmoid") sigmoid = elemwise.Elemwise(scalar_sigmoid, name="sigmoid") sigmoid_inplace = elemwise.Elemwise( ScalarSigmoid(scalar.transfer_type(0)), inplace_pattern={0: 0}, name="sigmoid_inplace", ) pprint.assign(sigmoid, printing.FunctionPrinter("sigmoid")) class UltraFastScalarSigmoid(scalar.UnaryScalarOp): """ This is just speed opt. Not for stability. """ @staticmethod def st_impl(x): x = 0.5 * x # The if is a tanh approximate. if x >= 0: if x < 1.7: z = 1.5 * x / (1 + x) elif x < 3:
plt.savefig(fname) print("New picture saved at", fname) print(val_ultra.max()) print(val_ultra.min()) scalar_sigmoid = ScalarSigmoid(scalar.upgrade_to_float, name='scalar_sigmoid') sigmoid = elemwise.Elemwise(scalar_sigmoid, name='sigmoid') sigmoid_inplace = elemwise.Elemwise( ScalarSigmoid(scalar.transfer_type(0)), inplace_pattern={0: 0}, name='sigmoid_inplace', ) pprint.assign(sigmoid, printing.FunctionPrinter('sigmoid')) class UltraFastScalarSigmoid(scalar.UnaryScalarOp): """ This is just speed opt. Not for stability. """ @staticmethod def st_impl(x): x = 0.5 * x # The if is a tanh approximate. if x >= 0: if x < 1.7: z = (1.5 * x / (1 + x)) elif x < 3:
os.path.dirname(theano.__file__), "..", "doc", "library", "tensor", "nnet", "sigmoid_prec.png" ) plt.savefig(fname) print("New picture saved at", fname) print(val_ultra.max()) print(val_ultra.min()) scalar_sigmoid = ScalarSigmoid(scalar.upgrade_to_float, name="scalar_sigmoid") sigmoid = elemwise.Elemwise(scalar_sigmoid, name="sigmoid") sigmoid_inplace = elemwise.Elemwise( ScalarSigmoid(scalar.transfer_type(0)), inplace_pattern={0: 0}, name="sigmoid_inplace" ) pprint.assign(sigmoid, printing.FunctionPrinter("sigmoid")) class UltraFastScalarSigmoid(scalar.UnaryScalarOp): """ This is just speed opt. Not for stability. """ @staticmethod def st_impl(x): x = 0.5 * x # The if is a tanh approximate. if x >= 0: if x < 1.7: z = 1.5 * x / (1 + x)
plt.savefig(fname) print "New picture saved at", fname print val_ultra.max() print val_ultra.min() scalar_sigmoid = ScalarSigmoid(scalar.upgrade_to_float, name='scalar_sigmoid') sigmoid = elemwise.Elemwise(scalar_sigmoid, name='sigmoid') sigmoid_inplace = elemwise.Elemwise( ScalarSigmoid(scalar.transfer_type(0)), inplace_pattern={0: 0}, name='sigmoid_inplace', ) pprint.assign(sigmoid, printing.FunctionPrinter('sigmoid')) class UltraFastScalarSigmoid(scalar.UnaryScalarOp): """ This is just speed opt. Not for stability. """ @staticmethod def st_impl(x): x = 0.5 * x # The if is a tanh approximate. if x >= 0: if x < 1.7: z = (1.5 * x / (1 + x)) elif x < 3: z = (0.935409070603099 + 0.0458812946797165 * (x - 1.7))
def i1_inplace(x): """Modified Bessel function of the first kind of order 1.""" @_scal_inplace def iv_inplace(v, x): """Modified Bessel function of the first kind of order v (real).""" @_scal_inplace def second_inplace(a): """Fill `a` with `b`""" fill_inplace = second_inplace pprint.assign(fill_inplace, printing.FunctionPrinter('fill=')) @_scal_inplace def maximum_inplace(a, b): """elementwise addition (inplace on `a`)""" @_scal_inplace def minimum_inplace(a, b): """elementwise addition (inplace on `a`)""" @_scal_inplace def add_inplace(a, b): """elementwise addition (inplace on `a`)"""
def c_code_cache_version(self): v = super(ScalarSigmoid, self).c_code_cache_version() if v: return (2,) + v else: return v scalar_sigmoid = ScalarSigmoid(scalar.upgrade_to_float, name='scalar_sigmoid') sigmoid = elemwise.Elemwise(scalar_sigmoid, name='sigmoid') sigmoid_inplace = elemwise.Elemwise( ScalarSigmoid(scalar.transfer_type(0)), inplace_pattern={0:0}, name='sigmoid_inplace', ) pprint.assign(sigmoid, printing.FunctionPrinter('sigmoid')) class ScalarSoftplus(scalar.UnaryScalarOp): @staticmethod def static_impl(x): if x < -30.0: return 0.0 if x > 30.0: return x return numpy.log1p(numpy.exp(x)) def impl(self, x): return ScalarSoftplus.static_impl(x) def grad(self, inp, grads): x, = inp gz, = grads
def erf_inplace(a): """error function""" @_scal_inplace def erfc_inplace(a): """complementary error function""" @_scal_inplace def second_inplace(a): """Fill `a` with `b`""" fill_inplace = second_inplace pprint.assign(fill_inplace, printing.FunctionPrinter("fill=")) @_scal_inplace def maximum_inplace(a, b): """elementwise addition (inplace on `a`)""" @_scal_inplace def minimum_inplace(a, b): """elementwise addition (inplace on `a`)""" @_scal_inplace def add_inplace(a, b): """elementwise addition (inplace on `a`)"""
if v: return (2, ) + v else: return v scalar_sigmoid = ScalarSigmoid(scalar.upgrade_to_float, name='scalar_sigmoid') sigmoid = elemwise.Elemwise(scalar_sigmoid, name='sigmoid') sigmoid_inplace = elemwise.Elemwise( ScalarSigmoid(scalar.transfer_type(0)), inplace_pattern={0: 0}, name='sigmoid_inplace', ) pprint.assign(sigmoid, printing.FunctionPrinter('sigmoid')) class ScalarSoftplus(scalar.UnaryScalarOp): @staticmethod def static_impl(x): if x < -30.0: return 0.0 if x > 30.0: return x return numpy.log1p(numpy.exp(x)) def impl(self, x): return ScalarSoftplus.static_impl(x) def grad(self, inp, grads):
def i1_inplace(x): """Modified Bessel function of the first kind of order 1.""" @scalar_elemwise def iv_inplace(v, x): """Modified Bessel function of the first kind of order v (real).""" @scalar_elemwise def second_inplace(a): """Fill `a` with `b`""" fill_inplace = second_inplace pprint.assign(fill_inplace, printing.FunctionPrinter("fill=")) @scalar_elemwise(symbolname="scalar_maximum_inplace") def maximum_inplace(a, b): """elementwise addition (inplace on `a`)""" @scalar_elemwise(symbolname="scalar_minimum_inplace") def minimum_inplace(a, b): """elementwise addition (inplace on `a`)""" @scalar_elemwise def add_inplace(a, b): """elementwise addition (inplace on `a`)"""