提交 8471510b authored 作者: Olivier Breuleux's avatar Olivier Breuleux

added scalar/tensor.iround

上级 543e0d11
......@@ -574,15 +574,6 @@ class Identity(UnaryScalarOp):
return gz,
identity = Identity(same_out, name = 'identity')
class Neg(UnaryScalarOp):
def impl(self, x):
return -x
def grad(self, (x, ), (gz, )):
return -gz,
def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = -%(x)s;" % locals()
neg = Neg(same_out, name = 'neg')
class Abs(UnaryScalarOp):
#TODO: for complex input, output is some flavour of float
def impl(self, x):
......@@ -611,6 +602,24 @@ class Sgn(UnaryScalarOp):
return "%(z)s = (%(x)s >= 0) ? (%(x)s == 0) ? 0.0 : 1.0 : -1.0;" % locals()
sgn = Sgn(same_out, name = 'sgn')
class IRound(UnaryScalarOp):
def impl(self, x):
return numpy.asarray(numpy.round(x), dtype = 'int64')
def grad(self, (x, ), (gz, )):
return gz * sgn(x),
def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = round(%(x)s);" % locals()
iround = IRound(int_out)
class Neg(UnaryScalarOp):
def impl(self, x):
return -x
def grad(self, (x, ), (gz, )):
return -gz,
def c_code(self, node, name, (x, ), (z, ), sub):
return "%(z)s = -%(x)s;" % locals()
neg = Neg(same_out, name = 'neg')
class Inv(UnaryScalarOp):
def impl(self, x):
return 1.0 / x
......
......@@ -868,6 +868,10 @@ def log2(a):
def sgn(a):
"""sign of a"""
@_scal_elemwise
def iround(a):
"""int(round(a))"""
@_scal_elemwise
def sqr(a):
"""square of a"""
......
......@@ -107,6 +107,10 @@ def log2_inplace(a):
def sgn_inplace(a):
"""sign of `a` (inplace on `a`)"""
@_scal_inplace
def iround_inplace(a):
"""int(round(a)) (inplace on `a`)"""
@_scal_inplace
def sqr_inplace(a):
"""square of `a` (inplace on `a`)"""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论