提交 65952fad authored 作者: Frederic Bastien's avatar Frederic Bastien

Fix ticket #656. Disable complex in clip. The numpy have implementation with…

Fix ticket #656. Disable complex in clip. The numpy have implementation with complex don't have any mathematical meaning.
上级 86148591
......@@ -1103,7 +1103,9 @@ class Clip(ScalarOp):
return gx, None, None
else:
return None, None, None
clip = Clip(upcast_out, name = 'clip')
# Don't allow complex even if numpy do
# As there is no mathematical reason for this function on complex
clip = Clip(upcast_out_no_complex, name = 'clip')
class First(BinaryScalarOp):
def impl(self, x, y):
......
......@@ -924,36 +924,13 @@ ClipTester = makeTester(name='ClipTester',
)
# I can't think of any way to make this fail at runtime
@dec.knownfailureif(True,
("clip should raise an error at instantiation if any "
"argument is complex, see #656"))
def test_clip_complex_value():
def check(a, b, c, aval, bval, cval, dtype):
f = function([a, b, c], clip(a, b, c))
assert numpy.allclose(numpy.clip(aval, bval, cval),
f(aval, bval, cval))
for dtype in ['complex64', 'complex128']:
av = randcomplex(5).astype(dtype)
bv = numpy.array(-1)
cv = numpy.array(1)
a = tensor.vector(dtype=dtype)
b = tensor.scalar()
c = tensor.scalar()
yield check, a, b, c, av, bv, cv, dtype
av = rand(5)
bv = numpy.array(-1+1j).astype(dtype)
cv = numpy.array(1)
a = tensor.vector()
b = tensor.scalar(dtype=dtype)
c = tensor.scalar()
yield check, a, b, c, av, bv, cv, dtype
av = rand(5)
bv = numpy.array(-1)
cv = numpy.array(1+1j).astype(dtype)
a = tensor.vector()
b = tensor.scalar()
c = tensor.scalar(dtype=dtype)
yield check, a, b, c, av, bv, cv, dtype
class T_Clip(unittest.TestCase):
def test_complex_value(self):
for dtype in ['complex64', 'complex128']:
a = tensor.vector(dtype=dtype)
b = tensor.scalar()
c = tensor.scalar()
self.assertRaises(TypeError, clip, a, b, c)
#TODO: consider moving this function / functionality to gradient.py
# rationale: it's tricky, and necessary everytime you want to verify
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论