torch-einops-utils 0.0.4__py3-none-any.whl

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.
@@ -0,0 +1,7 @@
1
+
2
+ from torch_einops_utils.torch_einops_utils import (
3
+ pad_at_dim,
4
+ pad_left_at_dim,
5
+ pad_right_at_dim,
6
+ pack_with_inverse
7
+ )
@@ -0,0 +1,60 @@
1
+ from __future__ import annotations
2
+
3
+ import torch
4
+ from torch import is_tensor
5
+ import torch.nn.functional as F
6
+
7
+ from einops import rearrange, repeat, reduce, pack, unpack
8
+
9
+ # helper functions
10
+
11
+ def exists(v):
12
+ return v is not None
13
+
14
+ def default(v, d):
15
+ return v if exists(v) else d
16
+
17
+ def first(arr):
18
+ return arr[0]
19
+
20
+ # exported functions
21
+
22
+ # padding
23
+
24
+ def pad_at_dim(
25
+ t,
26
+ pad: tuple[int, int],
27
+ *,
28
+ dim = -1,
29
+ value = 0.
30
+ ):
31
+ dims_from_right = (- dim - 1) if dim < 0 else (t.ndim - dim - 1)
32
+ zeros = ((0, 0) * dims_from_right)
33
+ return F.pad(t, (*zeros, *pad), value = value)
34
+
35
+ def pad_left_at_dim(t, pad: int, **kwargs):
36
+ return pad_at_dim(t, (pad, 0), **kwargs)
37
+
38
+ def pad_right_at_dim(t, pad: int, **kwargs):
39
+ return pad_at_dim(t, (0, pad), **kwargs)
40
+
41
+ # einops pack
42
+
43
+ def pack_with_inverse(t, pattern):
44
+ is_one = is_tensor(t)
45
+
46
+ if is_one:
47
+ t = [t]
48
+
49
+ packed, packed_shape = pack(t, pattern)
50
+
51
+ def inverse(out, inv_pattern = None):
52
+ inv_pattern = default(inv_pattern, pattern)
53
+ out = unpack(out, packed_shape, inv_pattern)
54
+
55
+ if is_one:
56
+ out = first(out)
57
+
58
+ return out
59
+
60
+ return packed, inverse
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: torch-einops-utils
3
+ Version: 0.0.4
4
+ Summary: Personal utility functions
5
+ Project-URL: Homepage, https://pypi.org/project/torch-einops-utils/
6
+ Project-URL: Repository, https://github.com/lucidrains/torch-einops-utils
7
+ Author-email: Phil Wang <lucidrains@gmail.com>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Phil Wang
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Keywords: einops,torch
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
36
+ Requires-Python: >=3.9
37
+ Requires-Dist: einops>=0.8.1
38
+ Requires-Dist: torch>=2.5
39
+ Provides-Extra: examples
40
+ Provides-Extra: test
41
+ Requires-Dist: pytest; extra == 'test'
42
+ Description-Content-Type: text/markdown
43
+
44
+ ## torch-einops-utils
45
+
46
+ Some utility functions to help myself (and perhaps others) to go faster with ML/AI work
@@ -0,0 +1,6 @@
1
+ torch_einops_utils/__init__.py,sha256=-8iTNDGOPUv59HPx-Jm-4RSkTZe9WEbtRA_Hxc7aw7U,136
2
+ torch_einops_utils/torch_einops_utils.py,sha256=2p-gGpYXQojtxSXsLyRES3dyjjnHB6qrF6FU8BnQ5M0,1179
3
+ torch_einops_utils-0.0.4.dist-info/METADATA,sha256=UXnpWSU1lX0iZuWXE3_NRouJSyilKkVN_NPC14sSqrA,2141
4
+ torch_einops_utils-0.0.4.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
+ torch_einops_utils-0.0.4.dist-info/licenses/LICENSE,sha256=e6AOF7Z8EFdK3IdcL0x0fLw4cY7Q0d0kNR0o0TmBewM,1066
6
+ torch_einops_utils-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Phil Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.