Giter Site home page Giter Site logo

V(g) not the same as 1:vcount about rigraph HOT 5 OPEN

maelle avatar maelle commented on August 23, 2024
V(g) not the same as 1:vcount

from rigraph.

Comments (5)

clpippel avatar clpippel commented on August 23, 2024 1

Instead of identical(index, V(graph)) use all(index == V(graph)).
Straightforward and easy to understand.

from rigraph.

clpippel avatar clpippel commented on August 23, 2024

@maelle,
I am afraid this is not going to work.
Because of the <weak reference> in V(g).
For example, consider:

g1 <- make_graph(c(1, 2, 3, 4))
index <- V(g1)
identical(index, V(g1))
# FALSE

# delete all vertices
g2 <- delete_vertices(g1, V(g1))
identical(V(g2), V(g2))
# FALSE

# This works for empty and non-empty sets V().
# For example.
all(V(g2) == seq_len(vcount(g2)))
# TRUE
all(index == seq_len(vcount(g1)))
# TRUE
all(index == V(g1))
#TRUE

Function identical() could be too strong.
Note thatidentical(1:4, c(1, 2, 3, 4)) returns FALSE.
Both parameters do not have the same class.

from rigraph.

maelle avatar maelle commented on August 23, 2024

would equal work? feel free to suggest a change directly on the PR. I any case, thanks a ton!

from rigraph.

szhorvat avatar szhorvat commented on August 23, 2024

My point about V(g) not being the same as 1:vcount was a general one. I did not have the time / chance to understand the issue you were working on in detail.

Maybe this perspective helps clarify what I meant:

distances(g, 1, V(g) will be faster than distances(g, 1, 1:vcount(g)), even though they are semantically equivalent. This is because V(g) indicates "all vertices" in a more efficient manner, and in a way that can be tested for in the C core, to help choose a better algorithm. Some algorithms are specialized for the "all vertices" case and the performance difference can be quite significant. From memory, some variants of transitivity() as well as igraph_ecc() should show a considerable difference.

from rigraph.

szhorvat avatar szhorvat commented on August 23, 2024

Generally, I would recommend introducing a helper function to check if a vertex sequence vs includes all vertices in standard order.

I think all(vs == seq_len(vcount(g)) should work (as @clpippel says), but keep in mind that I don't know any R (!!). An optimization can/should be added to check attr(vs, 'is_all'). This is TRUE for V(g) specifically. All this assumes that vs is indeed of class igraph.vs.

from rigraph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.