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

Define promotion rules #19

Closed
oxinabox opened this issue Oct 29, 2020 · 1 comment · Fixed by #25
Closed

Define promotion rules #19

oxinabox opened this issue Oct 29, 2020 · 1 comment · Fixed by #25

Comments

@oxinabox
Copy link
Member

oxinabox commented Oct 29, 2020

if one e.g. vcats two arrays of ShortStrings the result should be an array of ShortStrings of the larger size.

Like for the integers that back them:

julia> vcat(Int16[1,2,3], Int64[1,2,3])
6-element Vector{Int64}:
 1
 2
 3                                                                                                                                                     1
 2
 3

We want the same for ShortStrings

julia> vcat(ShortString3["ab", "cd"], ShortString7["abcd", "efgc"])
ERROR: MethodError: promote_rule(::Type{Union{}}, ::Type{UInt64}) is ambiguous. Candidates:
  promote_rule(::Type{var"#s818"} where var"#s818"<:AbstractIrrational, ::Type{T}) where T<:Real in Base at irrationals.jl:42
  promote_rule(::Type{S}, ::Type{T}) where {S<:AbstractIrrational, T<:Number} in Base at irrationals.jl:43
  promote_rule(::Type{X}, ::Type{Y}) where {X<:Union{BitIntegers.AbstractBitSigned, BitIntegers.AbstractBitUnsigned}, Y<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8, BitIntegers.AbstractBitSigned, BitIntegers.AbstractBitUnsigned}} in BitIntegers at /Users/oxinabox/.julia/packages/BitIntegers/fcpdN/src/BitIntegers.jl:223
Possible fix, define
  promote_rule(::Type{Union{}}, ::Type{Y}) where Y<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8, BitIntegers.AbstractBitSigned, BitIntegers.AbstractBitUnsigned}
Stacktrace:
 [1] promote_rule(#unused#::Type{ShortString{Union{}}}, #unused#::Type{ShortString7})
   @ ShortStrings ~/.julia/packages/ShortStrings/qiyr7/src/base.jl:67
 [2] promote_type
   @ ./promotion.jl:233 [inlined]
 [3] promote_result
   @ ./promotion.jl:247 [inlined]
 [4] promote_type
   @ ./promotion.jl:233 [inlined]
 [5] promote_eltype(v1::Vector{ShortString3}, vs::Vector{ShortString7})
   @ Base /usr/local/src/julia/julia-master/base/abstractarray.jl:1413
 [6] vcat(::Vector{ShortString3}, ::Vector{ShortString7})
   @ SparseArrays /usr/local/src/julia/julia-master/usr/share/julia/stdlib/v1.6/SparseArrays/src/sparsevector.jl:1113
 [7] top-level scope
   @ REPL[19]:1

Behavour is correct for vcating Vector{String} to Vector{ShortSting3} though. That does promote to String

julia> vcat(ShortString3["ab", "cd"], ["abcd", "efgc"])
4-element Vector{String}:
 "ab"
 "cd"
 "abcd"
 "efgc"

This requires #18 to be efficient

@xiaodaigh
Copy link
Collaborator

ShortString{Union{}}

what I don't understand is , where does this come from?

@xiaodaigh xiaodaigh mentioned this issue Oct 31, 2020
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 a pull request may close this issue.

2 participants