<commit_before>import util


class test_reduce_views:
    """ Test reduction of all kind of views"""
    def init(self):
        for cmd, shape in util.gen_random_arrays("R", 4, dtype="np.float32"):
            cmd = "R = bh.random.RandomState(42); a = %s; " % cmd
            for i in range(len(shape)):
                yield (cmd, i)
            for i in range(len(shape)):
                yield (cmd, -i)

    def test_reduce(self, (cmd, axis)):
        cmd += "res = M.add.reduce(a, axis=%d)" % axis
        return cmd


class test_reduce_sum:
    """ Test reduction of sum() and prod()"""
    def init(self):
        for cmd, shape in util.gen_random_arrays("R", 3, dtype="np.float32"):
            cmd = "R = bh.random.RandomState(42); a = %s; " % cmd
            for op in ["sum", "prod"]:
                yield (cmd, op)

    def test_func(self, (cmd, op)):
        cmd += "res = M.%s(a)" % op
        return cmd

    def test_method(self, (cmd, op)):
        cmd += "res = a.%s()" % op
        return cmd


class test_reduce_primitives:
    def init(self):
        for op in ["add", "multiply", "minimum", "maximum"]:
            yield (op, "np.float64")

        for op in ["bitwise_or", "bitwise_xor"]:
            yield (op, "np.uint64")

        for op in ["add", "logical_or", "logical_and", "logical_xor"]:
            yield (op, "np.bool")

    def test_vector(self, (op, dtype)):
        cmd = "R = bh.random.RandomState(42); a = R.random(10, dtype=%s, bohrium=BH); " % dtype
        cmd += "res = M.%s.reduce(a)" % op
        return cmd
<commit_msg>test: added complex and boolean to test_reduce_primitives<commit_after>import util


class test_reduce_views:
    """ Test reduction of all kind of views"""
    def init(self):
        for cmd, shape in util.gen_random_arrays("R", 4, dtype="np.float32"):
            cmd = "R = bh.random.RandomState(42); a = %s; " % cmd
            for i in range(len(shape)):
                yield (cmd, i)
            for i in range(len(shape)):
                yield (cmd, -i)

    def test_reduce(self, (cmd, axis)):
        cmd += "res = M.add.reduce(a, axis=%d)" % axis
        return cmd


class test_reduce_sum:
    """ Test reduction of sum() and prod()"""
    def init(self):
        for cmd, shape in util.gen_random_arrays("R", 3, dtype="np.float32"):
            cmd = "R = bh.random.RandomState(42); a = %s; " % cmd
            for op in ["sum", "prod"]:
                yield (cmd, op)

    def test_func(self, (cmd, op)):
        cmd += "res = M.%s(a)" % op
        return cmd

    def test_method(self, (cmd, op)):
        cmd += "res = a.%s()" % op
        return cmd


class test_reduce_primitives:
    def init(self):
        for op in ["add", "multiply"]:
            yield (op, "np.float64")
            yield (op, "np.complex128")

        for op in ["add", "multiply", "minimum", "maximum"]:
            yield (op, "np.float64")
            yield (op, "np.bool")

        for op in ["bitwise_or", "bitwise_xor"]:
            yield (op, "np.uint64")

        for op in ["add", "logical_or", "logical_and", "logical_xor"]:
            yield (op, "np.bool")

    def test_vector(self, (op, dtype)):
        cmd = "R = bh.random.RandomState(42); a = R.random(10, dtype=%s, bohrium=BH); " % dtype
        cmd += "res = M.%s.reduce(a)" % op
        return cmd

{'fraction_non_alphanumeric': 0.16251126464403726, 'fraction_numerical': 0.012316010814058276, 'mean_word_length': 2.080481036077706, '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': '6938441', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1102, 'n_words': 324}