<commit_before>import numpy as np
import cudarray
from .wrap import elementwise
from . import helpers


def broadcast_type(shape1, shape2):
    if shape1 == shape2:
        return None

    error = ValueError('operands could not be broadcast together with shapes '
                       + str(shape1) + ' ' + str(shape2))

    # Bring shapes to same length by setting missing trailing dimensions to 1's
    len_diff = len(shape1) - len(shape2)
    if len_diff > 0:
        shape2 = (1,)*len_diff + shape2

    # Find out which axes to broadcast
    b_axes = []
    for a_idx, (a1, a2) in enumerate(zip(shape1, shape2)):
        if a1 != a2:
            if a1 == 1 or a2 == 1:
                b_axes.append(a_idx)
            else:
                raise error

    ndim = len(shape1)
    # Detect leading broadcast
    if b_axes == list(range(len(b_axes))):
        k = 1
        m = helpers.prod([shape1[a] for a in b_axes])
        n = helpers.prod(shape1) // m
        return elementwise.btype_leading, k, m, n
    # Detect trailing broadcast
    if b_axes == list(range(ndim-len(b_axes), ndim)):
        k = 1
        m = helpers.prod([shape1[a] for a in b_axes])
        n = helpers.prod(shape1) // m
        return elementwise.btype_trailing, k, m, n
    # Detect inner broadcast
    if b_axes == list(range(b_axes[0], b_axes[0] + len(b_axes))):
        k = helpers.prod(shape1[:b_axes[0]])
        m = helpers.prod(shape1[b_axes[0]:b_axes[-1]+1])
        n = helpers.prod(shape1[b_axes[-1]+1:])<commit_msg>fixed error when determining broadcast dimensions<commit_after>import numpy as np
import cudarray
from .wrap import elementwise
from . import helpers


def broadcast_type(shape1, shape2):
    if shape1 == shape2:
        return None

    error = ValueError('operands could not be broadcast together with shapes '
                       + str(shape1) + ' ' + str(shape2))

    # Bring shapes to same length by setting missing trailing dimensions to 1's
    len_diff = len(shape1) - len(shape2)
    if len_diff > 0:
        shape2 = (1,)*len_diff + shape2

    # Find out which axes to broadcast
    b_axes = []
    has_broadcasted = False
    for a_idx, (a1, a2) in enumerate(zip(shape1, shape2)):
        if a1 != a2:
            if a1 == 1 or a2 == 1:
                b_axes.append(a_idx)
                has_broadcasted = True
            else:
                raise error
        else:
            if has_broadcasted:
                b_axes.extend(range(a_idx+1, len(shape2)))
                break

    ndim = len(shape1)
    # Detect leading broadcast
    if b_axes == list(range(len(b_axes))):
        k = 1
        m = helpers.prod([shape1[a] for a in b_axes])
        n = helpers.prod(shape1) // m
        return elementwise.btype_leading, k, m, n
    # Detect trailing broadcast
    if b_axes == list(range(ndim-len(b_axes), ndim)):
        k = 1
        m = helpers.prod([shape1[a] for a in b_axes])
        n = helpers.prod(shape1) // m
        return elementwise.btype_trailing, k, m, n
    # Detect inner broadcast
    if b_axes == list(range(b_axes[0], b_axes[0] + len(b_axes))):
        k = helpers.prod(shape1[:b_axes[0]])
        m = helpers.prod(shape1[b_axes[0]:b_axes[-1]+1])
        n = helpers.prod(shape1[b_axes[-1]+1:])
{'fraction_non_alphanumeric': 0.11455773955773955, 'fraction_numerical': 0.025798525798525797, 'mean_word_length': 2.2407960199004977, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6164845', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1078, 'n_words': 296}