Python 参数类型与 C++ 签名不匹配
Posted
技术标签:
【中文标题】Python 参数类型与 C++ 签名不匹配【英文标题】:Python argument types did not match C++ signature 【发布时间】:2017-01-26 12:01:52 【问题描述】:我一直在使用图形工具中的推理模块,并尝试复制食谱部分中的一段代码。但是,在运行 gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))
时,我会收到一条错误消息。
它似乎围绕着与 C++ 签名不匹配的 Python 参数类型展开。在对不同的模块(?)使用不同的编译器时,似乎会出现一些搜索。但是,在这种情况下,我正在运行从 apt-get
(2.19 (commit da041f33, Sat Nov 12 17:27:48 2016 +0100)) 下载的包,所以我很惊讶地看到它。如果在源代码的编译版本(2.20dev (commit 01432d60, Sun Jan 15 19:54:52 2017 +0000))上运行它,也会引发相同的错误。
有人知道这里出了什么问题/我该如何解决?
这是相关代码sn -p:
import graph_tool.all as gt
import timeit, os
import cPickle as pickle
import numpy as np
g = gt.load_graph('graph_no_multi_reac_type.gt')
gt.remove_parallel_edges(g)
state = gt.minimize_nested_blockmodel_dl(g, deg_corr=True)
# We will first equilibrate the Markov chain
gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))
这是我收到的错误消息:
Traceback (most recent call last):
File "num_groups_marg_prob.py", line 26, in <module>
gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10))
File "/usr/lib/python2.7/dist-packages/graph_tool/inference/mcmc.py", line 127, in mcmc_equilibrate
delta, nmoves = state.mcmc_sweep(**mcmc_args)
File "/usr/lib/python2.7/dist-packages/graph_tool/inference/nested_blockmodel.py", line 576, in mcmc_sweep
return self._h_sweep(lambda s, **a: s.mcmc_sweep(**a), c=c, **kwargs)
File "/usr/lib/python2.7/dist-packages/graph_tool/inference/nested_blockmodel.py", line 499, in _h_sweep
get_entropy_args(eargs))
File "/usr/lib/python2.7/dist-packages/graph_tool/inference/blockmodel.py", line 616, in _couple_state
self._state.couple_state(state._state, entropy_args)
Boost.Python.ArgumentError: Python argument types in
graph_tool::BlockState<boost::adj_list<unsigned long>, graph_tool::simple_degs_t, std::integral_constant<bool, false>, std::integral_constant<bool, false>, boost::any, boost::any, boost::any, boost::unchecked_vector_property_map<int, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, bool, int, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::typed_identity_property_map<unsigned long> >, double, double, double, double, double, double, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, bool>.couple_state(graph_tool::BlockState<boost::adj_list<unsigned long>, graph_tool::simple_degs_t, std::integral_constant<bool, false>, std::integral_constant<bool, false>, boost::any, boost::any, boost::any, boost::unchecked_vector_property_map<int, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, bool, int, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::typed_identity_property_map<unsigned long> >, double, double, double, double, double, double, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, bool>, graph_tool::BlockState<boost::adj_list<unsigned long>, graph_tool::simple_degs_t, std::integral_constant<bool, true>, std::integral_constant<bool, false>, boost::any, boost::any, boost::any, boost::unchecked_vector_property_map<int, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, bool, int, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::typed_identity_property_map<unsigned long> >, double, double, double, double, double, double, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, bool>, entropy_args)
did not match C++ signature:
couple_state(graph_tool::BlockState<boost::adj_list<unsigned long>, graph_tool::simple_degs_t, std::integral_constant<bool, false>, std::integral_constant<bool, false>, boost::any, boost::any, boost::any, boost::unchecked_vector_property_map<int, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, bool, int, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::typed_identity_property_map<unsigned long> >, double, double, double, double, double, double, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, bool> lvalue, graph_tool::BlockState<boost::adj_list<unsigned long>, graph_tool::simple_degs_t, std::integral_constant<bool, false>, std::integral_constant<bool, false>, boost::any, boost::any, boost::any, boost::unchecked_vector_property_map<int, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, std::vector<unsigned long, std::allocator<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<int, boost::typed_identity_property_map<unsigned long> >, bool, int, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::adj_edge_index_property_map<unsigned long> >, boost::unchecked_vector_property_map<double, boost::typed_identity_property_map<unsigned long> >, double, double, double, double, double, double, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, boost::unchecked_vector_property_map<unsigned char, boost::typed_identity_property_map<unsigned long> >, bool> lvalue, graph_tool::entropy_args_t)
【问题讨论】:
【参考方案1】:代码不起作用,因为在执行 mcmc 平衡之前必须启用采样
state = state.copy(sampling=True)
正如这里指出的http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/self-state-couple-state-state-state-entropy-args-Python-argument-types-did-not-match-C-signature-td4026975.html#a4026979
【讨论】:
以上是关于Python 参数类型与 C++ 签名不匹配的主要内容,如果未能解决你的问题,请参考以下文章
C++,2参数类模板的部分特化:无法将函数定义与现有声明匹配
如何检查检查PInvoke签名的调用约定和参数与非托管的目标签名是不是匹配?
C# DllImport“调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配 ”