Yes that's fine

On Tuesday, April 28, 2015 at 10:41:15 AM UTC-4, Ján Dolinský wrote:
>
> Thanks for the clarification.
>
> If my function foo has more parameters I just go like this ?
>
> function foo{V<:VecOrMat}(X::Vector{V}, param1::Int, param2::String)  
> ... 
> end
>
> Regards,
> Jan
>
>
>
> Dňa utorok, 28. apríla 2015 16:31:37 UTC+2 Tom Breloff napísal(-a):
>>
>> The reason is a little subtle, but it's because you have an abstract type 
>> inside a parametric type, which confuses Julia.  When you annotate 
>> a::MyAbstractType, julia understands what to do with it (i.e. compiles 
>> functions for each concrete subtype).  When you annotate 
>> a::Vector{MyAbstractType}, it is expecting a concrete type 
>> Vector{MyAbstractType}, but you are in fact passing it a different concrete 
>> type Vector{MyConcreteType}. Use the signature that Tim suggested to get 
>> around the issue.
>>
>> On Tuesday, April 28, 2015 at 10:08:57 AM UTC-4, Ján Dolinský wrote:
>>>
>>> Hi Tim,
>>>
>>> Thanks for the tip. Very interesting. In function definition it works. I 
>>> read the parametric-composite-types manual. I am still puzzled however.
>>>
>>> Consider the example below which works as I expect:
>>>
>>> a = rand(10)
>>> b = rand(10,2)
>>>
>>> julia> a :: VecOrMat{Float64}
>>> 10-element Array{Float64,1}:
>>> ...
>>>
>>> julia> b :: VecOrMat{Float64}
>>> 10x2 Array{Float64,2}:
>>> ...
>>>
>>>
>>> The following example does not work as I would expect:
>>>
>>> a = Vector{Float64}[rand(10), rand(10)]
>>> b = Matrix{Float64}[rand(10,2), rand(10,2)]
>>>
>>> julia> a :: Vector{VecOrMat{Float64}}
>>> ERROR: type: typeassert: expected 
>>> Array{Union(Array{Float64,1},Array{Float64,2}),1}, got 
>>> Array{Array{Float64,1},1}
>>>
>>> julia> b :: Vector{VecOrMat{Float64}}
>>> ERROR: type: typeassert: expected 
>>> Array{Union(Array{Float64,1},Array{Float64,2}),1}, got 
>>> Array{Array{Float64,2},1}
>>>
>>> however, this:
>>> julia> a :: Vector{Vector{Float64}}
>>> 2-element Array{Array{Float64,1},1}:
>>> ...
>>> and this works:
>>> julia> b :: Vector{Matrix{Float64}}
>>> 2-element Array{Array{Float64,2},1}:
>>> ...
>>>
>>> Thanks,
>>> Jan
>>>
>>>
>>>
>>> Dňa utorok, 28. apríla 2015 13:13:36 UTC+2 Tim Holy napísal(-a):
>>>>
>>>>
>>>> http://docs.julialang.org/en/release-0.3/manual/types/#parametric-composite-types
>>>>  
>>>>
>>>> Use foo{V<:VecOrMat}(X::Vector{V}) 
>>>>
>>>> --Tim 
>>>>
>>>> On Tuesday, April 28, 2015 02:40:41 AM Ján Dolinský wrote: 
>>>> > Hi guys, 
>>>> > 
>>>> > I am trying to write a function which accepts as an input either a 
>>>> vector 
>>>> > of vectors or a vector of matrices e.g. 
>>>> > 
>>>> > function foo(X::Vector{VecOrMat{Float64}}) 
>>>> > 
>>>> > When running the function with a vector of matrices I get the 
>>>> following 
>>>> > error " 'foo' has no method matching 
>>>> foo(::Array{Array{Float64,2},1})" 
>>>> > 
>>>> > Am I missing something here ? 
>>>> > 
>>>> > Thanks, 
>>>> > Jan 
>>>>
>>>>

Reply via email to