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

promote_type stack overflow #160

Closed
ArrogantGao opened this issue Jan 2, 2024 · 3 comments
Closed

promote_type stack overflow #160

ArrogantGao opened this issue Jan 2, 2024 · 3 comments

Comments

@ArrogantGao
Copy link
Contributor

ArrogantGao commented Jan 2, 2024

In

@inline function get_size_dict(ixs, xs, size_info=nothing)
    LT = promote_type(eltype.(ixs)...)
    return get_size_dict!(ixs, xs, size_info===nothing ? Dict{LT,Int}() : size_info)
end

the function promote_type is directly used and I found when the eltype.(ixs) is large (greater that 10000 for example), it causes stack overflow.

@ArrogantGao
Copy link
Contributor Author

A possible solution

julia> function promote_type_array(T::Vector{DataType})
           LT = T[1]
           for i in 1:length(T)
               LT = promote_type(LT, T[i])
           end
           return LT
       end
promote_type_array (generic function with 1 method)

julia> type_array = [Int32 for i in 1:100000];

julia> promote_type_array(type_array)
Int32

@GiggleLiu
Copy link
Collaborator

GiggleLiu commented Jan 3, 2024

A possible solution

julia> function promote_type_array(T::Vector{DataType})
           LT = T[1]
           for i in 1:length(T)
               LT = promote_type(LT, T[i])
           end
           return LT
       end
promote_type_array (generic function with 1 method)

julia> type_array = [Int32 for i in 1:100000];

julia> promote_type_array(type_array)
Int32

Yeah, that is true. Could you please help implement this change by submitting a PR?
Also, have you tried the reduce function? It could be an easier solution.

@ArrogantGao
Copy link
Contributor Author

ArrogantGao commented Jan 4, 2024

After using the reduce function the code seems much better

julia> type_array = [Int32 for i in 1:10000];

julia> @btime reduce($promote_type, $type_array)
  663.625 μs (0 allocations: 0 bytes)
Int32

I will submit a PR for that.

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

No branches or pull requests

2 participants