-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
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
LangJuliaalso work for scalars / immutable types - Generate the function twice e.g. signature
dummy(::Number)inLangJulia - Take the matlab-code generation code and make it more general e.g
LangMatlabJuliawherecomment_signetc is a parameter. + Make theLangMatlaba wrapper forLangMatlabJulia
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.
Metadata
Metadata
Assignees
Labels
No labels