torch-einops-kit 0.1.8__tar.gz → 0.1.10__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_kit-0.1.8 → torch_einops_kit-0.1.10}/PKG-INFO +40 -28
- {torch_einops_kit-0.1.8 → torch_einops_kit-0.1.10}/README.md +24 -11
- torch_einops_kit-0.1.10/pyproject.toml +287 -0
- torch_einops_kit-0.1.10/setup.cfg +4 -0
- torch_einops_kit-0.1.10/tests/test_cat_stack.py +80 -0
- torch_einops_kit-0.1.10/tests/test_device.py +44 -0
- torch_einops_kit-0.1.10/tests/test_device_extended.py +151 -0
- torch_einops_kit-0.1.10/tests/test_dimensions.py +280 -0
- torch_einops_kit-0.1.10/tests/test_einops.py +85 -0
- torch_einops_kit-0.1.10/tests/test_helpers.py +197 -0
- torch_einops_kit-0.1.10/tests/test_masking.py +252 -0
- torch_einops_kit-0.1.10/tests/test_nn.py +102 -0
- torch_einops_kit-0.1.10/tests/test_nn_extended.py +166 -0
- torch_einops_kit-0.1.10/tests/test_padding.py +443 -0
- torch_einops_kit-0.1.10/tests/test_save_load.py +158 -0
- torch_einops_kit-0.1.10/tests/test_save_load_extended.py +471 -0
- torch_einops_kit-0.1.10/tests/test_scaleValues.py +181 -0
- torch_einops_kit-0.1.10/tests/test_slicing.py +145 -0
- torch_einops_kit-0.1.10/tests/test_utils.py +341 -0
- torch_einops_kit-0.1.10/tests/test_utils_extended.py +61 -0
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/__init__.py +5 -4
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_cat_and_stack.py +2 -1
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_helpers.py +7 -6
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_masking.py +2 -1
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_padding.py +4 -2
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_slicing.py +4 -1
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_theTypes.py +26 -7
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/device.py +4 -2
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/einops.py +2 -1
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/nn.py +56 -11
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/save_load.py +13 -12
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/scaleValues.py +6 -3
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/utils.py +6 -3
- torch_einops_kit-0.1.10/torch_einops_kit.egg-info/PKG-INFO +494 -0
- torch_einops_kit-0.1.10/torch_einops_kit.egg-info/SOURCES.txt +40 -0
- torch_einops_kit-0.1.10/torch_einops_kit.egg-info/dependency_links.txt +1 -0
- torch_einops_kit-0.1.10/torch_einops_kit.egg-info/requires.txt +4 -0
- torch_einops_kit-0.1.10/torch_einops_kit.egg-info/top_level.txt +1 -0
- torch_einops_kit-0.1.8/pyproject.toml +0 -71
- {torch_einops_kit-0.1.8 → torch_einops_kit-0.1.10}/LICENSE +0 -0
- {torch_einops_kit-0.1.8 → torch_einops_kit-0.1.10}/LICENSE-WANG +0 -0
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/_dimensions.py +0 -0
- {torch_einops_kit-0.1.8/src → torch_einops_kit-0.1.10}/torch_einops_kit/py.typed +0 -0
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: torch-einops-kit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.10
|
|
4
4
|
Summary: Typed tensor-shaping, masking, padding, device-routing, and checkpoint utilities for PyTorch and `einops`. A superset of `lucidrains/torch-einops-utils` with similar utilities from other lucidrains packages. Adds strict typing, extensive tests, and comprehensive docstrings.
|
|
5
|
-
Keywords: artificial intelligence,einops,machine learning,pytorch,torch
|
|
6
|
-
Author: Hunter Hogan
|
|
7
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
|
+
Maintainer-email: Hunter Hogan <HunterHogan@pm.me>
|
|
8
7
|
License-Expression: CC-BY-NC-4.0
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Project-URL: Context7, https://context7.com/hunterhogan/torch_einops_kit
|
|
9
|
+
Project-URL: Donate, https://www.patreon.com/integrated
|
|
10
|
+
Project-URL: Download, https://pypi.org/project/torch_einops_kit
|
|
11
|
+
Project-URL: Homepage, https://github.com/hunterhogan/torch_einops_kit
|
|
12
|
+
Project-URL: Issues, https://github.com/hunterhogan/torch_einops_kit/issues
|
|
13
|
+
Project-URL: Repository, https://github.com/hunterhogan/torch_einops_kit.git
|
|
14
|
+
Keywords: artificial intelligence,einops,machine learning,pytorch,torch
|
|
11
15
|
Classifier: Development Status :: 4 - Beta
|
|
12
16
|
Classifier: Environment :: Console
|
|
13
17
|
Classifier: Environment :: GPU :: NVIDIA CUDA
|
|
@@ -15,26 +19,22 @@ Classifier: Intended Audience :: Developers
|
|
|
15
19
|
Classifier: Intended Audience :: Science/Research
|
|
16
20
|
Classifier: Natural Language :: English
|
|
17
21
|
Classifier: Operating System :: OS Independent
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
23
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
24
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
25
|
Classifier: Topic :: Utilities
|
|
22
26
|
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.11
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
License-File: LICENSE-WANG
|
|
23
31
|
Requires-Dist: einops>=0.8.2
|
|
24
32
|
Requires-Dist: huntermakespy>=0.7.0
|
|
25
|
-
Requires-Dist: torch>=2.
|
|
33
|
+
Requires-Dist: torch>=2.6
|
|
26
34
|
Requires-Dist: typing-extensions>=4.0.0
|
|
27
|
-
|
|
28
|
-
Maintainer-email: Hunter Hogan <HunterHogan@pm.me>
|
|
29
|
-
Requires-Python: >=3.10
|
|
30
|
-
Project-URL: Context7, https://context7.com/hunterhogan/torch_einops_kit
|
|
31
|
-
Project-URL: Donate, https://www.patreon.com/integrated
|
|
32
|
-
Project-URL: Download, https://pypi.org/project/torch_einops_kit
|
|
33
|
-
Project-URL: Homepage, https://github.com/hunterhogan/torch_einops_kit
|
|
34
|
-
Project-URL: Issues, https://github.com/hunterhogan/torch_einops_kit/issues
|
|
35
|
-
Project-URL: Repository, https://github.com/hunterhogan/torch_einops_kit.git
|
|
36
|
-
Description-Content-Type: text/markdown
|
|
35
|
+
Dynamic: license-file
|
|
37
36
|
|
|
37
|
+
<!-- path-sync copy -n hunterhogan -->
|
|
38
38
|
# torch_einops_kit
|
|
39
39
|
|
|
40
40
|
Typed tensor-shaping, masking, padding, device-routing, lightweight `nn.Module` adapters, and checkpoint utilities for PyTorch and `einops`.
|
|
@@ -54,7 +54,7 @@ Use `torch_einops_kit` when you want strict typing, a `py.typed` marker, focused
|
|
|
54
54
|
|
|
55
55
|
- Project name: `torch_einops_kit`.
|
|
56
56
|
- Import path: `torch_einops_kit`.
|
|
57
|
-
- Python requirement: `>=3.
|
|
57
|
+
- Python requirement: `>=3.11`.
|
|
58
58
|
- Runtime dependencies: `torch`, `einops`, and `typing-extensions`.
|
|
59
59
|
- Root package exports: helper functions, slicing helpers, rank-alignment helpers, mask helpers, safe concatenation helpers, padding helpers, normalization helpers, and PyTree / `einops` helpers.
|
|
60
60
|
- Submodules with dedicated imports: `torch_einops_kit.device`, `torch_einops_kit.einops`, `torch_einops_kit.nn`, `torch_einops_kit.save_load`, and `torch_einops_kit.scaleValues`.
|
|
@@ -447,19 +447,25 @@ This repository is not a repackaged mirror of upstream. This repository makes a
|
|
|
447
447
|
|
|
448
448
|
## Repository layout
|
|
449
449
|
|
|
450
|
-
- `
|
|
451
|
-
- `
|
|
452
|
-
- `
|
|
453
|
-
- `
|
|
454
|
-
- `
|
|
450
|
+
- `torch_einops_kit/` — package source.
|
|
451
|
+
- `torch_einops_kit/device.py` — device inference and input-routing decorators.
|
|
452
|
+
- `torch_einops_kit/nn.py` — lightweight `torch.nn.Module` adapters and a `Sequential` constructor that ignores `None` modules.
|
|
453
|
+
- `torch_einops_kit/save_load.py` — checkpoint save / load decorator and nested reconstruction helpers.
|
|
454
|
+
- `torch_einops_kit/scaleValues.py` — exclusive and reverse cumulative sums, vector normalization, masked mean, and the `RMSNorm` layer.
|
|
455
455
|
- `tests/` — regression tests and usage examples for helpers, masks, padding, device routing, and checkpoint reconstruction.
|
|
456
456
|
|
|
457
457
|
## Development
|
|
458
458
|
|
|
459
|
-
Set up the repository:
|
|
459
|
+
Set up the repository. Installing dependency groups requires `pip>=25.1`. The `development` group includes the `testing` group:
|
|
460
460
|
|
|
461
461
|
```bash
|
|
462
|
-
|
|
462
|
+
pip install --editable . --group development
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
To install only what the test suite needs, use the `testing` group:
|
|
466
|
+
|
|
467
|
+
```bash
|
|
468
|
+
pip install --editable . --group testing
|
|
463
469
|
```
|
|
464
470
|
|
|
465
471
|
Run the test suite:
|
|
@@ -474,9 +480,15 @@ Run static analysis:
|
|
|
474
480
|
ruff check .
|
|
475
481
|
```
|
|
476
482
|
|
|
483
|
+
<!-- === DO_NOT_EDIT: path-sync hunterhogan === -->
|
|
477
484
|
## My recovery
|
|
478
485
|
|
|
479
|
-
[](https://HunterThinks.com/support)
|
|
487
|
+

|
|
488
|
+
|
|
489
|
+
By law, authors retain their copyrights unless they grant exceptions. The Creative Commons Attribution-NonCommercial 4.0 International Deed outlines how you may use this work.
|
|
490
|
+
|
|
491
|
+
The restriction on commercial use (without a license) limits advantage-taking, unjust enrichment, and exploitation. You would be morally wrong if you were to enrich yourself by using this work while I am denied healthcare, housing, security of property, and the safety of my person.
|
|
481
492
|
|
|
482
|
-
|
|
493
|
+
To obtain and retain the right to use this work, you incur the cost of attributing the work to me. Your nominal cost might accrue as a benefit that mitigates my suffering or saves my life.
|
|
494
|
+
<!-- === OK_EDIT: path-sync hunterhogan === -->
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
<!-- path-sync copy -n hunterhogan -->
|
|
1
2
|
# torch_einops_kit
|
|
2
3
|
|
|
3
4
|
Typed tensor-shaping, masking, padding, device-routing, lightweight `nn.Module` adapters, and checkpoint utilities for PyTorch and `einops`.
|
|
@@ -17,7 +18,7 @@ Use `torch_einops_kit` when you want strict typing, a `py.typed` marker, focused
|
|
|
17
18
|
|
|
18
19
|
- Project name: `torch_einops_kit`.
|
|
19
20
|
- Import path: `torch_einops_kit`.
|
|
20
|
-
- Python requirement: `>=3.
|
|
21
|
+
- Python requirement: `>=3.11`.
|
|
21
22
|
- Runtime dependencies: `torch`, `einops`, and `typing-extensions`.
|
|
22
23
|
- Root package exports: helper functions, slicing helpers, rank-alignment helpers, mask helpers, safe concatenation helpers, padding helpers, normalization helpers, and PyTree / `einops` helpers.
|
|
23
24
|
- Submodules with dedicated imports: `torch_einops_kit.device`, `torch_einops_kit.einops`, `torch_einops_kit.nn`, `torch_einops_kit.save_load`, and `torch_einops_kit.scaleValues`.
|
|
@@ -410,19 +411,25 @@ This repository is not a repackaged mirror of upstream. This repository makes a
|
|
|
410
411
|
|
|
411
412
|
## Repository layout
|
|
412
413
|
|
|
413
|
-
- `
|
|
414
|
-
- `
|
|
415
|
-
- `
|
|
416
|
-
- `
|
|
417
|
-
- `
|
|
414
|
+
- `torch_einops_kit/` — package source.
|
|
415
|
+
- `torch_einops_kit/device.py` — device inference and input-routing decorators.
|
|
416
|
+
- `torch_einops_kit/nn.py` — lightweight `torch.nn.Module` adapters and a `Sequential` constructor that ignores `None` modules.
|
|
417
|
+
- `torch_einops_kit/save_load.py` — checkpoint save / load decorator and nested reconstruction helpers.
|
|
418
|
+
- `torch_einops_kit/scaleValues.py` — exclusive and reverse cumulative sums, vector normalization, masked mean, and the `RMSNorm` layer.
|
|
418
419
|
- `tests/` — regression tests and usage examples for helpers, masks, padding, device routing, and checkpoint reconstruction.
|
|
419
420
|
|
|
420
421
|
## Development
|
|
421
422
|
|
|
422
|
-
Set up the repository:
|
|
423
|
+
Set up the repository. Installing dependency groups requires `pip>=25.1`. The `development` group includes the `testing` group:
|
|
423
424
|
|
|
424
425
|
```bash
|
|
425
|
-
|
|
426
|
+
pip install --editable . --group development
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
To install only what the test suite needs, use the `testing` group:
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
pip install --editable . --group testing
|
|
426
433
|
```
|
|
427
434
|
|
|
428
435
|
Run the test suite:
|
|
@@ -437,9 +444,15 @@ Run static analysis:
|
|
|
437
444
|
ruff check .
|
|
438
445
|
```
|
|
439
446
|
|
|
447
|
+
<!-- === DO_NOT_EDIT: path-sync hunterhogan === -->
|
|
440
448
|
## My recovery
|
|
441
449
|
|
|
442
|
-
[](https://HunterThinks.com/support)
|
|
451
|
+

|
|
452
|
+
|
|
453
|
+
By law, authors retain their copyrights unless they grant exceptions. The Creative Commons Attribution-NonCommercial 4.0 International Deed outlines how you may use this work.
|
|
454
|
+
|
|
455
|
+
The restriction on commercial use (without a license) limits advantage-taking, unjust enrichment, and exploitation. You would be morally wrong if you were to enrich yourself by using this work while I am denied healthcare, housing, security of property, and the safety of my person.
|
|
444
456
|
|
|
445
|
-
|
|
457
|
+
To obtain and retain the right to use this work, you incur the cost of attributing the work to me. Your nominal cost might accrue as a benefit that mitigates my suffering or saves my life.
|
|
458
|
+
<!-- === OK_EDIT: path-sync hunterhogan === -->
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# path-sync copy -n hunterhogan
|
|
2
|
+
[project]
|
|
3
|
+
name = "torch-einops-kit"
|
|
4
|
+
version = "0.1.10"
|
|
5
|
+
description = "Typed tensor-shaping, masking, padding, device-routing, and checkpoint utilities for PyTorch and `einops`. A superset of `lucidrains/torch-einops-utils` with similar utilities from other lucidrains packages. Adds strict typing, extensive tests, and comprehensive docstrings."
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
license = "CC-BY-NC-4.0"
|
|
9
|
+
license-files = ["LICEN[CS]E*"]
|
|
10
|
+
authors = [{ name = "Hunter Hogan", email = "HunterHogan@pm.me" }]
|
|
11
|
+
maintainers = [{ name = "Hunter Hogan", email = "HunterHogan@pm.me" }]
|
|
12
|
+
keywords = [
|
|
13
|
+
"artificial intelligence",
|
|
14
|
+
"einops",
|
|
15
|
+
"machine learning",
|
|
16
|
+
"pytorch",
|
|
17
|
+
"torch",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Environment :: Console",
|
|
22
|
+
"Environment :: GPU :: NVIDIA CUDA",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Intended Audience :: Science/Research",
|
|
25
|
+
"Natural Language :: English",
|
|
26
|
+
"Operating System :: OS Independent",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
30
|
+
"Topic :: Utilities",
|
|
31
|
+
"Typing :: Typed",
|
|
32
|
+
]
|
|
33
|
+
dependencies = [
|
|
34
|
+
"einops>=0.8.2",
|
|
35
|
+
"huntermakespy>=0.7.0",
|
|
36
|
+
"torch>=2.6",
|
|
37
|
+
"typing-extensions>=4.0.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Context7 = "https://context7.com/hunterhogan/torch_einops_kit"
|
|
42
|
+
Donate = "https://www.patreon.com/integrated"
|
|
43
|
+
Download = "https://pypi.org/project/torch_einops_kit"
|
|
44
|
+
Homepage = "https://github.com/hunterhogan/torch_einops_kit"
|
|
45
|
+
Issues = "https://github.com/hunterhogan/torch_einops_kit/issues"
|
|
46
|
+
Repository = "https://github.com/hunterhogan/torch_einops_kit.git"
|
|
47
|
+
|
|
48
|
+
[dependency-groups]
|
|
49
|
+
development = ["pytest-cov", { include-group = "testing" }]
|
|
50
|
+
testing = ["more-itertools", "numpy>=2.0.0", "pytest"]
|
|
51
|
+
|
|
52
|
+
[build-system]
|
|
53
|
+
requires = ["setuptools>=77.0.1"]
|
|
54
|
+
build-backend = "setuptools.build_meta"
|
|
55
|
+
|
|
56
|
+
[tool.coverage]
|
|
57
|
+
report = { ignore_errors = false }
|
|
58
|
+
run = { branch = true, data_file = "tests/coverage/.coverage", omit = ["tests/*"], source = ["."] }
|
|
59
|
+
|
|
60
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
61
|
+
[tool.isort]
|
|
62
|
+
add_imports = ["from __future__ import annotations"]
|
|
63
|
+
append_only = true
|
|
64
|
+
atomic = true
|
|
65
|
+
combine_as_imports = true
|
|
66
|
+
extend_skip_glob = ["*.pyi"]
|
|
67
|
+
filter_files = true
|
|
68
|
+
force_alphabetical_sort_within_sections = true
|
|
69
|
+
from_first = true
|
|
70
|
+
honor_noqa = true
|
|
71
|
+
indent = "\t"
|
|
72
|
+
line_length = 140
|
|
73
|
+
lines_after_imports = 1
|
|
74
|
+
lines_between_types = 0
|
|
75
|
+
multi_line_output = 4
|
|
76
|
+
no_sections = true
|
|
77
|
+
skip_gitignore = true
|
|
78
|
+
use_parentheses = true
|
|
79
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
80
|
+
|
|
81
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
82
|
+
[tool.pyrefly]
|
|
83
|
+
enabled-ignores = ["pyrefly"]
|
|
84
|
+
# ignore-errors-in-generated-code = true
|
|
85
|
+
infer-with-first-use = false
|
|
86
|
+
preset = "strict"
|
|
87
|
+
python-platform = "all"
|
|
88
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
89
|
+
|
|
90
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
91
|
+
[tool.pyrefly.errors]
|
|
92
|
+
bad-return = "warn"
|
|
93
|
+
invalid-yield = "warn"
|
|
94
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
95
|
+
|
|
96
|
+
[tool.pytest]
|
|
97
|
+
addopts = ["--color=yes"]
|
|
98
|
+
log_auto_indent = "On"
|
|
99
|
+
testpaths = ["tests"]
|
|
100
|
+
|
|
101
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
102
|
+
[tool.ruff]
|
|
103
|
+
line-length = 140
|
|
104
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
105
|
+
|
|
106
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
107
|
+
[tool.ruff.lint]
|
|
108
|
+
allowed-confusables = ["–", "’", "′", "×", "−", "∖", "∗", "∣", "∨", "∪", "∼", "⊗", "ℂ", "ℋ", "ℒ", "ℓ", "ℕ", "ℙ", "ℚ", "ℝ", "ℤ", "ℰ", "ℱ", "𝒪", "𝒮", "𝔼", "𝕀", "𝟙", "α", "Β", "γ", "ι", "Κ", "ν", "ο", "ρ", "σ"]
|
|
109
|
+
future-annotations = true
|
|
110
|
+
ignore = [
|
|
111
|
+
# ====== Linters ===========
|
|
112
|
+
"FIX", # flake8-fixme
|
|
113
|
+
"I", # isort
|
|
114
|
+
"N", # pep8-naming
|
|
115
|
+
"TD", # flake8-todos
|
|
116
|
+
# ====== complexity ========
|
|
117
|
+
"dict-index-missing-items",
|
|
118
|
+
"explicit-f-string-type-conversion",
|
|
119
|
+
"non-pep695-type-alias",
|
|
120
|
+
"redundant-numeric-union",
|
|
121
|
+
"static-join-to-f-string",
|
|
122
|
+
"unnecessary-literal-dict",
|
|
123
|
+
"useless-import-alias",
|
|
124
|
+
# ====== correctness =======
|
|
125
|
+
"unused-variable",
|
|
126
|
+
# ====== formatting ========
|
|
127
|
+
"bad-quotes-inline-string",
|
|
128
|
+
"blank-lines-after-function-or-class",
|
|
129
|
+
"blank-lines-top-level",
|
|
130
|
+
"docstring-tab-indentation",
|
|
131
|
+
"incorrect-blank-line-after-class",
|
|
132
|
+
"line-too-long",
|
|
133
|
+
"missing-newline-at-end-of-file",
|
|
134
|
+
"missing-trailing-comma",
|
|
135
|
+
"no-space-after-block-comment",
|
|
136
|
+
"tab-indentation",
|
|
137
|
+
"too-many-blank-lines",
|
|
138
|
+
# ====== pedantic ==========
|
|
139
|
+
"any-type",
|
|
140
|
+
"blanket-noqa",
|
|
141
|
+
"docstring-in-stub",
|
|
142
|
+
"docstring-missing-exception",
|
|
143
|
+
"docstring-missing-returns",
|
|
144
|
+
"docstring-missing-yields",
|
|
145
|
+
"if-else-block-instead-of-if-exp",
|
|
146
|
+
"incorrect-section-order",
|
|
147
|
+
"magic-value-comparison",
|
|
148
|
+
"missing-copyright-notice",
|
|
149
|
+
"missing-trailing-period",
|
|
150
|
+
"non-ascii-import-name",
|
|
151
|
+
"non-ascii-name",
|
|
152
|
+
"non-imperative-mood",
|
|
153
|
+
"redefined-loop-name",
|
|
154
|
+
"superfluous-else-continue",
|
|
155
|
+
"superfluous-else-return",
|
|
156
|
+
"too-many-arguments",
|
|
157
|
+
"too-many-branches",
|
|
158
|
+
"too-many-locals",
|
|
159
|
+
"too-many-nested-blocks",
|
|
160
|
+
"too-many-positional-arguments",
|
|
161
|
+
"too-many-public-methods",
|
|
162
|
+
"too-many-statements",
|
|
163
|
+
"typed-argument-default-in-stub",
|
|
164
|
+
"yoda-conditions",
|
|
165
|
+
# ====== restriction =======
|
|
166
|
+
"complex-structure",
|
|
167
|
+
# ====== security ==========
|
|
168
|
+
"subprocess-without-shell-equals-true",
|
|
169
|
+
"suspicious-pickle-import",
|
|
170
|
+
# ====== style =============
|
|
171
|
+
"snake-case-type-alias",
|
|
172
|
+
"type-name-incorrect-variance",
|
|
173
|
+
# ====== suspicious ========
|
|
174
|
+
"self-or-cls-assignment",
|
|
175
|
+
"subclass-builtin",
|
|
176
|
+
"unused-import",
|
|
177
|
+
"useless-else-on-loop",
|
|
178
|
+
]
|
|
179
|
+
preview = true
|
|
180
|
+
select = ["ALL"]
|
|
181
|
+
extend-select = ["missing-terminal-punctuation", "undocumented-param", "undocumented-public-init"]
|
|
182
|
+
task-tags = ["DEVELOPMENT", "NOTE", "SEMIOTICS", "TODO"]
|
|
183
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
184
|
+
|
|
185
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
186
|
+
[tool.ruff.lint.flake8-comprehensions]
|
|
187
|
+
allow-dict-calls-with-keyword-arguments = true
|
|
188
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
189
|
+
|
|
190
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
191
|
+
[tool.ruff.lint.flake8-import-conventions]
|
|
192
|
+
banned-aliases = { altair = ["alt"], datetime = ["dt"], holoviews = ["hv"], matplotlib = ["mpl"], "matplotlib.pyplot" = ["plt"], networkx = ["nx"], numpy = ["np"], "numpy.typing" = ["npt"], optype = ["op"], pandas = ["pd"], panel = ["pn"], "plotly.express" = ["px"], polars = ["pl"], pyarrow = ["pa"], regex = ["re"], seaborn = ["sns"], tensorflow = ["tf"], tkinter = ["tk"], "xml.etree.ElementTree" = ["ET"] }
|
|
193
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
194
|
+
|
|
195
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
196
|
+
[tool.ruff.lint.flake8-import-conventions.aliases]
|
|
197
|
+
"accelerate.utils.dataclasses" = "accelerate_dataclasses"
|
|
198
|
+
"fs.path" = "fs_path"
|
|
199
|
+
"gmpy2.bit_test" = "isBit1吗"
|
|
200
|
+
"gmpy2.is_even" = "isEven吗"
|
|
201
|
+
"gmpy2.is_odd" = "isOdd吗"
|
|
202
|
+
"humpy_cytoolz.assoc" = "associateKeyValue"
|
|
203
|
+
"humpy_cytoolz.curry" = "syntacticCurry"
|
|
204
|
+
"humpy_cytoolz.groupby" = "toolz_groupby"
|
|
205
|
+
"itertools.product" = "CartesianProduct"
|
|
206
|
+
"math.comb" = "nCr"
|
|
207
|
+
"more_itertools.all_unique" = "allUnique吗"
|
|
208
|
+
"regex" = "regex"
|
|
209
|
+
"scipy" = "scipy"
|
|
210
|
+
"sympy.binomial" = "sympy_binomial"
|
|
211
|
+
"sympy.catalan" = "sympy_catalan"
|
|
212
|
+
"sympy.functions.combinatorial.factorials.binomial" = "sympy_binomial"
|
|
213
|
+
"sympy.functions.combinatorial.numbers.catalan" = "sympy_catalan"
|
|
214
|
+
"sympy" = "sympy"
|
|
215
|
+
"torch.autograd.grad" = "torch_grad"
|
|
216
|
+
"torch.nn.functional" = "F"
|
|
217
|
+
"torch.nn.parallel.DistributedDataParallel" = "DDP"
|
|
218
|
+
numpy = "numpy"
|
|
219
|
+
pandas = "pandas"
|
|
220
|
+
polars = "polars"
|
|
221
|
+
re = "regex"
|
|
222
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
223
|
+
|
|
224
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
225
|
+
[tool.ruff.lint.flake8-quotes]
|
|
226
|
+
inline-quotes = "single"
|
|
227
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
228
|
+
|
|
229
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
230
|
+
[tool.ruff.lint.per-file-ignores]
|
|
231
|
+
"**/*_test.py" = ["ARG", "assert", "BLE", "D", "DTZ", "FBT", "PT", "suspicious-non-cryptographic-random-usage", "TRY"]
|
|
232
|
+
"**/conftest*.py" = ["ARG", "assert", "BLE", "D", "DTZ", "FBT", "PT", "suspicious-non-cryptographic-random-usage", "TRY"]
|
|
233
|
+
"**/test_*.py" = ["ARG", "assert", "BLE", "D", "DTZ", "FBT", "PT", "suspicious-non-cryptographic-random-usage", "TRY"]
|
|
234
|
+
"**/tests/**" = ["ARG", "assert", "BLE", "D", "DTZ", "FBT", "PT", "suspicious-non-cryptographic-random-usage", "TRY"]
|
|
235
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
236
|
+
|
|
237
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
238
|
+
[tool.ruff.lint.pydocstyle]
|
|
239
|
+
convention = "numpy"
|
|
240
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
241
|
+
|
|
242
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
243
|
+
[tool.ruff.format]
|
|
244
|
+
docstring-code-format = true
|
|
245
|
+
indent-style = "tab"
|
|
246
|
+
line-ending = "lf"
|
|
247
|
+
nested-string-quote-style = "preferred"
|
|
248
|
+
quote-style = "single"
|
|
249
|
+
skip-magic-trailing-comma = true
|
|
250
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
251
|
+
|
|
252
|
+
[tool.setuptools]
|
|
253
|
+
packages = { find = { include = ["torch_einops_kit", "torch_einops_kit.*"], namespaces = false } }
|
|
254
|
+
|
|
255
|
+
[tool.setuptools.package-data]
|
|
256
|
+
torch_einops_kit = ["py.typed"]
|
|
257
|
+
|
|
258
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
259
|
+
[tool.tombi.format.rules]
|
|
260
|
+
line-ending = "lf"
|
|
261
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
262
|
+
|
|
263
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
264
|
+
[tool.ty.analysis]
|
|
265
|
+
respect-type-ignore-comments = false
|
|
266
|
+
return-type-inference = "always"
|
|
267
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
268
|
+
|
|
269
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
270
|
+
[tool.ty.environment]
|
|
271
|
+
extra-paths = ["./typings"]
|
|
272
|
+
python-platform = "all"
|
|
273
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
274
|
+
|
|
275
|
+
# === DO_NOT_EDIT: path-sync hunterhogan ===
|
|
276
|
+
[tool.ty.rules]
|
|
277
|
+
blanket-ignore-comment = "error"
|
|
278
|
+
missing-override-decorator = "error"
|
|
279
|
+
missing-type-argument = "error"
|
|
280
|
+
possibly-missing-attribute = "warn" # Might annoy you: ty's docs say this rule produces many false positives.
|
|
281
|
+
possibly-unresolved-reference = "warn" # Might annoy you: ty's docs say this rule produces many false positives.
|
|
282
|
+
truthiness-test-of-none-union = "warn" # Might annoy you: flags `if value:` on `int | None` or `str | None` even when treating 0 or '' like None is deliberate.
|
|
283
|
+
# === OK_EDIT: path-sync hunterhogan ===
|
|
284
|
+
|
|
285
|
+
[tool.updateCitation]
|
|
286
|
+
filenameCitationDOTcff = "CITATION.cff"
|
|
287
|
+
pathFilenameCitationSSOT = "citations/CITATION.cff"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from torch import Tensor
|
|
4
|
+
from torch_einops_kit import broadcast_cat, safe_cat, safe_stack
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
import pytest
|
|
7
|
+
import torch
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import Sequence
|
|
11
|
+
|
|
12
|
+
def test_safe_stack(sequence_collection: list[Sequence[Tensor]]) -> None:
|
|
13
|
+
for sequence in sequence_collection:
|
|
14
|
+
unique_shapes = {t.shape for t in sequence}
|
|
15
|
+
if len(unique_shapes) != 1:
|
|
16
|
+
continue
|
|
17
|
+
result = safe_stack(sequence)
|
|
18
|
+
assert isinstance(result, Tensor), (
|
|
19
|
+
f'safe_stack returned {type(result).__name__}, expected Tensor '
|
|
20
|
+
f'for sequence of {len(sequence)} tensors each with shape {sequence[0].shape}.'
|
|
21
|
+
)
|
|
22
|
+
assert result.shape[0] == len(sequence), (
|
|
23
|
+
f'safe_stack returned shape {result.shape}, expected dim 0 to be {len(sequence)} '
|
|
24
|
+
f'for {len(sequence)} input tensors with shape {sequence[0].shape}.'
|
|
25
|
+
)
|
|
26
|
+
assert result.shape[1:] == sequence[0].shape, (
|
|
27
|
+
f'safe_stack returned shape {result.shape}, expected trailing shape {sequence[0].shape} '
|
|
28
|
+
f'matching input tensor shape for sequence of length {len(sequence)}.'
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def test_safe_cat(sequence_collection: list[Sequence[Tensor]]) -> None:
|
|
32
|
+
for sequence in sequence_collection:
|
|
33
|
+
unique_ranks = {t.dim() for t in sequence}
|
|
34
|
+
unique_trailing_shapes = {t.shape[1:] for t in sequence}
|
|
35
|
+
if len(unique_ranks) != 1 or len(unique_trailing_shapes) != 1:
|
|
36
|
+
continue
|
|
37
|
+
result = safe_cat(sequence)
|
|
38
|
+
expected_dim0 = sum(t.shape[0] for t in sequence)
|
|
39
|
+
assert isinstance(result, Tensor), (
|
|
40
|
+
f'safe_cat returned {type(result).__name__}, expected Tensor for sequence of {len(sequence)} tensors.'
|
|
41
|
+
)
|
|
42
|
+
assert result.shape[0] == expected_dim0, (
|
|
43
|
+
f'safe_cat returned shape {result.shape}, expected dim 0 to be {expected_dim0} '
|
|
44
|
+
f'from concatenating {len(sequence)} tensors along dim 0.'
|
|
45
|
+
)
|
|
46
|
+
assert result.shape[1:] == sequence[0].shape[1:], (
|
|
47
|
+
f'safe_cat returned shape {result.shape}, expected trailing shape {sequence[0].shape[1:]} '
|
|
48
|
+
f'matching input tensor trailing shape for sequence of length {len(sequence)}.'
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
@pytest.mark.parametrize(
|
|
52
|
+
('singleton_axes', 'dim'),
|
|
53
|
+
[
|
|
54
|
+
pytest.param((0,), 0, id='singleton-leading-cat-leading'),
|
|
55
|
+
pytest.param((-1,), -1, id='singleton-trailing-cat-trailing'),
|
|
56
|
+
pytest.param((0, -1), 0, id='singleton-leading-trailing-cat-leading'),
|
|
57
|
+
],
|
|
58
|
+
)
|
|
59
|
+
def test_broadcast_cat(t: Tensor, singleton_axes: tuple[int, ...], dim: int) -> None:
|
|
60
|
+
normalized_axes = {axis if axis >= 0 else t.ndim + axis for axis in singleton_axes}
|
|
61
|
+
broadcast_source = t[tuple(slice(0, 1) if axis_index in normalized_axes else slice(None) for axis_index in range(t.ndim))]
|
|
62
|
+
result = broadcast_cat((t, broadcast_source), dim=dim)
|
|
63
|
+
expected = torch.cat((t, broadcast_source.expand_as(t)), dim=dim)
|
|
64
|
+
normalized_dim = dim if dim >= 0 else t.ndim + dim
|
|
65
|
+
expected_shape = list(t.shape)
|
|
66
|
+
expected_shape[normalized_dim] *= 2
|
|
67
|
+
|
|
68
|
+
assert broadcast_source.ndim == t.ndim, (
|
|
69
|
+
f'broadcast_cat test constructed rank {broadcast_source.ndim} tensor, expected rank {t.ndim} '
|
|
70
|
+
f'for input shape {tuple(t.shape)} and {singleton_axes=}.'
|
|
71
|
+
)
|
|
72
|
+
assert result.shape == torch.Size(expected_shape), (
|
|
73
|
+
f'broadcast_cat returned shape {tuple(result.shape)}, expected {tuple(expected_shape)} '
|
|
74
|
+
f'for input shape {tuple(t.shape)}, broadcast source shape {tuple(broadcast_source.shape)}, '
|
|
75
|
+
f'and {dim=}.'
|
|
76
|
+
)
|
|
77
|
+
assert torch.equal(result, expected), (
|
|
78
|
+
f'broadcast_cat returned values {result} that do not match explicit broadcast-plus-cat result {expected} '
|
|
79
|
+
f'for input shape {tuple(t.shape)}, broadcast source shape {tuple(broadcast_source.shape)}, and {dim=}.'
|
|
80
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from torch import nn
|
|
4
|
+
from torch_einops_kit.device import module_device, move_inputs_to_device
|
|
5
|
+
import torch
|
|
6
|
+
|
|
7
|
+
def test_module_device() -> None:
|
|
8
|
+
|
|
9
|
+
assert module_device(nn.Linear(3, 3)) == torch.device('cpu')
|
|
10
|
+
assert module_device(nn.Identity()) is None
|
|
11
|
+
|
|
12
|
+
def test_move_input_to_device() -> None:
|
|
13
|
+
|
|
14
|
+
def fn(t: torch.Tensor) -> torch.Tensor:
|
|
15
|
+
return t
|
|
16
|
+
|
|
17
|
+
decorated = move_inputs_to_device(torch.device('cpu'))(fn)
|
|
18
|
+
decorated(torch.randn(3))
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
Some or all of the logic in this module may be protected by the following.
|
|
22
|
+
|
|
23
|
+
MIT License
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2026 Phil Wang
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
|
44
|
+
"""
|