Skip to content

BUG: gen_kernel failing (in albop/compat07 #52

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

Closed
albop opened this issue Sep 18, 2018 · 7 comments
Closed

BUG: gen_kernel failing (in albop/compat07 #52

albop opened this issue Sep 18, 2018 · 7 comments

Comments

@albop
Copy link
Member

albop commented Sep 18, 2018

Working on compatibility branch. Thef following raises an error:


import DataStructures
import Dolang

fff =  Dolang.FlatFunctionFactory(
    # equations
    DataStructures.OrderedDict{Symbol,Union{Expr, Number, Symbol}}(
        :_out_1_=>:(_pi__1_ / _R__0_ - _beta_ * (_C_s__0_ / _C_s__1_)),
        :_out_2_=>:(_nu_ * _N_s__0_ ^ _phi_ - _W__0_ / _C_s__0_),
        :_out_3_=>:((((_epsilon_ / (_epsilon_ - 1)) * _mc__0_ * _C__0_) / _C_s__0_ + _theta_ * _beta_ * _pi__1_ ^ _epsilon_ * _F1__1_) - _F1__0_),
        :_out_4_=>:(((_C__0_ * 1) / _C_s__0_ + _theta_ * _beta_ * _pi__1_ ^ (_epsilon_ - 1) * _F2__1_) - _F2__0_),
        :_out_5_=>:(_C__0_ - (_N__0_ - _mu_ * _C_star_) / _Delta__0_),
        :_out_6_=>:(_R__0_ - _R_st_ * _pi__0_ ^ _phi_pi_ * (_C__0_ / _C_star_) ^ _phi_y_),:_out_7_=>:(_R__0_ / _pi__1_ - _real_r__0_)),
    # argument names
    DataStructures.OrderedDict(
        :m=>[:_e_z__0_],
        :s=>[:_z__0_, :_Delta__L__0_],
        :x=>[:_C_s__0_, :_N_s__0_, :_F1__0_, :_F2__0_, :_R__0_, :_real_r__0_, :_C__0_],:M=>[:_e_z__1_],
        :S=>[:_z__1_, :_Delta__L__1_],:X=>[:_C_s__1_, :_N_s__1_, :_F1__1_, :_F2__1_, :_R__1_, :_real_r__1_, :_C__1_],
        :p=>[:_epsilon_, :_phi_, :_mu_, :_nu_, :_C_star_, :_pi_st_, :_R_st_, :_lbda_, :_NC_, :_beta_, :_phi_pi_, :_phi_y_, :_theta_, :_sig_z_, :_rho_z_]),
    # output names
    Symbol[:_out_1_, :_out_2_, :_out_3_, :_out_4_, :_out_5_, :_out_6_, :_out_7_],
    # preamble
    DataStructures.OrderedDict{Symbol,Union{Expr, Number, Symbol}}(
        :_pi__0_=>:(((1 - (_F1__0_ / _F2__0_) ^ (1 - _epsilon_) * (1 - _theta_)) / _theta_) ^ (1 / (_epsilon_ - 1))),
        :_Delta__0_=>:(_theta_ * _pi__0_ ^ _epsilon_ * _Delta__L__0_ + (1 - _theta_) * (_F1__0_ / _F2__0_) ^ -_epsilon_),
        :_pi__1_=>:(((1 - (_F1__1_ / _F2__1_) ^ (1 - _epsilon_) * (1 - _theta_)) / _theta_) ^ (1 / (_epsilon_ - 1))),:_W__0_=>:(_C_h__0_ / _N_h__0_),
        :_mc__0_=>:(_W__0_ * exp(_z__0_)),:_N__0_=>:((1 - _lbda_) * _N_s__0_ + _lbda_ * _N_h__0_)),
    # funname
    :arbitrage)


Dolang.gen_kernel(fff, [0])

Error is:

ERROR: BoundsError: attempt to access ()
  at index [1]
Stacktrace:
 [1] getindex(::Tuple{}, ::Int64) at ./tuple.jl:24
 [2] _cat at /home/pablo/.julia/packages/AxisArrays/G6pZY/src/combine.jl:20 [inlined]
 [3] #cat#44(::Int64, ::Function) at /home/pablo/.julia/packages/AxisArrays/G6pZY/src/combine.jl:16
 [4] (::getfield(Base, Symbol("#kw##cat")))(::NamedTuple{(:dims,),Tuple{Int64}}, ::typeof(cat)) at ./none:0
 [5] #gen_kernel#89(::Symbol, ::DataStructures.OrderedDict{Symbol,Array{Symbol,1}}, ::Function, ::Dolang.FlatFunctionFactory, ::Array{Int64,1}) at /home/pablo/.julia/dev/Dolang/src/compiler_new.jl:133
 [6] gen_kernel(::Dolang.FlatFunctionFactory, ::Array{Int64,1}) at /home/pablo/.julia/dev/Dolang/src/compiler_new.jl:107
 [7] top-level scope at none:0

@albop
Copy link
Member Author

albop commented Sep 18, 2018

this happens only if AxisArrays is imported before. (it is not used directly in Dolang)

@albop
Copy link
Member Author

albop commented Sep 18, 2018

So this is a pure AxisArrays bug:

julia> using AxisArrays

julia> ll = Array{Array{Symbol,1},1}()
0-element Array{Array{Symbol,1},1}

julia> cat(ll..., dims=1)
ERROR: BoundsError: attempt to access ()
  at index [1]
Stacktrace:
 [1] getindex(::Tuple{}, ::Int64) at ./tuple.jl:24
 [2] _cat at /home/pablo/.julia/packages/AxisArrays/G6pZY/src/combine.jl:20 [inlined]
 [3] #cat#44(::Int64, ::Function) at /home/pablo/.julia/packages/AxisArrays/G6pZY/src/combine.jl:16
 [4] (::getfield(Base, Symbol("#kw##cat")))(::NamedTuple{(:dims,),Tuple{Int64}}, ::typeof(cat)) at ./none:0
 [5] top-level scope at none:0

@sglyon
Copy link
Member

sglyon commented Sep 18, 2018

Looks like they do some type piracy :(

@albop
Copy link
Member Author

albop commented Sep 19, 2018

Yes, I opened an issue there: JuliaArrays/AxisArrays.jl#145

@nalimilan
Copy link

In general if the number of arrays to concatenate is large, better call reduce(vcat, ll) (which is optimized on Julia 0.7/1.0). Maybe that will also work around the problem.

@albop
Copy link
Member Author

albop commented Sep 20, 2018

Thank you @nalimilan, I'll follow your suggestion.

@albop
Copy link
Member Author

albop commented Sep 20, 2018

Closing as it was fixed by AxisArrays people.

@albop albop closed this as completed Sep 21, 2018
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

3 participants