我正在尝试创建顶点,我在Graphs.jl文档中找到了一些示例,但我不知道为什么它不能工作。
using Graphs
V1 = ExVertex(1, "V1");
V1.attributes["size"] = 5.0但是它说ExVertex没有与ExVertex(Int64,ASCIIString)匹配的方法。有什么帮助吗?
发布于 2015-11-02 11:36:53
首先,使用?命令查看ExVertex()函数的参数类型,以获得帮助:
help?> ExVertex
search: ExVertex
No documentation found.
Summary:
type Graphs.ExVertex <: Any
Fields:
index :: Int32
label :: UTF8String
attributes :: Dict{UTF8String,Any}因此,在我的机器上,index必须为Int32,现在我们将检查1:typeof(1) # => Int32的实际类型,因此,如果我像您所调用的那样调用该函数,我将不会得到任何错误:
V1 = ExVertex(1, "V1") # => vertex [1] "V1"
这个测试提出了另一个问题:“为什么我们的机器中1的类型不同?”
为了得到正确的答案,我们必须查看Julia手册中关于integer types的部分:
整数文本的默认类型取决于目标系统是32位体系结构还是64位体系结构:
# 32-bit system: julia> typeof(1) Int32
# 64-bit system: julia> typeof(1) Int64
Julia内部变量WORD_SIZE表示目标系统是大于32位还是大于64位。
# 32-bit system: julia> WORD_SIZE 32
# 64-bit system: julia> WORD_SIZE 64
提示:您可以像这样键入cast 1 as UInt32:V1 = ExVertex(1%UInt32, "V1") # => vertex [1] "V1"
https://stackoverflow.com/questions/33467427
复制相似问题