torch-einops-utils 0.0.21__tar.gz → 0.0.23__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/PKG-INFO +1 -1
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/pyproject.toml +1 -1
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/tests/test_utils.py +14 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/torch_einops_utils/torch_einops_utils.py +6 -3
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/.github/workflows/python-publish.yml +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/.github/workflows/test.yml +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/.gitignore +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/LICENSE +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/README.md +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/tests/test_save_load.py +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/torch_einops_utils/__init__.py +0 -0
- {torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/torch_einops_utils/save_load.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: torch-einops-utils
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.23
|
|
4
4
|
Summary: Personal utility functions
|
|
5
5
|
Project-URL: Homepage, https://pypi.org/project/torch-einops-utils/
|
|
6
6
|
Project-URL: Repository, https://github.com/lucidrains/torch-einops-utils
|
|
@@ -127,6 +127,20 @@ def test_better_pad_sequence():
|
|
|
127
127
|
mask = lens_to_mask(lens)
|
|
128
128
|
assert torch.allclose(mask.sum(dim = -1), lens)
|
|
129
129
|
|
|
130
|
+
def test_pad_sequence_uneven_images():
|
|
131
|
+
images = [
|
|
132
|
+
torch.randn(3, 16, 17),
|
|
133
|
+
torch.randn(3, 15, 18),
|
|
134
|
+
torch.randn(3, 17, 16)
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
padded_height = pad_sequence(images, dim = -2, return_stacked = False)
|
|
138
|
+
assert len(padded_height) == 3
|
|
139
|
+
assert all([t.shape[1] == 17 for t in padded_height])
|
|
140
|
+
|
|
141
|
+
stacked = pad_sequence(padded_height, dim = -1, return_stacked = True)
|
|
142
|
+
assert stacked.shape == (3, 3, 17, 18)
|
|
143
|
+
|
|
130
144
|
def test_and_masks():
|
|
131
145
|
assert not exists(and_masks([None]))
|
|
132
146
|
|
{torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/torch_einops_utils/torch_einops_utils.py
RENAMED
|
@@ -244,6 +244,7 @@ def pad_sequence(
|
|
|
244
244
|
value = 0.,
|
|
245
245
|
left = False,
|
|
246
246
|
dim_stack = 0,
|
|
247
|
+
return_stacked = True,
|
|
247
248
|
return_lens = False,
|
|
248
249
|
pad_lens = False # returns padding length instead of sequence lengths
|
|
249
250
|
):
|
|
@@ -258,15 +259,17 @@ def pad_sequence(
|
|
|
258
259
|
pad_fn = pad_left_at_dim if left else pad_right_at_dim
|
|
259
260
|
padded_tensors = [pad_fn(t, max_len - t_len, dim = dim, value = value) for t, t_len in zip(tensors, lens)]
|
|
260
261
|
|
|
261
|
-
|
|
262
|
+
output = padded_tensors
|
|
263
|
+
if return_stacked:
|
|
264
|
+
output = stack(output, dim = dim_stack)
|
|
262
265
|
|
|
263
266
|
if not return_lens:
|
|
264
|
-
return
|
|
267
|
+
return output
|
|
265
268
|
|
|
266
269
|
if pad_lens:
|
|
267
270
|
lens = max_len - lens
|
|
268
271
|
|
|
269
|
-
return
|
|
272
|
+
return output, lens
|
|
270
273
|
|
|
271
274
|
# tree flatten with inverse
|
|
272
275
|
|
{torch_einops_utils-0.0.21 → torch_einops_utils-0.0.23}/.github/workflows/python-publish.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|