Julia Cxx 在模块中打包不同的行为
julia Cxx package different behavior when in module
我正在使用Julia 1.1.1和Cxx的0.3.2版本。我发现当我从我定义的模块中调用 icxx" 时出现错误,但在 REPL 中调用它时则没有。在 REPL 中,我有:
using Cxx
function xformVectors()
cxx"""
#include <iostream>
#include <vector>
class Summer {
public:
Summer() {}
std::vector<int> compute_sum(const std::vector<std::vector<int>> &input) {
std::vector<int> 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;
}
};
"""
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
如果我然后调用xformVectors()
,它会写出几个整数并退出(预期行为(。如果我使用 Pkg.generate(( 将此代码包装在模块中,然后调用xformVectors()
,则会出现致命错误:
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 /home/jov9025/.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 /home/jov9025/sandbox/julia/Vector2Vector.jl/src/Vector2Vector.jl:30
[6] top-level scope at none:0
如果在 REPL 中包含源文件 (include("src/Vector2Vector.jl"
(,然后调用Vector2Vector.xformVectors()
,它运行而不会抱怨。
知道发生了什么吗?
我的代码中产生错误的行是:
cxx_v = icxx"$summer->compute_sum($x);"
我仍然不明白 icxx"的问题是什么,但我实际上不需要在此示例(或我的真实代码(中使用它。我只能使用@cxx
宏,瞧,没有崩溃:
cxx_v = @cxx compute_sum(x)
所以,我可能问错了问题(尽管我认为这是一个有趣的问题(。
在 2020 年 1 月重新审视这一点:使用 Cxx 的 0.3.3 版,代码在 REPL 中的原始 icxx" 行中执行得很好。
相关文章:
- 将不同类型的模板参数包提取到双精度向量中会产生警告
- 将函数应用于元组中的每个元素,将每个元素强制转换为类型包中的不同类型,然后作为参数包传递
- 在不同的模板参数包之间分发非类型参数包
- Julia Cxx 在模块中打包不同的行为
- 不同的数据包,联合 - 正确的用法\验证?
- 是否可以调用具有不同参数数量的函数,传递相同的参数包
- 空包的函数variadic模板包扩展在Clang 和G 中给出了不同的结果
- 从参数包创建不同的参数包
- 如何将具有不同模板参数的相同结构作为参数包传递
- 在变差函数的不同参数包中推导两个不同的已知类型变量
- 如何使用 C# 创建 Nuget 包,以及如何使用不同选项生成的C++库
- 如何使用 CMake 强制 c++ 编译器使用不同已安装包的版本之一?
- 如何在两个文本文件中计算不同的数据包编号
- 从c++中的串行端口读取不同包大小的数据流的最佳方式
- 数据包:有效地表示不同的数据包类型
- 展开具有不同长度的参数包
- 将从不同模块和包生成的类导入到当前类中
- 如何在OMNeT++中存储不同时间戳的数据包
- 在具有不同UDP端口的网络计算机上发送/接收数据包
- 传递不同类型的数据,以void指针函数添加到网络数据包(我认为?)