| 384 | ]) |
| 385 | @pytest.mark.parametrize('dtype_str,arrow_type', tensor_type_pairs) |
| 386 | def test_dense_to_sparse_tensor(dtype_str, arrow_type, sparse_tensor_type): |
| 387 | dtype = np.dtype(dtype_str) |
| 388 | array = np.array([[4, 0, 9, 0], |
| 389 | [0, 7, 0, 0], |
| 390 | [0, 0, 0, 0], |
| 391 | [0, 0, 0, 5]]).astype(dtype) |
| 392 | dim_names = ('x', 'y') |
| 393 | |
| 394 | sparse_tensor = sparse_tensor_type.from_dense_numpy(array, dim_names) |
| 395 | tensor = sparse_tensor.to_tensor() |
| 396 | result_array = tensor.to_numpy() |
| 397 | |
| 398 | assert sparse_tensor.type == arrow_type |
| 399 | assert tensor.type == arrow_type |
| 400 | assert sparse_tensor.dim_names == dim_names |
| 401 | assert np.array_equal(array, result_array) |
| 402 | |
| 403 | |
| 404 | @pytest.mark.skipif(not coo_matrix, reason="requires scipy") |