|
1 | 1 | import torch |
2 | 2 | from pytest import mark |
| 3 | +from torch import Tensor, tensor |
3 | 4 | from torch.ops import aten # type: ignore |
4 | 5 | from torch.testing import assert_close |
5 | 6 | from utils.tensors import randn_, tensor_, zeros_ |
|
12 | 13 | from torchjd.sparse._aten_function_overrides.shape import unsquash_pdim |
13 | 14 | from torchjd.sparse._structured_sparse_tensor import ( |
14 | 15 | StructuredSparseTensor, |
15 | | - clear_null_stride_columns, |
16 | 16 | encode_by_order, |
17 | 17 | fix_ungrouped_dims, |
| 18 | + fix_zero_stride_columns, |
18 | 19 | get_groupings, |
19 | 20 | ) |
20 | 21 |
|
@@ -283,26 +284,32 @@ def test_concatenate( |
283 | 284 | @mark.parametrize( |
284 | 285 | ["physical", "strides", "expected_physical", "expected_strides"], |
285 | 286 | [ |
286 | | - ([[1, 2, 3], [4, 5, 6]], [[1, 0], [1, 0], [2, 0]], [6, 15], [[1], [1], [2]]), |
287 | 287 | ( |
288 | | - [[1, 2, 3], [4, 5, 6]], |
289 | | - [[1, 1], [1, 0], [2, 0]], |
290 | | - [[1, 2, 3], [4, 5, 6]], |
291 | | - [[1, 1], [1, 0], [2, 0]], |
| 288 | + tensor_([[1, 2, 3], [4, 5, 6]]), |
| 289 | + tensor([[1, 0], [1, 0], [2, 0]]), |
| 290 | + tensor_([6, 15]), |
| 291 | + tensor([[1], [1], [2]]), |
| 292 | + ), |
| 293 | + ( |
| 294 | + tensor_([[1, 2, 3], [4, 5, 6]]), |
| 295 | + tensor([[1, 1], [1, 0], [2, 0]]), |
| 296 | + tensor_([[1, 2, 3], [4, 5, 6]]), |
| 297 | + tensor([[1, 1], [1, 0], [2, 0]]), |
| 298 | + ), |
| 299 | + ( |
| 300 | + tensor_([[3, 2, 1], [6, 5, 4]]), |
| 301 | + tensor([[0, 0], [0, 0], [0, 0]]), |
| 302 | + tensor_(21), |
| 303 | + tensor([[], [], []], dtype=torch.int64), |
292 | 304 | ), |
293 | 305 | ], |
294 | 306 | ) |
295 | | -def test_clear_null_stride_columns( |
296 | | - physical: list, |
297 | | - strides: list, |
298 | | - expected_physical: list, |
299 | | - expected_strides: list, |
| 307 | +def test_fix_zero_stride_columns( |
| 308 | + physical: Tensor, |
| 309 | + strides: Tensor, |
| 310 | + expected_physical: Tensor, |
| 311 | + expected_strides: Tensor, |
300 | 312 | ): |
301 | | - physical, strides = torch.tensor(physical), torch.tensor(strides) |
302 | | - expected_physical, expected_strides = torch.tensor(expected_physical), torch.tensor( |
303 | | - expected_strides |
304 | | - ) |
305 | | - |
306 | | - physical, strides = clear_null_stride_columns(physical, strides) |
307 | | - assert_close(physical, expected_physical) |
308 | | - assert_close(strides, expected_strides) |
| 313 | + physical, strides = fix_zero_stride_columns(physical, strides) |
| 314 | + assert torch.equal(physical, expected_physical) |
| 315 | + assert torch.equal(strides, expected_strides) |
0 commit comments