()
| 458 | |
| 459 | |
| 460 | def test_formats(): |
| 461 | g = dgl.rand_graph(10, 20) |
| 462 | # in_degrees works if coo or csc available |
| 463 | # out_degrees works if coo or csr available |
| 464 | try: |
| 465 | g.in_degrees() |
| 466 | g.out_degrees() |
| 467 | g.formats("coo").in_degrees() |
| 468 | g.formats("coo").out_degrees() |
| 469 | g.formats("csc").in_degrees() |
| 470 | g.formats("csr").out_degrees() |
| 471 | fail = False |
| 472 | except DGLError: |
| 473 | fail = True |
| 474 | finally: |
| 475 | assert not fail |
| 476 | # in_degrees NOT works if csc available only |
| 477 | try: |
| 478 | g.formats("csc").out_degrees() |
| 479 | fail = True |
| 480 | except DGLError: |
| 481 | fail = False |
| 482 | finally: |
| 483 | assert not fail |
| 484 | # out_degrees NOT works if csr available only |
| 485 | try: |
| 486 | g.formats("csr").in_degrees() |
| 487 | fail = True |
| 488 | except DGLError: |
| 489 | fail = False |
| 490 | finally: |
| 491 | assert not fail |
| 492 | |
| 493 | # If the intersection of created formats and allowed formats is |
| 494 | # not empty, then retain the intersection. |
| 495 | # Case1: intersection is not empty and intersected is equal to |
| 496 | # created formats. |
| 497 | g = g.formats(["coo", "csr"]) |
| 498 | g.create_formats_() |
| 499 | g = g.formats(["coo", "csr", "csc"]) |
| 500 | assert sorted(g.formats()["created"]) == sorted(["coo", "csr"]) |
| 501 | assert sorted(g.formats()["not created"]) == sorted(["csc"]) |
| 502 | |
| 503 | # Case2: intersection is not empty and intersected is not equal |
| 504 | # to created formats. |
| 505 | g = g.formats(["coo", "csr"]) |
| 506 | g.create_formats_() |
| 507 | g = g.formats(["coo", "csc"]) |
| 508 | assert sorted(g.formats()["created"]) == sorted(["coo"]) |
| 509 | assert sorted(g.formats()["not created"]) == sorted(["csc"]) |
| 510 | |
| 511 | # If the intersection of created formats and allowed formats is |
| 512 | # empty, then create a format in the order of `coo` -> `csr` -> |
| 513 | # `csc`. |
| 514 | # Case1: intersection is empty and just one format is allowed. |
| 515 | g = g.formats(["coo", "csr"]) |
| 516 | g.create_formats_() |
| 517 | g = g.formats(["csc"]) |
no test coverage detected