提交 69a019a1 authored 作者: Frederic's avatar Frederic

Rename an op to BadSub to make it clear that it behave incorrectly.

上级 d37fab58
......@@ -129,7 +129,7 @@ class Add(Binary):
add = Add()
class Sub(Binary):
class BadSub(Binary):
def c_code(self, node, name, inp, out, sub):
x, y = inp
z, = out
......@@ -137,7 +137,7 @@ class Sub(Binary):
def impl(self, x, y):
return -10 # erroneous (most of the time)
sub = Sub()
bad_sub = BadSub()
class Mul(Binary):
......@@ -180,7 +180,7 @@ def Env(inputs, outputs):
def test_clinker_straightforward():
x, y, z = inputs()
e = add(mul(add(x, y), div(x, y)), sub(sub(x, y), z))
e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z))
lnk = CLinker().accept(Env([x, y, z], [e]))
fn = lnk.make_function()
assert fn(2.0, 2.0, 2.0) == 2.0
......@@ -189,7 +189,7 @@ def test_clinker_straightforward():
def test_clinker_literal_inlining():
x, y, z = inputs()
z = Constant(tdouble, 4.12345678)
e = add(mul(add(x, y), div(x, y)), sub(sub(x, y), z))
e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z))
lnk = CLinker().accept(Env([x, y], [e]))
fn = lnk.make_function()
assert abs(fn(2.0, 2.0) + 0.12345678) < 1e-9
......@@ -232,7 +232,7 @@ def test_clinker_dups_inner():
def test_opwiseclinker_straightforward():
x, y, z = inputs()
e = add(mul(add(x, y), div(x, y)), sub(sub(x, y), z))
e = add(mul(add(x, y), div(x, y)), bad_sub(bad_sub(x, y), z))
lnk = OpWiseCLinker().accept(Env([x, y, z], [e]))
fn = lnk.make_function()
assert fn(2.0, 2.0, 2.0) == 2.0
......@@ -273,8 +273,8 @@ def test_duallinker_straightforward():
def test_duallinker_mismatch():
x, y, z = inputs()
# sub is correct in C but erroneous in Python
e = sub(mul(x, y), mul(y, z))
# bad_sub is correct in C but erroneous in Python
e = bad_sub(mul(x, y), mul(y, z))
g = Env([x, y, z], [e])
lnk = DualLinker(checker=_my_checker).accept(g)
fn = lnk.make_function()
......@@ -283,6 +283,7 @@ def test_duallinker_mismatch():
assert CLinker().accept(g).make_function()(1.0, 2.0, 3.0) == -4.0
# good
assert OpWiseCLinker().accept(g).make_function()(1.0, 2.0, 3.0) == -4.0
# (purposely) wrong
assert PerformLinker().accept(g).make_function()(1.0, 2.0, 3.0) == -10.0
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论