提交 c6b619c9 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Don't check the .type of a string.

上级 6058586d
...@@ -1488,7 +1488,7 @@ class Add(ScalarOp): ...@@ -1488,7 +1488,7 @@ class Add(ScalarOp):
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(z,) = outputs (z,) = outputs
op = " + " op = " + "
if z.type == bool: if node.outputs[0].type == bool:
op = " || " op = " || "
if not inputs: if not inputs:
return z + " = 0;" return z + " = 0;"
...@@ -1530,7 +1530,7 @@ class Mul(ScalarOp): ...@@ -1530,7 +1530,7 @@ class Mul(ScalarOp):
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(z,) = outputs (z,) = outputs
op = " * " op = " * "
if z.type == bool: if node.outputs[0].type == bool:
op = " && " op = " && "
if not inputs: if not inputs:
return z + " = 1;" return z + " = 1;"
...@@ -1585,7 +1585,7 @@ class Sub(BinaryScalarOp): ...@@ -1585,7 +1585,7 @@ class Sub(BinaryScalarOp):
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x, y) = inputs (x, y) = inputs
(z,) = outputs (z,) = outputs
if z.type == bool: if node.outputs[0].type == bool:
# xor # xor
return "%(z)s = (%(x)s || %(y)s) && !(%(x)s && %(y)s);" % locals() return "%(z)s = (%(x)s || %(y)s) && !(%(x)s && %(y)s);" % locals()
return "%(z)s = %(x)s - %(y)s;" % locals() return "%(z)s = %(x)s - %(y)s;" % locals()
...@@ -2095,7 +2095,7 @@ class Cast(UnaryScalarOp): ...@@ -2095,7 +2095,7 @@ class Cast(UnaryScalarOp):
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
(z,) = outputs (z,) = outputs
if z.type == bool: if node.outputs[0].type == bool:
return "%s = (%s) ? 1 : 0" % (z, x) return "%s = (%s) ? 1 : 0" % (z, x)
return "%s = (%s)%s;" % (z, node.outputs[0].type.dtype_specs()[1], x) return "%s = (%s)%s;" % (z, node.outputs[0].type.dtype_specs()[1], x)
...@@ -2468,7 +2468,7 @@ class Neg(UnaryScalarOp): ...@@ -2468,7 +2468,7 @@ class Neg(UnaryScalarOp):
def c_code(self, node, name, inputs, outputs, sub): def c_code(self, node, name, inputs, outputs, sub):
(x,) = inputs (x,) = inputs
(z,) = outputs (z,) = outputs
if z.type == bool: if node.outputs[0].type == bool:
return "%(z)s = !%(x)s;" % locals() return "%(z)s = !%(x)s;" % locals()
return "%(z)s = -%(x)s;" % locals() return "%(z)s = -%(x)s;" % locals()
neg = Neg(same_out, name='neg') neg = Neg(same_out, name='neg')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论