简体   繁体   English

R / igraph:在深度优先搜索回调中对获取/设置顶点属性的任何调用都会导致段错误

[英]R / igraph : any call to get/set vertex attribute within a depth-first-search callback causes a segfault

I'm finding that any call to get/set vertex attribute using the igraph library within callback causes a segfault in R. For example, the trivial callback from a segment of code: 我发现在回调中使用igraph库对get / set vertex属性的任何调用都会导致R中出现段错误。例如,一段代码中的琐碎回调:

  dfsCallBack <- function(graph, data, extra) {
    cat("in:", paste(collapse=", ", data), "\n")
    distFromRoot <- data[2]
    vertexID <- data[1]
    set.vertex.attribute(graph, 0, name = 'color', value = 'blue')
    FALSE    
  }
  graph.dfs(g, 1, in.callback = dfsCallBack)

Produces this error: 产生此错误:

  graph.dfs(g, 1, in.callback = dfsCallBack)
in: 0, 0 

 *** caught segfault ***
address 0x0, cause 'memory not mapped'

Traceback:
 1: .Call("R_igraph_dfs", graph, root, neimode, unreachable, as.logical(order),     as.logical(order.out), as.logical(father), as.logical(dist),     in.callback, out.callback, extra, rho, PACKAGE = "igraph")
 2: graph.dfs(g, 1, in.callback = dfsCallBack)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 

What's wrong here? 怎么了 Also, igraph should probably be more robust in dealing with these errors, crashing out of R is not ideal for a high-level language like R. 另外,igraph在处理这些错误时可能应该更健壮,因为R之类的崩溃对于R之类的高级语言而言并不理想。

A couple of points. 有两点。

  1. If you say set.vertex.attribute(graph, ...) , graph is actually not changed, but a new copy is returned with the attribute updated. 如果您说set.vertex.attribute(graph, ...) ,则实际上不会更改graph ,但是会返回具有更新属性的新副本。 R objects are (almost always) immutable, you cannot change them, only create new objects based on them. R对象(几乎总是)是不可变的,您不能更改它们,只能基于它们创建新对象。

  2. set.vertex.attribute(graph, 0, name = 'color', value = 'blue') is wrong, because vertex ids start at 1, so the 0 is invalid. set.vertex.attribute(graph, 0, name = 'color', value = 'blue')是错误的,因为顶点ID从1开始,所以0无效。 This should be reported as an error, and was already fixed in our development tree. 这应该报告为错误,并且已经在我们的开发树中修复。

  3. This is not an error, it is a bug. 这不是错误,而是错误。 igraph errors do not crash R, they just give an error message. igraph错误不会使R崩溃,它们只会给出错误消息。 Because the igraph code and R run in the same thread, igraph bugs might crash R, and apart from avoiding bugs, there is not much we can do about this. 由于igraph代码和R在同一线程中运行,igraph错误可能会使R崩溃,并且除了避免错误外,我们对此无能为力。

I would suggest to use the results of igraph.dfs to set the attributes appropriately. 我建议使用igraph.dfs的结果来igraph.dfs地设置属性。 You can of course use the callback to record information, or to terminate the DFS. 当然,您可以使用回调来记录信息或终止DFS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM