Open mtfishman opened 6 months ago
So you mean like:
struct PartitionedGraph{V,PV,G<:AbstractGraph{V},PG<:AbstractGraph{PV}, PV<:AbstractDict, WP<:AbstractDict} <:
AbstractPartitionedGraph{V,PV}
graph::G
partitioned_graph::PG
partitioned_vertices::PV
which_partition::WP
end
instead?
I was thinking like this:
struct PartitionedGraph{V,PV,G<:AbstractGraph{V},PG<:AbstractGraph{PV}} <:
AbstractPartitionedGraph{V,PV}
graph::G
partitioned_graph::PG
partitioned_vertices::Dictionary{PV,V}
which_partition::Dictionary{V,PV}
end
which restricts the storage to be Dictionary
but either style fixes the type stability issue. Basically the point is that you should try to expose the types of the fields as much as possible in the type parameters of PartitionedGraph
(there are reasons for not doing that if you want the object to be more dynamic, like the ITensor
type, but that is fairly uncommon and there isn't a good reason for doing that here).
The
partitioned_vertices
andwhich_partition
fields ofPartitionedGraph
are currently abstract: https://github.com/mtfishman/NamedGraphs.jl/blob/d561823168be7d042fcfac31162c6c2495f10ba4/src/Graphs/partitionedgraphs/partitionedgraph.jl#L5-L6. To improve performance and type stability they should be parametrized, see https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-fields-with-abstract-type. @JoeyT1994