prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add unit tests for stride_tricks/broadcast_shape
  
  
  </issue>
  <code>
  [start of heat/core/stride_tricks.py]
  1 import itertools
  2 
  3 
  4 def broadcast_shape(shape_a, shape_b):
  5     """
  6     Infers, if possible, the broadcast output shape of two operands a and b. Inspired by stackoverflow post:
  7     https://stackoverflow.com/questions/24743753/test-if-an-array-is-broadcastable-to-a-shape
  8 
  9     Parameters
  10     ----------
  11     shape_a : tuple of ints
  12         shape of operand a
  13     shape_b : tuple of ints
  14         shape of operand b
  15 
  16     Returns
  17     -------
  18     broadcast_shape : tuple of ints
  19         the broadcast shape
  20 
  21     Raises
  22     -------
  23     ValueError
  24         If the two shapes cannot be broadcast.
  25     """
  26     #TODO: test me
  27     it = itertools.zip_longest(shape_a[::-1], shape_b[::-1], fillvalue=1)
  28     resulting_shape = max(len(shape_a), len(shape_b)) * [None]
  29     for i, (a, b) in enumerate(it):
  30         if a == 1 or b == 1 or a == b:
  31             resulting_shape[i] = max(a, b)
  32         else:
  33             raise ValueError('operands could not be broadcast, input shapes {} {}'.format(shape_a, shape_b))
  34 
  35     return tuple(resulting_shape[::-1])
  36 
  37 
  38 def sanitize_axis(shape, axis):
  39     """
  40     Checks conformity of an axis with respect to a given shape. The axis will be converted to its positive equivalent
  41     and is checked to be within bounds
  42 
  43     Parameters
  44     ----------
  45     shape : tuple of ints
  46         shape of an array
  47     axis : ints
  48         the axis to be sanitized
  49 
  50     Returns
  51     -------
  52     sane_axis : int
  53         the sane axis
  54 
  55     Raises
  56     -------
  57     ValueError
  58         if the axis cannot be sanitized, i.e. out of bounds.
  59     TypeError
  60         if the the axis is not integral.
  61     """
  62     #TODO: test me
  63     
  64     if axis is not None:
  65         if isinstance(axis, tuple):
  66             raise NotImplementedError('Not implemented for axis: tuple of ints')
  67         if not isinstance(axis, int):
  68             raise TypeError('axis must be None or int, but was {}'.format(type(axis)))
  69 
  70     if axis is None or 0 <= axis < len(shape):
  71         return axis
  72     elif axis < 0:
  73         axis += len(shape)
  74 
  75     if axis < 0 or axis >= len(shape):
  76         raise ValueError('axis axis {} is out of bounds for shape {}'.format(axis, shape))
  77 
  78     return axis
  79 
  80 
  81 def sanitize_shape(shape):
  82     """
  83     Verifies and normalizes the given shape.
  84 
  85     Parameters
  86     ----------
  87     shape : int or sequence of ints
  88         Shape of an array.
  89 
  90     Returns
  91     -------
  92     sane_shape : tuple of ints
  93         The sanitized shape.
  94 
  95     Raises
  96     -------
  97     ValueError
  98         If the shape contains illegal values, e.g. negative numbers.
  99     TypeError
  100         If the given shape is neither and int or a sequence of ints.
  101 
  102     Examples
  103     --------
  104     >>> sanitize_shape(3)
  105     (3,)
  106 
  107     >>> sanitize_shape([1, 2, 3])
  108     (1, 2, 3,)
  109 
  110     >>> sanitize_shape(1.0)
  111     TypeError
  112     """
  113     shape = (shape,) if not hasattr(shape, '__iter__') else tuple(shape)
  114 
  115     for dimension in shape:
  116         if not isinstance(dimension, int):
  117             raise TypeError('expected sequence object with length >= 0 or a single integer')
  118         if dimension <= 0:
  119             raise ValueError('negative dimensions are not allowed')
  120 
  121     return shape
  122
  [end of heat/core/stride_tricks.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/heat/core/stride_tricks.py b/heat/core/stride_tricks.py
  --- a/heat/core/stride_tricks.py
  +++ b/heat/core/stride_tricks.py
  @@ -22,8 +22,22 @@
       -------
       ValueError
           If the two shapes cannot be broadcast.
  +
  +    Examples
  +    -------
  +    >>> broadcast_shape((5,4),(4,))
  +    (5,4)
  +
  +    >>> broadcast_shape((1,100,1),(10,1,5))
  +    (10,100,5)
  +
  +    >>> broadcast_shape((8,1,6,1),(7,1,5,))
  +    (8,7,6,5))
  +
  +    >>> broadcast_shape((2,1),(8,4,3))
  +    ValueError
       """
  -    #TODO: test me
  +
       it = itertools.zip_longest(shape_a[::-1], shape_b[::-1], fillvalue=1)
       resulting_shape = max(len(shape_a), len(shape_b)) * [None]
       for i, (a, b) in enumerate(it):
  @@ -58,9 +72,23 @@
           if the axis cannot be sanitized, i.e. out of bounds.
       TypeError
           if the the axis is not integral.
  +
  +    Examples
  +    -------
  +    >>> sanitize_axis((5,4,4),1)
  +    1
  +
  +    >>> sanitize_axis((5,4,4),-1)
  +    2
  +
  +    >>> sanitize_axis((5, 4), (1,))
  +    NotImplementedError
  +
  +    >>> sanitize_axis((5, 4), 1.0)
  +    TypeError
  +
       """
  -    #TODO: test me
  -    
  +
       if axis is not None:
           if isinstance(axis, tuple):
               raise NotImplementedError('Not implemented for axis: tuple of ints')
  
