New interface for GraphsExtensions.similar_graph; misc bug fixes.#147
New interface for GraphsExtensions.similar_graph; misc bug fixes.#147jack-dunham wants to merge 16 commits intoITensor:mainfrom
GraphsExtensions.similar_graph; misc bug fixes.#147Conversation
Was assuming a specific constructor previously.
Is that supposed to be: empty_graph(T::Type{<:AbstractGraph})? |
I thought we had decided it would be a graph with the same vertices and edges as the input graph (in the case where a graph instance is input)? That would be analogous to julia> using SparseArrays
julia> a = sprandn(5, 5, 0.5)
5×5 SparseMatrixCSC{Float64, Int64} with 13 stored entries:
⋅ ⋅ -0.313373 ⋅ ⋅
⋅ 0.360588 -2.40419 ⋅ -0.885288
-0.538721 -1.59639 ⋅ ⋅ 2.41016
-1.25074 ⋅ -0.652935 ⋅ ⋅
-2.0638 -0.512399 2.09563 ⋅ -1.35611
julia> similar(a)
5×5 SparseMatrixCSC{Float64, Int64} with 13 stored entries:
⋅ ⋅ 2.27785e-314 ⋅ ⋅
⋅ 2.76437e-314 2.27785e-314 ⋅ 2.27785e-314
2.27785e-314 2.20064e-314 ⋅ ⋅ 2.76437e-314
2.27785e-314 ⋅ 2.27785e-314 ⋅ ⋅
2.27785e-314 2.27785e-314 2.27785e-314 ⋅ 2.76437e-314
EDIT: I think I see that is how it is implemented, so maybe it is just that the description in the first post is outdated. |
Sorry this is my mistake in the post description. It should construct a graph with the same vertices and edges. I've updated the head comment. |
…ss_graph` import.
…`.GraphsExtensions`.
|
(I closed and reopened the PR to try to trigger the CI again, I'm trying to fix the docs build.) |
…copy of its vertices and edges
qThis PR overhauls the way the
GraphsExtensions.similar_graphfunction behaves, and includes some minor bug fixes and refactors.New
similar_graphinterfaceEssentially, the base case is now the three argument method, where one provides both
verticesandedges. This defaults to constructing a concreteNamedGraphorNamedDiGraphdepending on theIsDirectedtrait of the input graph.If edges are not provided, then the function attempts to construct a similar graph to the input graph, but with the provided vertices and no edges. If no vertices or edges are provided, then the output graph will be a similar graph with the same vertices and edges. For a given subtype of
AbstractNamedGraph, one should overload the three argument method only (if a different return type is desired).Type domain
If instead a graph type is provided as the first argument to
similar_graph, then the constructor is called by default:Note, unlike the case where a graph value is provided, the one argument method is not defined in terms of the two or three argument method. This is to accommodate cases where a given
AbstractGraphmay have fixed edges, say (a notable example would be a tree graph). In that case, it is assumes there exists a constructorT(vertices). As the methodmay or may not return an edgeless graph, depending on the definition of the constructor.
In light of this, there now exists the function
that attempts to explicitly a construct an edgeless graph, thus throwing an error when this is not possible. Likewise, there exists a function
for explicitly constructing a graph of type
Twith no vertices or edges.If your graph type
MyGraphhas freedom over vertices and edges, all three type-based method can be overloaded simultaneously using the followings signature: