-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PyROOT][DF] Improve RDataFrame.AsNumpy performance #6496
Conversation
* Fixed broken memory adoption formely triggered by numpy.array. Switched to the numpy.asarray adoption mechanism. * Added tests confirming the adoption of the memory from the C++ objects
Starting build on |
Build failed on windows10/cxx14. Errors:
|
Build failed on ROOT-performance-centos7-multicore/default. Failing tests: |
@@ -76,7 +76,7 @@ def RDataFrameAsNumpy(df, columns=None, exclude=None): | |||
for column in columns: | |||
cpp_reference = result_ptrs[column].GetValue() | |||
if hasattr(cpp_reference, "__array_interface__"): | |||
tmp = numpy.array(cpp_reference) # This adopts the memory of the C++ object. | |||
tmp = numpy.asarray(cpp_reference) # This adopts the memory of the C++ object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @stwunsch ! So only asarray
adopts now and array
copies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked the adoption when we put this into legacy pyroot, but we haven't had a test for it. For some reason it seems that the numpy.array
constructor does not adopt anymore. I'm pretty sure it did before! However, np.asarray
does and we check this now.
df = ROOT.ROOT.RDataFrame(1).Define("x", "1.0") | ||
npy = df.AsNumpy(["x"]) | ||
pyarr = npy["x"] | ||
cpparr = pyarr.result_ptr.GetValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This result_ptr
is RDataFrame's result pointer that you store?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, exactly!
numpy.array
We should merge first the respective benchmarks in rootbench. The PR is ongoing here: root-project/rootbench#195