MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_trace

Function test_trace

imperative/python/test/unit/jit/test_tracing.py:35–58  ·  view source on GitHub ↗
(trace_mode, return_mode)

Source from the content-addressed store, hash-verified

33@pytest.mark.parametrize("trace_mode", [False, True])
34@pytest.mark.parametrize("return_mode", ["Value", "Tuple", "List", "Dict"])
35def test_trace(trace_mode, return_mode):
36 @trace(symbolic=trace_mode)
37 def f(x):
38 if return_mode == "Tuple":
39 return (-x,)
40 elif return_mode == "List":
41 return [-x]
42 elif return_mode == "Dict":
43 return {"neg": -x}
44 else:
45 return -x
46
47 def get_numpy(y):
48 if return_mode == "Tuple" or return_mode == "List":
49 return y[0].numpy()
50 elif return_mode == "Dict":
51 return y["neg"].numpy()
52 return y.numpy()
53
54 x = tensor([1])
55 y = get_numpy(f(x))
56
57 for i in range(3):
58 np.testing.assert_equal(get_numpy(f(x)), y)
59
60
61def test_output_copy_trace():

Callers

nothing calls this directly

Calls 3

get_numpyFunction · 0.85
assert_equalMethod · 0.80
fFunction · 0.70

Tested by

no test coverage detected