我正在尝试使用cProfile
和pstats
库对代码进行基准测试。这是我目前掌握的代码:
profile = cProfile.Profile()
profile.runcall(gillespie_tau_leaping(propensity_calc, popul_num, LHS, stoch_rate, popul_num_all, tao_all, rxn_vector, delta_t, tao, epsi))
ps = pstats.Stats(profile)
ps.print_stats()
我试图对gillespie_tau_leaping
函数进行基准测试,该函数的输入都是数组,除了作为函数的propensity_calc
和作为常量的delta_t
之外
只是目前我得到了以下错误:
File "c:/Users/Mike/visual studio code project/MSc dissertation code/tau_leaping_variant_ssa.py", line 190, in <module>
profile.runcall(gillespie_tau_leaping(propensity_calc, popul_num, LHS, stoch_rate, popul_num_all, tao_all, rxn_vector, delta_t, tao, epsi))
TypeError: 'tuple' object is not callable
在线profile.runcall(gillespie_tau_leaping(propensity_calc, popul_num, LHS, stoch_rate, popul_num_all, tao_all, rxn_vector, delta_t, tao, epsi))
我以前也遇到过类似的问题,我实际上没有将函数作为参数传递,而是调用函数并将结果(元组)传递给内置函数,根据文档,内置函数需要传递函数
这里是不是也有同样的问题,如果是,我该如何解决它(我上次没弄明白)
干杯
对于这个函数以及大多数类似的函数,将函数本身(未调用)传递给函数,然后将参数作为参数传递给
runcall
it's documented取func
,然后是varargs和kwargs(*args
和**kwargs
)。您所做的所有更改都是删除函数的调用参数,并在函数后面加一个逗号以将其与其参数分隔开:相关问题 更多 >
编程相关推荐