verification_info: {"golden_diff": "diff --git a/heat/core/stride_tricks.py b/heat/core/stride_tricks.py\n--- a/heat/core/stride_tricks.py\n+++ b/heat/core/stride_tricks.py\n@@ -22,8 +22,22 @@\n     -------\n     ValueError\n         If the two shapes cannot be broadcast.\n+\n+    Examples\n+    -------\n+    >>> broadcast_shape((5,4),(4,))\n+    (5,4)\n+\n+    >>> broadcast_shape((1,100,1),(10,1,5))\n+    (10,100,5)\n+\n+    >>> broadcast_shape((8,1,6,1),(7,1,5,))\n+    (8,7,6,5))\n+\n+    >>> broadcast_shape((2,1),(8,4,3))\n+    ValueError\n     \"\"\"\n-    #TODO: test me\n+\n     it = itertools.zip_longest(shape_a[::-1], shape_b[::-1], fillvalue=1)\n     resulting_shape = max(len(shape_a), len(shape_b)) * [None]\n     for i, (a, b) in enumerate(it):\n@@ -58,9 +72,23 @@\n         if the axis cannot be sanitized, i.e. out of bounds.\n     TypeError\n         if the the axis is not integral.\n+\n+    Examples\n+    -------\n+    >>> sanitize_axis((5,4,4),1)\n+    1\n+\n+    >>> sanitize_axis((5,4,4),-1)\n+    2\n+\n+    >>> sanitize_axis((5, 4), (1,))\n+    NotImplementedError\n+\n+    >>> sanitize_axis((5, 4), 1.0)\n+    TypeError\n+\n     \"\"\"\n-    #TODO: test me\n-    \n+\n     if axis is not None:\n         if isinstance(axis, tuple):\n             raise NotImplementedError('Not implemented for axis: tuple of ints')\n", "issue": "Add unit tests for stride_tricks/broadcast_shape\n\n", "before_files": [{"content": "import itertools\n\n\ndef broadcast_shape(shape_a, shape_b):\n    \"\"\"\n    Infers, if possible, the broadcast output shape of two operands a and b. Inspired by stackoverflow post:\n    https://stackoverflow.com/questions/24743753/test-if-an-array-is-broadcastable-to-a-shape\n\n    Parameters\n    ----------\n    shape_a : tuple of ints\n        shape of operand a\n    shape_b : tuple of ints\n        shape of operand b\n\n    Returns\n    -------\n    broadcast_shape : tuple of ints\n        the broadcast shape\n\n    Raises\n    -------\n    ValueError\n        If the two shapes cannot be broadcast.\n    \"\"\"\n    #TODO: test me\n    it = itertools.zip_longest(shape_a[::-1], shape_b[::-1], fillvalue=1)\n    resulting_shape = max(len(shape_a), len(shape_b)) * [None]\n    for i, (a, b) in enumerate(it):\n        if a == 1 or b == 1 or a == b:\n            resulting_shape[i] = max(a, b)\n        else:\n            raise ValueError('operands could not be broadcast, input shapes {} {}'.format(shape_a, shape_b))\n\n    return tuple(resulting_shape[::-1])\n\n\ndef sanitize_axis(shape, axis):\n    \"\"\"\n    Checks conformity of an axis with respect to a given shape. The axis will be converted to its positive equivalent\n    and is checked to be within bounds\n\n    Parameters\n    ----------\n    shape : tuple of ints\n        shape of an array\n    axis : ints\n        the axis to be sanitized\n\n    Returns\n    -------\n    sane_axis : int\n        the sane axis\n\n    Raises\n    -------\n    ValueError\n        if the axis cannot be sanitized, i.e. out of bounds.\n    TypeError\n        if the the axis is not integral.\n    \"\"\"\n    #TODO: test me\n    \n    if axis is not None:\n        if isinstance(axis, tuple):\n            raise NotImplementedError('Not implemented for axis: tuple of ints')\n        if not isinstance(axis, int):\n            raise TypeError('axis must be None or int, but was {}'.format(type(axis)))\n\n    if axis is None or 0 <= axis < len(shape):\n        return axis\n    elif axis < 0:\n        axis += len(shape)\n\n    if axis < 0 or axis >= len(shape):\n        raise ValueError('axis axis {} is out of bounds for shape {}'.format(axis, shape))\n\n    return axis\n\n\ndef sanitize_shape(shape):\n    \"\"\"\n    Verifies and normalizes the given shape.\n\n    Parameters\n    ----------\n    shape : int or sequence of ints\n        Shape of an array.\n\n    Returns\n    -------\n    sane_shape : tuple of ints\n        The sanitized shape.\n\n    Raises\n    -------\n    ValueError\n        If the shape contains illegal values, e.g. negative numbers.\n    TypeError\n        If the given shape is neither and int or a sequence of ints.\n\n    Examples\n    --------\n    >>> sanitize_shape(3)\n    (3,)\n\n    >>> sanitize_shape([1, 2, 3])\n    (1, 2, 3,)\n\n    >>> sanitize_shape(1.0)\n    TypeError\n    \"\"\"\n    shape = (shape,) if not hasattr(shape, '__iter__') else tuple(shape)\n\n    for dimension in shape:\n        if not isinstance(dimension, int):\n            raise TypeError('expected sequence object with length >= 0 or a single integer')\n        if dimension <= 0:\n            raise ValueError('negative dimensions are not allowed')\n\n    return shape\n", "path": "heat/core/stride_tricks.py"}]}