You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
julia generation generation does not work for scalars #76
Currently the Julia code generator does not work for scalars.
julia> (graph,_)=graph_ps([1 2 3.0 33 4.4 10.0]);
julia> gen_code("/tmp/mycode.jl",graph);
julia> include("/tmp/mycode.jl")
dummy! (generic function with 1 method)
julia> dummy(0.3)
ERROR: MethodError: no method matching similar(::Float64, ::Type{Float64})
Closest candidates are:
similar(::UpperHessenberg, ::Type{T}, ::Tuple{Vararg{Int64, N}}) where {T, N}
...
julia> # Wrap it as a matrix and it works
julia> dummy(reshape([0.3],1,1))
1×1 Matrix{Float64}:
2.8209400000000002
There are lines like this in the generated code:
copyto!(A_copy, A);
which assumes that we can modify the contents of the variable A_copy, i.e., that it is mutable; e.g., Float64-numbers are immutable.
Observation: The generated MATLAB-code is very close to code that could be executed in Julia. One needs only to replace the comment sign, remove the I=eye and change the function definition to make it run. Seems close to efficient Julia code for scalars.
Alternatives:
Make the generated Julia code with LangJulia also work for scalars / immutable types
Generate the function twice e.g. signature dummy(::Number) in LangJulia
Take the matlab-code generation code and make it more general e.g LangMatlabJulia where comment_sign etc is a parameter. + Make the LangMatlab a wrapper for LangMatlabJulia
I have my doubts that option 0 is doable, since we have mul!-calls etc based on memory managements. Option 2 seems to be better in terms of avoiding code-repetition in our package, but would make matlab code generation more involved.
Activity
[-]julia generation that works for scalar variables[/-][+]julia generation generation does not work for scalars [/+]