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

convenience feature setter #284

Closed
CarloLucibello opened this issue May 22, 2023 · 2 comments
Closed

convenience feature setter #284

CarloLucibello opened this issue May 22, 2023 · 2 comments

Comments

@CarloLucibello
Copy link
Member

Right now we can conveniently add new features with

julia> g = rand_graph(3, 2)
GNNGraph:
  num_nodes: 3
  num_edges: 2

julia> g.ndata.x = rand(1, 3)
1×3 Matrix{Float64}:
 0.31553  0.824744  0.86907

Shoul we also allow the following (currently erroring)?

julia> g.x = rand(1, 3)
ERROR: type GNNGraph has no field x
Stacktrace:
 [1] setproperty!(x::GNNGraph{Tuple{Vector{Int64}, Vector{Int64}, Nothing}}, f::Symbol, v::Matrix{Float64})
   @ Base ./Base.jl:38
 [2] top-level scope
   @ REPL[9]:1
@rbSparky
Copy link
Contributor

Would this include editing the Base.setproperty! function in datastore.jl to handle this specific case?

function Base.setproperty!(ds::DataStore, s::Symbol, x)
    @assert s != :_n "cannot set _n directly"
    @assert s != :_data "cannot set _data directly"

    # changes

    if getn(ds) >= 0
        numobs(x) == getn(ds) || throw(DimensionMismatch("expected $(getn(ds)) object features but got $(numobs(x))."))
    end
    return getdata(ds)[s] = x
end

@CarloLucibello
Copy link
Member Author

This would involve implementing setproperty!(g::GNNGraph, ...). I think it is better to not proceed with this though, g.ndata.x = ... is much more transparent and convenient enough.

@CarloLucibello CarloLucibello closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2024
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