I have a type that wraps a vector. I have defined two-argument getindex
for vectors of this type, i.e.,
getindex(v::Vector{MyVec}, i::Int, j::Int) = v[j][i]
. This works well, but it messes up REPL display of one of these vectors, MWE below. The error seems to be that print_matrix
is called, in which the two-argument getindex
is called, even though it’s a vector being printed. What is the cleanest way to ensure that the printing of Vector{MyVec}
is correct?
julia> struct MyVec
v::Vector
end
julia> Base.getindex(v::MyVec, i::Int) = v.v[i]
julia> Base.getindex(v::Vector{MyVec}, i::Int, j::Int) = v[j][i]
julia> v = MyVec([1,2])
MyVec([1, 2])
julia> vv = [v,v] # This does not produce the correct output!
2-element Array{MyVec,1}:
1
2