Skip to content

Commit

Permalink
Support reshaping custom 0-dimensional arrays (#26870)
Browse files Browse the repository at this point in the history
Fixes #26163.
  • Loading branch information
mbauman authored and JeffBezanson committed Apr 23, 2018
1 parent 923cb6a commit 43fe63c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions base/reshapedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ function __reshape(p::Tuple{AbstractArray,IndexCartesian}, dims::Dims)
ReshapedArray(parent, dims, reverse(mi))
end

function __reshape(p::Tuple{AbstractArray{<:Any,0},IndexCartesian}, dims::Dims)
parent = p[1]
ReshapedArray(parent, dims, ())
end

function __reshape(p::Tuple{AbstractArray,IndexLinear}, dims::Dims)
parent = p[1]
ReshapedArray(parent, dims, ())
Expand Down
16 changes: 16 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,22 @@ end
end
end

struct Z26163 <: AbstractArray{Int,0}; end
Base.size(::Z26163) = ()
Base.getindex(::Z26163) = 0
struct V26163 <: AbstractArray{Int,1}; end
Base.size(::V26163) = (1,)
Base.getindex(::V26163, ::Int) = 0
@testset "reshape of custom zero- and one-dimensional arrays" begin
z = Z26163()
v = V26163()
@test z == reshape(v, ()) == fill(0, ())
@test reshape(z, 1) == v == [0]
@test reshape(z, 1, 1) == reshape(v, 1, 1) == fill(0, 1, 1)
@test occursin("1-element reshape", summary(reshape(z, 1)))
@test_broken occursin("0-dimensional reshape", summary(reshape(v, ())))
end

@test reshape(1:5, (5,)) === 1:5
@test reshape(1:5, 5) === 1:5

Expand Down
3 changes: 2 additions & 1 deletion test/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@
end
end
@testset "join()" begin
@test join([]) == ""
@test join([]) == join([],",") == ""
@test_broken join(()) == join((),",") == ""
@test join(["a"],"?") == "a"
@test join("HELLO",'-') == "H-E-L-L-O"
@test join(1:5, ", ", " and ") == "1, 2, 3, 4 and 5"
Expand Down

0 comments on commit 43fe63c

Please sign in to comment.