(nx)
| 282 | |
| 283 | |
| 284 | def test_func_backends(nx): |
| 285 | rnd = np.random.RandomState(0) |
| 286 | M = rnd.randn(10, 3) |
| 287 | SquareM = rnd.randn(10, 10) |
| 288 | v = rnd.randn(3) |
| 289 | val = np.array([1.0]) |
| 290 | |
| 291 | M1 = rnd.randn(1, 2, 10, 10) |
| 292 | M2 = rnd.randn(3, 1, 10, 10) |
| 293 | |
| 294 | # Sparse tensors test |
| 295 | sp_row = np.array([0, 3, 1, 0, 3]) |
| 296 | sp_col = np.array([0, 3, 1, 2, 2]) |
| 297 | sp_data = np.array([4, 5, 7, 9, 0], dtype=np.float64) |
| 298 | |
| 299 | lst_tot = [] |
| 300 | |
| 301 | for nx in [ot.backend.NumpyBackend(), nx]: |
| 302 | print("Backend: ", nx.__name__) |
| 303 | |
| 304 | lst_b = [] |
| 305 | lst_name = [] |
| 306 | |
| 307 | Mb = nx.from_numpy(M) |
| 308 | SquareMb = nx.from_numpy(SquareM) |
| 309 | vb = nx.from_numpy(v) |
| 310 | |
| 311 | M1b = nx.from_numpy(M1) |
| 312 | M2b = nx.from_numpy(M2) |
| 313 | |
| 314 | val = nx.from_numpy(val) |
| 315 | |
| 316 | sp_rowb = nx.from_numpy(sp_row) |
| 317 | sp_colb = nx.from_numpy(sp_col) |
| 318 | sp_datab = nx.from_numpy(sp_data) |
| 319 | |
| 320 | A = nx.set_gradients(val, v, v) |
| 321 | |
| 322 | lst_b.append(nx.to_numpy(A)) |
| 323 | lst_name.append("set_gradients") |
| 324 | |
| 325 | A = nx.detach(Mb) |
| 326 | A, B = nx.detach(Mb, Mb) |
| 327 | lst_b.append(nx.to_numpy(A)) |
| 328 | lst_name.append("detach") |
| 329 | |
| 330 | A = nx.zeros((10, 3)) |
| 331 | A = nx.zeros((10, 3), type_as=Mb) |
| 332 | lst_b.append(nx.to_numpy(A)) |
| 333 | lst_name.append("zeros") |
| 334 | |
| 335 | A = nx.ones((10, 3)) |
| 336 | A = nx.ones((10, 3), type_as=Mb) |
| 337 | lst_b.append(nx.to_numpy(A)) |
| 338 | lst_name.append("ones") |
| 339 | |
| 340 | A = nx.arange(10, 1, 2) |
| 341 | lst_b.append(nx.to_numpy(A)) |
nothing calls this directly
no test coverage detected