I have defined a custom Vector type which appears to work as required.
struct MyVector{T} <: AbstractVector{T}
data::Vector{T}
end
Base.size(A::MyVector) = size(A.data)
Base.IndexStyle(::Type{T}) where {T<:MyVector} = IndexStyle(fieldtype(T, :data))
@inline Base.getindex(A::MyVector, i::Int) = A.data[i]
@inline Base.setindex!(A::MyVector, x, i::Int) = A.data[i] = x
A = MyVector(collect(1:5))
A[:] .= 8
@assert A == fill(8, length(A))
But when I define the following convert
method, it seems to break colon broadcasting.
Base.convert(::Type{MyVector{T}}, v::AbstractVector{T}) where {T} = MyVector(convert(Vector{T}, v))
A = MyVector(collect(1:5))
A[:] .= 8
@assert A == fill(8, length(A))
A
Julia-1.3.0-rc5> @assert A == fill(8, length(A))
ERROR: AssertionError: A == fill(8, length(A))
Stacktrace:
[1] top-level scope at REPL[12]:1
Julia-1.3.0-rc5> A
5-element MyVector{Int64}:
1
2
3
4
5
Can someone explain what happening here?