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).

@vtjnash vtjnash added the forget me not PRs that one wants to make sure aren't forgotten label Jul 19, 2021
jishnub added a commit that referenced this pull request Dec 17, 2024
jishnub added a commit that referenced this pull request Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] forget me not PRs that one wants to make sure aren't forgotten
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants