Hi guys,
I came across a problem of setting up a (general) subarray with an object
(value which is not an ordinary number) e.g.
julia> z = Array(Matrix{Float64}, 10)
10-element Array{Array{Float64,2},1}:
#undef
#undef
#undef
#undef
#undef
#undef
#undef
#undef
#undef
#undef
julia> z[2:5] = rand(2,2)
ERROR: MethodError: `convert` has no method matching convert(::Type{Array{
Float64,2}}, ::Float64)
This may have arisen from a call to the constructor Array{Float64,2}(...),
since type constructors fall back to convert methods.
Closest candidates are:
call{T}(::Type{T}, ::Any)
convert{T,S,N}(::Type{Array{T,N}}, ::SubArray{S,N,P<:AbstractArray{T,N},I
<:Tuple{Vararg{Union{AbstractArray{T,1},Colon,Int64}}},LD})
convert{T,n}(::Type{Array{T,n}}, ::Array{T,n})
...
in setindex! at array.jl:339
What is a "correct" way of doing this ? I can do it via "sub" and "fill!"
e.g.
julia> zz = sub(z, 2:5)
4-element SubArray{Array{Float64,2},1,Array{Array{Float64,2},1},Tuple{
UnitRange{Int64}},1}:
#undef
#undef
#undef
#undef
julia> fill!(zz, rand(2,2))
4-element SubArray{Array{Float64,2},1,Array{Array{Float64,2},1},Tuple{
UnitRange{Int64}},1}:
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
julia> z
10-element Array{Array{Float64,2},1}:
#undef
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
2x2 Array{Float64,2}:
0.313155 0.553893
0.74854 0.997401
#undef
#undef
#undef
#undef
#undef
Thanks,
Jan