diff --git a/src/CircularArrays.jl b/src/CircularArrays.jl index 210053e..268b8a3 100644 --- a/src/CircularArrays.jl +++ b/src/CircularArrays.jl @@ -75,11 +75,11 @@ end @inline _similar(::Type{CircularArray{T,N,A}}, dims) where {T,N,A} = CircularArray{T,N}(similar(A, dims)) @inline Base.similar(CA::Type{CircularArray{T,N,A}}, dims::Tuple{Base.DimOrInd, Vararg{Base.DimOrInd}}) where {T,N,A} = _similar(CA, dims) # Ambiguity resolution with Base -@inline Base.similar(CA::Type{CircularArray{T,N,A}}, dims::Dims) where {T,N,A} = _similar(CA, T, dims) +@inline Base.similar(CA::Type{CircularArray{T,N,A}}, dims::Dims) where {T,N,A} = _similar(CA, dims) @inline Base.similar(CA::Type{CircularArray{T,N,A}}, dims::Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}) where {T,N,A} = _similar(CA, dims) @inline Broadcast.BroadcastStyle(::Type{CircularArray{T,N,A}}) where {T,N,A} = Broadcast.ArrayStyle{CircularArray{T,N,A}}() -@inline Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{CircularArray{T,N,A}}}, ::Type{ElType}, dims=axes(bc)) where {T,N,A,ElType} = CircularArray(similar(convert(Broadcast.Broadcasted{typeof(Broadcast.BroadcastStyle(A))}, bc), ElType, dims)) +@inline Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{CircularArray{T,N,A}}}, ::Type{ElType}) where {T,N,A,ElType} = CircularArray(similar(convert(Broadcast.Broadcasted{typeof(Broadcast.BroadcastStyle(A))}, bc), ElType)) @inline Base.dataids(arr::CircularArray) = Base.dataids(parent(arr)) diff --git a/test/runtests.jl b/test/runtests.jl index a0f9bdd..ba23421 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -111,6 +111,8 @@ end @test v3 isa CircularVector{Int64} @test v3 == CircularArray([2, 3, 4, 5]) @test similar(v3, Base.OneTo(4)) isa typeof(v3) + @test similar(typeof(v3), Base.OneTo(4)) isa typeof(v3) + @test similar(typeof(v3), 4) isa typeof(v3) v4 = @inferred(CircularArray([1, 2, 3, 4]) .+ 1) @test v4 isa CircularVector{Int64}