I’m using Cxx, and my use case involves converting std::vector return values into Julia arrays. I’m able to define my functions in the REPL, and everything behaves as I would expect. However, if I wrap all this in a module, I get a fatal error at an invocation of icxx"". I’ve been able to replicate this behavior with a reasonably simple test case:
module Vector2Vector
using Cxx
export xformVectors, defineSummer
function defineSummer()
cxx"“”
#include
#includeclass Summer {
public:
Summer() {}
std::vector compute_sum(const std::vector<std::vector> &input) {
std::vector result(input.size(), 0);
for (std::size_t i = 0; i != input.size(); ++i) {
for (std::size_t j = 0; j != input[i].size(); ++j) {
result[i] += input[i][j];
}
}
return result;
}
};
“”"
endfunction xformVectors()
as = [rand(1:10,5), rand(1:10,6)] x = convert(cxxt"std::vector< std::vector< int > >", as) summer = @cxxnew Summer() cxx_v = icxx"$summer->compute_sum($x);" for v in cxx_v println(collect(v)) end
end
end # module
If, in the REPL, I now type:
using Vector2Vector:, defineSummer, xformVectors
defineSummer()
xformVectors()
I get this error:
ERROR: BoundsError: attempt to access 36-element Array{Tuple{AbstractString,Symbol,Int64,Int64,Bool},1} at index [37]
Stacktrace:
[1] getindex(::Array{Tuple{AbstractString,Symbol,Int64,Int64,Bool},1}, ::Int64) at ./array.jl:729
[2] #s37#70 at …/.julia/packages/Cxx/vxYtJ/src/cxxstr.jl:705 [inlined]
[3] #s37#70(::Any, ::Any, ::Any, ::Any) at ./none:0
[4] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:522
[5] xformVectors() at …/sandbox/julia/Vector2Vector.jl/src/Vector2Vector.jl:33
[6] top-level scope at none:0
Line 33 in Vector2Vector.jl is:
cxx_v = icxx"$summer->compute_sum($x);"
The version of Julia I’m running is 1.1.1 and 0.3.2 of Cxx. I’ve tried running with Debugger.jl, but haven’t learned anything helpful.