Reputation: 63
I am new to Julia and trying to compile a function. My code is something like this and I get an error saying "@ccallable: argument types must be concrete" when I run the code. I also found this is because of the initial value I set to the function. Could anyone help me to solve this problem?
# this doesn't work
Base.@ccallable function test_function(a::Vector{Float64}, b::Float64, c=0.0::Float64)::Vector{Int64}
c = b + c
return a
end
# this works
Base.@ccallable function test_function(a::Vector{Float64}, b::Float64, c::Float64)::Vector{Int64}
c = b + c
return a
end
Upvotes: 2
Views: 243
Reputation: 4510
For the error itself, the problem is c=0.0::Float64
doesn't annotate the type of c
, it asserts that the type of the default value 0.0
is Float64
. You can actually check methods(test_function)
to confirm this. To annotate c
, write this: c::Float64=0
, though that's not actually C-compatible.
Bigger picture, I'm confused about what you mean by "compile a function." The code looks like you're using PackageCompiler
and making a Julia function callable from C. If you only want to compile a Julia function instead, Julia just does it upon every first call with a unique set of concrete argument types.
Upvotes: 1
Reputation: 2838
The function needs to be C-compatible and C does not have optional arguments.
Also, you probably don't want to take Julia Arrays from C, you want to take pointers, see the example at https://github.com/simonbyrne/libcg/blob/25e859ef587f3d00a0a8b6f304a7494f222874d3/CG/src/CG.jl#L27-L38.
Upvotes: 2