igraph / rigraph

igraph R package
https://r.igraph.org
551 stars 200 forks source link

Error in `igraph::subgraph_isomorphisms`: REAL() can only be applied to a 'numeric', not a 'integer' #1218

Closed bockthom closed 8 months ago

bockthom commented 8 months ago

What happens?

Since the major release of the igraph package, I get some weird error which I cannot trace down because it seems to be related to some internal calls from the R function to the C code. That is, getting the error message, I have no idea what I could do to get rid of this error. Either it might be a bug in igraph, or I need some help on how to fix this problem.

So, the problem occurs when using subgraph_isomorphisms function with method "vf2" and specifying vertex colors. Then, the following error occurs:

 REAL() can only be applied to a 'numeric', not a 'integer'

In previous versions of igraph, this did not fail. Do you have any idea on what's going wrong here? Thanks in advance!

Below I provide a (stupid) example which already triggers the above stated error. There was no error in this examples prior to igraph 2.0.

To Reproduce

motif = igraph::make_empty_graph(directed = FALSE) + 
    igraph::vertices("D1", "D2", type = c("type1", "type1")) + 
    igraph::edges("D1", "D2", type = c("type2"))
igraph::subgraph_isomorphisms(target = motif, pattern = motif, method = "vf2", 
                              vertex.color1 = 2, vertex.color2 = 1)
krlmlr commented 8 months ago

Thanks. Reprex:

motif <- igraph::make_empty_graph(directed = FALSE) +
  igraph::vertices("D1", "D2", type = c("type1", "type1")) +
  igraph::edges("D1", "D2", type = c("type2"))
igraph::subgraph_isomorphisms(
  target = motif, pattern = motif, method = "vf2",
  vertex.color1 = 2, vertex.color2 = 1
)
#> Error in graph.get.subisomorphisms.vf2(target, pattern, ...): REAL() can only be applied to a 'numeric', not a 'integer'

Created on 2024-02-08 with reprex v2.1.0

szhorvat commented 8 months ago

It would be a good idea to have a look at the other isomorphism functions as well, as all of these use hand-written glue code at the moment. All of them should be using integer vectors in 0.10 for colours, as well as for mappings. Any sign of double or REAL in isomorphism function glue code is a red flag.

krlmlr commented 8 months ago

The fix in #1218 now gives a different error, which hints at problems in the code:

motif <- igraph::make_empty_graph(directed = FALSE) +
  igraph::vertices("D1", "D2", type = c("type1", "type1")) +
  igraph::edges("D1", "D2", type = c("type2"))
igraph::subgraph_isomorphisms(
  target = motif, pattern = motif, method = "vf2",
  vertex.color1 = 2, vertex.color2 = 1
)
#> Error in graph.get.subisomorphisms.vf2(target, pattern, ...): At vendor/cigraph/src/isomorphism/vf2.c:1089 : Invalid vertex color vector length, Invalid value
szhorvat commented 8 months ago

This error is expected. The usage is incorrect. The length of vertex.color1 and vertex.color2 must be the same as vcount(motif).

Correct usage would be:

motif <- igraph::make_empty_graph(directed = FALSE) +
  igraph::vertices("D1", "D2", type = c("type1", "type1")) +
  igraph::edges("D1", "D2", type = c("type2"))
igraph::subgraph_isomorphisms(
  target = motif, pattern = motif, method = "vf2",
  vertex.color1 = c(2,1), vertex.color2 = c(1,2)
)
bockthom commented 8 months ago

Sorry, the wrong vector length was my bad - I just wanted to create a minimum example that shows the initial error that I reported and, inadvertently, I reduced the vector length. In my actual code, the vectors are as long as vcount. I just wanted to report the initial real/integer/numeric error.

krlmlr commented 8 months ago

Thanks for the heads-up!