(nx)
| 44 | |
| 45 | |
| 46 | def test_get_backend(nx): |
| 47 | A = np.zeros((3, 2)) |
| 48 | B = np.zeros((3, 1)) |
| 49 | |
| 50 | nx_np = get_backend(A) |
| 51 | assert nx_np.__name__ == "numpy" |
| 52 | |
| 53 | A2, B2 = nx.from_numpy(A, B) |
| 54 | |
| 55 | effective_nx = get_backend(A2) |
| 56 | assert effective_nx.__name__ == nx.__name__ |
| 57 | |
| 58 | effective_nx = get_backend(A2, B2) |
| 59 | assert effective_nx.__name__ == nx.__name__ |
| 60 | |
| 61 | if nx.__name__ != "numpy": |
| 62 | # test that types mathcing different backends in input raise an error |
| 63 | with pytest.raises(ValueError): |
| 64 | get_backend(A, B2) |
| 65 | else: |
| 66 | # Check that subclassing a numpy array does not break get_backend |
| 67 | # note: This is only tested for numpy as this is hard to be consistent |
| 68 | # with other backends |
| 69 | class nx_subclass(nx.__type__): |
| 70 | pass |
| 71 | |
| 72 | A3 = nx_subclass(0) |
| 73 | |
| 74 | effective_nx = get_backend(A3, B2) |
| 75 | assert effective_nx.__name__ == nx.__name__ |
| 76 | |
| 77 | |
| 78 | def test_convert_between_backends(nx): |
nothing calls this directly
no test coverage detected