MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / test_matrices_are_not_copies

Function test_matrices_are_not_copies

tests/test_ProblemData.py:461–491  ·  view source on GitHub ↗

The matrices returned by ``distance_matrix()`` and ``duration_matrix()`` offer views into data owned by the underlying ``ProblemData`` instance. There is no copying going on when accessing this data.

()

Source from the content-addressed store, hash-verified

459
460
461def test_matrices_are_not_copies():
462 """
463 The matrices returned by ``distance_matrix()`` and ``duration_matrix()``
464 offer views into data owned by the underlying ``ProblemData`` instance.
465 There is no copying going on when accessing this data.
466 """
467 mat = np.array([[0, 0], [0, 0]])
468 data = ProblemData(
469 clients=[Client(x=0, y=1)],
470 depots=[Depot(x=0, y=0)],
471 vehicle_types=[VehicleType(2)],
472 distance_matrices=[mat],
473 duration_matrices=[mat],
474 )
475
476 # Ownership is taken, so the memory that's referenced is not that of the
477 # matrices that are passed into ProblemData's constructor.
478 assert_(data.distance_matrix(profile=0).base is not mat)
479 assert_(data.duration_matrix(profile=0).base is not mat)
480
481 # Repeated calls should return matrices that reference the same base data,
482 # implying nothing is copied: the memory is not owned by the matrix.
483 dist1 = data.distance_matrix(profile=0)
484 dist2 = data.distance_matrix(profile=0)
485 assert_(not dist1.flags["OWNDATA"])
486 assert_(dist1.base is dist2.base)
487
488 dur1 = data.duration_matrix(profile=0)
489 dur2 = data.duration_matrix(profile=0)
490 assert_(not dur1.flags["OWNDATA"])
491 assert_(dur1.base is dur2.base)
492
493
494@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

ProblemDataClass · 0.90
ClientClass · 0.90
DepotClass · 0.90
VehicleTypeClass · 0.90

Tested by

no test coverage detected