MCPcopy
hub / github.com/dmlc/dgl / test_column_subcolumn

Function test_column_subcolumn

tests/python/common/test_frame.py:13–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def test_column_subcolumn():
14 data = F.copy_to(
15 F.tensor(
16 [
17 [1.0, 1.0, 1.0, 1.0],
18 [0.0, 2.0, 9.0, 0.0],
19 [3.0, 2.0, 1.0, 0.0],
20 [1.0, 1.0, 1.0, 1.0],
21 [0.0, 2.0, 4.0, 0.0],
22 ]
23 ),
24 F.ctx(),
25 )
26 original = Column(data)
27
28 # subcolumn from cpu context
29 i1 = F.tensor([0, 2, 1, 3], dtype=F.int64)
30 l1 = original.subcolumn(i1)
31
32 assert len(l1) == i1.shape[0]
33 assert F.array_equal(l1.data, F.gather_row(data, i1))
34
35 # next subcolumn from target context
36 i2 = F.copy_to(F.tensor([0, 2], dtype=F.int64), F.ctx())
37 l2 = l1.subcolumn(i2)
38
39 assert len(l2) == i2.shape[0]
40 i1i2 = F.copy_to(F.gather_row(i1, F.copy_to(i2, F.context(i1))), F.ctx())
41 assert F.array_equal(l2.data, F.gather_row(data, i1i2))
42
43 # next subcolumn also from target context
44 i3 = F.copy_to(F.tensor([1], dtype=F.int64), F.ctx())
45 l3 = l2.subcolumn(i3)
46
47 assert len(l3) == i3.shape[0]
48 i1i2i3 = F.copy_to(
49 F.gather_row(i1i2, F.copy_to(i3, F.context(i1i2))), F.ctx()
50 )
51 assert F.array_equal(l3.data, F.gather_row(data, i1i2i3))
52
53
54def test_serialize_deserialize_plain():

Callers

nothing calls this directly

Calls 5

subcolumnMethod · 0.95
ColumnClass · 0.90
contextMethod · 0.80
copy_toMethod · 0.45
ctxMethod · 0.45

Tested by

no test coverage detected