astrofrog / astrofrog/fast-histogram

Bug: Histogram2d result does not match that of the numpy function

Open
#10 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
281
Forks
28
PR merge metrics
No merged PRs in 30d

Description

Thank you for this package, it is indeed very fast and I am looking forward to using it.

There is a discrepancy between your histogram2d function and the numpy equivalent, which is demonstrated below:

```python
import numpy as np
from fast_histogram import histogram2d as fast_hist_2d

n_bins = 5

x = np.array([3,2,5,4,6,2,3,5,3,2,5,3,6,7,3])
y = np.array([1,6,3,2,5,3,1,6,4,6,4,2,4,5,3])

xmin, xmax = np.min(x), np.max(x)
ymin, ymax = np.min(y), np.max(y)

h_fast = fast_hist_2d(x,y,
range=[[xmin,xmax], [ymin,ymax]],
bins = [n_bins,n_bins])

h_np = np.histogram2d(x,y,
range=[[xmin,xmax], [ymin,ymax]],
bins = [n_bins,n_bins])[0]

print "h_fast =\n", h_fast
print "\nh_np =\n", h_np
```
On my machine this outputs

h_fast =
[[ 0. 0. 1. 0. 0.]
[ 2. 1. 1. 1. 0.]
[ 0. 1. 0. 0. 0.]
[ 0. 0. 1. 1. 0.]
[ 0. 0. 0. 1. 1.]]

h_np =
[[ 0. 0. 1. 0. 2.]
[ 2. 1. 1. 1. 0.]
[ 0. 1. 0. 0. 0.]
[ 0. 0. 1. 1. 1.]
[ 0. 0. 0. 1. 2.]]

The fast_histogram result only includes 11 of the 15 points. The 4 missing points are all from the final column

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the reported Python reproduction and inspecting the fast_histogram.histogram2d entry point alongside NumPy's histogram2d behavior. Focus on how values at the maximum range edge are assigned, then add a regression test showing that the fast result matches NumPy and counts all 15 points.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, numpy, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.