MCPcopy Index your code
hub / github.com/numpy/numpy / assert_same_as_ufunc

Function assert_same_as_ufunc

numpy/lib/tests/test_stride_tricks.py:41–60  ·  view source on GitHub ↗
(shape0, shape1, transposed=False, flipped=False)

Source from the content-addressed store, hash-verified

39
40
41def 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
63def test_same():

Callers 1

test_same_as_ufuncFunction · 0.85

Calls 4

broadcast_arraysFunction · 0.90
assert_array_equalFunction · 0.90
reshapeMethod · 0.80
reduceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…