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 types of fields in PartitionedGraph more specific #63

Open
mtfishman opened this issue Apr 15, 2024 · 2 comments
Open

Make types of fields in PartitionedGraph more specific #63

mtfishman opened this issue Apr 15, 2024 · 2 comments

Comments

@mtfishman
Copy link
Member

The partitioned_vertices and which_partition fields of PartitionedGraph 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

@JoeyT1994
Copy link
Contributor

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?

@mtfishman
Copy link
Member Author

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).

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

No branches or pull requests

2 participants