小编Eri*_*ren的帖子

线路分析 Cython 0.25

我正在尝试对我在 Cython 中编写的一些代码进行分析。但我无法让它发挥作用。

我尝试按照如何逐行分析 cython 函数中给出的所有步骤进行操作

但结果我没有得到任何计时。我所做的发布在这里:

我正在使用 python 3.6 和 Cython 0.25.2

我尝试做的事情:

首先我运行:

python setup.py build_ext --inplace
Run Code Online (Sandbox Code Playgroud)

在 setup.py 中我添加了:

import Cython.Compiler.Options

Cython.Compiler.Options.get_directive_defaults()['profile'] = True
Cython.Compiler.Options.get_directive_defaults()['linetrace'] = True
Cython.Compiler.Options.get_directive_defaults()['binding'] = True
Run Code Online (Sandbox Code Playgroud)

以及我添加的扩展,

define_macros=[('CYTHON_TRACE', '1')]
Run Code Online (Sandbox Code Playgroud)

在脚本 runMIcython.pyx 中,我添加了:

@cython.profile(True)
@cython.linetrace(True)
@cython.binding(True)
Run Code Online (Sandbox Code Playgroud)

在 ipython shell 中,我尝试运行(大约需要 1 分钟):

%load_ext line_profiler
import line_profiler 
import runMolecularIntegrals  
profile = line_profiler.LineProfiler(runMolecularIntegrals.runCythonIntegrals)
profile.runcall(runMolecularIntegrals.runIntegrals) 
profile.print_stats()
Run Code Online (Sandbox Code Playgroud)

但我得到的输出是:

Line #      Hits         Time  Per Hit   % Time  Line Contents  
==============================================================  
    10                                           cpdef 
runCythonIntegrals(int [:,:] basisidx, double [:,:] basisfloat, …
Run Code Online (Sandbox Code Playgroud)

python cython line-profiler

5
推荐指数
0
解决办法
317
查看次数

在 Numba 优化的 Python 中将类对象作为函数参数传递

我想将一个类对象传递给一个函数。我可以让它工作,但我想知道是否有我可以分配的类型?我有一个我正在尝试做的“最小”示例。

spec = [("a", float64),("b",float64)]
@jitclass(spec)
class SOMETHING_3():
    def __init__(self):
        self.a = 1.1
        self.b = 2.3

    def sum(self):
        return self.a + self.b


@jit(float64(float64, XXX), nopython = True)
def get_sum_3(c, someobj):
    d = 0
    for i in range(1000):
        for j in range(1000):
            d += c + someobj.sum()
    return d   
Run Code Online (Sandbox Code Playgroud)

如果我删除显式类型赋值“float64(float64, XXX)”,它工作正常。

但是有什么我可以用 XXX 替换它来告诉它是我正在传递的类对象。

numba

3
推荐指数
1
解决办法
1724
查看次数

标签 统计

cython ×1

line-profiler ×1

numba ×1

python ×1