diffct-mlx 1.0.3__tar.gz → 2.0.1__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 (131) hide show
  1. diffct_mlx-2.0.1/.github/workflows/docs.yml +37 -0
  2. diffct_mlx-2.0.1/.github/workflows/publish.yml +30 -0
  3. diffct_mlx-2.0.1/.github/workflows/release.yml +20 -0
  4. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/.gitignore +6 -16
  5. diffct_mlx-2.0.1/ATTRIBUTION.md +60 -0
  6. diffct_mlx-2.0.1/CHANGELOG.md +365 -0
  7. diffct_mlx-2.0.1/PKG-INFO +479 -0
  8. diffct_mlx-2.0.1/README.md +454 -0
  9. diffct_mlx-2.0.1/diffct/__init__.py +78 -0
  10. diffct_mlx-2.0.1/diffct/analytical.py +521 -0
  11. diffct_mlx-2.0.1/diffct/constants.py +66 -0
  12. diffct_mlx-2.0.1/diffct/differentiable.py +74 -0
  13. diffct_mlx-2.0.1/diffct/footprint.py +554 -0
  14. diffct_mlx-2.0.1/diffct/geometry.py +1004 -0
  15. diffct_mlx-2.0.1/diffct/kernels/__init__.py +37 -0
  16. diffct_mlx-2.0.1/diffct/kernels/cone_beam.py +819 -0
  17. diffct_mlx-2.0.1/diffct/kernels/cone_footprint.py +376 -0
  18. diffct_mlx-2.0.1/diffct/kernels/fan_beam.py +415 -0
  19. diffct_mlx-2.0.1/diffct/kernels/fan_footprint.py +187 -0
  20. diffct_mlx-2.0.1/diffct/kernels/parallel_beam.py +376 -0
  21. diffct_mlx-2.0.1/diffct/kernels/parallel_footprint.py +135 -0
  22. diffct_mlx-2.0.1/diffct/projectors.py +1124 -0
  23. diffct_mlx-2.0.1/diffct/utils.py +298 -0
  24. diffct_mlx-2.0.1/diffct_mlx/__init__.py +380 -0
  25. diffct_mlx-2.0.1/diffct_mlx/analytical.py +29 -0
  26. diffct_mlx-2.0.1/diffct_mlx/backend/__init__.py +70 -0
  27. diffct_mlx-2.0.1/diffct_mlx/backend/_mlx.py +141 -0
  28. diffct_mlx-2.0.1/diffct_mlx/backend/_torch.py +383 -0
  29. diffct_mlx-2.0.1/diffct_mlx/backend/metal/__init__.py +13 -0
  30. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/geometry.py +1 -1
  31. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/kernels/cone_beam.py +47 -110
  32. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/kernels/fan_beam.py +6 -43
  33. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/kernels/parallel_beam.py +6 -45
  34. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/projectors.py +5 -3
  35. diffct_mlx-2.0.1/diffct_mlx/calibration.py +127 -0
  36. diffct_mlx-2.0.1/diffct_mlx/filters.py +368 -0
  37. diffct_mlx-2.0.1/diffct_mlx/functionals.py +311 -0
  38. diffct_mlx-2.0.1/diffct_mlx/geometry.py +226 -0
  39. diffct_mlx-2.0.1/diffct_mlx/operators.py +461 -0
  40. diffct_mlx-2.0.1/diffct_mlx/orchestration/__init__.py +47 -0
  41. diffct_mlx-2.0.1/diffct_mlx/orchestration/out_of_core.py +1146 -0
  42. diffct_mlx-2.0.1/diffct_mlx/phantoms/__init__.py +12 -0
  43. diffct_mlx-2.0.1/diffct_mlx/phantoms/engine.py +201 -0
  44. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/phantoms/shepp_logan.py +6 -1
  45. diffct_mlx-2.0.1/diffct_mlx/physics/__init__.py +80 -0
  46. diffct_mlx-2.0.1/diffct_mlx/physics/corrections.py +174 -0
  47. diffct_mlx-2.0.1/diffct_mlx/physics/data/spectra.npz +0 -0
  48. diffct_mlx-2.0.1/diffct_mlx/physics/pipeline.py +137 -0
  49. diffct_mlx-2.0.1/diffct_mlx/physics/simulate.py +295 -0
  50. diffct_mlx-2.0.1/diffct_mlx/physics/spectra.py +149 -0
  51. diffct_mlx-2.0.1/diffct_mlx/projectors.py +84 -0
  52. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/real_measured_data_helper.py +17 -5
  53. diffct_mlx-2.0.1/diffct_mlx/rebinning.py +347 -0
  54. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/__init__.py +93 -27
  55. diffct_mlx-2.0.1/diffct_mlx/reconstruction_algorithms/_analytic.py +133 -0
  56. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/_core.py +263 -156
  57. diffct_mlx-2.0.1/diffct_mlx/reconstruction_algorithms/_solver.py +214 -0
  58. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/asd_pocs.py +10 -6
  59. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/awtv_pocs.py +14 -10
  60. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/cases.py +84 -64
  61. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/dart.py +28 -18
  62. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/fbp.py +1 -3
  63. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/fdk.py +1 -1
  64. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/sart.py +22 -19
  65. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/sirt.py +19 -15
  66. diffct_mlx-2.0.1/diffct_mlx/reconstruction_algorithms/solvers.py +404 -0
  67. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/reconstruction_algorithms/tv_pocs.py +10 -6
  68. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/regularizers.py +14 -11
  69. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/diffct_mlx/tv_gradients.py +13 -11
  70. diffct_mlx-2.0.1/docs/Makefile +20 -0
  71. diffct_mlx-2.0.1/docs/source/_static/.gitkeep +0 -0
  72. diffct_mlx-2.0.1/docs/source/api.rst +314 -0
  73. diffct_mlx-2.0.1/docs/source/conf.py +36 -0
  74. diffct_mlx-2.0.1/docs/source/examples.rst +30 -0
  75. diffct_mlx-2.0.1/docs/source/fbp_fan_example.rst +84 -0
  76. diffct_mlx-2.0.1/docs/source/fbp_parallel_example.rst +69 -0
  77. diffct_mlx-2.0.1/docs/source/fdk_cone_example.rst +99 -0
  78. diffct_mlx-2.0.1/docs/source/getting_started.rst +88 -0
  79. diffct_mlx-2.0.1/docs/source/index.rst +90 -0
  80. diffct_mlx-2.0.1/docs/source/iterative_reco_cone_example.rst +131 -0
  81. diffct_mlx-2.0.1/docs/source/iterative_reco_fan_example.rst +90 -0
  82. diffct_mlx-2.0.1/docs/source/iterative_reco_parallel_example.rst +96 -0
  83. diffct_mlx-2.0.1/examples/circular_trajectory/fbp_fan.py +291 -0
  84. diffct_mlx-2.0.1/examples/circular_trajectory/fbp_parallel.py +143 -0
  85. diffct_mlx-2.0.1/examples/circular_trajectory/fdk_cone.py +337 -0
  86. diffct_mlx-2.0.1/examples/circular_trajectory/iterative_reco_cone.py +183 -0
  87. diffct_mlx-2.0.1/examples/circular_trajectory/iterative_reco_fan.py +151 -0
  88. diffct_mlx-2.0.1/examples/circular_trajectory/iterative_reco_parallel.py +146 -0
  89. diffct_mlx-2.0.1/examples/non_circular_trajectory/iterative_reco_cone.py +313 -0
  90. diffct_mlx-2.0.1/examples/non_circular_trajectory/iterative_reco_fan.py +270 -0
  91. diffct_mlx-2.0.1/examples/non_circular_trajectory/iterative_reco_parallel.py +284 -0
  92. diffct_mlx-2.0.1/examples/plot_trajectory.py +326 -0
  93. diffct_mlx-2.0.1/pyproject.toml +47 -0
  94. diffct_mlx-2.0.1/pytest.ini +14 -0
  95. diffct_mlx-2.0.1/requirements.txt +9 -0
  96. diffct_mlx-2.0.1/tests/__init__.py +0 -0
  97. diffct_mlx-2.0.1/tests/_phantoms.py +77 -0
  98. diffct_mlx-2.0.1/tests/benchmarks/README.md +56 -0
  99. diffct_mlx-2.0.1/tests/benchmarks/__init__.py +0 -0
  100. diffct_mlx-2.0.1/tests/benchmarks/_common.py +57 -0
  101. diffct_mlx-2.0.1/tests/benchmarks/test_bench_cone.py +137 -0
  102. diffct_mlx-2.0.1/tests/benchmarks/test_bench_fan.py +121 -0
  103. diffct_mlx-2.0.1/tests/benchmarks/test_bench_parallel.py +113 -0
  104. diffct_mlx-2.0.1/tests/test_adjoint_inner_product.py +170 -0
  105. diffct_mlx-2.0.1/tests/test_cone_projector_autograd.py +76 -0
  106. diffct_mlx-2.0.1/tests/test_cuda_smoke.py +121 -0
  107. diffct_mlx-2.0.1/tests/test_diffct_mlx_extensions.py +296 -0
  108. diffct_mlx-2.0.1/tests/test_fbp_fan_accuracy.py +92 -0
  109. diffct_mlx-2.0.1/tests/test_fbp_fan_offsets.py +117 -0
  110. diffct_mlx-2.0.1/tests/test_fbp_parallel_accuracy.py +72 -0
  111. diffct_mlx-2.0.1/tests/test_fdk_cone_accuracy.py +114 -0
  112. diffct_mlx-2.0.1/tests/test_fdk_cone_offsets.py +118 -0
  113. diffct_mlx-2.0.1/tests/test_gradcheck.py +125 -0
  114. diffct_mlx-2.0.1/tests/test_known_operator_gradflow.py +468 -0
  115. diffct_mlx-2.0.1/tests/test_metal_kernel_static.py +34 -0
  116. diffct_mlx-2.0.1/tests/test_ramp_filter_windows.py +98 -0
  117. diffct_mlx-2.0.1/tests/test_regressions.py +333 -0
  118. diffct_mlx-2.0.1/tests/test_siddon_centering.py +127 -0
  119. diffct_mlx-2.0.1/tests/test_weights.py +126 -0
  120. diffct_mlx-2.0.1/tools/generate_spectra.py +92 -0
  121. diffct_mlx-1.0.3/PKG-INFO +0 -373
  122. diffct_mlx-1.0.3/README.md +0 -343
  123. diffct_mlx-1.0.3/diffct_mlx/__about__.py +0 -3
  124. diffct_mlx-1.0.3/diffct_mlx/__init__.py +0 -223
  125. diffct_mlx-1.0.3/diffct_mlx/phantoms/__init__.py +0 -5
  126. diffct_mlx-1.0.3/diffct_mlx/reconstruction_algorithms/_analytic.py +0 -101
  127. diffct_mlx-1.0.3/pyproject.toml +0 -61
  128. {diffct_mlx-1.0.3 → diffct_mlx-2.0.1}/LICENSE +0 -0
  129. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/constants.py +0 -0
  130. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/kernels/__init__.py +0 -0
  131. {diffct_mlx-1.0.3/diffct_mlx → diffct_mlx-2.0.1/diffct_mlx/backend/metal}/utils.py +0 -0
@@ -0,0 +1,37 @@
1
+ name: Deploy Documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main # Or your default branch
7
+
8
+ jobs:
9
+ build-and-deploy:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: '3.x'
21
+
22
+ - name: Install dependencies
23
+ run: |
24
+ pip install sphinx-rtd-theme
25
+ pip install sphinx
26
+ pip install -r requirements.txt
27
+
28
+ - name: Build documentation
29
+ run: |
30
+ cd docs
31
+ make html
32
+
33
+ - name: Deploy to GitHub Pages
34
+ uses: peaceiris/actions-gh-pages@v4
35
+ with:
36
+ github_token: ${{ secrets.GITHUB_TOKEN }}
37
+ publish_dir: docs/build/html
@@ -0,0 +1,30 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ publish:
10
+ name: Build and publish
11
+ runs-on: ubuntu-latest
12
+ environment: pypi
13
+ permissions:
14
+ id-token: write # OIDC for PyPI trusted publishing — no API token needed
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: '3.12'
23
+
24
+ - name: Build sdist and wheel
25
+ run: |
26
+ pip install build
27
+ python -m build
28
+
29
+ - name: Publish to PyPI
30
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,20 @@
1
+ name: Create Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ release:
10
+ name: Create Release
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ steps:
15
+ - name: Checkout code
16
+ uses: actions/checkout@v4
17
+ - name: Create Release
18
+ uses: softprops/action-gh-release@v2
19
+ with:
20
+ generate_release_notes: true
@@ -3,23 +3,9 @@ __pycache__/
3
3
  *.py[cod]
4
4
  *$py.class
5
5
 
6
- # Data
7
- *.csv
8
- *.tif
9
- *.rek
10
- *.npy
11
- *.npz
12
-
13
- # macOS Finder metadata
14
- .DS_Store
15
- **/.DS_Store
16
-
17
6
  # C extensions
18
7
  *.so
19
8
 
20
- # Notes
21
- notes/
22
-
23
9
  # Distribution / packaging
24
10
  .Python
25
11
  build/
@@ -84,7 +70,6 @@ instance/
84
70
 
85
71
  # Sphinx documentation
86
72
  docs/_build/
87
- docs/build/
88
73
 
89
74
  # PyBuilder
90
75
  .pybuilder/
@@ -200,4 +185,9 @@ cython_debug/
200
185
  projectBrief.md
201
186
  .kiro
202
187
  .claude
203
- examples/non_circular_trajectory/sample_data/reko/sim_obj_1_diffct.npy
188
+
189
+ # local reference clone (LLNL LEAP), not part of this package
190
+ LEAP/
191
+
192
+ # macOS Finder metadata
193
+ .DS_Store
@@ -0,0 +1,60 @@
1
+ # Attribution
2
+
3
+ This `cuda` branch of **DiffCT-MLX** is **adapted from the original
4
+ [diffct](https://github.com/sypsyp97/diffct)** by Yipeng Sun et al.
5
+
6
+ ## Source
7
+
8
+ | | |
9
+ |---|---|
10
+ | **Upstream project** | [diffct](https://github.com/sypsyp97/diffct) |
11
+ | **Original author** | Yipeng Sun (<yipeng.sun@fau.de>) |
12
+ | **License** | Apache License 2.0 — see [LICENSE](LICENSE) |
13
+ | **Imported from** | upstream `dev` branch (arbitrary-trajectory line), v1.3.3.dev0, commit `cb516cf` |
14
+ | **Import date** | 2026-07-06 |
15
+ | **Maintained here by** | Linda-Sophie Schneider (<linda-sophie.schneider@fau.de>) |
16
+
17
+ The `dev` branch was chosen as the basis (rather than `main`) because its
18
+ module layout (`projectors`, `geometry`, `analytical`, `kernels`) and its
19
+ per-view projector convention (`src_pos, det_center, det_u_vec[, det_v_vec]`)
20
+ match the DiffCT-MLX port, enabling a shared public API across backends.
21
+
22
+ ## Relationship between branches
23
+
24
+ - **`main`** — the Apple Silicon / MLX port of diffct (this repository, DiffCT-MLX).
25
+ - **`cuda`** — a clean snapshot of the CUDA / PyTorch implementation from the
26
+ original diffct, being grown into an **auto-backend** package: it detects the
27
+ available backend at import (MLX on Apple Silicon, Torch/CUDA otherwise) and
28
+ dispatches to it, so the same user code runs unchanged on both platforms.
29
+
30
+ This mirrors the historical relationship in which diffct's former `apple`
31
+ branch became the standalone DiffCT-MLX repository.
32
+
33
+ ## Notice of changes (Apache-2.0 §4)
34
+
35
+ This branch is a modified redistribution of diffct. The initial commit is a
36
+ clean snapshot of diffct `dev` (`cb516cf`) taken on 2026-07-06, **without**
37
+ upstream commit history. All subsequent modifications — including the
38
+ auto-backend restructuring and the ported high-level reconstruction layer —
39
+ are tracked in this repository's git history.
40
+
41
+ - The original `LICENSE` (Apache License 2.0) is retained unchanged.
42
+ - Any third-party data attribution shipped with examples is preserved in the
43
+ corresponding `NOTICE` files.
44
+
45
+ ## Embedded spectrum data (XrayPhysics)
46
+
47
+ The physically-based example X-ray spectra and material attenuation curves in
48
+ `diffct_mlx/physics/data/spectra.npz` were **generated offline** with the
49
+ LLNL **[XrayPhysics](https://github.com/kylechampley/XrayPhysics)** library
50
+ (Kyle Champley, LLNL; **MIT License**), whose tube-spectrum model is validated
51
+ against TASMICS. XrayPhysics is used **only** as an offline reference to produce
52
+ this static data — it is **not** a runtime dependency and is not imported by the
53
+ package. The generator that reproduces the data is committed at
54
+ [`tools/generate_spectra.py`](tools/generate_spectra.py). If you rely on these
55
+ spectra quantitatively, please also credit XrayPhysics and TASMICS.
56
+
57
+ ## Citation
58
+
59
+ Please cite the original work. See the citation section of the
60
+ [README](README.md) for the BibTeX entry.
@@ -0,0 +1,365 @@
1
+ # Changelog
2
+
3
+ All notable changes to DiffCT-MLX are documented in this file. Entries up to
4
+ 1.3.0.dev0 track the vendored ``diffct`` dev line this repository was adapted
5
+ from; entries from 2.0.0.dev0 on track the unified ``diffct_mlx`` package.
6
+
7
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
8
+ and the project follows [Semantic Versioning](https://semver.org/).
9
+
10
+ ## [Unreleased]
11
+
12
+ ## [2.0.1] - 2026-07-15
13
+
14
+ ### Added
15
+
16
+ - **Analytic geometry gradients for the cone Siddon projector (CUDA and
17
+ Metal)**:
18
+ `_cone_3d_geometry_grad_kernel` computes closed-form per-view gradients
19
+ for `src_pos`, `det_center`, `det_u_vec` and `det_v_vec` in a single
20
+ kernel pass (endpoint derivatives of the trilinearly smoothed line
21
+ integral, with the projected moment accumulated by the same segment
22
+ quadrature as the gradient terms). Default for cone geometry gradients
23
+ (`DIFFCT_GEOMETRY_VJP=fd` forces finite differences). The CUDA path is
24
+ validated against an exact torch-autograd `grid_sample` reference
25
+ (cos > 0.998, norm ratio within 1%) and is ~4× faster than FD; the Metal
26
+ port uses the same center-based sampling, projected-moment quadrature and
27
+ world/voxel unit conversion.
28
+ - **Footprint forward projectors are geometry-trainable** (parallel, fan,
29
+ cone): finite-difference VJPs for their geometry arrays, so the operator
30
+ layer's default `projector_mode="footprint"` — and pipelines built on it,
31
+ e.g. differentiable view-coverage objectives — receive source/detector
32
+ gradients. Backprojectors remain data-only.
33
+
34
+ ## [2.0.0] - 2026-07-10
35
+
36
+ First stable release of the unified package. Includes everything in
37
+ [2.0.0.dev0] below; on top of it, the MLX backend is now runtime-validated
38
+ on Apple Silicon (the last open item of the unification) and the Torch
39
+ backend gains trainable projector geometry.
40
+
41
+ - **Trainable geometry on the Torch backend**: the Siddon projectors
42
+ (parallel/fan/cone) return finite-difference VJPs for their per-view
43
+ geometry arrays (`src_pos`, `det_center`/`det_origin`, `det_u_vec`,
44
+ `det_v_vec`, `ray_dir`) — computed only for inputs that `requires_grad`,
45
+ with magnitude-relative step sizes (mm- and m-scale setups both work).
46
+ Enables pose/trajectory optimization and geometry-aware known-operator
47
+ networks; verified by an exact matched-step contraction test and a
48
+ pose-recovery integration test. Footprint projectors remain data-only;
49
+ the FD gradients are smoothed subgradients (Siddon is piecewise-linear
50
+ in geometry) and not second-order differentiable.
51
+ - `power_iteration` re-exported at the top level; README documents the
52
+ bounded step-size parametrization for unrolled networks
53
+ (`(1.8/L)*sigmoid(theta)`).
54
+ - Known-operator gradient-flow guarantees: torch `xp.grad` is composable
55
+ (`create_graph` when the input carries gradients — unrolled TV steps are
56
+ second-order differentiable, mirroring `mx.grad`), correct under
57
+ `torch.no_grad()`; pinned by `tests/test_known_operator_gradflow.py`.
58
+
59
+ ### Fixed (MLX runtime validation on Apple Silicon, 2026-07-10)
60
+
61
+ - **Metal Siddon kernels aligned with the CUDA reference** (parallel, fan
62
+ and cone, forward *and* adjoint): the vendored kernels interpolated the
63
+ image/volume bi-/trilinearly on nodes at **integer** indices — voxel
64
+ centers live at `k + 0.5 - c`, so every Siddon projection was shifted by
65
+ half a voxel per axis against the footprint kernels, the FBP/FDK gathers
66
+ and the analytic phantom projector (view-dependent detector shifts up to
67
+ ±1.24 px at fan/cone magnification 1.75). They now accumulate the
68
+ traversed cell (`image[cell] * seg_len`), exactly like the CUDA kernels.
69
+ **Geometry-affecting** for MLX-Siddon users: results shift by half a
70
+ voxel relative to earlier MLX builds. Siddon-vs-footprint cone
71
+ correlation on a 64³ Shepp-Logan rises from 0.972 to 0.994, case-builder
72
+ FDK from 0.923 to 0.986.
73
+ - **Metal cone Siddon forward had a stray `voxel_spacing` factor** its
74
+ adjoint lacked, breaking the forward/adjoint pairing (and CUDA parity)
75
+ for `voxel_spacing != 1`.
76
+ - Regression-pinned in the backend-neutral `tests/test_siddon_centering.py`
77
+ (centered-object centroid probes, anisotropic-spacing adjoint,
78
+ Siddon-vs-footprint agreement), which runs on MLX and torch/CUDA alike.
79
+
80
+
81
+ ## [2.0.0.dev0] - 2026-07-10
82
+
83
+ The unified, auto-backend **`diffct_mlx`** package: one API that runs on
84
+ Torch/numba-CUDA (NVIDIA) and MLX/Metal (Apple Silicon), selected at import
85
+ (`DIFFCT_BACKEND` overrides).
86
+
87
+ ### Added
88
+
89
+ - **Unified API** with full parity to the Apple-Silicon `main` package:
90
+ functional projectors (Siddon + separable footprint, all geometries,
91
+ sparse cone backprojection), trajectory generators (+ laminography),
92
+ FBP/FDK, SART/SIRT/normalized-SART, TV-/ASD-/AwTV-POCS, DART, case
93
+ builders for simulated/measured/npy data, measured-data helpers.
94
+ - **Native CUDA footprint kernels** for parallel/fan/cone plus a sparse cone
95
+ footprint backprojection (`indices=` → 1D vector).
96
+ - **Operator/functional/solver framework**: differentiable `LinearOperator`
97
+ algebra with `ProjectionOperator.subset`, functionals
98
+ (L1/Lp/Huber/TV/AwTV/Box/...), solver registry (`cgls`, `pcg`,
99
+ `ls`/`wls`/`rls`/`rwls`, `dls`/`rdls`, `mlem`/`osem`, `mltr`,
100
+ `landweber`) and Plug-and-Play denoisers (bilateral, guided, median,
101
+ histogram-sparsity, azimuthal, dictionary).
102
+ - **Physics & simulation**: GPU-native preprocessing (flat field, rings, bad
103
+ pixels, beam hardening, Wiener deblur, scatter, MAR inpainting) with a
104
+ `PreprocessingPipeline`; forward simulation (`simulate_scan`) with an
105
+ embedded, offline-generated X-ray spectrum + material-attenuation library
106
+ (W anode, 40–225 kVp).
107
+ - **Sinogram-domain tools**: Parker short-scan and offset-detector
108
+ weighting, truncation extension, fan→parallel and curved↔flat rebinning —
109
+ backend-neutral.
110
+ - **Analytic phantom engine** (`Ellipsoid`/`Phantom`, exact cone-beam line
111
+ integrals) and center-of-rotation self-calibration.
112
+ - **Out-of-core + multi-GPU orchestration** (CUDA): chunked
113
+ forward/backward/FDK/SIRT/OS-SART with z-slab / v-band shadow geometry,
114
+ async disk↔GPU conveyor, automatic RAM/disk spill (memmap or zarr),
115
+ GPU-FFT streaming ramp filter; validated to 2048³ with a bounded working
116
+ set.
117
+ - **MLX backend wiring**: the Metal kernels + `mx.custom_function`
118
+ projectors from `main` are vendored under `diffct_mlx/backend/metal/` and
119
+ adapted in `backend/_mlx.py`; the `xp` namespace is attribute-identical to
120
+ the torch shim (pinned by a static parity test). Runtime validation on
121
+ Apple hardware pending.
122
+
123
+ ### Fixed (review/debug session, 2026-07-10)
124
+
125
+ - **Detector/voxel grid conventions standardized** to `(k - n/2) * spacing`
126
+ package-wide: the CUDA *and* Metal cone footprint kernels (and the Metal
127
+ cone Siddon kernels) used `(n-1)/2` — a half-pixel shift whenever kernel
128
+ families were mixed; the FBP/FDK gather kernels placed voxel centers at
129
+ `ix - c` instead of `ix + 0.5 - c` — a half-voxel shift of analytic
130
+ volumes against iterative ones. Rebinning helpers aligned to the same
131
+ grid. **Geometry-affecting** for cone-footprint / FDK-gather /
132
+ MLX-cone-Siddon users: results shift by half a pixel/voxel relative to
133
+ earlier builds.
134
+ - **Parker weights** in `rebinning` had half the correct feathering
135
+ argument (conjugate-ray sums didn't normalize); now exactly matches the
136
+ validated `diffct.analytical` formula, and real per-view angles can be
137
+ passed via `betas`.
138
+ - Rebinning gathers build flat indices in int64 (float32 index math
139
+ silently corrupted arrays above 2^24 elements); `curved_to_flat` /
140
+ `flat_to_curved` resample the u axis (axis 1) of 3D stacks; single-view /
141
+ non-uniform `fan_to_parallel` inputs now raise instead of mis-rebinning.
142
+ - Warm-started SART/SIRT no longer skip their first iteration; `rls` no
143
+ longer discards `weights`; `rwls` rejects non-smooth regularizers instead
144
+ of silently ignoring them; AwTV-POCS actually anneals `alpha`; POCS
145
+ drivers reuse the geometry-only sweep cache; `normalized_sart_relaxation`
146
+ is honored (`backprojection_scale` defaults to `None`); DART's masked
147
+ subproblem no longer clips negative residual measurements.
148
+ - `build_npy_cone_3d_case` kept detector counts consistent with the data
149
+ axes under `transpose_uv` (non-square detectors crashed; the expected
150
+ stack order is now documented as `(views, v, u)` with the default
151
+ `transpose_uv=True`).
152
+ - `scatter_correction`/`add_scatter` blur per view in the detector plane
153
+ only (views used to mix); `box_filter` is separable (+`axes=`) and ~1000×
154
+ cheaper at radius 12 in 3D; `detector_deblur` has unit DC gain (values
155
+ were shrunk by ~`reg`); `auto_voxel_spacing_from_detector` bounds both
156
+ lateral axes by the horizontal FOV; `load_tiff_projections` applies
157
+ `revert` before the log transform; `estimate_cone_isocenter` survives a
158
+ single view.
159
+ - Out-of-core conveyor propagates worker exceptions (a failing thread used
160
+ to deadlock the run); auto disk scratch is cleaned up (TB-scale leaks);
161
+ zarr gather writes are serialized; the gather path uploads the filtered
162
+ sinogram once per GPU; `chunked_sirt` takes memmap/zarr inputs lazily;
163
+ memmap outputs are flushed; the caller's CUDA device is restored.
164
+ - Backend hardening: auto-detection picks MLX only when Metal is available
165
+ (Linux MLX wheels no longer shadow CUDA); `xp.grad` returns zeros for
166
+ disconnected objectives (single-slice `tv_gradient` crashed); `xp.clip`
167
+ with no bounds, `Box(-inf, inf).prox`, `xp.max(axis=...)` fixed;
168
+ `ProjectionOperator.subset(slice)` reports correct metadata; sparse cone
169
+ backprojection guards int32 overflow and empty index vectors.
170
+
171
+ ### Changed
172
+
173
+ - Package renamed/versioned as `diffct-mlx 2.0.0.dev0` with extras
174
+ `[cuda]` / `[mlx]` / `[zarr]`; docs (README, Sphinx) rewritten for the
175
+ unified package; dead code removed (unused `_trig_tables`, eager
176
+ deprecated-shim import, never-read parameters).
177
+
178
+ ## [1.3.0.dev0] - 2026-04-14
179
+
180
+ First sync of the dev (arbitrary-trajectory) branch against the main
181
+ branch's 1.2.10 / 1.2.11 analytical reconstruction overhaul. Brings
182
+ dev up to functional parity with main 1.2.11 except for the 1.3.0
183
+ separable-footprint (SF) projector backends, which rely on closed-form
184
+ circular-orbit geometry and are not yet generalised to arbitrary
185
+ trajectories.
186
+
187
+ ### Added
188
+
189
+ #### Analytical reconstruction helpers (``diffct.analytical``)
190
+
191
+ A new module exposes the following helpers, all trajectory-agnostic so
192
+ they work with both the circular trajectories and the arbitrary
193
+ ``(src_pos, det_center, det_u_vec[, det_v_vec])`` trajectory arrays
194
+ that dev-branch kernels already accept:
195
+
196
+ - ``detector_coordinates_1d`` — detector cell centre coordinates.
197
+ - ``angular_integration_weights`` — trapezoidal per-view weights for
198
+ the analytical FBP/FDK sum. Optional ``redundant_full_scan`` flag
199
+ absorbs the ``1/2`` redundancy factor for full scans.
200
+ - ``fan_cosine_weights`` / ``cone_cosine_weights`` — per-detector-cell
201
+ ``cos(gamma)`` pre-weight for fan / cone FBP pipelines.
202
+ - ``parker_weights`` — Parker short-scan redundancy weights for
203
+ circular fan geometries.
204
+ - ``ramp_filter_1d`` — generic 1D ramp filter with ``sample_spacing``,
205
+ ``pad_factor``, ``window`` (``"ram-lak"``, ``"hann"``, ``"hamming"``,
206
+ ``"cosine"``, ``"shepp-logan"``), and ``use_rfft`` options, rescaled
207
+ by ``1 / sample_spacing`` so the output is in physical units.
208
+ - ``parallel_weighted_backproject`` / ``fan_weighted_backproject`` /
209
+ ``cone_weighted_backproject`` — voxel-driven FBP / FDK backprojection
210
+ wrappers that dispatch to new dedicated gather kernels and apply the
211
+ analytical Fourier-convention constant (``1/(2*pi)`` for parallel,
212
+ ``sdd_mean/(2*pi*sid_mean)`` for fan and cone). These are the
213
+ **recommended path for analytical reconstruction** and replace the
214
+ previous pattern of passing a filtered sinogram through
215
+ ``*BackprojectorFunction.apply``.
216
+
217
+ #### Voxel-driven FBP / FDK gather kernels
218
+
219
+ Three new CUDA kernels, each under the dedicated ``fastmath=False``
220
+ ``_FDK_ACCURACY_DECORATOR`` added to ``diffct.constants``:
221
+
222
+ - ``_parallel_2d_fbp_backproject_kernel`` — no distance weighting.
223
+ - ``_fan_2d_fbp_backproject_kernel`` — ``(|S|/U_n)^2`` weighted,
224
+ where ``U_n`` is the signed distance from the per-view source to
225
+ the voxel along the detector normal.
226
+ - ``_cone_3d_fdk_backproject_kernel`` — same pattern in 3D.
227
+
228
+ Every kernel is voxel-driven: one thread per output pixel/voxel, loops
229
+ over views inside, projects the voxel onto the detector using the
230
+ per-view ``(src_pos, det_center, det_u_vec[, det_v_vec])`` arrays,
231
+ bilinearly samples the filtered sinogram, applies the per-view weight
232
+ and accumulates. They are completely separate from the pure Siddon
233
+ adjoint kernels that back the autograd path; autograd is untouched.
234
+
235
+ #### Tests (``tests/``)
236
+
237
+ The dev branch had no test directory at all prior to this change.
238
+ ``pytest.ini`` and ``tests/__init__.py`` are new, plus 58 tests across
239
+ 11 files that mirror the main-branch test layout:
240
+
241
+ - ``tests/test_adjoint_inner_product.py`` — ``<A x, y> = <x, A^T y>``
242
+ identity for parallel / fan / cone autograd pairs, plus an extra
243
+ ``test_cone_autograd_backward_matches_backprojector_forward`` that
244
+ protects the autograd ``ConeProjectorFunction.backward`` from
245
+ drifting away from the standalone ``ConeBackprojectorFunction``.
246
+ - ``tests/test_gradcheck.py`` — ``torch.autograd.gradcheck`` for every
247
+ projector Function with float32-calibrated tolerances.
248
+ - ``tests/test_weights.py`` — unit tests for ``detector_coordinates_1d``,
249
+ ``angular_integration_weights``, ``fan_cosine_weights``,
250
+ ``cone_cosine_weights`` and ``parker_weights``.
251
+ - ``tests/test_cuda_smoke.py`` — end-to-end smoke tests for every
252
+ Projector / Backprojector Function pair + the analytical
253
+ ``*_weighted_backproject`` wrappers.
254
+ - ``tests/test_cone_projector_autograd.py`` — gradient finiteness and
255
+ sparsity guard for the cone projector Function (circular + spiral
256
+ trajectories).
257
+ - ``tests/test_fbp_parallel_accuracy.py`` /
258
+ ``tests/test_fbp_fan_accuracy.py`` /
259
+ ``tests/test_fdk_cone_accuracy.py`` — quantitative RMSE and
260
+ amplitude bounds for a full Shepp-Logan FBP / FDK pipeline per
261
+ geometry. These would have tripped on the old dev reconstruction
262
+ path, which silently produced wrong-amplitude volumes.
263
+ - ``tests/test_fbp_fan_offsets.py`` /
264
+ ``tests/test_fdk_cone_offsets.py`` — adapted from main's offset
265
+ tests: dev's arbitrary-trajectory kernels have no scalar
266
+ ``detector_offset`` / ``center_offset_*`` parameters, so offsets
267
+ are applied by shifting the trajectory arrays directly. Verifies
268
+ that the FBP / FDK gather kernels handle non-centred trajectories.
269
+ - ``tests/test_ramp_filter_windows.py`` — 29 parametrised tests covering
270
+ every ``_ramp_window`` option (DC gain, Nyquist value, non-negativity)
271
+ and the full ``ramp_filter_1d`` end-to-end (shape, DC annihilation,
272
+ rfft vs complex-fft parity, ``sample_spacing`` scaling, high-frequency
273
+ pass-through).
274
+
275
+ #### Benchmark suite (``tests/benchmarks/``)
276
+
277
+ Opt-in ``pytest-benchmark`` suite covering every CUDA kernel in the
278
+ library (forward projector, pure-adjoint backprojector, and the full
279
+ analytical FBP / FDK pipeline) across three sizes for each of the
280
+ three geometries. 27 benchmarks total, excluded from the default
281
+ ``pytest tests/`` run via ``--ignore=tests/benchmarks`` in
282
+ ``pytest.ini``. Run explicitly with
283
+ ``pytest tests/benchmarks/ --benchmark-only``.
284
+
285
+ #### Parker short-scan demos in examples
286
+
287
+ ``examples/circular_trajectory/fbp_fan.py`` and
288
+ ``examples/circular_trajectory/fdk_cone.py`` now expose an
289
+ ``apply_parker`` switch. When enabled, the example switches the
290
+ trajectory to a minimal ``pi + 2*gamma_max`` short scan and applies
291
+ ``parker_weights`` to the sinogram before the ramp filter; when
292
+ disabled, the pipeline runs a full ``2*pi`` scan with the ``1/2``
293
+ redundancy factor absorbed by ``angular_integration_weights``. Both
294
+ branches produce correctly amplitude-calibrated reconstructions.
295
+
296
+ #### Documentation (``docs/source/api.rst``)
297
+
298
+ New "Analytical Reconstruction Helpers", "Ramp Filter Options", and
299
+ "Analytical FBP / FDK architecture" sections describe the new
300
+ ``diffct.analytical`` module, enumerate every ``ramp_filter_1d``
301
+ option, and explain the analytical scale factors used in each
302
+ ``*_weighted_backproject`` wrapper.
303
+
304
+ ### Fixed
305
+
306
+ #### FBP / FDK amplitude bugs in the ``circular_trajectory/*.py`` examples
307
+
308
+ Prior to this release the circular-trajectory FBP / FDK examples
309
+ (``examples/circular_trajectory/fbp_parallel.py``,
310
+ ``examples/circular_trajectory/fbp_fan.py``,
311
+ ``examples/circular_trajectory/fdk_cone.py``) produced amplitude-wrong
312
+ reconstructions because they:
313
+
314
+ - used ``*BackprojectorFunction.apply`` (the pure Siddon adjoint) as if
315
+ it were an FBP gather, so they missed the ``(sid/U)^2`` / ``(|S|/U_n)^2``
316
+ distance weight that the classical FBP / FDK formula requires;
317
+ - hand-rolled a ramp filter missing the ``1/sample_spacing`` scale;
318
+ - multiplied by a standalone ``pi/num_views`` normalisation that only
319
+ absorbs the angular step, not the ``1/(2*pi)`` Fourier-convention
320
+ constant.
321
+
322
+ All three examples now go through the new
323
+ ``parallel_weighted_backproject`` / ``fan_weighted_backproject`` /
324
+ ``cone_weighted_backproject`` wrappers and end-to-end produce raw MSE
325
+ matching the main branch's 1.2.11 release to within rounding:
326
+
327
+ | Example | Raw MSE | Range |
328
+ |-----------------------------------------|-----------|-------------------|
329
+ | ``circular_trajectory/fbp_parallel.py`` | ~0.00366 | ``[-0.02, 1.00]`` |
330
+ | ``circular_trajectory/fbp_fan.py`` | ~0.00220 | ``[-0.10, 1.01]`` |
331
+ | ``circular_trajectory/fdk_cone.py`` | ~0.00333 | ``[-0.07, 1.00]`` |
332
+
333
+ ### Notes on the sync from ``main``
334
+
335
+ The ``main`` branch's 1.2.10 / 1.2.11 / 1.3.0 releases introduced several
336
+ changes which this update brings to the dev branch, adapted where
337
+ necessary for the arbitrary-trajectory kernel API:
338
+
339
+ - ``1.2.10`` FDK / FBP voxel-driven gather, ``ramp_filter_1d`` options,
340
+ analytical constants, and the ``(sid/U)^2`` correctness fix: **ported**.
341
+ Because dev's kernels take per-view ``(src_pos, det_center, u_vec,
342
+ v_vec)`` arrays instead of closed-form ``sin(beta)/cos(beta)`` math,
343
+ the new gather kernels use ``U_n = (P - S) . n`` (where
344
+ ``n = u_vec x v_vec``) as the generalisation of the classical ``U``.
345
+ For a canonical circular orbit this reduces to the textbook
346
+ ``sid + x*sin(beta) - y*cos(beta)``.
347
+ - ``1.2.10`` cone / fan autograd ``distance_weight=1.0`` bug fix:
348
+ **not applicable**. The dev cone / fan backward kernels were
349
+ already correct (they never had that parameter), so the autograd
350
+ adjoint identity holds on dev and is now protected by
351
+ ``tests/test_adjoint_inner_product.py``.
352
+ - ``1.2.11`` gradcheck / ramp window tests / CHANGELOG: **ported**.
353
+ - ``1.2.11`` benchmark suite: **not ported yet** (dev's benchmarks
354
+ directory stays empty).
355
+ - ``1.3.0`` SF-TR / SF-TT projector backends: **not ported**. SF relies
356
+ on closed-form ``sin(beta)/cos(beta)`` math for the trapezoidal
357
+ transaxial / rectangular axial footprints. Generalising SF to
358
+ arbitrary per-view ``(S, C, u_vec, v_vec)`` trajectories is a
359
+ non-trivial research effort (the "separable" part is not separable
360
+ when the detector is not plane-aligned to the voxel axes) and will
361
+ be tackled in a dedicated follow-up.
362
+
363
+ [Unreleased]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.1...HEAD
364
+ [2.0.1]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.0...v2.0.1
365
+ [2.0.0]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/releases/tag/v2.0.0