code: def test_sample_result():
      """
      Ensure the SampleResult class returns zero-copy cupy arrays and properly
      frees device memory when all references to it are gone and it's garbage
      collected.
      """
      from pylibcugraph.testing.type_utils import create_sampling_result
  
      gc.collect()
  
      resource_handle = ResourceHandle()
      # Assume GPU 0 will be used and the test has exclusive access and nothing
      # else can use its memory while the test is running.
      device = cp.cuda.Device(0)
      free_memory_before = device.mem_info[0]
  
      # Use the testing utility to create a large sampling result.  This API is
      # intended for testing only - SampleResult objects are normally only
      # created by running a sampling algo.
      sampling_result = create_sampling_result(
          resource_handle,
          device_sources=cp.arange(1e8, dtype="int32"),
          device_destinations=cp.arange(1, 1e8 + 1, dtype="int32"),
          device_weights=cp.arange(1e8 + 2, dtype="float32"),
          device_edge_id=cp.arange(1e8 + 3, dtype="int32"),
          device_edge_type=cp.arange(1e8 + 4, dtype="int32"),
          device_hop=cp.arange(1e8 + 5, dtype="int32"),
          device_batch_label=cp.arange(1e8 + 6, dtype="int32"),
      )
  
      assert (
          free_memory_before > device.mem_info[0]
      ) or mem_leak_assert_disabled
  
      sources = sampling_result.get_sources()
      destinations = sampling_result.get_destinations()
      indices = sampling_result.get_indices()
  
      assert isinstance(sources, cp.ndarray)
      assert isinstance(destinations, cp.ndarray)
      assert isinstance(indices, cp.ndarray)
  
      print("sources:", destinations)
  
      # Delete the SampleResult instance. This *should not* free the device
      # memory yet since the variables sources, destinations, and indices are
      # keeping the refcount >0.
      del sampling_result
      gc.collect()
      assert (
          free_memory_before > device.mem_info[0]
      ) or mem_leak_assert_disabled
  
      # Check that the data is still valid
      assert sources[999] == 999
      assert destinations[999] == 1000
      assert indices[999] == 999
  
      # Add yet another reference to the original data, which should prevent it
      # from being freed when the GC runs.
      sources2 = sources
  
      # delete the variables which should take the ref count on sampling_result
      # to 0, which will cause it to be garbage collected.
      del sources
      del destinations
      del indices
      gc.collect()
  
      # sources2 should be keeping the data alive
      assert sources2[999] == 999
      assert (
          free_memory_before > device.mem_info[0]
      ) or mem_leak_assert_disabled
  
      # All memory should be freed once the last reference is deleted
      del sources2
      gc.collect()
      assert (
          free_memory_before == device.mem_info[0]
      ) or mem_leak_assert_disabled
  
file_path: cugraph/python/pylibcugraph/pylibcugraph/tests/test_uniform_neighbor_sample.py
imports: import gc
  import pytest
  import cupy
  import numpy
  import cudf
  from pylibcugraph import SGGraph, ResourceHandle, GraphProperties
  from pylibcugraph import uniform_neighbor_sample
label_desc: Use image node_id 5 for calling a global function with example usage: test_sample_result() without return types