On Wed, Jul 8, 2015 at 8:32 AM, Seth <[email protected]> wrote:
> Yichao,
>
> That works - thanks. Why does it work, though?
My guess is that the default constructor couldn't infer the type
parameter T so explicitly supplying it should make it work.
Not sure what is the expected behavior (what should the default
constructor be able to infer).
P.S. do you have T as a global variable somewhere?
P.P.S. I see your bug report.
>
>
> On Tuesday, July 7, 2015 at 8:47:30 PM UTC-5, Yichao Yu wrote:
>>
>> Not sure what changed so it might worth a bug report/doc update but
>> can you try this?
>>
>> function MinCutVisitor{T}(graph::SimpleGraph, distmx::AbstractArray{T, 2})
>> n = nv(graph)
>> MinCutVisitor{T}(
>> graph,
>> falses(n),
>> zeros(Int,n),
>> typemax(T),
>> zero(T),
>> zero(Int),
>> distmx,
>> @compat(Vector{Int}())
>> )
>> end
>>
>> I.e. add `{T}` to the call to the default constructor
>>
>>
>> On Tue, Jul 7, 2015 at 8:05 PM, andrew cooke <[email protected]> wrote:
>> >
>> > what's T in the last chunk of code? you have typemax(T), but no T as a
>> > type
>> > parameter. is that really working?
>> >
>> >
>> > On Tuesday, 7 July 2015 20:03:24 UTC-3, Seth wrote:
>> >>
>> >> I have the following code:
>> >>
>> >> type MinCutVisitor{T} <: AbstractMASVisitor
>> >> graph::SimpleGraph
>> >> parities::AbstractArray{Bool,1}
>> >> colormap::Vector{Int}
>> >> bestweight::T
>> >> cutweight::T
>> >> visited::Integer
>> >> distmx::AbstractArray{T, 2}
>> >> vertices::Vector{Int}
>> >> end
>> >>
>> >> function MinCutVisitor{T}(graph::SimpleGraph, distmx::AbstractArray{T,
>> >> 2})
>> >> n = nv(graph)
>> >> MinCutVisitor(
>> >> graph,
>> >> falses(n),
>> >> zeros(Int,n),
>> >> typemax(T),
>> >> zero(T),
>> >> zero(Int),
>> >> distmx,
>> >> @compat(Vector{Int}())
>> >> )
>> >> end
>> >>
>> >>
>> >> and up until June 30th the outer constructor was working in 0.4:
>> >>
>> >> julia> g = Graph(8)
>> >> {8, 0} undirected graph
>> >>
>> >>
>> >> julia> LightGraphs.MinCutVisitor(g,spzeros(Float64,8,8))
>> >> LightGraphs.MinCutVisitor{Float64}({8, 0} undirected
>> >>
>> >> graph,Bool[false,false,false,false,false,false,false,false],[0,0,0,0,0,0,0,0],Inf,0.0,0,8x8
>> >> sparse matrix with 0 Float64 entries:,Int64[])
>> >>
>> >>
>> >> Now it fails on Float64 but not with Int:
>> >>
>> >> julia> LightGraphs.MinCutVisitor(g,spzeros(Float64,8,8))
>> >> ERROR: MethodError: `convert` has no method matching
>> >> convert(::Type{LightGraphs.MinCutVisitor{T}}, ::LightGraphs.Graph,
>> >> ::BitArray{1}, ::Array{Int64,1}, ::Float64, ::Float64, ::Int64,
>> >> ::Base.SparseMatrix.SparseMatrixCSC{Float64,Int64}, ::Array{Int64,1})
>> >> This may have arisen from a call to the constructor
>> >> LightGraphs.MinCutVisitor{T}(...),
>> >> since type constructors fall back to convert methods.
>> >> Closest candidates are:
>> >>
>> >>
>> >> LightGraphs.MinCutVisitor{T}(::Union{LightGraphs.Graph,LightGraphs.DiGraph},
>> >> ::AbstractArray{Bool,1}, ::Array{Int64,1}, ::T, ::T, ::Integer,
>> >> ::AbstractArray{T,2}, ::Array{Int64,1})
>> >>
>> >>
>> >> LightGraphs.MinCutVisitor{T}(::Union{LightGraphs.Graph,LightGraphs.DiGraph},
>> >> ::AbstractArray{T,2})
>> >> call{T}(::Type{T}, ::Any)
>> >> ...
>> >> in call at /Users/seth/.julia/v0.4/LightGraphs/src/maxadjvisit.jl:99
>> >>
>> >>
>> >> julia> LightGraphs.MinCutVisitor(g,spzeros(Int,8,8))
>> >> LightGraphs.MinCutVisitor{Int64}({8, 0} undirected
>> >>
>> >> graph,Bool[false,false,false,false,false,false,false,false],[0,0,0,0,0,0,0,0],9223372036854775807,0,0,8x8
>> >> sparse matrix with 0 Int64 entries:,Int64[])
>> >>
>> >> However, if I remove the type parameterization from the outer
>> >> constructor:
>> >>
>> >> function MinCutVisitor(graph::SimpleGraph, distmx::AbstractArray)
>> >>
>> >> n = nv(graph)
>> >> MinCutVisitor(
>> >> graph,
>> >> falses(n),
>> >> zeros(Int,n),
>> >> typemax(T),
>> >> zero(T),
>> >> zero(Int),
>> >> distmx,
>> >> @compat(Vector{Int}())
>> >> )
>> >> end
>> >>
>> >>
>> >> it works. Can someone tell me why this is?