Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AbstractArray reshape method less specific #333

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Jun 29, 2023

Since this method is meant to be a fallback, this should be less specific than other methods in both the array type and the axis type. This fixes an ambiguity error while using OffsetArrays and FillArrays together:

julia> reshape(Fill(2,6), big(2), :)
ERROR: MethodError: reshape(::Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}, ::Tuple{BigInt, Colon}) is ambiguous.

Candidates:
  reshape(A::AbstractArray, inds::Tuple{Union{Colon, Integer, AbstractUnitRange}, Vararg{Union{Colon, Integer, AbstractUnitRange}}})
    @ OffsetArrays ~/Dropbox/JuliaPackages/OffsetArrays.jl/src/OffsetArrays.jl:352
  reshape(parent::AbstractFill, dims::Tuple{Vararg{Union{Colon, Integer}}})
    @ FillArrays ~/Dropbox/JuliaPackages/FillArrays.jl/src/FillArrays.jl:253

Possible fix, define
  reshape(::AbstractFill, ::Tuple{Union{Colon, Integer}, Vararg{Union{Colon, Integer}}})

After this PR

julia> reshape(Fill(2,6), big(2), :)
2×3 Fill{Int64}, with entries equal to 2

@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #333 (79e70d0) into master (0929e07) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #333   +/-   ##
=======================================
  Coverage   98.67%   98.67%           
=======================================
  Files           5        5           
  Lines         452      452           
=======================================
  Hits          446      446           
  Misses          6        6           
Impacted Files Coverage Δ
src/OffsetArrays.jl 98.29% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@timholy
Copy link
Member

timholy commented Jun 29, 2023

The only potential problem with that is that Tuple{} <: Tuple{Vararg{T}}. Do we have a test for a 0d reshape?

@jishnub
Copy link
Member Author

jishnub commented Jun 29, 2023

Yes, I have added a test for that in this PR. That works because Base defines reshape for Tuple{Vararg{Int}}, which is more specific than Tuple{Vararg{OffsetAxis}}.

@timholy
Copy link
Member

timholy commented Jun 29, 2023

Shoot, I missed that. Thanks for doing this! This is subtle design and you've clearly mastered it.

@jishnub
Copy link
Member Author

jishnub commented Jun 30, 2023

Test failure on v1.0 is due to JuliaMath/IntegerMathUtils.jl#5, and would hopefully be fixed by JuliaRegistries/General#86557

@jishnub jishnub merged commit e8964c8 into master Jul 3, 2023
27 of 30 checks passed
@jishnub jishnub deleted the jb/reshapeambiguity branch July 3, 2023 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants