PyCDFt 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.
Files changed (49) hide show
  1. pycdft-0.1.0/.github/workflows/ci.yml +44 -0
  2. pycdft-0.1.0/CHANGELOG.md +77 -0
  3. pycdft-0.1.0/CONTRIBUTING.md +51 -0
  4. pycdft-0.1.0/LICENSE +201 -0
  5. pycdft-0.1.0/MANIFEST.in +18 -0
  6. pycdft-0.1.0/Makefile +33 -0
  7. pycdft-0.1.0/PKG-INFO +289 -0
  8. pycdft-0.1.0/PyCDFt.egg-info/PKG-INFO +289 -0
  9. pycdft-0.1.0/PyCDFt.egg-info/SOURCES.txt +47 -0
  10. pycdft-0.1.0/PyCDFt.egg-info/dependency_links.txt +1 -0
  11. pycdft-0.1.0/PyCDFt.egg-info/requires.txt +17 -0
  12. pycdft-0.1.0/PyCDFt.egg-info/top_level.txt +1 -0
  13. pycdft-0.1.0/README.md +249 -0
  14. pycdft-0.1.0/benchmarks/benchmark_gpu.py +91 -0
  15. pycdft-0.1.0/benchmarks/run_hybrid_benchmark.sh +25 -0
  16. pycdft-0.1.0/docs/design.md +260 -0
  17. pycdft-0.1.0/docs/gpu.md +180 -0
  18. pycdft-0.1.0/docs/guide.html +496 -0
  19. pycdft-0.1.0/examples/example_grid.py +120 -0
  20. pycdft-0.1.0/examples/example_ibicus_compare.py +67 -0
  21. pycdft-0.1.0/examples/example_r_gaussian.py +85 -0
  22. pycdft-0.1.0/examples/example_skewed.py +84 -0
  23. pycdft-0.1.0/examples/figures/example_grid.png +0 -0
  24. pycdft-0.1.0/examples/figures/example_r_gaussian.png +0 -0
  25. pycdft-0.1.0/examples/figures/example_skewed.png +0 -0
  26. pycdft-0.1.0/examples/gpu_example.py +67 -0
  27. pycdft-0.1.0/pycdft/__init__.py +59 -0
  28. pycdft-0.1.0/pycdft/api.py +199 -0
  29. pycdft-0.1.0/pycdft/core.py +489 -0
  30. pycdft-0.1.0/pycdft/gpu/__init__.py +42 -0
  31. pycdft-0.1.0/pycdft/gpu/_torch.py +29 -0
  32. pycdft-0.1.0/pycdft/gpu/api.py +634 -0
  33. pycdft-0.1.0/pycdft/gpu/devices.py +160 -0
  34. pycdft-0.1.0/pycdft/gpu/kernels.py +554 -0
  35. pycdft-0.1.0/pycdft/math.py +561 -0
  36. pycdft-0.1.0/pycdft/py.typed +0 -0
  37. pycdft-0.1.0/pyproject.toml +79 -0
  38. pycdft-0.1.0/setup.cfg +4 -0
  39. pycdft-0.1.0/tests/naive_cdft.py +101 -0
  40. pycdft-0.1.0/tests/r_cdft_reference.py +217 -0
  41. pycdft-0.1.0/tests/test_api.py +132 -0
  42. pycdft-0.1.0/tests/test_core.py +300 -0
  43. pycdft-0.1.0/tests/test_equivalence.py +128 -0
  44. pycdft-0.1.0/tests/test_gpu.py +482 -0
  45. pycdft-0.1.0/tests/test_ibicus.py +127 -0
  46. pycdft-0.1.0/tests/test_math.py +341 -0
  47. pycdft-0.1.0/tests/test_nan.py +139 -0
  48. pycdft-0.1.0/tests/test_r_cdft.py +133 -0
  49. pycdft-0.1.0/tests/test_tails.py +75 -0
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test-core:
10
+ name: core tests (Python ${{ matrix.python-version }})
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+ - name: Install
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install numpy pytest
25
+ pip install -e .
26
+ - name: Run core tests (numpy only)
27
+ run: pytest -m "not cross" -q
28
+
29
+ test-cross:
30
+ name: cross-validation (ibicus + R port, Python 3.11)
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - uses: actions/setup-python@v5
35
+ with:
36
+ python-version: "3.11"
37
+ - name: Install
38
+ run: |
39
+ python -m pip install --upgrade pip
40
+ pip install numpy pytest
41
+ pip install -e .
42
+ pip install ibicus
43
+ - name: Run cross tests (skipped when ibicus is missing)
44
+ run: pytest -m cross -q
@@ -0,0 +1,77 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/) and versioning follows
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Documentation
10
+
11
+ - README: added a Documentation section (links to `docs/design.md`,
12
+ `docs/gpu.md` and `docs/guide.html`), a glossary note for the CDF-t
13
+ notation, a Limitations section, and honest cross-test skip wording;
14
+ fixed the grid-field example ("per-cell drift" was a field-wide offset)
15
+ and the calibration-reuse example (was a no-op); removed the
16
+ maintainer-only PyPI-name paragraph and the multivariate references
17
+ unrelated to the package; added a note that the R `CDFt` source is GPL
18
+ and reproduced in the tests for validation only.
19
+ - `docs/design.md`: replaced unverifiable "measured" claims with the
20
+ actual numbers and test references; removed informal wording and
21
+ un-attributed "reference implementation" / "parent project" phrasing;
22
+ cross-referenced the README comparison table.
23
+ - `docs/gpu.md`: added the measured MI210 speedup table (23× vs numpy);
24
+ corrected the hardware/test-count claims to what the logs show.
25
+ - `docs/guide.html`: linked from the README, removed the hardcoded version
26
+ badge, removed the invented "verification period" inputs, fixed the
27
+ no-op quick-start example, trimmed the reference list.
28
+ - `CONTRIBUTING.md`: fixed the release instructions (version is
29
+ single-sourced), the setup comment, added the GPU test command and a
30
+ documentation-maintenance note.
31
+ - `docs/guide.html`: removed the duplication with the README — quick start
32
+ shrunk to a teaser, the comparison table and measured numbers dropped
33
+ (README/`docs/design.md` §4 only), the reference list replaced by a
34
+ pointer, the FAQ removed (its answers restated earlier sections), and the
35
+ GPU install table removed (see `docs/gpu.md`). The notation table now ties
36
+ the symbols to the `obs`/`cm_hist`/`cm_future` names.
37
+ - `README.md`: removed the "Memory-lean design", "Tail semantics" and
38
+ "NaN semantics" sections (conventions live in `docs/design.md` and the
39
+ plain-language guide §6) and the measured comparison table (now
40
+ `docs/design.md` §4 only); kept the aspect comparison table and trimmed
41
+ the low-level API example.
42
+
43
+ ### Changed
44
+
45
+ - The package is now called **PyCDFt**. The import name stays `pycdft`
46
+ (lowercase, Python module convention), so existing imports are unchanged.
47
+
48
+ ### Packaging
49
+
50
+ - Added `MANIFEST.in` so the sdist ships the docs, examples, benchmarks,
51
+ the CI workflow and **all** test helpers (`tests/naive_cdft.py`,
52
+ `tests/r_cdft_reference.py`), which the previous sdist silently omitted
53
+ (tests from the sdist failed at collection).
54
+ - Added the `py.typed` marker: the package is fully type-annotated, so
55
+ type checkers now treat it as typed.
56
+ - Switched to the SPDX license expression (`license = "Apache-2.0"` +
57
+ `license-files`) and bumped the setuptools build requirement to `>=77`
58
+ (the deprecated `license = { text = ... }` form is gone).
59
+ - Single-sourced the version: `pycdft/__init__.py` is now the only place
60
+ that defines it (`[tool.setuptools.dynamic] version`).
61
+ - Extended the CI matrix to Python 3.9–3.13.
62
+ - Added the `dev` extra (pytest + pyflakes).
63
+
64
+ ## [0.1.0] - 2026-10-12
65
+
66
+ ### Added
67
+
68
+ - Vectorized CDF-t (Michelangeli, Vrac & Loukos 2009) on a numpy core:
69
+ `pycdft.CDFt`, `calibrate` / `apply_cdft` / `calibrate_hist` /
70
+ `apply_cdft_hist`, `cdft_transform`, `transfer`.
71
+ - Grid-ready kernels (sorted ECDF, type-7 quantiles, windowed-slope tails,
72
+ histogram path), NaN conventions, float32 support, chunked processing and
73
+ a `workers` thread pool.
74
+ - Optional torch GPU backend `pycdft.gpu` (CUDA / ROCm / MPS / CPU)
75
+ mirroring the numpy API, verified numerically identical to the numpy core.
76
+ - Cross-validation against ibicus and a reference R CDFt port; tests,
77
+ benchmarks, examples and this documentation set.
@@ -0,0 +1,51 @@
1
+ # Contributing to PyCDFt
2
+
3
+ Thanks for contributing! This package is intentionally small, numpy-only and
4
+ dependency-light: keep it that way.
5
+
6
+ ## Setup
7
+
8
+ ```bash
9
+ pip install -e .[test] # numpy + pytest (matplotlib via .[examples])
10
+ pip install ibicus # only needed for the ibicus cross tests
11
+ ```
12
+
13
+ ## Tests
14
+
15
+ ```bash
16
+ pytest # everything
17
+ pytest -m "not cross" # core suite (no external deps, CI runs this)
18
+ pytest -m cross -s # cross-validation (ibicus + R port, prints metrics)
19
+ pytest -m gpu # torch GPU backend (skipped without torch)
20
+ ```
21
+
22
+ - New kernels go in `pycdft/math.py` (numpy only, vectorized over the cell
23
+ axis, docstrings with the convention); the pipeline in `pycdft/core.py`;
24
+ the public API in `pycdft/api.py`.
25
+ - Any change to the numerics must keep the conventions documented in
26
+ `docs/design.md` (step ECDF, type-7 quantiles, delta shift, grid, tails,
27
+ NaN semantics) — and the cross-test tolerances must stay honest: if a
28
+ tolerance is loosened, update the numbers in `README.md` and
29
+ `docs/design.md` (they are reproduced by `pytest -m cross -s`).
30
+ - Documentation: the public docs are `README.md`, `docs/design.md`,
31
+ `docs/gpu.md` and `docs/guide.html` (the plain-language companion).
32
+ Any API or convention change must update all of them consistently —
33
+ `docs/guide.html` is hand-maintained, so check it for drift too.
34
+
35
+ ## Conventions
36
+
37
+ - numpy only in the core; scipy/xarray/pandas/matplotlib must stay optional.
38
+ - 1-D series and `(T, N)` fields both supported (any trailing dims are
39
+ flattened into cells).
40
+ - Never mutate the caller's arrays (`np.sort` only on private copies).
41
+ - Deterministic: `workers > 1` must not change results.
42
+ - No project-specific paths, no network access in the tests.
43
+
44
+ ## Releasing (maintainers)
45
+
46
+ 1. Bump `__version__` in `pycdft/__init__.py` (single-sourced:
47
+ `pyproject.toml` reads it via `[tool.setuptools.dynamic]`).
48
+ 2. `python -m build` (or `pip install build && python -m build`).
49
+ 3. `twine check dist/* && twine upload dist/*` (the name `pycdft` was free
50
+ at the time of writing; re-check `https://pypi.org/pypi/pycdft/json`
51
+ before publishing).
pycdft-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but not
32
+ limited to compiled object code, generated documentation, and
33
+ conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the
49
+ original version of the Work and any modifications or additions to
50
+ that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 pycdft contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,18 @@
1
+ # Files that must reach the source distribution (sdist).
2
+ # README.md, LICENSE and pyproject.toml are included automatically.
3
+
4
+ include CHANGELOG.md
5
+ include Makefile
6
+ include CONTRIBUTING.md
7
+ recursive-include docs *
8
+ recursive-include examples *.py
9
+ recursive-include examples/figures *.png
10
+ recursive-include benchmarks *
11
+ recursive-include tests *.py
12
+ recursive-include .github *
13
+
14
+ # Internal notes and machine-local artifacts: never ship these.
15
+ exclude HANDOFF.md
16
+ prune .hybrid_logs
17
+ prune .pytest_cache
18
+ global-exclude *.py[cod]
pycdft-0.1.0/Makefile ADDED
@@ -0,0 +1,33 @@
1
+ # Convenience targets for development.
2
+ # The package core is pure numpy; the cross tests additionally need ibicus.
3
+
4
+ PYTHON ?= python
5
+
6
+ .PHONY: test test-core test-cross lint install editable clean examples
7
+
8
+ test:
9
+ $(PYTHON) -m pytest
10
+
11
+ test-core:
12
+ $(PYTHON) -m pytest -m "not cross"
13
+
14
+ test-cross:
15
+ $(PYTHON) -m pytest -m cross -s
16
+
17
+ lint:
18
+ $(PYTHON) -m pyflakes pycdft tests examples || true
19
+
20
+ install:
21
+ $(PYTHON) -m pip install .
22
+
23
+ editable:
24
+ $(PYTHON) -m pip install -e .[test]
25
+
26
+ examples:
27
+ $(PYTHON) examples/example_r_gaussian.py
28
+ $(PYTHON) examples/example_skewed.py
29
+ $(PYTHON) examples/example_grid.py
30
+
31
+ clean:
32
+ rm -rf build dist *.egg-info .pytest_cache .coverage htmlcov
33
+ find . -name __pycache__ -type d -prune -exec rm -rf {} \;