| 9 | |
| 10 | |
| 11 | def test_vectorize(capture): |
| 12 | assert np.isclose(m.vectorized_func3(np.array(3 + 7j)), [6 + 14j]) |
| 13 | |
| 14 | for f in [m.vectorized_func, m.vectorized_func2]: |
| 15 | with capture: |
| 16 | assert np.isclose(f(1, 2, 3), 6) |
| 17 | assert capture == "my_func(x:int=1, y:float=2, z:float=3)" |
| 18 | with capture: |
| 19 | assert np.isclose(f(np.array(1), np.array(2), 3), 6) |
| 20 | assert capture == "my_func(x:int=1, y:float=2, z:float=3)" |
| 21 | with capture: |
| 22 | assert np.allclose(f(np.array([1, 3]), np.array([2, 4]), 3), [6, 36]) |
| 23 | assert ( |
| 24 | capture |
| 25 | == """ |
| 26 | my_func(x:int=1, y:float=2, z:float=3) |
| 27 | my_func(x:int=3, y:float=4, z:float=3) |
| 28 | """ |
| 29 | ) |
| 30 | with capture: |
| 31 | a = np.array([[1, 2], [3, 4]], order="F") |
| 32 | b = np.array([[10, 20], [30, 40]], order="F") |
| 33 | c = 3 |
| 34 | result = f(a, b, c) |
| 35 | assert np.allclose(result, a * b * c) |
| 36 | assert result.flags.f_contiguous |
| 37 | # All inputs are F order and full or singletons, so we the result is in col-major order: |
| 38 | assert ( |
| 39 | capture |
| 40 | == """ |
| 41 | my_func(x:int=1, y:float=10, z:float=3) |
| 42 | my_func(x:int=3, y:float=30, z:float=3) |
| 43 | my_func(x:int=2, y:float=20, z:float=3) |
| 44 | my_func(x:int=4, y:float=40, z:float=3) |
| 45 | """ |
| 46 | ) |
| 47 | with capture: |
| 48 | a, b, c = ( |
| 49 | np.array([[1, 3, 5], [7, 9, 11]]), |
| 50 | np.array([[2, 4, 6], [8, 10, 12]]), |
| 51 | 3, |
| 52 | ) |
| 53 | assert np.allclose(f(a, b, c), a * b * c) |
| 54 | assert ( |
| 55 | capture |
| 56 | == """ |
| 57 | my_func(x:int=1, y:float=2, z:float=3) |
| 58 | my_func(x:int=3, y:float=4, z:float=3) |
| 59 | my_func(x:int=5, y:float=6, z:float=3) |
| 60 | my_func(x:int=7, y:float=8, z:float=3) |
| 61 | my_func(x:int=9, y:float=10, z:float=3) |
| 62 | my_func(x:int=11, y:float=12, z:float=3) |
| 63 | """ |
| 64 | ) |
| 65 | with capture: |
| 66 | a, b, c = np.array([[1, 2, 3], [4, 5, 6]]), np.array([2, 3, 4]), 2 |
| 67 | assert np.allclose(f(a, b, c), a * b * c) |
| 68 | assert ( |