Hello,
I have a Julia function like
function f(x::AbstractVector{Float64}, y::AbstractVector{Float64})
y[1] = 2.0*x[1];
y[2] = 2.0*x[2];
return nothing;
end;
which takes in input two arrays of Float64
and modifies the second one in place.
I am trying to use CxxWrap
to evaluate this function with x
and y
as std::vector<double>
, but I haven’t been able to succeed so far.
On the C++ side I have:
JLCXX_MODULE define_julia_module(jlcxx::Module& mod) {
mod.method("call_val", [](void(*func)(std::vector<double>, std::vector<double>)) {
std::vector<double> x = {1.0, 2.0};
std::vector<double> y(x.size());
func(x, y);
return y;
});
mod.method("call_ref", [](void(*func)(std::vector<double>&, std::vector<double>&)) {
std::vector<double> x = {1.0, 2.0};
std::vector<double> y(x.size());
func(x, y);
return y;
});
}
while on the Julia side:
f_val_c = @safe_cfunction(f, Cvoid, (CxxWrap.StdLib.StdVectorAllocated{Float64}, CxxWrap.StdLib.StdVectorAllocated{Float64},));
f_ref_c = @safe_cfunction(f, Cvoid, (CxxRef{CxxWrap.StdLib.StdVectorAllocated{Float64}}, CxxRef{CxxWrap.StdLib.StdVectorAllocated{Float64}},));
a = call_val(f_val_c);
println(a);
b = call_ref(f_ref_c);
println(b);
the first option doesn’t throw any error, but since y
is passed by value to func
, I have no way to use the outcome of the function evaluation.
In the second case, I get this error:
ERROR: Incorrect argument type for cfunction at position 1, expected: CxxRef, obtained: CxxRef
I tried to modify the signature passed to @safe_cfunction
in few different ways, but none seems to work.
Do you have any suggestion?