Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make zero function not mandatory for AbstractGraph interface #85

Conversation

simonschoelly
Copy link
Contributor

The current documentation declares the zero function as mandatory for any implementation of AbstractGraph. This function takes a graph (type) and constructs a graph of the same type with zero vertices. I propose to remove that requirement. My reasons for that are

  1. The existence of zero for any graph type assumes that it is possible to have such a graph without any vertices. But for some graph types it is not clear, that such a graph even exists, for example some wrapper types that take some existing object and return a graph view of that object, parametrized graphs such as hypercubes (such a hypercube would have dimension -infinity), or certain geometric graphs.
  2. It makes it difficult to construct wrapper graphs, as a graph wrapping another object must also implement some functionality for constructing an object of the wrapped type.
  3. Constructing a graph with zero vertices usually only makes sense if that graph is mutable and implements add_vertex! and add_edge!, but this is not required for all graph types.

Removing this requirement should therefore make it easier to create custom subtypes of AbstractGraph.

@simonschoelly simonschoelly self-assigned this Jan 9, 2022
@codecov
Copy link

codecov bot commented Jan 9, 2022

Codecov Report

Merging #85 (001672a) into master (3e4d7ef) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master      #85   +/-   ##
=======================================
  Coverage   97.79%   97.79%           
=======================================
  Files         110      110           
  Lines        6203     6203           
=======================================
  Hits         6066     6066           
  Misses        137      137           

@etiennedeg
Copy link
Member

I agree with it. We need to ensure we do not use it in the codebase (when the function is defined for AbstractGraph. I did not fully check it but there is at least an occurrence in induced_subgraph(g::AG, elist::AbstractVector{U})

@gdalle
Copy link
Member

gdalle commented Jan 10, 2022

I agree with this proposal too

@etiennedeg etiennedeg mentioned this pull request Jan 10, 2022
@simonschoelly simonschoelly force-pushed the remove-zero-from-abstract-graph-interface branch from a5ff346 to 001672a Compare January 17, 2022 17:41
@simonschoelly
Copy link
Contributor Author

Could someone approve this, so I can put it into v1.6?

@simonschoelly simonschoelly merged commit 3628517 into JuliaGraphs:master Feb 9, 2022
@simonschoelly simonschoelly deleted the remove-zero-from-abstract-graph-interface branch February 9, 2022 20:27
@mtfishman
Copy link
Contributor

I always thought zero was a weird name for that definition anyway. I guess I could see the analogy to zero(::Matrix) when thinking about a graph as an adjacency matrix but then I would think it would have the same vertices but no edges. Also I think of zero as creating an additive identity, which isn't directly relevant for the Graphs.jl interface (maybe you could define graph addition through adding the adjacency matrices, but again it makes more sense to return a graph with the same number of vertices and no edges). Wouldn't it make more sense to call it empty, or something more descriptive like empty_vertices or zero_vertices?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants