<commit_before>import numpy as np

from ..numpy import _histogram_2d_vectorized, histogram
from itertools import combinations


def test_histogram_results_1d():
    nrows, ncols = 5, 20
    data = np.random.randn(nrows, ncols)
    bins = np.linspace(-4, 4, 10)

    h2d = histogram(data, bins=bins, axis=1)
    assert h2d.shape == (nrows, len(bins)-1)

    # make sure we get the same thing as histogram
    hist, _ = np.histogram(data, bins=bins)
    np.testing.assert_array_equal(hist, h2d.sum(axis=0))

    # check that weights works
    h2d_d = histogram(data, bins=bins, axis=1, weights=2*np.ones_like(data))
    np.testing.assert_array_equal(2*h2d, h2d_d)


def test_histogram_shape():
    b = np.random.randn(10, 15, 12, 20)
    bins = np.linspace(-4, 4, 27)

    # no axis
    c = histogram(b, bins=bins)
    assert c.shape == (len(bins) - 1,)
    # same thing
    for axis in [(0, 1, 2, 3), (0, 1, 3, 2), (3, 2, 1, 0), (3, 2, 0, 1)]:
        c = histogram(b, bins=bins, axis=axis)
        assert c.shape == (len(bins) - 1,)

    # scalar axis
    for axis in range(4):<commit_msg>added more tests<commit_after>import numpy as np

from ..numpy import _histogram_2d_vectorized, histogram
from itertools import combinations


def test_histogram_results_1d():
    nrows, ncols = 5, 20
    data = np.random.randn(nrows, ncols)
    bins = np.linspace(-4, 4, 10)

    h2d = histogram(data, bins=bins, axis=1)
    assert h2d.shape == (nrows, len(bins)-1)

    # make sure we get the same thing as histogram
    hist, _ = np.histogram(data, bins=bins)
    np.testing.assert_array_equal(hist, h2d.sum(axis=0))

    # now try with no axis
    h2d_na = histogram(data, bins=bins)
    np.testing.assert_array_equal(hist, h2d_na)

    # check that weights works
    h2d_d = histogram(data, bins=bins, axis=1, weights=2*np.ones_like(data))
    np.testing.assert_array_equal(2*h2d, h2d_d)


def test_histogram_shape():
    b = np.random.randn(10, 15, 12, 20)
    bins = np.linspace(-4, 4, 27)

    # no axis
    c = histogram(b, bins=bins)
    assert c.shape == (len(bins) - 1,)
    # same thing
    for axis in [(0, 1, 2, 3), (0, 1, 3, 2), (3, 2, 1, 0), (3, 2, 0, 1)]:
        c = histogram(b, bins=bins, axis=axis)
        assert c.shape == (len(bins) - 1,)

    # scalar axis
    for axis in range(4):
{'fraction_non_alphanumeric': 0.14235959947757945, 'fraction_numerical': 0.046147148454505876, 'mean_word_length': 3.133093525179856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7223373', 'n_tokens_mistral': 999, 'n_tokens_neox': 878, 'n_words': 239}