stacked-linear 0.1.0__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.
- stacked_linear-0.1.0/.codecov.yaml +17 -0
- stacked_linear-0.1.0/.cruft.json +43 -0
- stacked_linear-0.1.0/.editorconfig +15 -0
- stacked_linear-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +93 -0
- stacked_linear-0.1.0/.github/ISSUE_TEMPLATE/config.yml +5 -0
- stacked_linear-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +11 -0
- stacked_linear-0.1.0/.github/workflows/build.yaml +26 -0
- stacked_linear-0.1.0/.github/workflows/release.yaml +27 -0
- stacked_linear-0.1.0/.github/workflows/test.yaml +105 -0
- stacked_linear-0.1.0/.gitignore +25 -0
- stacked_linear-0.1.0/.pre-commit-config.yaml +38 -0
- stacked_linear-0.1.0/.readthedocs.yaml +16 -0
- stacked_linear-0.1.0/CHANGELOG.md +15 -0
- stacked_linear-0.1.0/LICENSE +29 -0
- stacked_linear-0.1.0/PKG-INFO +118 -0
- stacked_linear-0.1.0/README.md +70 -0
- stacked_linear-0.1.0/biome.jsonc +17 -0
- stacked_linear-0.1.0/docs/_static/.gitkeep +0 -0
- stacked_linear-0.1.0/docs/_static/css/custom.css +4 -0
- stacked_linear-0.1.0/docs/_templates/.gitkeep +0 -0
- stacked_linear-0.1.0/docs/_templates/autosummary/class.rst +61 -0
- stacked_linear-0.1.0/docs/api.md +14 -0
- stacked_linear-0.1.0/docs/changelog.md +3 -0
- stacked_linear-0.1.0/docs/conf.py +136 -0
- stacked_linear-0.1.0/docs/extensions/typed_returns.py +32 -0
- stacked_linear-0.1.0/docs/index.md +11 -0
- stacked_linear-0.1.0/pyproject.toml +137 -0
- stacked_linear-0.1.0/src/stacked_linear/__init__.py +4 -0
- stacked_linear-0.1.0/src/stacked_linear/linear_layer.py +55 -0
- stacked_linear-0.1.0/src/stacked_linear/stacked_linear_layer.py +224 -0
- stacked_linear-0.1.0/tests/__init__.py +1 -0
- stacked_linear-0.1.0/tests/test_layers.py +149 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Based on pydata/xarray
|
|
2
|
+
codecov:
|
|
3
|
+
require_ci_to_pass: no
|
|
4
|
+
|
|
5
|
+
coverage:
|
|
6
|
+
status:
|
|
7
|
+
project:
|
|
8
|
+
default:
|
|
9
|
+
# Require 1% coverage, i.e., always succeed
|
|
10
|
+
target: 1
|
|
11
|
+
patch: false
|
|
12
|
+
changes: false
|
|
13
|
+
|
|
14
|
+
comment:
|
|
15
|
+
layout: diff, flags, files
|
|
16
|
+
behavior: once
|
|
17
|
+
require_base: no
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"template": "https://github.com/scverse/cookiecutter-scverse",
|
|
3
|
+
"commit": "5ff4cf19f50c028f0e78291d56ab3beb28ca357c",
|
|
4
|
+
"checkout": null,
|
|
5
|
+
"context": {
|
|
6
|
+
"cookiecutter": {
|
|
7
|
+
"project_name": "stacked-linear",
|
|
8
|
+
"package_name": "stacked_linear",
|
|
9
|
+
"project_description": "Efficient implementation of stacked linear modules",
|
|
10
|
+
"author_full_name": "Amir Ali Moinfar",
|
|
11
|
+
"author_email": "moinfar.amirali@gmail.com",
|
|
12
|
+
"github_user": "moinfar",
|
|
13
|
+
"github_repo": "stacked-linear",
|
|
14
|
+
"license": "BSD 3-Clause License",
|
|
15
|
+
"ide_integration": false,
|
|
16
|
+
"_copy_without_render": [
|
|
17
|
+
".github/workflows/build.yaml",
|
|
18
|
+
".github/workflows/test.yaml",
|
|
19
|
+
"docs/_templates/autosummary/**.rst"
|
|
20
|
+
],
|
|
21
|
+
"_exclude_on_template_update": [
|
|
22
|
+
"CHANGELOG.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md",
|
|
25
|
+
"docs/api.md",
|
|
26
|
+
"docs/index.md",
|
|
27
|
+
"docs/notebooks/example.ipynb",
|
|
28
|
+
"docs/references.bib",
|
|
29
|
+
"docs/references.md",
|
|
30
|
+
"src/**",
|
|
31
|
+
"tests/**"
|
|
32
|
+
],
|
|
33
|
+
"_render_devdocs": false,
|
|
34
|
+
"_jinja2_env_vars": {
|
|
35
|
+
"lstrip_blocks": true,
|
|
36
|
+
"trim_blocks": true
|
|
37
|
+
},
|
|
38
|
+
"_template": "https://github.com/scverse/cookiecutter-scverse",
|
|
39
|
+
"_commit": "5ff4cf19f50c028f0e78291d56ab3beb28ca357c"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"directory": null
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
indent_style = space
|
|
5
|
+
indent_size = 4
|
|
6
|
+
end_of_line = lf
|
|
7
|
+
charset = utf-8
|
|
8
|
+
trim_trailing_whitespace = true
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
|
|
11
|
+
[{*.{yml,yaml,toml},.cruft.json}]
|
|
12
|
+
indent_size = 2
|
|
13
|
+
|
|
14
|
+
[Makefile]
|
|
15
|
+
indent_style = tab
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
name: Bug report
|
|
2
|
+
description: Report something that is broken or incorrect
|
|
3
|
+
type: Bug
|
|
4
|
+
body:
|
|
5
|
+
- type: markdown
|
|
6
|
+
attributes:
|
|
7
|
+
value: |
|
|
8
|
+
**Note**: Please read [this guide](https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports)
|
|
9
|
+
detailing how to provide the necessary information for us to reproduce your bug. In brief:
|
|
10
|
+
* Please provide exact steps how to reproduce the bug in a clean Python environment.
|
|
11
|
+
* In case it's not clear what's causing this bug, please provide the data or the data generation procedure.
|
|
12
|
+
* Replicate problems on public datasets or share data subsets when full sharing isn't possible.
|
|
13
|
+
|
|
14
|
+
- type: textarea
|
|
15
|
+
id: report
|
|
16
|
+
attributes:
|
|
17
|
+
label: Report
|
|
18
|
+
description: A clear and concise description of what the bug is.
|
|
19
|
+
validations:
|
|
20
|
+
required: true
|
|
21
|
+
|
|
22
|
+
- type: textarea
|
|
23
|
+
id: versions
|
|
24
|
+
attributes:
|
|
25
|
+
label: Versions
|
|
26
|
+
description: |
|
|
27
|
+
Which version of packages.
|
|
28
|
+
|
|
29
|
+
Please install `session-info2`, run the following command in a notebook,
|
|
30
|
+
click the “Copy as Markdown” button, then paste the results into the text box below.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
In[1]: import session_info2; session_info2.session_info(dependencies=True)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Alternatively, run this in a console:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
>>> import session_info2; print(session_info2.session_info(dependencies=True)._repr_mimebundle_()["text/markdown"])
|
|
40
|
+
```
|
|
41
|
+
render: python
|
|
42
|
+
placeholder: |
|
|
43
|
+
anndata 0.11.3
|
|
44
|
+
---- ----
|
|
45
|
+
charset-normalizer 3.4.1
|
|
46
|
+
coverage 7.7.0
|
|
47
|
+
psutil 7.0.0
|
|
48
|
+
dask 2024.7.1
|
|
49
|
+
jaraco.context 5.3.0
|
|
50
|
+
numcodecs 0.15.1
|
|
51
|
+
jaraco.functools 4.0.1
|
|
52
|
+
Jinja2 3.1.6
|
|
53
|
+
sphinxcontrib-jsmath 1.0.1
|
|
54
|
+
sphinxcontrib-htmlhelp 2.1.0
|
|
55
|
+
toolz 1.0.0
|
|
56
|
+
session-info2 0.1.2
|
|
57
|
+
PyYAML 6.0.2
|
|
58
|
+
llvmlite 0.44.0
|
|
59
|
+
scipy 1.15.2
|
|
60
|
+
pandas 2.2.3
|
|
61
|
+
sphinxcontrib-devhelp 2.0.0
|
|
62
|
+
h5py 3.13.0
|
|
63
|
+
tblib 3.0.0
|
|
64
|
+
setuptools-scm 8.2.0
|
|
65
|
+
more-itertools 10.3.0
|
|
66
|
+
msgpack 1.1.0
|
|
67
|
+
sparse 0.15.5
|
|
68
|
+
wrapt 1.17.2
|
|
69
|
+
jaraco.collections 5.1.0
|
|
70
|
+
numba 0.61.0
|
|
71
|
+
pyarrow 19.0.1
|
|
72
|
+
pytz 2025.1
|
|
73
|
+
MarkupSafe 3.0.2
|
|
74
|
+
crc32c 2.7.1
|
|
75
|
+
sphinxcontrib-qthelp 2.0.0
|
|
76
|
+
sphinxcontrib-serializinghtml 2.0.0
|
|
77
|
+
zarr 2.18.4
|
|
78
|
+
asciitree 0.3.3
|
|
79
|
+
six 1.17.0
|
|
80
|
+
sphinxcontrib-applehelp 2.0.0
|
|
81
|
+
numpy 2.1.3
|
|
82
|
+
cloudpickle 3.1.1
|
|
83
|
+
sphinxcontrib-bibtex 2.6.3
|
|
84
|
+
natsort 8.4.0
|
|
85
|
+
jaraco.text 3.12.1
|
|
86
|
+
setuptools 76.1.0
|
|
87
|
+
Deprecated 1.2.18
|
|
88
|
+
packaging 24.2
|
|
89
|
+
python-dateutil 2.9.0.post0
|
|
90
|
+
---- ----
|
|
91
|
+
Python 3.13.2 | packaged by conda-forge | (main, Feb 17 2025, 14:10:22) [GCC 13.3.0]
|
|
92
|
+
OS Linux-6.11.0-109019-tuxedo-x86_64-with-glibc2.39
|
|
93
|
+
Updated 2025-03-18 15:47
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
name: Feature request
|
|
2
|
+
description: Propose a new feature for stacked-linear
|
|
3
|
+
type: Enhancement
|
|
4
|
+
body:
|
|
5
|
+
- type: textarea
|
|
6
|
+
id: description
|
|
7
|
+
attributes:
|
|
8
|
+
label: Description of feature
|
|
9
|
+
description: Please describe your suggestion for a new feature. It might help to describe a problem or use case, plus any alternatives that you have considered.
|
|
10
|
+
validations:
|
|
11
|
+
required: true
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Check Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
package:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v6
|
|
18
|
+
with:
|
|
19
|
+
filter: blob:none
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
- name: Install uv
|
|
22
|
+
uses: astral-sh/setup-uv@v7
|
|
23
|
+
- name: Build package
|
|
24
|
+
run: uv build
|
|
25
|
+
- name: Check package
|
|
26
|
+
run: uvx twine check --strict dist/*.whl
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
# Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/
|
|
8
|
+
jobs:
|
|
9
|
+
release:
|
|
10
|
+
name: Upload release to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment:
|
|
13
|
+
name: pypi
|
|
14
|
+
url: https://pypi.org/p/stacked_linear
|
|
15
|
+
permissions:
|
|
16
|
+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
|
+
with:
|
|
20
|
+
filter: blob:none
|
|
21
|
+
fetch-depth: 0
|
|
22
|
+
- name: Install uv
|
|
23
|
+
uses: astral-sh/setup-uv@v7
|
|
24
|
+
- name: Build package
|
|
25
|
+
run: uv build
|
|
26
|
+
- name: Publish package distributions to PyPI
|
|
27
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: "0 5 1,15 * *"
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
# Get the test environment from hatch as defined in pyproject.toml.
|
|
17
|
+
# This ensures that the pyproject.toml is the single point of truth for test definitions and the same tests are
|
|
18
|
+
# run locally and on continuous integration.
|
|
19
|
+
# Check [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml and https://hatch.pypa.io/latest/environment/ for
|
|
20
|
+
# more details.
|
|
21
|
+
get-environments:
|
|
22
|
+
runs-on: ubuntu-slim
|
|
23
|
+
outputs:
|
|
24
|
+
envs: ${{ steps.get-envs.outputs.envs }}
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v6
|
|
27
|
+
with:
|
|
28
|
+
filter: blob:none
|
|
29
|
+
fetch-depth: 0
|
|
30
|
+
- name: Install uv
|
|
31
|
+
uses: astral-sh/setup-uv@v7
|
|
32
|
+
- name: Get test environments
|
|
33
|
+
id: get-envs
|
|
34
|
+
run: |
|
|
35
|
+
ENVS_JSON=$(uvx hatch env show --json | jq -c 'to_entries
|
|
36
|
+
| map(
|
|
37
|
+
select(.key | startswith("hatch-test"))
|
|
38
|
+
| {
|
|
39
|
+
name: .key,
|
|
40
|
+
label: (if (.key | contains("pre")) then .key + " (PRE-RELEASE DEPENDENCIES)" else .key end),
|
|
41
|
+
python: .value.python
|
|
42
|
+
}
|
|
43
|
+
)')
|
|
44
|
+
echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT
|
|
45
|
+
|
|
46
|
+
# Run tests through hatch. Spawns a separate runner for each environment defined in the hatch matrix obtained above.
|
|
47
|
+
test:
|
|
48
|
+
needs: get-environments
|
|
49
|
+
permissions:
|
|
50
|
+
id-token: write # for codecov OIDC
|
|
51
|
+
|
|
52
|
+
strategy:
|
|
53
|
+
fail-fast: false
|
|
54
|
+
matrix:
|
|
55
|
+
os: [ubuntu-latest]
|
|
56
|
+
env: ${{ fromJSON(needs.get-environments.outputs.envs) }}
|
|
57
|
+
|
|
58
|
+
name: ${{ matrix.env.label }}
|
|
59
|
+
runs-on: ${{ matrix.os }}
|
|
60
|
+
continue-on-error: ${{ contains(matrix.env.name, 'pre') }} # make "all-green" pass even if pre-release job fails
|
|
61
|
+
|
|
62
|
+
steps:
|
|
63
|
+
- uses: actions/checkout@v6
|
|
64
|
+
with:
|
|
65
|
+
filter: blob:none
|
|
66
|
+
fetch-depth: 0
|
|
67
|
+
- name: Install uv
|
|
68
|
+
uses: astral-sh/setup-uv@v7
|
|
69
|
+
with:
|
|
70
|
+
python-version: ${{ matrix.env.python }}
|
|
71
|
+
- name: create hatch environment
|
|
72
|
+
run: uvx hatch env create ${{ matrix.env.name }}
|
|
73
|
+
- name: list all all installed package versions
|
|
74
|
+
run: uvx hatch run ${{ matrix.env.name }}:uv pip list
|
|
75
|
+
- name: run tests using hatch
|
|
76
|
+
env:
|
|
77
|
+
MPLBACKEND: agg
|
|
78
|
+
PLATFORM: ${{ matrix.os }}
|
|
79
|
+
DISPLAY: :42
|
|
80
|
+
run: uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto
|
|
81
|
+
- name: generate coverage report
|
|
82
|
+
run: |
|
|
83
|
+
# See https://coverage.readthedocs.io/en/latest/config.html#run-patch
|
|
84
|
+
test -f .coverage || uvx hatch run ${{ matrix.env.name }}:cov-combine
|
|
85
|
+
uvx hatch run ${{ matrix.env.name }}:cov-report # report visibly
|
|
86
|
+
uvx hatch run ${{ matrix.env.name }}:coverage xml # create report for upload
|
|
87
|
+
- name: Upload coverage
|
|
88
|
+
uses: codecov/codecov-action@v5
|
|
89
|
+
with:
|
|
90
|
+
fail_ci_if_error: true
|
|
91
|
+
use_oidc: true
|
|
92
|
+
|
|
93
|
+
# Check that all tests defined above pass. This makes it easy to set a single "required" test in branch
|
|
94
|
+
# protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why.
|
|
95
|
+
check:
|
|
96
|
+
name: Tests pass in all hatch environments
|
|
97
|
+
if: always()
|
|
98
|
+
needs:
|
|
99
|
+
- get-environments
|
|
100
|
+
- test
|
|
101
|
+
runs-on: ubuntu-latest
|
|
102
|
+
steps:
|
|
103
|
+
- uses: re-actors/alls-green@release/v1
|
|
104
|
+
with:
|
|
105
|
+
jobs: ${{ toJSON(needs) }}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Temp files
|
|
2
|
+
.DS_Store
|
|
3
|
+
*~
|
|
4
|
+
buck-out/
|
|
5
|
+
|
|
6
|
+
# IDEs
|
|
7
|
+
/.idea/
|
|
8
|
+
/.vscode/
|
|
9
|
+
|
|
10
|
+
# Compiled files
|
|
11
|
+
.venv/
|
|
12
|
+
__pycache__/
|
|
13
|
+
.*cache/
|
|
14
|
+
|
|
15
|
+
# Distribution / packaging
|
|
16
|
+
/dist/
|
|
17
|
+
|
|
18
|
+
# Tests and coverage
|
|
19
|
+
/data/
|
|
20
|
+
/node_modules/
|
|
21
|
+
/.coverage*
|
|
22
|
+
|
|
23
|
+
# docs
|
|
24
|
+
/docs/generated/
|
|
25
|
+
/docs/_build/
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
fail_fast: false
|
|
2
|
+
default_language_version:
|
|
3
|
+
python: python3
|
|
4
|
+
default_stages:
|
|
5
|
+
- pre-commit
|
|
6
|
+
- pre-push
|
|
7
|
+
minimum_pre_commit_version: 2.16.0
|
|
8
|
+
repos:
|
|
9
|
+
- repo: https://github.com/biomejs/pre-commit
|
|
10
|
+
rev: v2.4.10
|
|
11
|
+
hooks:
|
|
12
|
+
- id: biome-format
|
|
13
|
+
exclude: ^\.cruft\.json$ # inconsistent indentation with cruft - file never to be modified manually.
|
|
14
|
+
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
15
|
+
rev: v2.21.0
|
|
16
|
+
hooks:
|
|
17
|
+
- id: pyproject-fmt
|
|
18
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
19
|
+
rev: v0.15.9
|
|
20
|
+
hooks:
|
|
21
|
+
- id: ruff-check
|
|
22
|
+
types_or: [python, pyi, jupyter]
|
|
23
|
+
args: [--fix, --exit-non-zero-on-fix]
|
|
24
|
+
- id: ruff-format
|
|
25
|
+
types_or: [python, pyi, jupyter]
|
|
26
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
27
|
+
rev: v6.0.0
|
|
28
|
+
hooks:
|
|
29
|
+
- id: detect-private-key
|
|
30
|
+
- id: check-ast
|
|
31
|
+
- id: end-of-file-fixer
|
|
32
|
+
- id: mixed-line-ending
|
|
33
|
+
args: [--fix=lf]
|
|
34
|
+
- id: trailing-whitespace
|
|
35
|
+
- id: check-case-conflict
|
|
36
|
+
# Check that there are no merge conflicts (could be generated by template sync)
|
|
37
|
+
- id: check-merge-conflict
|
|
38
|
+
args: [--assume-in-merge]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# https://docs.readthedocs.io/en/stable/config-file/v2.html
|
|
2
|
+
version: 2
|
|
3
|
+
build:
|
|
4
|
+
os: ubuntu-24.04
|
|
5
|
+
tools:
|
|
6
|
+
python: "3.14"
|
|
7
|
+
nodejs: latest
|
|
8
|
+
jobs:
|
|
9
|
+
create_environment:
|
|
10
|
+
- asdf plugin add uv
|
|
11
|
+
- asdf install uv latest
|
|
12
|
+
- asdf global uv latest
|
|
13
|
+
build:
|
|
14
|
+
html:
|
|
15
|
+
- uvx hatch run docs:build
|
|
16
|
+
- mv docs/_build $READTHEDOCS_OUTPUT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog][],
|
|
6
|
+
and this project adheres to [Semantic Versioning][].
|
|
7
|
+
|
|
8
|
+
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
|
|
9
|
+
[semantic versioning]: https://semver.org/spec/v2.0.0.html
|
|
10
|
+
|
|
11
|
+
## [Unreleased]
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Basic tool, preprocessing and plotting functions
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Amir Ali Moinfar
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stacked-linear
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Efficient implementation of stacked linear modules
|
|
5
|
+
Project-URL: Documentation, https://stacked-linear.readthedocs.io/
|
|
6
|
+
Project-URL: Homepage, https://github.com/moinfar/stacked-linear
|
|
7
|
+
Project-URL: Source, https://github.com/moinfar/stacked-linear
|
|
8
|
+
Author: Amir Ali Moinfar
|
|
9
|
+
Maintainer-email: Amir Ali Moinfar <moinfar.amirali@gmail.com>
|
|
10
|
+
License: BSD 3-Clause License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026, Amir Ali Moinfar
|
|
13
|
+
All rights reserved.
|
|
14
|
+
|
|
15
|
+
Redistribution and use in source and binary forms, with or without
|
|
16
|
+
modification, are permitted provided that the following conditions are met:
|
|
17
|
+
|
|
18
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
19
|
+
list of conditions and the following disclaimer.
|
|
20
|
+
|
|
21
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
22
|
+
this list of conditions and the following disclaimer in the documentation
|
|
23
|
+
and/or other materials provided with the distribution.
|
|
24
|
+
|
|
25
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
26
|
+
contributors may be used to endorse or promote products derived from
|
|
27
|
+
this software without specific prior written permission.
|
|
28
|
+
|
|
29
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
30
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
31
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
32
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
33
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
34
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
35
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
36
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
37
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
38
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
45
|
+
Requires-Python: >=3.11
|
|
46
|
+
Requires-Dist: torch>=2
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# Parallel Stacked Linear Modules for PyTorch
|
|
50
|
+
|
|
51
|
+
[![Tests][badge-tests]][tests]
|
|
52
|
+
[![Documentation][badge-docs]][documentation]
|
|
53
|
+
|
|
54
|
+
Efficient implementation of stacked linear modules in PyTorch, with support for output and stack subsetting.
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- **`StackedLinearLayer`**: A parallelized linear layer that applies multiple independent transformations across different input stacks simultaneously. This is significantly more efficient than for loop over multiple `nn.Linear` layers. This is useful for specialized neural architectures like Additive Decoders.
|
|
59
|
+
- **Subsetting Support**: Both layers allow for subsetting output features during the forward pass, and `StackedLinearLayer` additionally supports subsetting stacks.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install stacked-linear
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or install from source:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install git+https://github.com/moinfar/stacked-linear.git
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
### Linear Layer with Output Subsetting
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import torch
|
|
79
|
+
from stacked_linear import LinearLayer
|
|
80
|
+
|
|
81
|
+
# Initialize a layer (10 inputs, 5 outputs)
|
|
82
|
+
layer = LinearLayer(10, 5)
|
|
83
|
+
x = torch.randn(2, 10)
|
|
84
|
+
|
|
85
|
+
# Forward pass on a subset of output features (indices 0, 2, and 4)
|
|
86
|
+
subset = torch.tensor([0, 2, 4])
|
|
87
|
+
output = layer(x, output_subset=subset) # Shape: (2, 3)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Stacked Linear Layer
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import torch
|
|
94
|
+
from stacked_linear import StackedLinearLayer
|
|
95
|
+
|
|
96
|
+
# 3 parallel stacks, each mapping 10 inputs to 5 outputs
|
|
97
|
+
layer = StackedLinearLayer(n_stacks=3, in_features=10, out_features=5)
|
|
98
|
+
x = torch.randn(2, 3, 10) # (batch, stacks, features)
|
|
99
|
+
|
|
100
|
+
# Efficient parallel forward pass
|
|
101
|
+
output = layer(x) # Shape: (2, 3, 5)
|
|
102
|
+
|
|
103
|
+
# Forward pass on a subset of output features across all stacks
|
|
104
|
+
subset = torch.tensor([1, 3])
|
|
105
|
+
output_subset = layer(x, output_subset=subset) # Shape: (2, 3, 2)
|
|
106
|
+
|
|
107
|
+
# Forward pass on a subset of stacks
|
|
108
|
+
stack_subset = torch.tensor([[0, 2], [1, 2]]) # Indices for each batch item
|
|
109
|
+
x_subset = torch.randn(2, 2, 10)
|
|
110
|
+
output_stack_subset = layer(x_subset, stack_subset=stack_subset) # Shape: (2, 2, 5)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
[badge-tests]: https://img.shields.io/github/actions/workflow/status/moinfar/stacked-linear/test.yaml?branch=main
|
|
115
|
+
[badge-docs]: https://img.shields.io/readthedocs/stacked-linear
|
|
116
|
+
[tests]: https://github.com/moinfar/stacked-linear/actions/workflows/test.yaml
|
|
117
|
+
[documentation]: https://stacked-linear.readthedocs.io
|
|
118
|
+
[issue tracker]: https://github.com/moinfar/stacked-linear/issues
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Parallel Stacked Linear Modules for PyTorch
|
|
2
|
+
|
|
3
|
+
[![Tests][badge-tests]][tests]
|
|
4
|
+
[![Documentation][badge-docs]][documentation]
|
|
5
|
+
|
|
6
|
+
Efficient implementation of stacked linear modules in PyTorch, with support for output and stack subsetting.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **`StackedLinearLayer`**: A parallelized linear layer that applies multiple independent transformations across different input stacks simultaneously. This is significantly more efficient than for loop over multiple `nn.Linear` layers. This is useful for specialized neural architectures like Additive Decoders.
|
|
11
|
+
- **Subsetting Support**: Both layers allow for subsetting output features during the forward pass, and `StackedLinearLayer` additionally supports subsetting stacks.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install stacked-linear
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install from source:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install git+https://github.com/moinfar/stacked-linear.git
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### Linear Layer with Output Subsetting
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import torch
|
|
31
|
+
from stacked_linear import LinearLayer
|
|
32
|
+
|
|
33
|
+
# Initialize a layer (10 inputs, 5 outputs)
|
|
34
|
+
layer = LinearLayer(10, 5)
|
|
35
|
+
x = torch.randn(2, 10)
|
|
36
|
+
|
|
37
|
+
# Forward pass on a subset of output features (indices 0, 2, and 4)
|
|
38
|
+
subset = torch.tensor([0, 2, 4])
|
|
39
|
+
output = layer(x, output_subset=subset) # Shape: (2, 3)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Stacked Linear Layer
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import torch
|
|
46
|
+
from stacked_linear import StackedLinearLayer
|
|
47
|
+
|
|
48
|
+
# 3 parallel stacks, each mapping 10 inputs to 5 outputs
|
|
49
|
+
layer = StackedLinearLayer(n_stacks=3, in_features=10, out_features=5)
|
|
50
|
+
x = torch.randn(2, 3, 10) # (batch, stacks, features)
|
|
51
|
+
|
|
52
|
+
# Efficient parallel forward pass
|
|
53
|
+
output = layer(x) # Shape: (2, 3, 5)
|
|
54
|
+
|
|
55
|
+
# Forward pass on a subset of output features across all stacks
|
|
56
|
+
subset = torch.tensor([1, 3])
|
|
57
|
+
output_subset = layer(x, output_subset=subset) # Shape: (2, 3, 2)
|
|
58
|
+
|
|
59
|
+
# Forward pass on a subset of stacks
|
|
60
|
+
stack_subset = torch.tensor([[0, 2], [1, 2]]) # Indices for each batch item
|
|
61
|
+
x_subset = torch.randn(2, 2, 10)
|
|
62
|
+
output_stack_subset = layer(x_subset, stack_subset=stack_subset) # Shape: (2, 2, 5)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
[badge-tests]: https://img.shields.io/github/actions/workflow/status/moinfar/stacked-linear/test.yaml?branch=main
|
|
67
|
+
[badge-docs]: https://img.shields.io/readthedocs/stacked-linear
|
|
68
|
+
[tests]: https://github.com/moinfar/stacked-linear/actions/workflows/test.yaml
|
|
69
|
+
[documentation]: https://stacked-linear.readthedocs.io
|
|
70
|
+
[issue tracker]: https://github.com/moinfar/stacked-linear/issues
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.0/schema.json",
|
|
3
|
+
"vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true },
|
|
4
|
+
"formatter": { "useEditorconfig": true },
|
|
5
|
+
"overrides": [
|
|
6
|
+
{
|
|
7
|
+
"includes": ["./.vscode/*.json", "**/*.jsonc"],
|
|
8
|
+
"json": {
|
|
9
|
+
"formatter": { "trailingCommas": "all" },
|
|
10
|
+
"parser": {
|
|
11
|
+
"allowComments": true,
|
|
12
|
+
"allowTrailingCommas": true,
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
}
|