Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ Base.reshape(A::OffsetVector, ::Colon) = A
Base.reshape(A::OffsetArray, inds::Union{Int,Colon}...) = reshape(parent(A), inds)
Base.reshape(A::OffsetArray, inds::Tuple{Vararg{Union{Int,Colon}}}) = reshape(parent(A), inds)

function Base.similar(::Type{T}, shape::Tuple{OffsetAxis,Vararg{OffsetAxis}}) where {T<:AbstractArray}
function Base.similar(::Type{T}, shape::Tuple{OffsetAxisKnownLength,Vararg{OffsetAxisKnownLength}}) where {T<:AbstractArray}
P = T(undef, map(_indexlength, shape))
OffsetArray(P, map(_offset, axes(P), shape))
end
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,22 @@ end
@test_throws MethodError similar(A, (: ,2))
@test_throws MethodError similar(A, Float64, (: ,:))
@test_throws MethodError similar(A, Float64, (: ,2))

function testsimilar(args...)
try
similar(args...)
catch e
@test e isa MethodError
io = IOBuffer()
showerror(io, e)
s = split(String(take!(io)),'\n')[1]
@test occursin(repr(similar), s)
end
end

testsimilar(typeof(A), (:, :))
testsimilar(typeof(A), (:, 2))
testsimilar(typeof(A), (:, 1:3))
end

@testset "reshape" begin
Expand Down