R / igraph:任何在深度优先搜索回调中获取/设置顶点属性的调用都会导致段错误 [英] R / igraph : any call to get/set vertex attribute within a depth-first-search callback causes a segfault
问题描述
我发现在回调中使用igraph库获取/设置顶点属性的任何调用都会导致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)
生成此错误:
graph.dfs(g,1,in。 callback = dfsCallBack)
in:0,0
***发现段错误***
地址0x0,导致'内存未映射'
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 =igr aph)
2:graph.dfs(g,1,in.callback = dfsCallBack)
可能的操作:
1:abort(如果启用了核心转储)
2:正常R退出
3:退出R而不保存工作区
4:退出R保存工作区
选择:
这里有什么问题?另外,igraph在处理这些错误时应该更加健壮,崩溃掉R对于像R这样的高级语言来说并不理想。
解决方案如果你说 set.vertex.attribute(图表,...),图表
实际上没有改变,但是新的副本返回并更新了属性。 R对象(几乎总是)不可变的,你不能改变它们,只能根据它们创建新的对象。 属性(图形0,name ='color',value ='blue')是错误的,因为顶点id从1开始,所以0无效。这应该被报告为一个错误,并且已经在我们的开发树中修复了。 这不是错误,而是错误。 igraph错误不会崩溃R,他们只是给出错误消息。由于igraph代码和R在同一个线程中运行,因此igraph错误可能会导致R崩溃,除了避免错误之外,我们无法做到这一点。
我建议使用 igraph.dfs
的结果适当地设置属性。您当然可以使用回调来记录信息,或者终止DFS。
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:
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.
解决方案 A couple of points.
If you say set.vertex.attribute(graph, ...)
, graph
is actually not changed, but a new copy is returned with the attribute updated. R objects are (almost always) immutable, you cannot change them, only create new objects based on them.
set.vertex.attribute(graph, 0, name = 'color', value = 'blue')
is wrong, because vertex ids start at 1, so the 0 is invalid. This should be reported as an error, and was already fixed in our development tree.
This is not an error, it is a bug. igraph errors do not crash R, they just give an error message. 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.
I would suggest to use the results of igraph.dfs
to set the attributes appropriately. You can of course use the callback to record information, or to terminate the DFS.
这篇关于R / igraph:任何在深度优先搜索回调中获取/设置顶点属性的调用都会导致段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文