Esempio n. 1
0
def test_slice_and_rebin():
    from boost_histogram.cpp.algorithm import reduce, slice_and_rebin

    h = bhc.histogram(bhc.axis.regular(5, 0, 5))
    np.asarray(h)[:] = 1
    hs = reduce(h, slice_and_rebin(0, 1, 3, 2))
    assert hs.axis(0) == bhc.axis.regular(1, 1, 3)
    assert_array_equal(hs, [2])
    hs2 = reduce(h, slice_and_rebin(1, 3, 2))
    assert hs == hs2
Esempio n. 2
0
def test_rebin():
    from boost_histogram.cpp.algorithm import reduce, rebin

    h = bhc.histogram(bhc.axis.regular(4, 1, 5))
    np.asarray(h)[:] = 1
    assert_array_equal(h, [1, 1, 1, 1])

    hs = reduce(h, rebin(0, 4))
    assert hs.axis(0) == bhc.axis.regular(1, 1, 5)
    assert_array_equal(hs, [4])

    hs2 = reduce(h, rebin(4))
    assert hs == hs2
Esempio n. 3
0
def test_crop():
    from boost_histogram.cpp.algorithm import reduce, crop

    h = bhc.histogram(bhc.axis.regular(4, 1, 5))
    np.asarray(h)[:] = 1

    hs = reduce(h, crop(0, 2, 3))
    assert hs.axis(0) == bhc.axis.regular(1, 2, 3)
    assert_array_equal(hs, [1])
    assert hs.at(-1) == 0
    assert hs.at(1) == 0

    hs2 = reduce(h, crop(2, 3))
    assert hs == hs2
Esempio n. 4
0
def test_slice(mode):
    from boost_histogram.cpp.algorithm import reduce, slice

    h = bhc.histogram(bhc.axis.regular(4, 1, 5))
    np.asarray(h)[:] = 1
    assert_array_equal(h, [1, 1, 1, 1])

    hs = reduce(h, slice(0, 1, 2, mode=mode))
    assert hs.axis(0) == bhc.axis.regular(1, 2, 3)
    assert_array_equal(hs, [1])
    assert hs.at(-1) == (1 if mode == slice_mode.shrink else 0)
    assert hs.at(1) == (2 if mode == slice_mode.shrink else 0)

    hs2 = reduce(h, slice(1, 2, mode=mode))
    assert hs == hs2