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