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

Type piracy on similar with Unions #857

Open
kapple19 opened this issue Nov 12, 2024 · 2 comments
Open

Type piracy on similar with Unions #857

kapple19 opened this issue Nov 12, 2024 · 2 comments
Labels

Comments

@kapple19
Copy link
Contributor

kapple19 commented Nov 12, 2024

During development of #852, a new method defined as

function DimArray(gen::Base.Generator, argdims=nothing; dims=nothing, kw...) 
    A = collect(gen)
    ds = isnothing(dims) ? argdims : dims
    if isnothing(ds)
        A isa DimArray || throw(ArgumentError("No dims. Use Dimensions wrappers in the generator or pass `dims` as a keyword or second argument."))
        rebuild(A; kw...)
    else
        rebuild(A; dims=ds, kw...)
    end
end

triggers the following error

ERROR: MethodError: similar(::Type{Matrix{Int64}}, ::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}) is ambiguous.

when the following generator example (which has no DimArray involvement) is run

(x + y for x in 1:5, y in 1:3)

Full error message:

ERROR: MethodError: similar(::Type{Matrix{Int64}}, ::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}) is ambiguous.

Candidates:
  similar(T::Type{<:AbstractArray}, shape::Tuple{Union{Integer, Base.OneTo, DimensionalData.Dimensions.DimUnitRange}, Union{Integer, Base.OneTo, DimensionalData.Dimensions.DimUnitRange}, Vararg{Union{Integer, Base.OneTo, DimensionalData.Dimensions.DimUnitRange}}}; kw...)
    @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:208
  similar(::Type{T}, shape::Tuple{Union{Integer, Base.OneTo}, Vararg{Union{Integer, Base.OneTo}}}) where T<:AbstractArray
    @ Base abstractarray.jl:867

Possible fix, define
  similar(::Type{T}, ::Tuple{Union{…}, Union{…}, Vararg{…}}) where T<:AbstractArray

Stacktrace:
 [1] _similar(::Type{…}, shape::Tuple{…}; kw::@Kwargs{})
   @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:252
 [2] _similar(::Type{…}, shape::Tuple{…})
   @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:251
 [3] similar(T::Type{…}, shape::Tuple{…}; kw::@Kwargs{})
   @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:211
 [4] similar(T::Type{…}, shape::Tuple{…})
   @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:208
 [5] _array_for(::Type{…}, ::Base.HasShape{…}, axs::Tuple{…})
   @ Base .\array.jl:665
 [6] collect(itr::Base.Generator{Base.Iterators.ProductIterator{Tuple{Dim{…}, Dim{…}}}, var"#15#16"})
   @ Base .\array.jl:0
 [7] DimArray(gen::Base.Generator{Base.Iterators.ProductIterator{Tuple{…}}, var"#15#16"}; dims::Nothing, kw::@Kwargs{})
   @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:492
 [8] DimArray(gen::Base.Generator{Base.Iterators.ProductIterator{Tuple{Dim{…}, Dim{…}}}, var"#15#16"})
   @ DimensionalData C:\Users\Aaron\.julia\dev\DimensionalData\src\array\array.jl:491
 [9] top-level scope
   @ REPL[5]:1
@rafaqz rafaqz added the piracy label Dec 13, 2024
@rafaqz
Copy link
Owner

rafaqz commented Dec 13, 2024

Not sure how this is getting past Aqua.jl checks

@rafaqz
Copy link
Owner

rafaqz commented Dec 14, 2024

Do you have a complete MWE so I can try to reproduce this? Best to show all the methods you are calling from a clean start that will trigger the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants