astrofrog / fast-histogram

:zap: Fast 1D and 2D histogram functions in Python :zap:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve robustness to arbitrary input

astrofrog opened this issue · comments

I started trying to add some full hypothesis tests such as:


# First some tests with hypothesis value generation to make sure our
# implementation doesn't crash, and do basic checks of validity of the output.

@given(values=arrays(dtype='<f8', shape=st.integers(0, 50),
                     elements=st.floats(-1000, 1000, allow_subnormal=False),
                     unique=True),
       nx=st.integers(1, 10),
       xmin=st.floats(-1e10, 1e10),
       xmax=st.floats(-1e10, 1e10),
       weights=st.booleans(),
       dtype=st.sampled_from(['>f4', '<f4', '>f8', '<f8']))
@settings(max_examples=1000)
def test_1d_basic(values, nx, xmin, xmax, weights, dtype):
    size = len(values) // 2
    w = values[:size] if weights else None
    x = values[size:]
    fast = histogram1d(x, bins=nx, weights=w, range=(xmin, xmax))
    assert np.sum(fast) == np.sum((x < xmax) & (x >= xmin))

but this crashes with a segmentation fault currently, so need to investigate further.