copy Module Subroutine

module subroutine copy(this, source, sparse)

Copy the graph structure.

Arguments

Type IntentOptional Attributes Name
class(graph_type), intent(inout) :: this

Parent. Instance of the graph structure.

class(graph_type), intent(in) :: source

Source graph to copy from.

logical, intent(in), optional :: sparse

Boolean whether to copy the graph as sparse. Default is False.


Source Code

  module subroutine copy(this, source, sparse)
    !! Copy the graph structure.
    implicit none

    ! Arguments
    class(graph_type), intent(inout) :: this
    !! Parent. Instance of the graph structure.
    class(graph_type), intent(in) :: source
    !! Source graph to copy from.
    logical, intent(in), optional :: sparse
    !! Boolean whether to copy the graph as sparse. Default is False.

    this%num_vertices = source%num_vertices
    this%num_edges = source%num_edges
    this%num_vertex_features = source%num_vertex_features
    this%num_edge_features = source%num_edge_features
    this%is_sparse = source%is_sparse
    this%directed = source%directed
    this%name = source%name
    if(this%is_sparse)then
       this%adj_ia = source%adj_ia
       this%adj_ja = source%adj_ja
       this%vertex_features = source%vertex_features
       this%edge_features = source%edge_features
       this%edge_weights = source%edge_weights
    else
       allocate(this%vertex(this%num_vertices))
       this%vertex = source%vertex
       allocate(this%edge(this%num_edges))
       this%edge = source%edge
       this%adjacency = source%adjacency
    end if
    if(present(sparse))then
       if(sparse.and..not.this%is_sparse)then
          call this%convert_to_sparse()
       elseif(.not.sparse.and.this%is_sparse)then
          call this%convert_to_dense()
       end if
    end if
  end subroutine copy