Skip to content
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

refactor: scikit-hep compatible API for Regular and Variable binnings #20

Closed
wants to merge 2 commits into from

Conversation

Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Aug 6, 2024

Closes #6

Warning

Does not work with multiple axes at the moment because of underflows :(

Example -

In [1]: import cuda_histogram; import numpy as np; import hist

In [2]: a = cuda_histogram.axis.Variable([0, 2, 3, 9, 10], name="r")

In [3]: c = cuda_histogram.Hist(a)

In [4]: c.fill(np.random.normal(size=1_000_000))

In [5]: c.values(), type(c.values())
Out[5]: (array([478065.,  21503.,   1305.,      0.]), cupy.ndarray)

In [6]: c.values(flow=True), type(c.values(flow=True))
Out[6]: (array([499127., 478065.,  21503.,   1305.,      0.,      0.]), cupy.ndarray)

In [7]: c[1], type(c[1])
Out[7]: (array(21503.), cupy.ndarray)

In [8]: c[::hist.rebin(2)]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 1
----> 1 c[:hist.rebin]

File ~\Saransh_softwares\OpenSource\Python\cuda-histogram\src\cuda_histogram\hist.py:75, in Hist._getitem_(self, keys)
     73     return self._sumw[keys]
     74 else:
---> 75     raise ValueError("Convert the histogram to CPU to access full UHI")

ValueError: Convert the histogram to CPU to access full UHI

In [9]: c.to_cpu()[::hist.rebin(2)]
Out[9]: Hist(Variable([0, 3, 10], name='r', label='Axis 0'), storage=Double()) # Sum: 500873.0

In [10]: c.to_cpu()[::hist.rebin(2)].values(), type(c.to_cpu()[::hist.rebin(2)].values())
Out[10]: (array([499568.,   1305.]), numpy.ndarray)

@Saransh-cpp
Copy link
Member Author

I was going in the wrong direction here -

Boost-histogram was designed around allowing inheritance, as Hist has to inherit from it. But that wasn’t designed to allow swapping out the computation so that might be best.

-- Henry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the package follow UHI
1 participant