Segfault when drawing TKDE

Dear all,

Using ROOT from the repo, I get a segfault when calling ‘TKDE::Draw()’. The following snippet is enough to generate the crash:

import ROOT as R
import numpy as np
arr = np.array([10., 20., 30.])
kde = R.TKDE(len(arr), arr)
# No crash up to here
kde.Draw()

Drawing into a canvas or opening a file does not change anything. The same code in a macro does not cause any problem.

Am I maybe doing something wrong in the way I pass the array?

By the way, it’s not really the right forum for this, but I’ve noticed it is not possible to write a TKDE object to a ROOT file because the sub-class TKernel does not have a dictionary generated by default…

Cheers,
Sébastien

Works for me in C++:

root [0] double arr[3] = {10., 20., 30.};
root [1] TKDE kde(3, arr);
root [2] kde.Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1

So I suspect it’s indeed an issue in the Python interaction. Let me ask people who know :slight_smile:

Axel.

Hi,

I see this code working if pasted to the interpreter and if I run it in a script.
It is true though that at tear-down I see a segfault in the TKDE destructor.
Looking into this.

Cheers,
Danilo

Created issue ROOT-8694

Thanks a lot for the feedback!

What about the problem when writing to a file?

Good point. I’ll have a look.

This class TKDE has members which are basically pointers to methods or functions, so it is not trivial to make objects of this class persistent.

KernelFunction_Ptr fKernelFunction;

So, for the time being what we can do is to document property that you cannot write objects of this class to files. If you describe your use case perhaps we could investigate a way to do it or workaround.

Thanks for looking into it!

I don’t have a real use-case for the moment, I was kinda playing around to gauge the possibilities (comparing e.g. to scikit-learn KDEs)…
Since instantiating the class from an array is almost free, it looks like it should be possible to use it without persistence. Saving only the TF1 returned by TKDE::GetFunction() might be sufficient for many purposes.

Of course others may have more documented point of views… I’ll update this thread once/if I have a clearer view of real-life uses!

And yes, documenting the missing feature would be good :slight_smile: There’s no documentation for this class at the moment…

Hi,

a new fixed version of TKDE is available in ROOT 6.09/02 in case you are interested.

Cheers,
D