Skip to content

Conversation

@jishnub
Copy link
Member

@jishnub jishnub commented Jun 3, 2021

This collects the less controversial fixes from #41003.

After this PR, the following will work:

julia> reshape(1:3, Int8(1), :)
1×3 reshape(::UnitRange{Int64}, 1, 3) with eltype Int64:
 1  2  3

julia> reshape(1:3, Base.OneTo(1), :)
1×3 reshape(::UnitRange{Int64}, 1, 3) with eltype Int64:
 1  2  3

julia> reshape(1:3, Base.OneTo(1), :, 1)
1×3×1 reshape(::UnitRange{Int64}, 1, 3, 1) with eltype Int64:
[:, :, 1] =
 1  2  3

@jishnub jishnub changed the title make reshape accept Integers and ranges Make reshape accept a combination of Integers, Base.OneTo and a single Colon consistently Jun 3, 2021
@dkarrasch dkarrasch added the arrays [a, r, r, a, y, s] label Jun 3, 2021
reshape(parent::AbstractArray, dims::Int...) = reshape(parent, dims)
reshape(parent::AbstractArray, dims::Union{Int,Colon}...) = reshape(parent, dims)
reshape(parent::AbstractArray, dims::Tuple{Vararg{Union{Int,Colon}}}) = reshape(parent, _reshape_uncolon(parent, dims))
reshape(parent::AbstractArray, dims::Tuple{Vararg{Union{Integer,Colon,Base.OneTo}}}) = reshape(parent, _reshape_uncolon(parent, dims))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it should be:

Suggested change
reshape(parent::AbstractArray, dims::Tuple{Vararg{Union{Integer,Colon,Base.OneTo}}}) = reshape(parent, _reshape_uncolon(parent, dims))
reshape(parent::AbstractArray, dims::Tuple) = reshape(parent, _reshape_uncolon(parent, dims))

wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, although perhaps worth mentioning that this almost makes _reshape_uncolon part of the API (it becomes a tempting target for package specialization).

@DilumAluthge
Copy link
Member

Is this PR still needed? If so, @jishnub can you rebase and fix the merge conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants