pyluma 0.1.2__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.
Files changed (46) hide show
  1. pyluma-0.1.2/.cargo/config.toml +4 -0
  2. pyluma-0.1.2/.github/dependabot.yml +17 -0
  3. pyluma-0.1.2/.github/workflows/ci.yml +71 -0
  4. pyluma-0.1.2/.github/workflows/release.yml +123 -0
  5. pyluma-0.1.2/.gitignore +14 -0
  6. pyluma-0.1.2/.pre-commit-config.yaml +27 -0
  7. pyluma-0.1.2/CHANGELOG.md +26 -0
  8. pyluma-0.1.2/CONTRIBUTING.md +88 -0
  9. pyluma-0.1.2/Cargo.lock +1443 -0
  10. pyluma-0.1.2/Cargo.toml +26 -0
  11. pyluma-0.1.2/LICENSE-APACHE +202 -0
  12. pyluma-0.1.2/LICENSE-MIT +9 -0
  13. pyluma-0.1.2/PKG-INFO +320 -0
  14. pyluma-0.1.2/README.md +289 -0
  15. pyluma-0.1.2/benchmarks/gaussian_nb.py +505 -0
  16. pyluma-0.1.2/build.rs +35 -0
  17. pyluma-0.1.2/examples/basics.py +38 -0
  18. pyluma-0.1.2/examples/conv1d.py +29 -0
  19. pyluma-0.1.2/examples/custom_kernel.py +88 -0
  20. pyluma-0.1.2/examples/datasci.py +17 -0
  21. pyluma-0.1.2/pyproject.toml +73 -0
  22. pyluma-0.1.2/python/lumapy/__init__.py +500 -0
  23. pyluma-0.1.2/python/lumapy/_lumapy.pyi +431 -0
  24. pyluma-0.1.2/python/lumapy/py.typed +0 -0
  25. pyluma-0.1.2/rustfmt.toml +2 -0
  26. pyluma-0.1.2/src/array.rs +265 -0
  27. pyluma-0.1.2/src/closures.rs +176 -0
  28. pyluma-0.1.2/src/context.rs +247 -0
  29. pyluma-0.1.2/src/convert.rs +209 -0
  30. pyluma-0.1.2/src/dtype.rs +303 -0
  31. pyluma-0.1.2/src/error.rs +29 -0
  32. pyluma-0.1.2/src/functions.rs +434 -0
  33. pyluma-0.1.2/src/inner.rs +194 -0
  34. pyluma-0.1.2/src/kernel.rs +234 -0
  35. pyluma-0.1.2/src/lib.rs +63 -0
  36. pyluma-0.1.2/src/operand.rs +247 -0
  37. pyluma-0.1.2/src/ops.rs +688 -0
  38. pyluma-0.1.2/src/reduce.rs +731 -0
  39. pyluma-0.1.2/src/scalar.rs +93 -0
  40. pyluma-0.1.2/src/view.rs +552 -0
  41. pyluma-0.1.2/tests/test_basics.py +280 -0
  42. pyluma-0.1.2/tests/test_docs.py +24 -0
  43. pyluma-0.1.2/tests/test_gaussian_nb.py +52 -0
  44. pyluma-0.1.2/tests/test_reductions.py +168 -0
  45. pyluma-0.1.2/tests/test_runtime.py +148 -0
  46. pyluma-0.1.2/tests/test_views.py +152 -0
@@ -0,0 +1,4 @@
1
+ [env]
2
+ # Builds and tests run from this repository keep Luma's compiled-pipeline and calibration cache
3
+ # in `target/` instead of the user's cache directory (see `LUMA_CACHE_DIR` in Luma's README).
4
+ LUMA_CACHE_DIR = { value = "target/luma-cache", relative = true }
@@ -0,0 +1,17 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: cargo
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ groups:
8
+ pyo3:
9
+ patterns: ["pyo3*", "numpy"]
10
+ - package-ecosystem: pip
11
+ directory: /
12
+ schedule:
13
+ interval: weekly
14
+ - package-ecosystem: github-actions
15
+ directory: /
16
+ schedule:
17
+ interval: monthly
@@ -0,0 +1,71 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ concurrency:
9
+ group: ${{ github.workflow }}-${{ github.ref }}
10
+ cancel-in-progress: true
11
+
12
+ env:
13
+ CARGO_TERM_COLOR: always
14
+ # GitHub's Linux runners have no GPU: Luma runs on Mesa's software Vulkan driver.
15
+ LUMA_DEVICE: cpu
16
+
17
+ jobs:
18
+ lint:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - uses: dtolnay/rust-toolchain@stable
23
+ with:
24
+ components: rustfmt, clippy
25
+ - uses: Swatinem/rust-cache@v2
26
+ - uses: actions/setup-python@v5
27
+ with:
28
+ python-version: "3.12"
29
+ - run: cargo fmt --check
30
+ - run: cargo clippy --all-targets -- -D warnings
31
+ - run: python -m pip install --upgrade pip && pip install --group lint
32
+ - run: ruff check python tests examples benchmarks
33
+ - run: ruff format --check python tests examples benchmarks
34
+ - run: mypy
35
+
36
+ test:
37
+ name: test (${{ matrix.os }}, Python ${{ matrix.python }})
38
+ runs-on: ${{ matrix.os }}
39
+ strategy:
40
+ fail-fast: false
41
+ matrix:
42
+ os: [ubuntu-latest]
43
+ python: ["3.10", "3.13"]
44
+ include:
45
+ # Apple Silicon runners have a (virtualized) Metal GPU.
46
+ - os: macos-latest
47
+ python: "3.13"
48
+ steps:
49
+ - uses: actions/checkout@v4
50
+ - uses: dtolnay/rust-toolchain@stable
51
+ - uses: Swatinem/rust-cache@v2
52
+ - uses: actions/setup-python@v5
53
+ with:
54
+ python-version: ${{ matrix.python }}
55
+ - name: Install software Vulkan (Mesa lavapipe)
56
+ if: runner.os == 'Linux'
57
+ run: sudo apt-get update && sudo apt-get install -y libvulkan1 mesa-vulkan-drivers
58
+ - name: Use the GPU on macOS
59
+ if: runner.os == 'macOS'
60
+ run: echo "LUMA_DEVICE=auto" >> "$GITHUB_ENV"
61
+ - name: Build and install
62
+ run: |
63
+ python -m pip install --upgrade pip
64
+ pip install --group test
65
+ pip install -v .
66
+ - run: pytest
67
+ - name: Check the type stubs against the extension
68
+ if: matrix.python == '3.13' && runner.os == 'Linux'
69
+ run: |
70
+ pip install --group lint
71
+ python -m mypy.stubtest lumapy._lumapy
@@ -0,0 +1,123 @@
1
+ # Builds abi3 wheels (one per platform, any CPython >= 3.10) and an sdist, and publishes them to
2
+ # PyPI with trusted publishing when a GitHub release is published.
3
+ name: Release
4
+
5
+ on:
6
+ release:
7
+ types: [published]
8
+ workflow_dispatch:
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ env:
14
+ CARGO_TERM_COLOR: always
15
+
16
+ jobs:
17
+ check-version:
18
+ if: github.event_name == 'release'
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+ - name: Check the release tag matches Cargo.toml
23
+ run: |
24
+ TAG="${GITHUB_REF_NAME#v}"
25
+ VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "lumapy") | .version')
26
+ if [ "$TAG" != "$VERSION" ]; then
27
+ echo "Tag v$TAG does not match Cargo.toml version $VERSION"
28
+ exit 1
29
+ fi
30
+
31
+ linux:
32
+ runs-on: ubuntu-latest
33
+ strategy:
34
+ matrix:
35
+ target: [x86_64, aarch64]
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ - uses: PyO3/maturin-action@v1
39
+ with:
40
+ target: ${{ matrix.target }}
41
+ args: --release --out dist
42
+ manylinux: auto
43
+ sccache: true
44
+ - uses: actions/upload-artifact@v4
45
+ with:
46
+ name: wheels-linux-${{ matrix.target }}
47
+ path: dist
48
+
49
+ windows:
50
+ runs-on: windows-latest
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+ - uses: actions/setup-python@v5
54
+ with:
55
+ python-version: "3.12"
56
+ - uses: PyO3/maturin-action@v1
57
+ with:
58
+ target: x64
59
+ args: --release --out dist
60
+ sccache: true
61
+ - uses: actions/upload-artifact@v4
62
+ with:
63
+ name: wheels-windows-x64
64
+ path: dist
65
+
66
+ # macos:
67
+ # runs-on: ${{ matrix.runner }}
68
+ # strategy:
69
+ # matrix:
70
+ # include:
71
+ # - runner: macos-13
72
+ # target: x86_64
73
+ # - runner: macos-14
74
+ # target: aarch64
75
+ # steps:
76
+ # - uses: actions/checkout@v4
77
+ # - uses: actions/setup-python@v5
78
+ # with:
79
+ # python-version: "3.12"
80
+ # - uses: PyO3/maturin-action@v1
81
+ # with:
82
+ # target: ${{ matrix.target }}
83
+ # args: --release --out dist
84
+ # sccache: true
85
+ # - uses: actions/upload-artifact@v4
86
+ # with:
87
+ # name: wheels-macos-${{ matrix.target }}
88
+ # path: dist
89
+
90
+ sdist:
91
+ runs-on: ubuntu-latest
92
+ steps:
93
+ - uses: actions/checkout@v4
94
+ - uses: PyO3/maturin-action@v1
95
+ with:
96
+ command: sdist
97
+ args: --out dist
98
+ - uses: actions/upload-artifact@v4
99
+ with:
100
+ name: wheels-sdist
101
+ path: dist
102
+
103
+ publish:
104
+ name: Publish to PyPI
105
+ if: github.event_name == 'release'
106
+ # needs: [check-version, linux, windows, macos, sdist]
107
+ needs: [check-version, linux, windows, sdist]
108
+ runs-on: ubuntu-latest
109
+ environment: release
110
+ permissions:
111
+ id-token: write
112
+ attestations: write
113
+ contents: read
114
+ steps:
115
+ - uses: actions/download-artifact@v4
116
+ with:
117
+ pattern: wheels-*
118
+ merge-multiple: true
119
+ path: dist
120
+ - uses: actions/attest-build-provenance@v2
121
+ with:
122
+ subject-path: dist/*
123
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,14 @@
1
+ /target
2
+ .idea
3
+ *.xml
4
+ .claude/
5
+ __pycache__/
6
+ *.py[cod]
7
+ *.so
8
+ *.pyd
9
+ .venv/
10
+ .pytest_cache/
11
+ dist/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ *.pdb
@@ -0,0 +1,27 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
+ hooks:
5
+ - id: check-toml
6
+ - id: check-yaml
7
+ - id: end-of-file-fixer
8
+ - id: trailing-whitespace
9
+ - repo: https://github.com/astral-sh/ruff-pre-commit
10
+ rev: v0.6.9
11
+ hooks:
12
+ - id: ruff
13
+ args: [--fix]
14
+ - id: ruff-format
15
+ - repo: local
16
+ hooks:
17
+ - id: cargo-fmt
18
+ name: cargo fmt
19
+ entry: cargo fmt --
20
+ language: system
21
+ types: [rust]
22
+ - id: cargo-clippy
23
+ name: cargo clippy
24
+ entry: cargo clippy --all-targets -- -D warnings
25
+ language: system
26
+ types: [rust]
27
+ pass_filenames: false
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to LumaPy are listed here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+
11
+ - First Python bindings for Luma 0.4: `lumapy.Array` over every element type (`float32`, `float64`, `df32`,
12
+ `uint32`, `int32`, `bool`) with NumPy-order shapes and axes, NumPy interop (`asarray`, `to_numpy`, `__array__`,
13
+ NumPy operators deferring to the GPU), operators with NumPy-like promotion, elementwise math, reductions with
14
+ `axis`/`keepdims`, scans, sorting, searching, group-by, scatters, filters, views and indexing (including in-place
15
+ assignment through slices and masks), `matmul`, 1-D convolution, tridiagonal solves, `iterate` /
16
+ `iterate_until` / `iterate_all` with Python step functions, `Scalar`, `Context` with its options and profiling,
17
+ and custom WGSL `Kernel`s.
18
+ - Type stubs (`_lumapy.pyi`, checked with `stubtest`) and `py.typed`.
19
+ - Wheels for Linux (x86_64, aarch64) and Windows (x64) (abi3, CPython 3.10+) built and published to PyPI on
20
+ release; macOS installs build from the sdist.
21
+ - `lumapy.__luma_version__`, `__luma_commit__` and `__luma_source__` (the Luma the build is compiled against, read
22
+ from `Cargo.lock` at build time) and `lumapy.show_versions()`.
23
+ - Python ports of Luma's `basics`, `conv1d` and `custom_kernel` examples, and `examples/datasci.py`.
24
+ - `benchmarks/gaussian_nb.py`: Gaussian naive Bayes with LumaPy against scikit-learn's `GaussianNB` and against
25
+ CPU implementations of the same formulation (NumPy on multithreaded BLAS, fused parallel Numba loops), with
26
+ first-call and spread reporting; a test checks that every implementation fits scikit-learn's model.
@@ -0,0 +1,88 @@
1
+ # Contributing to LumaPy
2
+
3
+ LumaPy is a [PyO3](https://pyo3.rs) extension built with [maturin](https://www.maturin.rs), laid out like other
4
+ Rust-backed Python packages (pydantic-core, polars, orjson):
5
+
6
+ ```
7
+ Cargo.toml, src/ the Rust extension module `lumapy._lumapy`
8
+ pyproject.toml Python packaging (maturin build backend), ruff, mypy and pytest settings
9
+ python/lumapy/ the Python package: __init__.py (re-exports and NumPy-style functions),
10
+ _lumapy.pyi (type stubs of the extension), py.typed
11
+ tests/ pytest suite, checked against NumPy (and scikit-learn)
12
+ examples/, benchmarks/ Python ports of Luma's examples; benchmarks against CPU libraries
13
+ .github/workflows/ ci.yml (lint and tests), release.yml (wheels and PyPI publishing)
14
+ ```
15
+
16
+ ## Setup
17
+
18
+ You need a Rust toolchain (1.99 or later) and Python 3.10 or later.
19
+
20
+ ```sh
21
+ python -m venv .venv
22
+ . .venv/bin/activate # Windows: .venv\Scripts\activate
23
+ python -m pip install --upgrade pip # pip >= 25.1 for --group
24
+ pip install --group dev
25
+ maturin develop --release # builds the extension into the venv; rerun after Rust changes
26
+ pytest
27
+ ```
28
+
29
+ `maturin develop` without `--release` builds faster but runs the GPU host code much slower.
30
+
31
+ ## Checks
32
+
33
+ CI runs all of these; [pre-commit](https://pre-commit.com) runs the formatters and linters on commit
34
+ (`pre-commit install`).
35
+
36
+ ```sh
37
+ cargo fmt --check
38
+ cargo clippy --all-targets -- -D warnings
39
+ ruff check python tests examples benchmarks
40
+ ruff format --check python tests examples benchmarks
41
+ mypy # the Python package and the stubs
42
+ python -m mypy.stubtest lumapy._lumapy # the stubs against the built extension
43
+ pytest
44
+ ```
45
+
46
+ `LUMA_DEVICE=cpu pytest` runs the tests on a software Vulkan driver, as CI does on Linux.
47
+
48
+ ## Developing against a local Luma
49
+
50
+ `Cargo.toml` pins Luma to a commit on GitHub, so builds are reproducible anywhere. To build against a Luma checkout
51
+ next to this repository instead (`../Luma`), override the dependency without editing `Cargo.toml`, for example in a
52
+ `.cargo/config.toml` in the directory that holds both repositories (Cargo reads config files from parent
53
+ directories):
54
+
55
+ ```toml
56
+ [patch."https://github.com/flipnoteman/Luma"]
57
+ luma = { path = "Luma" }
58
+ ```
59
+
60
+ or for a single build:
61
+
62
+ ```sh
63
+ cargo build --config 'patch."https://github.com/flipnoteman/Luma".luma.path="../Luma"'
64
+ ```
65
+
66
+ When a change needs a new Luma commit, push it to Luma and update the `rev` in `Cargo.toml` (and `Cargo.lock` with
67
+ `cargo update -p luma`). Then update the "Mirrors Luma" line at the top of the README and its feature parity
68
+ table; `tests/test_docs.py` fails while the README names another version or commit than the build. Once Luma publishes a release with everything the bindings use, depend on the crates.io
69
+ version instead.
70
+
71
+ ## Adding a binding
72
+
73
+ 1. Add the method or function in the matching `src/` module (`ops.rs` operators and elementwise math, `reduce.rs`
74
+ reductions, sorting and scatters, `view.rs` views and indexing, `functions.rs` module functions). Shapes and
75
+ axes arrive in NumPy order; convert them with `inner::luma_shape` / `inner::luma_axis`.
76
+ 2. Export new module-level functions and classes in the `#[pymodule]` in `src/lib.rs`, and re-export them from
77
+ `python/lumapy/__init__.py` (and its `__all__`).
78
+ 3. Add the signature to `python/lumapy/_lumapy.pyi`; `stubtest` fails until it matches.
79
+ 4. Test it against NumPy (or a host reference) in `tests/`.
80
+ 5. Note it in `CHANGELOG.md`.
81
+
82
+ ## Releasing
83
+
84
+ 1. Bump `version` in `Cargo.toml` (the Python package takes its version from it) and move the changelog entries
85
+ under the new version.
86
+ 2. Publish a GitHub release tagged `vX.Y.Z`. `release.yml` checks the tag against `Cargo.toml`, builds the wheels
87
+ and the sdist, and publishes them to PyPI with trusted publishing (configure the `release` environment and the
88
+ trusted publisher on PyPI once). The PyPI project is `pyluma`; the import name stays `lumapy`.