mlx-nufft 0.1.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.
- mlx_nufft-0.1.1/LICENSE +216 -0
- mlx_nufft-0.1.1/NOTICE +28 -0
- mlx_nufft-0.1.1/PKG-INFO +202 -0
- mlx_nufft-0.1.1/README.md +174 -0
- mlx_nufft-0.1.1/mlx_nufft/__init__.py +48 -0
- mlx_nufft-0.1.1/mlx_nufft/api.py +388 -0
- mlx_nufft-0.1.1/mlx_nufft/dfmath.py +134 -0
- mlx_nufft-0.1.1/mlx_nufft/gpu_t3.py +1364 -0
- mlx_nufft-0.1.1/mlx_nufft/nd.py +1119 -0
- mlx_nufft-0.1.1/mlx_nufft/ref_t3.py +228 -0
- mlx_nufft-0.1.1/mlx_nufft/sizing.py +111 -0
- mlx_nufft-0.1.1/mlx_nufft/types12.py +290 -0
- mlx_nufft-0.1.1/mlx_nufft/vkfft_backend.py +94 -0
- mlx_nufft-0.1.1/mlx_nufft.egg-info/PKG-INFO +202 -0
- mlx_nufft-0.1.1/mlx_nufft.egg-info/SOURCES.txt +18 -0
- mlx_nufft-0.1.1/mlx_nufft.egg-info/dependency_links.txt +1 -0
- mlx_nufft-0.1.1/mlx_nufft.egg-info/requires.txt +6 -0
- mlx_nufft-0.1.1/mlx_nufft.egg-info/top_level.txt +1 -0
- mlx_nufft-0.1.1/pyproject.toml +43 -0
- mlx_nufft-0.1.1/setup.cfg +4 -0
mlx_nufft-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
|
204
|
+
Copyright 2026 Martin Lachaine
|
|
205
|
+
|
|
206
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
207
|
+
you may not use this file except in compliance with the License.
|
|
208
|
+
You may obtain a copy of the License at
|
|
209
|
+
|
|
210
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
211
|
+
|
|
212
|
+
Unless required by applicable law or agreed to in writing, software
|
|
213
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
214
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
215
|
+
See the License for the specific language governing permissions and
|
|
216
|
+
limitations under the License.
|
mlx_nufft-0.1.1/NOTICE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
mlx-nufft
|
|
2
|
+
Copyright 2026 Martin Lachaine
|
|
3
|
+
|
|
4
|
+
mlx-nufft is an independent implementation of non-uniform fast Fourier
|
|
5
|
+
transforms (types 1, 2, 3, in 1/2/3 dimensions) for Apple GPUs via Metal/MLX.
|
|
6
|
+
Its algorithms and internal structure follow the FINUFFT and cuFINUFFT
|
|
7
|
+
libraries (Apache License 2.0, Copyright The Simons Foundation, Inc.) — the
|
|
8
|
+
exponential-of-semicircle kernel, the spreading/deconvolution structure, and
|
|
9
|
+
the type-3 construction — which were also used as the reference implementation
|
|
10
|
+
and numerical oracle during development. mlx-nufft was written from the
|
|
11
|
+
published methods with the FINUFFT source as a reference; it does not include
|
|
12
|
+
or redistribute FINUFFT source code.
|
|
13
|
+
|
|
14
|
+
If you use this software, please cite the underlying methods:
|
|
15
|
+
|
|
16
|
+
A. H. Barnett, J. Magland, and L. af Klinteberg, "A parallel nonuniform
|
|
17
|
+
fast Fourier transform library based on an exponential of semicircle
|
|
18
|
+
kernel," SIAM J. Sci. Comput. 41(5), C479-C504 (2019). arXiv:1808.06736
|
|
19
|
+
|
|
20
|
+
A. H. Barnett, "Aliasing error of the exp(beta sqrt(1-z^2)) kernel in the
|
|
21
|
+
nonuniform fast Fourier transform," Appl. Comput. Harmon. Anal. 51, 1-16
|
|
22
|
+
(2021). arXiv:2001.09405
|
|
23
|
+
|
|
24
|
+
Y. Shih, G. Wright, J. Anden, J. Blaschke, and A. H. Barnett, "cuFINUFFT:
|
|
25
|
+
a load-balanced GPU library for general-purpose nonuniform FFTs," PDSEC
|
|
26
|
+
(IPDPS workshops) 2021. arXiv:2102.08463
|
|
27
|
+
|
|
28
|
+
FINUFFT: https://github.com/flatironinstitute/finufft
|
mlx_nufft-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlx-nufft
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Non-uniform FFTs (types 1/2/3, dims 1/2/3) on Apple GPUs via Metal/MLX
|
|
5
|
+
Author: Martin Lachaine
|
|
6
|
+
Project-URL: Homepage, https://github.com/martinlachaine/mlx-nufft
|
|
7
|
+
Project-URL: Repository, https://github.com/martinlachaine/mlx-nufft
|
|
8
|
+
Project-URL: Issues, https://github.com/martinlachaine/mlx-nufft/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/martinlachaine/mlx-nufft/blob/main/CHANGELOG.md
|
|
10
|
+
Keywords: nufft,nonuniform-fft,fft,apple-silicon,metal,mlx,gpu
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
License-File: NOTICE
|
|
22
|
+
Requires-Dist: mlx==0.31.2
|
|
23
|
+
Requires-Dist: numpy>=2.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: finufft==2.5.1; extra == "dev"
|
|
26
|
+
Requires-Dist: scipy>=1.14; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# mlx-nufft — non-uniform FFTs on Apple GPUs (Metal/MLX)
|
|
30
|
+
|
|
31
|
+
[](https://github.com/martinlachaine/mlx-nufft/actions/workflows/ci.yml)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[](pyproject.toml)
|
|
34
|
+
[](#install)
|
|
35
|
+
[](https://github.com/ml-explore/mlx)
|
|
36
|
+
|
|
37
|
+
mlx-nufft computes non-uniform fast Fourier transforms — types 1, 2 and 3, in
|
|
38
|
+
dimensions 1, 2 and 3 — on Apple-silicon GPUs via Metal/MLX, with a drop-in
|
|
39
|
+
mirror of the `finufft` Python API. It runs an fp32 GPU pipeline with the
|
|
40
|
+
precision-critical coordinate setup performed in double precision at plan time
|
|
41
|
+
("crit64"), so it reaches fp64-grade accuracy on hardware that has no native
|
|
42
|
+
double precision.
|
|
43
|
+
|
|
44
|
+
> **Paper:** [`mlx-nufft.pdf`](mlx-nufft.pdf) — a technical report
|
|
45
|
+
> describing the method, accuracy, and performance (types 1/2/3 in 1/2/3D, the
|
|
46
|
+
> crit64 precision mechanism, and M1 / M5 Max benchmarks).
|
|
47
|
+
> Pin a tagged release rather than tracking `main`.
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
Requires an Apple-silicon Mac (Metal/MLX). Install the release directly from
|
|
52
|
+
GitHub (not yet on PyPI):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install "git+https://github.com/martinlachaine/mlx-nufft.git@v0.1.0"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
then `import mlx_nufft`. Dependencies are pinned (notably `mlx==0.31.2`).
|
|
59
|
+
|
|
60
|
+
For development — running the test/benchmark harness, which uses CPU `finufft`
|
|
61
|
+
and `scipy` as references:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/martinlachaine/mlx-nufft && cd mlx-nufft
|
|
65
|
+
uv venv --python 3.13 .venv
|
|
66
|
+
uv pip install -p .venv/bin/python -e ".[dev]"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Verify the install — run the full correctness suite (each test compares against
|
|
70
|
+
CPU `finufft` and/or an exact direct-summation oracle):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
.venv/bin/python harness/run_tests.py
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
It prints a per-test pass/fail summary and exits non-zero on any failure. The
|
|
77
|
+
optional VkFFT backend test reports `SKIP` unless the bridge in
|
|
78
|
+
`vkfft_bridge/` is built.
|
|
79
|
+
|
|
80
|
+
## Quickstart
|
|
81
|
+
|
|
82
|
+
A complete, copy-paste-runnable 2-D type-1 transform (M nonuniform points →
|
|
83
|
+
`N1 × N2` uniform Fourier modes):
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import numpy as np
|
|
87
|
+
import mlx_nufft as finufft
|
|
88
|
+
|
|
89
|
+
rng = np.random.default_rng(0)
|
|
90
|
+
M, N1, N2 = 100_000, 256, 256
|
|
91
|
+
x = rng.uniform(-np.pi, np.pi, M) # coords in [-pi, pi)
|
|
92
|
+
y = rng.uniform(-np.pi, np.pi, M)
|
|
93
|
+
c = rng.standard_normal(M) + 1j * rng.standard_normal(M) # source strengths
|
|
94
|
+
|
|
95
|
+
fk = finufft.nufft2d1(x, y, c, (N1, N2), eps=1e-6) # -> (256, 256) complex
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
A fuller runnable script (basic call, plan reuse, and a self-check against an
|
|
99
|
+
exact direct DFT — no `finufft` install needed) is in
|
|
100
|
+
[`examples/quickstart.py`](examples/quickstart.py):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
python examples/quickstart.py
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
Drop-in `finufft` API (same call surface):
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import mlx_nufft as finufft
|
|
112
|
+
|
|
113
|
+
fk = finufft.nufft2d1(x, y, c, (N1, N2), eps=1e-6) # all nufft{1,2,3}d{1,2,3}
|
|
114
|
+
plan = finufft.Plan(1, (N1, N2), n_trans=8, eps=1e-6)
|
|
115
|
+
plan.setpts(x, y)
|
|
116
|
+
fk = plan.execute(c)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Native plan classes — `Type3Plan` (type-3 engine) and `Type1PlanND` /
|
|
120
|
+
`Type2PlanND` (dims 1–3):
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from mlx_nufft import Type3Plan
|
|
124
|
+
|
|
125
|
+
# plan once (geometry-dependent setup cached), execute per call
|
|
126
|
+
plan = Type3Plan((x1, x2, x3), (s1, s2, s3), eps=1e-5, isign=+1)
|
|
127
|
+
f = plan.execute(c) # f[k] = sum_j c[j] exp(i*isign * s_k . x_j)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`Type1PlanND` also offers a batched multi-strength execute over one shared
|
|
131
|
+
point spread, and a cheap re-point of a fixed-mode-box plan to new coordinates:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from mlx_nufft import Type1PlanND
|
|
135
|
+
|
|
136
|
+
plan = Type1PlanND((x, y), (N1, N2), eps=1e-5, isign=+1)
|
|
137
|
+
fk = plan.execute_batch(cs) # cs: (B, P) over the same points -> (B, N1, N2)
|
|
138
|
+
plan.set_sources((x2, y2), backend="gpu") # re-point without recompiling kernels
|
|
139
|
+
fk2 = plan.execute(c2)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The double-single phase primitive is also exposed standalone, for callers with
|
|
143
|
+
a large-magnitude fp64 phase that cannot be reduced mod 2π in fp32 but want the
|
|
144
|
+
`cos`/`sin` on the GPU:
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from mlx_nufft import expi, EXPI_MAX_PHASE
|
|
148
|
+
|
|
149
|
+
z = expi(phi) # device complex64 e^{i*phi}, phi an fp64 array
|
|
150
|
+
z = expi([a, b, c], isign=-1) # phase summed in double-single: e^{-i*(a+b+c)}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
An optional VkFFT-Metal FFT backend is selectable for the type-3 slab path
|
|
154
|
+
(`Type3Plan(..., fft_backend="vkfft")`, requires building the bridge in
|
|
155
|
+
`vkfft_bridge/`); MLX's FFT is the default. `vkfft_available()` reports whether
|
|
156
|
+
the bridge is built.
|
|
157
|
+
|
|
158
|
+
## Documented differences from `finufft`
|
|
159
|
+
|
|
160
|
+
- Computation is fp32-grade (crit64): `eps` below 1e-6 clamps with a warning;
|
|
161
|
+
complex128 inputs are accepted and returned but transformed at fp32 grade.
|
|
162
|
+
- `modeord=1` (FFT ordering) is not implemented.
|
|
163
|
+
- 1D/2D type 3 run as degenerate slices of the 3D type-3 kernel.
|
|
164
|
+
- Plans hold points as plan state (`setpts`); `out=` and multi-vector
|
|
165
|
+
`(n_trans, ...)` shapes mirror finufft, and `Plan.execute_adjoint`
|
|
166
|
+
(finufft 2.5) is supported for all three types.
|
|
167
|
+
|
|
168
|
+
## Layout
|
|
169
|
+
|
|
170
|
+
- `mlx_nufft/` — the library: `gpu_t3.py` (type-3 engine), `nd.py`
|
|
171
|
+
(`Type1PlanND`/`Type2PlanND`), `types12.py`, `dfmath.py` (the `expi` /
|
|
172
|
+
double-single primitive), `sizing.py` (kernel/grid sizing), `api.py` (the
|
|
173
|
+
`finufft`-compatible surface), `vkfft_backend.py`.
|
|
174
|
+
- `examples/` — runnable, dependency-light usage examples
|
|
175
|
+
(`quickstart.py`).
|
|
176
|
+
- `harness/` — correctness tests (`test_*.py`), the suite runner
|
|
177
|
+
(`run_tests.py`), the acceptance/benchmark runner, and the CPU-reference
|
|
178
|
+
oracle.
|
|
179
|
+
- `vkfft_bridge/` — optional VkFFT-Metal backend build.
|
|
180
|
+
|
|
181
|
+
## Development and validation
|
|
182
|
+
|
|
183
|
+
mlx-nufft is AI-assisted, human-directed research software. Its scope, numerical
|
|
184
|
+
requirements, validation strategy, acceptance criteria, and release decisions
|
|
185
|
+
are the author's; generative AI tools accelerated implementation, refactoring,
|
|
186
|
+
test scaffolding, and documentation.
|
|
187
|
+
|
|
188
|
+
Generated code was not trusted by default. Every component was validated against
|
|
189
|
+
independent references — CPU FINUFFT, exact direct-summation oracles on small
|
|
190
|
+
problems, transform-convention and adjoint checks, full dimension/type coverage,
|
|
191
|
+
dtype/device behavior, and API-parity tests (see `harness/`).
|
|
192
|
+
|
|
193
|
+
The author is responsible for the released software — its design, limitations,
|
|
194
|
+
and maintenance. Known limitations and hardware assumptions are documented;
|
|
195
|
+
corrections are welcome via the issue tracker.
|
|
196
|
+
|
|
197
|
+
## License & citation
|
|
198
|
+
|
|
199
|
+
Apache-2.0 (see `LICENSE`). mlx-nufft is an independent implementation that
|
|
200
|
+
follows the FINUFFT/cuFINUFFT algorithms and was validated against FINUFFT;
|
|
201
|
+
see `NOTICE` for attribution and the methods papers to cite, and `CITATION.cff`
|
|
202
|
+
to cite mlx-nufft itself.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# mlx-nufft — non-uniform FFTs on Apple GPUs (Metal/MLX)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/martinlachaine/mlx-nufft/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](pyproject.toml)
|
|
6
|
+
[](#install)
|
|
7
|
+
[](https://github.com/ml-explore/mlx)
|
|
8
|
+
|
|
9
|
+
mlx-nufft computes non-uniform fast Fourier transforms — types 1, 2 and 3, in
|
|
10
|
+
dimensions 1, 2 and 3 — on Apple-silicon GPUs via Metal/MLX, with a drop-in
|
|
11
|
+
mirror of the `finufft` Python API. It runs an fp32 GPU pipeline with the
|
|
12
|
+
precision-critical coordinate setup performed in double precision at plan time
|
|
13
|
+
("crit64"), so it reaches fp64-grade accuracy on hardware that has no native
|
|
14
|
+
double precision.
|
|
15
|
+
|
|
16
|
+
> **Paper:** [`mlx-nufft.pdf`](mlx-nufft.pdf) — a technical report
|
|
17
|
+
> describing the method, accuracy, and performance (types 1/2/3 in 1/2/3D, the
|
|
18
|
+
> crit64 precision mechanism, and M1 / M5 Max benchmarks).
|
|
19
|
+
> Pin a tagged release rather than tracking `main`.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
Requires an Apple-silicon Mac (Metal/MLX). Install the release directly from
|
|
24
|
+
GitHub (not yet on PyPI):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install "git+https://github.com/martinlachaine/mlx-nufft.git@v0.1.0"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
then `import mlx_nufft`. Dependencies are pinned (notably `mlx==0.31.2`).
|
|
31
|
+
|
|
32
|
+
For development — running the test/benchmark harness, which uses CPU `finufft`
|
|
33
|
+
and `scipy` as references:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/martinlachaine/mlx-nufft && cd mlx-nufft
|
|
37
|
+
uv venv --python 3.13 .venv
|
|
38
|
+
uv pip install -p .venv/bin/python -e ".[dev]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Verify the install — run the full correctness suite (each test compares against
|
|
42
|
+
CPU `finufft` and/or an exact direct-summation oracle):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
.venv/bin/python harness/run_tests.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
It prints a per-test pass/fail summary and exits non-zero on any failure. The
|
|
49
|
+
optional VkFFT backend test reports `SKIP` unless the bridge in
|
|
50
|
+
`vkfft_bridge/` is built.
|
|
51
|
+
|
|
52
|
+
## Quickstart
|
|
53
|
+
|
|
54
|
+
A complete, copy-paste-runnable 2-D type-1 transform (M nonuniform points →
|
|
55
|
+
`N1 × N2` uniform Fourier modes):
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import numpy as np
|
|
59
|
+
import mlx_nufft as finufft
|
|
60
|
+
|
|
61
|
+
rng = np.random.default_rng(0)
|
|
62
|
+
M, N1, N2 = 100_000, 256, 256
|
|
63
|
+
x = rng.uniform(-np.pi, np.pi, M) # coords in [-pi, pi)
|
|
64
|
+
y = rng.uniform(-np.pi, np.pi, M)
|
|
65
|
+
c = rng.standard_normal(M) + 1j * rng.standard_normal(M) # source strengths
|
|
66
|
+
|
|
67
|
+
fk = finufft.nufft2d1(x, y, c, (N1, N2), eps=1e-6) # -> (256, 256) complex
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
A fuller runnable script (basic call, plan reuse, and a self-check against an
|
|
71
|
+
exact direct DFT — no `finufft` install needed) is in
|
|
72
|
+
[`examples/quickstart.py`](examples/quickstart.py):
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
python examples/quickstart.py
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
Drop-in `finufft` API (same call surface):
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import mlx_nufft as finufft
|
|
84
|
+
|
|
85
|
+
fk = finufft.nufft2d1(x, y, c, (N1, N2), eps=1e-6) # all nufft{1,2,3}d{1,2,3}
|
|
86
|
+
plan = finufft.Plan(1, (N1, N2), n_trans=8, eps=1e-6)
|
|
87
|
+
plan.setpts(x, y)
|
|
88
|
+
fk = plan.execute(c)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Native plan classes — `Type3Plan` (type-3 engine) and `Type1PlanND` /
|
|
92
|
+
`Type2PlanND` (dims 1–3):
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from mlx_nufft import Type3Plan
|
|
96
|
+
|
|
97
|
+
# plan once (geometry-dependent setup cached), execute per call
|
|
98
|
+
plan = Type3Plan((x1, x2, x3), (s1, s2, s3), eps=1e-5, isign=+1)
|
|
99
|
+
f = plan.execute(c) # f[k] = sum_j c[j] exp(i*isign * s_k . x_j)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`Type1PlanND` also offers a batched multi-strength execute over one shared
|
|
103
|
+
point spread, and a cheap re-point of a fixed-mode-box plan to new coordinates:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from mlx_nufft import Type1PlanND
|
|
107
|
+
|
|
108
|
+
plan = Type1PlanND((x, y), (N1, N2), eps=1e-5, isign=+1)
|
|
109
|
+
fk = plan.execute_batch(cs) # cs: (B, P) over the same points -> (B, N1, N2)
|
|
110
|
+
plan.set_sources((x2, y2), backend="gpu") # re-point without recompiling kernels
|
|
111
|
+
fk2 = plan.execute(c2)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The double-single phase primitive is also exposed standalone, for callers with
|
|
115
|
+
a large-magnitude fp64 phase that cannot be reduced mod 2π in fp32 but want the
|
|
116
|
+
`cos`/`sin` on the GPU:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from mlx_nufft import expi, EXPI_MAX_PHASE
|
|
120
|
+
|
|
121
|
+
z = expi(phi) # device complex64 e^{i*phi}, phi an fp64 array
|
|
122
|
+
z = expi([a, b, c], isign=-1) # phase summed in double-single: e^{-i*(a+b+c)}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
An optional VkFFT-Metal FFT backend is selectable for the type-3 slab path
|
|
126
|
+
(`Type3Plan(..., fft_backend="vkfft")`, requires building the bridge in
|
|
127
|
+
`vkfft_bridge/`); MLX's FFT is the default. `vkfft_available()` reports whether
|
|
128
|
+
the bridge is built.
|
|
129
|
+
|
|
130
|
+
## Documented differences from `finufft`
|
|
131
|
+
|
|
132
|
+
- Computation is fp32-grade (crit64): `eps` below 1e-6 clamps with a warning;
|
|
133
|
+
complex128 inputs are accepted and returned but transformed at fp32 grade.
|
|
134
|
+
- `modeord=1` (FFT ordering) is not implemented.
|
|
135
|
+
- 1D/2D type 3 run as degenerate slices of the 3D type-3 kernel.
|
|
136
|
+
- Plans hold points as plan state (`setpts`); `out=` and multi-vector
|
|
137
|
+
`(n_trans, ...)` shapes mirror finufft, and `Plan.execute_adjoint`
|
|
138
|
+
(finufft 2.5) is supported for all three types.
|
|
139
|
+
|
|
140
|
+
## Layout
|
|
141
|
+
|
|
142
|
+
- `mlx_nufft/` — the library: `gpu_t3.py` (type-3 engine), `nd.py`
|
|
143
|
+
(`Type1PlanND`/`Type2PlanND`), `types12.py`, `dfmath.py` (the `expi` /
|
|
144
|
+
double-single primitive), `sizing.py` (kernel/grid sizing), `api.py` (the
|
|
145
|
+
`finufft`-compatible surface), `vkfft_backend.py`.
|
|
146
|
+
- `examples/` — runnable, dependency-light usage examples
|
|
147
|
+
(`quickstart.py`).
|
|
148
|
+
- `harness/` — correctness tests (`test_*.py`), the suite runner
|
|
149
|
+
(`run_tests.py`), the acceptance/benchmark runner, and the CPU-reference
|
|
150
|
+
oracle.
|
|
151
|
+
- `vkfft_bridge/` — optional VkFFT-Metal backend build.
|
|
152
|
+
|
|
153
|
+
## Development and validation
|
|
154
|
+
|
|
155
|
+
mlx-nufft is AI-assisted, human-directed research software. Its scope, numerical
|
|
156
|
+
requirements, validation strategy, acceptance criteria, and release decisions
|
|
157
|
+
are the author's; generative AI tools accelerated implementation, refactoring,
|
|
158
|
+
test scaffolding, and documentation.
|
|
159
|
+
|
|
160
|
+
Generated code was not trusted by default. Every component was validated against
|
|
161
|
+
independent references — CPU FINUFFT, exact direct-summation oracles on small
|
|
162
|
+
problems, transform-convention and adjoint checks, full dimension/type coverage,
|
|
163
|
+
dtype/device behavior, and API-parity tests (see `harness/`).
|
|
164
|
+
|
|
165
|
+
The author is responsible for the released software — its design, limitations,
|
|
166
|
+
and maintenance. Known limitations and hardware assumptions are documented;
|
|
167
|
+
corrections are welcome via the issue tracker.
|
|
168
|
+
|
|
169
|
+
## License & citation
|
|
170
|
+
|
|
171
|
+
Apache-2.0 (see `LICENSE`). mlx-nufft is an independent implementation that
|
|
172
|
+
follows the FINUFFT/cuFINUFFT algorithms and was validated against FINUFFT;
|
|
173
|
+
see `NOTICE` for attribution and the methods papers to cite, and `CITATION.cff`
|
|
174
|
+
to cite mlx-nufft itself.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""mlx-nufft: non-uniform FFTs on Apple GPUs (Metal, via MLX).
|
|
2
|
+
|
|
3
|
+
Drop-in mirror of the `finufft` Python package's interface:
|
|
4
|
+
|
|
5
|
+
import mlx_nufft as finufft
|
|
6
|
+
fk = finufft.nufft2d1(x, y, c, (N1, N2), eps=1e-6) # types 1/2/3, dims 1/2/3
|
|
7
|
+
plan = finufft.Plan(1, (N1, N2), eps=1e-6)
|
|
8
|
+
plan.setpts(x, y)
|
|
9
|
+
fk = plan.execute(c)
|
|
10
|
+
|
|
11
|
+
plus the native plan classes:
|
|
12
|
+
|
|
13
|
+
from mlx_nufft import Type3Plan
|
|
14
|
+
plan = Type3Plan((x1, x2, x3), (s1, s2, s3), eps=1e-5, isign=+1)
|
|
15
|
+
f = plan.execute(c) # f[k] = sum_j c[j] exp(i*isign*s_k.x_j)
|
|
16
|
+
|
|
17
|
+
Precision model (see REPORT.md): fp32 GPU pipeline with the precision-
|
|
18
|
+
critical setup (coordinate rescale, pre/post phases) in fp64 at plan time
|
|
19
|
+
('crit64', the default). Plans cache all geometry-dependent state, so
|
|
20
|
+
fixed-geometry workloads pay setup once and execute() per call.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from .gpu_t3 import GpuT3Plan as Type3Plan
|
|
24
|
+
from .types12 import Type1Plan, Type2Plan
|
|
25
|
+
from .nd import Type1PlanND, Type2PlanND
|
|
26
|
+
from .dfmath import expi, EXPI_MAX_PHASE
|
|
27
|
+
from .sizing import kernel_params, next235even
|
|
28
|
+
from .api import (Plan,
|
|
29
|
+
nufft1d1, nufft1d2, nufft1d3,
|
|
30
|
+
nufft2d1, nufft2d2, nufft2d3,
|
|
31
|
+
nufft3d1, nufft3d2, nufft3d3)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def vkfft_available():
|
|
35
|
+
"""True if the optional VkFFT-Metal FFT backend (fft_backend='vkfft') is
|
|
36
|
+
built and loadable — see vkfft_bridge/build.sh."""
|
|
37
|
+
from . import vkfft_backend
|
|
38
|
+
return vkfft_backend.available()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
__version__ = "0.1.1"
|
|
42
|
+
__all__ = ["Type3Plan", "Type1Plan", "Type2Plan",
|
|
43
|
+
"Type1PlanND", "Type2PlanND", "Plan",
|
|
44
|
+
"nufft1d1", "nufft1d2", "nufft1d3",
|
|
45
|
+
"nufft2d1", "nufft2d2", "nufft2d3",
|
|
46
|
+
"nufft3d1", "nufft3d2", "nufft3d3",
|
|
47
|
+
"kernel_params", "next235even", "vkfft_available",
|
|
48
|
+
"expi", "EXPI_MAX_PHASE"]
|