That string does represent a filename, doesn't it? Do you obtain that by 
calling readdir() at some point perhaps? This can now return a 
Array{Union(UTF8String,ASCIIString),1}, which I believe was not the case in 
0.3. (At least I had to adapt my code at some point to deal with this)



Am 13.03.2015 um 18:43 schrieb Phil Tomson <[email protected]>:

> 
> 
> On Thursday, March 12, 2015 at 9:00:45 PM UTC-7, Avik Sengupta wrote:
> I think this is simply due to your passing a UTF8String, while your function 
> defined only for ASCIIString. Since there is no function defined for 
> UTF8String, julia falls back to the default constructor that calls convert. 
> 
> julia> type A
>          a::ASCIIString
>          b::Int
>        end
> 
> julia> function A(fn::ASCIIString)
>            A(fn, length(fn)
>        end
> ERROR: syntax: missing comma or ) in argument list
> 
> julia> function A(fn::ASCIIString)
>            A(fn, length(fn))
>        end
> A
> 
> julia> A("X")
> A("X",1)
> 
> julia> A("∞")
> ERROR: MethodError: `convert` has no method matching convert(::Type{A}, 
> ::UTF8String)
> This may have arisen from a call to the constructor A(...),
> since type constructors fall back to convert methods.
> Closest candidates are:
>   convert{T}(::Type{T}, ::T)
> 
>  in call at no file
> 
> 
> #Now try this: 
> 
> julia> type A
>          a::AbstractString
>          b::Int
>        end
> 
> julia> function A(fn::AbstractString)
>            A(fn, length(fn))
>        end
> A
> 
> julia> A("X")
> A("X",1)
> 
> julia> A("∞")
> A("∞",1)
> 
> Not that using AbstractString is only one way to solve this, which may or may 
> not be appropriate for your use case. The code above is simply to demonstrate 
> the issue at hand. 
> 
> 
> Why would this have changed in 0.4, though? 
> 
> Running in Julia 0.4:
> julia> typeof("string")
> ASCIIString
> 
> so a quoted string still has the same type as it did before.
> 
> 
>  
> 
> 
> On Thursday, 12 March 2015 23:43:58 UTC, Phil Tomson wrote:
> I thought I'd give 0.4 a spin to try out the new garbage collector.
> 
> On my current codebase developed with 0.3 I ran into several warnings 
> (float32() should now be Float32() - that sort of thing)
> 
> And then this error:
> 
> ERROR: LoadError: LoadError: LoadError: LoadError: LoadError: MethodError: 
> `convert` has no method matching convert(::Type{Img.ImgHSV}, ::UTF8String)
> This may have arisen from a call to the constructor Img.ImgHSV(...),
> since type constructors fall back to convert methods.
> Closest candidates are:
>   convert{T}(::Type{T}, ::T)
> 
> After poking around New Language Features and the list here a bit it seems 
> that there are changes to how overloaded constructors work.
> 
> In my case I've got:
> 
> type ImgHSV
>   name::ASCIIString
>   data::Array{HSV{Float32},2}  
>   #data::Array{IntHSV,2}  
>   height::Int64
>   wid::Int64
>   h_mean::Float32
>   s_mean::Float32
>   v_mean::Float32
>   h_std::Float32
>   s_std::Float32
>   v_std::Float32
> end
> 
> # Given a filename of an image file, construct an ImgHSV
> function ImgHSV(fn::ASCIIString)
>   name,ext = splitext(basename(fn))
>   source_img_hsv = Images.data(convert(Image{HSV{Float64}},imread(fn)))
>   #scale all the values up from (0->1) to (0->255)
>   source_img_scaled = map(x-> HSV( ((x.h/360)*255),(x.s*255),(x.v*255)),
>                           source_img_hsv)
>   img_ht  = size(source_img_hsv,2)
>   img_wid = size(source_img_hsv,1)
>   h_mean = (mean(map(x-> x.h,source_img_hsv)/360)*255)
>   s_mean = (mean(map(x-> x.s,source_img_hsv))*255)
>   v_mean = (mean(map(x-> x.v,source_img_hsv))*255)
>   h_std  = (std(map(x-> x.h,source_img_hsv)/360)*255)
>   s_std  = (std(map(x-> x.s,source_img_hsv))*255)
>   v_std  = (std(map(x-> x.v,source_img_hsv))*255)
>   ImgHSV(
>     name,
>     float32(source_img_scaled),
>     img_ht,
>     img_wid,
>     h_mean,
>     s_mean,
>     v_mean,
>     h_std,
>     s_std,
>     v_std
>   )
> end
> 
> Should I rename this function to something like buildImgHSV so it's not 
> actually a constructor and convert doesn't enter the picture?
> 
> Phil

Reply via email to