CxxWrap.jl
CxxWrap.jl copied to clipboard
failure on complex array
Code is here: https://gist.github.com/nbecker/e1d67619be96f788c6f8eba3cf9ca0d0
g++ and clang++ both have a similar complaint:
/usr/include/boost/accumulators/statistics/sum.hpp:46:23: error: no match for 'operator+=' (operand types are 'std::complex
I'm baffled - a very similar test "summer.cc" compiles fine. I don't know why the conversion here fails.
Where exactly in your code does this happen? It definitely looks like a CxxWrap bug, the JuliaComplex type should never "escape" into your code but be converted to std::complex automatically, possibly I missed some case where a reference is taken.
mod.method ("call", [](accum_t& a, xt::jlarray<el_t> s) {
for (auto e : s) a(e); <<<< error is here
return a;
});
I've updated the gist adding the complete compiler messages
I have no idea why, but iterating over the jlarray seems to return the Julia type, so replacing your loop with the following seems to work:
for (auto e : s) a(jlcxx::convert_to_cpp<el_t>(e));
But this doesn't fix this test:
mod.method ("inc", [](xt::jltensor<el_t,1> s) {
s[0] += 1;
});
In this case, convert_to_cpp can't be used because we need an lvalue
You can't modify the Julia value in-place because the numbers (both Float64
and Complex
) are immutable. I think something like this should work:
s[0] = jlcxx::convert_to_julia(jlcxx::convert_to_cpp<el_t>(s[0]) + 1);
@barche close?