Unverified Commit f25bc176 authored by Minjie Wang's avatar Minjie Wang Committed by GitHub
Browse files

[Hetero] Improve speed of several Hetero APIs (#1486)

* add clone function to frame

* add utest

* replace all local_var with local_scope

* fix utest

* avoid creating canonical types in __getitem__

* lint

* try another utest  appraoch for mx

* utest
parent 3c4506e9
......@@ -70,7 +70,7 @@ def choice(a, size, replace=True, prob=None): # pylint: disable=invalid-name
population = a
if prob is None:
prob = nd.null()
prob = nd.NULL
else:
prob = F.zerocopy_to_dgl_ndarray(prob)
......
......@@ -894,7 +894,7 @@ def to_block(g, dst_nodes=None, include_dst_in_src=True):
if nodes is not None:
dst_nodes_nd.append(F.zerocopy_to_dgl_ndarray(nodes))
else:
dst_nodes_nd.append(nd.null())
dst_nodes_nd.append(nd.NULL)
new_graph_index, src_nodes_nd, induced_edges_nd = _CAPI_DGLToBlock(
g._graph, dst_nodes_nd, include_dst_in_src)
......@@ -945,7 +945,7 @@ def remove_edges(g, edge_ids):
"Graph has more than one edge type; specify a dict for edge_id instead.")
edge_ids = {g.canonical_etypes[0]: edge_ids}
edge_ids_nd = [nd.null()] * len(g.etypes)
edge_ids_nd = [nd.NULL] * len(g.etypes)
for key, value in edge_ids.items():
edge_ids_nd[g.get_etype_id(key)] = F.zerocopy_to_dgl_ndarray(value)
new_graph_index, induced_eids_nd = _CAPI_DGLRemoveEdges(g._graph, edge_ids_nd)
......
......@@ -360,6 +360,23 @@ def test_inplace():
newa2addr = id(f['a2'])
assert a2addr == newa2addr
@unittest.skipIf(dgl.backend.backend_name == "tensorflow", reason="TF doesn't support inplace update")
def test_clone():
f = FrameRef(Frame(create_test_data()))
f1 = f.clone()
f2 = f.deepclone()
f1['b'] = F.randn((N, D))
f2['c'] = F.randn((N, D))
assert 'b' not in f
assert 'c' not in f
f1['a1'][0, 0] = -10.
assert float(F.asnumpy(f['a1'][0, 0])) == -10.
x = float(F.asnumpy(f['a2'][0, 0]))
f2['a2'][0, 0] = -10.
assert float(F.asnumpy(f['a2'][0, 0])) == x
def _reconstruct_pickle(obj):
f = io.BytesIO()
pickle.dump(obj, f)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment