是否有类似于Cython的Jython的IPython(笔记本)魔术?

时间:2014-05-09 01:09:51

标签: python ipython jython cython ipython-notebook

我找不到任何使用IPython魔法的Jython示例。这已经可以吗? 例如,在一个IPython笔记本中,我可以方便地使用Cython的“魔术”功能,这样我就不必编写setup.py文件并手动编译。我能以某种方式为Jython做这件事吗?如果没有,您将如何通过Jython在IPython笔记本中最好地运行以下代码?

%load_ext cythonmagic

%%cython
def cy_lstsqr(x, y):
    """ Computes the least-squares solution to a linear matrix equation. """
    cdef double x_avg, y_avg, temp, var_x, cov_xy, slope, y_interc, x_i, y_i
    x_avg = sum(x)/len(x)
    y_avg = sum(y)/len(y)
    var_x = 0
    cov_xy = 0
    for x_i, y_i in zip(x,y):
        temp = (x_i - x_avg)
        var_x += temp**2
        cov_xy += temp*(y_i - y_avg)
    slope = cov_xy / var_x
    y_interc = y_avg - slope*x_avg
    return (slope, y_interc)

0 个答案:

没有答案