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

Function _test_hypersparse

tests/python/common/test_heterograph.py:597–669  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

595 F._default_context_str == "gpu", reason="GPU does not have COO impl."
596)
597def _test_hypersparse():
598 N1 = 1 << 50 # should crash if allocated a CSR
599 N2 = 1 << 48
600
601 g = dgl.heterograph(
602 {
603 ("user", "follows", "user"): (
604 F.tensor([0], F.int64),
605 F.tensor([1], F.int64),
606 ),
607 ("user", "plays", "game"): (
608 F.tensor([0], F.int64),
609 F.tensor([N2], F.int64),
610 ),
611 },
612 {"user": N1, "game": N1},
613 device=F.ctx(),
614 )
615 assert g.num_nodes("user") == N1
616 assert g.num_nodes("game") == N1
617 assert g.num_edges("follows") == 1
618 assert g.num_edges("plays") == 1
619
620 assert g.has_edges_between(0, 1, "follows")
621 assert not g.has_edges_between(0, 0, "follows")
622 mask = F.asnumpy(g.has_edges_between([0, 0], [0, 1], "follows")).tolist()
623 assert mask == [0, 1]
624
625 assert g.has_edges_between(0, N2, "plays")
626 assert not g.has_edges_between(0, 0, "plays")
627 mask = F.asnumpy(g.has_edges_between([0, 0], [0, N2], "plays")).tolist()
628 assert mask == [0, 1]
629
630 assert F.asnumpy(g.predecessors(0, "follows")).tolist() == []
631 assert F.asnumpy(g.successors(0, "follows")).tolist() == [1]
632 assert F.asnumpy(g.predecessors(1, "follows")).tolist() == [0]
633 assert F.asnumpy(g.successors(1, "follows")).tolist() == []
634
635 assert F.asnumpy(g.predecessors(0, "plays")).tolist() == []
636 assert F.asnumpy(g.successors(0, "plays")).tolist() == [N2]
637 assert F.asnumpy(g.predecessors(N2, "plays")).tolist() == [0]
638 assert F.asnumpy(g.successors(N2, "plays")).tolist() == []
639
640 assert g.edge_ids(0, 1, etype="follows") == 0
641 assert g.edge_ids(0, N2, etype="plays") == 0
642
643 u, v = g.find_edges([0], "follows")
644 assert F.asnumpy(u).tolist() == [0]
645 assert F.asnumpy(v).tolist() == [1]
646 u, v = g.find_edges([0], "plays")
647 assert F.asnumpy(u).tolist() == [0]
648 assert F.asnumpy(v).tolist() == [N2]
649 u, v, e = g.all_edges("all", "eid", "follows")
650 assert F.asnumpy(u).tolist() == [0]
651 assert F.asnumpy(v).tolist() == [1]
652 assert F.asnumpy(e).tolist() == [0]
653 u, v, e = g.all_edges("all", "eid", "plays")
654 assert F.asnumpy(u).tolist() == [0]

Callers

nothing calls this directly

Calls 12

asnumpyMethod · 0.80
all_edgesMethod · 0.80
ctxMethod · 0.45
num_nodesMethod · 0.45
num_edgesMethod · 0.45
has_edges_betweenMethod · 0.45
predecessorsMethod · 0.45
successorsMethod · 0.45
edge_idsMethod · 0.45
find_edgesMethod · 0.45
in_degreesMethod · 0.45
out_degreesMethod · 0.45

Tested by

no test coverage detected