(shape0, shape1, transposed=False, flipped=False)
| 39 | |
| 40 | |
| 41 | def assert_same_as_ufunc(shape0, shape1, transposed=False, flipped=False): |
| 42 | # Broadcast two shapes against each other and check that the data layout |
| 43 | # is the same as if a ufunc did the broadcasting. |
| 44 | |
| 45 | x0 = np.zeros(shape0, dtype=int) |
| 46 | # Note that multiply.reduce's identity element is 1.0, so when shape1==(), |
| 47 | # this gives the desired n==1. |
| 48 | n = int(np.multiply.reduce(shape1)) |
| 49 | x1 = np.arange(n).reshape(shape1) |
| 50 | if transposed: |
| 51 | x0 = x0.T |
| 52 | x1 = x1.T |
| 53 | if flipped: |
| 54 | x0 = x0[::-1] |
| 55 | x1 = x1[::-1] |
| 56 | # Use the add ufunc to do the broadcasting. Since we're adding 0s to x1, the |
| 57 | # result should be exactly the same as the broadcasted view of x1. |
| 58 | y = x0 + x1 |
| 59 | b0, b1 = broadcast_arrays(x0, x1) |
| 60 | assert_array_equal(y, b1) |
| 61 | |
| 62 | |
| 63 | def test_same(): |
no test coverage detected
searching dependent graphs…