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

Function tester

imperative/python/test/unit/xla/functional/test_xla_tensor.py:17–36  ·  view source on GitHub ↗
(ishape, tgtshape)

Source from the content-addressed store, hash-verified

15@pytest.mark.skipif(not is_cuda_available(), reason="only support cuda now")
16def test_broadcast_to():
17 def tester(ishape, tgtshape):
18 dtype = None
19 dtype = dtype or np.float32
20 inp = tensor(np.random.randn(*ishape), dtype=dtype)
21 dout = tensor(np.random.randn(*tgtshape), dtype=dtype)
22
23 gm = GradManager()
24
25 @jit.xla_trace(without_host=True)
26 def func(inp, dout):
27 gm.attach([inp])
28 with gm:
29 out = F.broadcast_to(inp, tgtshape)
30 gm.backward(out, dout)
31 return [out, inp.grad]
32
33 mge_rsts = func(inp, dout)
34 xla_rsts = func(inp, dout)
35 for mge_rst, xla_rst in zip(mge_rsts, xla_rsts):
36 np.testing.assert_allclose(mge_rst.numpy(), xla_rst.numpy(), atol=1e-5)
37
38 tester((1, 1, 1), (1, 1, 1, 1))
39 tester((1, 1, 1, 1), (1, 1, 1, 1))

Callers 10

test_broadcast_toFunction · 0.70
test_reshapeFunction · 0.70
test_transposeFunction · 0.70
test_expand_dimsFunction · 0.70
test_concatFunction · 0.70
test_splitFunction · 0.70
test_stackFunction · 0.70
test_fill_and_fill_likeFunction · 0.70
test_whereFunction · 0.70
test_linspaceFunction · 0.70

Calls 6

GradManagerClass · 0.90
concatMethod · 0.80
funcFunction · 0.70
numpyMethod · 0.45
reshapeMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected