Cpython with pyROOT

when using cpython together with pyroot, does one need to specifically link the ROOT libs to benefit from speed up from cypthon? For example: the code “helloworld.py”:

import ROOT
print("Hello World")
bel_list = ROOT.std.vector('int')()

The setup file is as follows:

from setuptools import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize(['helloworld.py',
                         'example_py_cy.py'])
)

Then compile it:
python setup.py build_ext ----inplace -L$ROOTSYS/lib
or compile it without ROOT lib path:
python setup.py build_ext ----inplace

Does it make any difference?

Thanks
–Wei

Hello,

I guess you mean Cython, right? I’ve never compiled PyROOT scripts with Cython, but I’d say it would not make any difference in terms of performance, actually it should not even be necessary to link with the PyROOT libraries. What do you observe?

1 Like

I agree with @etejedor, I don’t think there is anything in PyROOT that Cython knows how to optimize, it will just do normal Python function calls.
Cython is good at taking statically typed Python, or numpy code, and speed it up, but it does not understand third-party libraries such as PyROOT.

Note that you can check which lines of code Cython compiles to binary and which it does not by using the annotate option.

Cheers,
Enrico

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.