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

Function test_condtake

imperative/python/test/unit/functional/test_tensor.py:112–128  ·  view source on GitHub ↗
(is_varnode)

Source from the content-addressed store, hash-verified

110
111@pytest.mark.parametrize("is_varnode", [True, False])
112def test_condtake(is_varnode):
113 if is_varnode:
114 network = Network()
115 else:
116 network = None
117
118 x = np.array([[1, 2, 3], [4, 5, 6]]).astype("float32")
119 y = np.array([[True, False, True], [False, True, True]])
120 xx = make_tensor(x, network)
121 yy = make_tensor(y, network)
122 val, idx = F.cond_take(yy, xx)
123 if is_varnode:
124 np.testing.assert_equal(get_var_value(val), x[y])
125 np.testing.assert_equal(get_var_value(idx), np.where(y.reshape(-1))[0])
126 else:
127 np.testing.assert_equal(val.numpy(), x[y])
128 np.testing.assert_equal(idx.numpy(), np.where(y.reshape(-1))[0])
129
130
131@pytest.mark.parametrize("as_tuple", [True, False])

Callers

nothing calls this directly

Calls 8

NetworkClass · 0.90
make_tensorFunction · 0.90
get_var_valueFunction · 0.90
arrayMethod · 0.80
assert_equalMethod · 0.80
astypeMethod · 0.45
reshapeMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected