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

Function test_subtensor

imperative/python/test/unit/core/test_indexing_op.py:293–315  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

291
292
293def test_subtensor():
294 x = np.arange(25).reshape(5, 5).astype("int32")
295 d = np.arange(2).astype("int32")
296 xx = Tensor(x)
297 (yy0,) = subtensor(xx, (slice(0, 4, 2), 3))
298 (yy1,) = set_subtensor(xx, d, (slice(0, 4, 2), 3))
299 (yy2,) = incr_subtensor(xx, d, (slice(0, 4, 2), 3))
300
301 np.testing.assert_equal(x[0:4:2, 3], yy0.numpy())
302
303 x_ = x.copy()
304 x_[0:4:2, 3] = d
305 np.testing.assert_equal(x_, yy1.numpy())
306
307 x_ = x.copy()
308 x_[0:4:2, 3] += d
309 np.testing.assert_equal(x_, yy2.numpy())
310
311 x_ = x.copy()
312 xx_ = Tensor(x_)
313 np.testing.assert_equal(x_[::-1], xx_[::-1].numpy())
314 np.testing.assert_equal(x_[::-2], xx_[::-2].numpy())
315 np.testing.assert_equal(x_[::-1, ::-2], xx_[::-1, ::-2].numpy())
316
317
318def test_advance_indexing():

Callers

nothing calls this directly

Calls 9

TensorClass · 0.90
subtensorFunction · 0.85
incr_subtensorFunction · 0.85
assert_equalMethod · 0.80
set_subtensorFunction · 0.70
astypeMethod · 0.45
reshapeMethod · 0.45
numpyMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected