Skip to content

Add constructors that infer the metadata types from the data values provided to constructor #6

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

Closed
CameronBieganek opened this issue May 10, 2020 · 4 comments · Fixed by #45
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@CameronBieganek
Copy link

CameronBieganek commented May 10, 2020

The current MetaGraph constructor requires the user to explicitly specify the types of the metadata via the arguments Label, VertexMeta, and EdgeMeta. That seems a little unusual to me. It's much more common for constructors to determine the values of type parameters based on the data passed to the constructor, e.g.

julia> [1, 2]
2-element Array{Int64,1}:
 1
 2

julia> ["hello", "world"]
2-element Array{String,1}:
 "hello"
 "world"

It would be nice if there were some constructors like the following that infer the type parameters from the data:

MetaGraph(
    SimpleGraph(),
    vertices = [(:a, :color => "blue"), (:b, :color => "red")],
    edges = [(:a, :b, :linewidth => 2)]
)

The fallback for creating a typed but empty graph would be something like the following:

MetaGraph{SimpleGraph{Int}, Symbol, Dict{Symbol, String}, Dict{Symbol, Int}}()

which corresponds to how one normally creates a typed but empty object. E.g., for a typed but empty dictionary, you would use this:

Dict{Symbol, String}()

Or for a typed but empty vector:

Vector{Int}()

...although for arrays we have the sugar Int[].

@CameronBieganek CameronBieganek changed the title Add constructors that infer the meta data types from the data values provided to constructor Add constructors that infer the metadata types from the data values provided to constructor May 10, 2020
@bramtayl
Copy link
Collaborator

This is a great idea!

@gdalle gdalle added enhancement New feature or request good first issue Good for newcomers labels Nov 29, 2021
@gdalle
Copy link
Member

gdalle commented Nov 29, 2021

We don't have lots of constructors yet, but this seems like the logical next step! Thanks for the idea

@gdalle
Copy link
Member

gdalle commented Mar 10, 2022

@CameronBieganek following up on this, do you want to draw up a PR?

@gdalle
Copy link
Member

gdalle commented Feb 22, 2023

Side note: this is actually essential for our type stability claim, cause the constructor with types as kwargs is not inferrable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants