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