|
44 | 44 | }, |
45 | 45 | { |
46 | 46 | "cell_type": "code", |
47 | | - "execution_count": 3, |
| 47 | + "execution_count": null, |
48 | 48 | "metadata": {}, |
49 | 49 | "outputs": [], |
50 | 50 | "source": [ |
51 | 51 | "res = 12\n", |
52 | | - "# basis = ZernikePolynomial(L=res, M=res, spectral_indexing=\"ansi\", sym=\"cos\")\n", |
53 | 52 | "basis = FourierZernikeBasis(L=res, M=res, N=res)\n", |
54 | 53 | "r = np.linspace(0, 1, 1000)" |
55 | 54 | ] |
|
63 | 62 | "name": "stderr", |
64 | 63 | "output_type": "stream", |
65 | 64 | "text": [ |
66 | | - "WARNING:2025-10-19 18:04:12,507:jax._src.xla_bridge:794: An NVIDIA GPU may be present on this machine, but a CUDA-enabled jaxlib is not installed. Falling back to cpu.\n" |
| 65 | + "WARNING:2026-02-24 16:12:18,619:jax._src.xla_bridge:794: An NVIDIA GPU may be present on this machine, but a CUDA-enabled jaxlib is not installed. Falling back to cpu.\n" |
67 | 66 | ] |
68 | 67 | }, |
69 | 68 | { |
70 | 69 | "name": "stdout", |
71 | 70 | "output_type": "stream", |
72 | 71 | "text": [ |
73 | | - "9.89 ms ± 827 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
74 | | - "46.7 ms ± 582 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" |
| 72 | + "10.9 ms ± 367 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
| 73 | + "46.4 ms ± 664 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" |
75 | 74 | ] |
76 | 75 | } |
77 | 76 | ], |
|
96 | 95 | "output_type": "stream", |
97 | 96 | "text": [ |
98 | 97 | "zernike_radial_poly, 0th derivative\n", |
99 | | - "5.61 ms ± 318 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
| 98 | + "4.81 ms ± 273 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
100 | 99 | "zernike_radial_poly, 1st derivative\n", |
101 | | - "5.82 ms ± 79.8 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
| 100 | + "4.81 ms ± 133 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
102 | 101 | "zernike_radial_poly, 2nd derivative\n", |
103 | | - "5.83 ms ± 148 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
| 102 | + "4.6 ms ± 273 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
104 | 103 | "zernike_radial_poly, 3rd derivative\n", |
105 | | - "6.46 ms ± 467 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" |
| 104 | + "4.75 ms ± 115 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" |
106 | 105 | ] |
107 | 106 | } |
108 | 107 | ], |
|
126 | 125 | "# Exact computation\n", |
127 | 126 | "mpmath.mp.dps = 100\n", |
128 | 127 | "c = zernike_radial_coeffs(basis.modes[:, 0], basis.modes[:, 1], exact=True)\n", |
129 | | - "zt0 = np.array([np.asarray(mpmath.polyval(list(ci), r), dtype=float) for ci in c]).T\n", |
130 | | - "zt1 = np.array([np.asarray(mpmath.polyval(list(ci), r), dtype=float) for ci in polyder_vec(c, 1, exact=True)]).T\n", |
131 | | - "zt2 = np.array([np.asarray(mpmath.polyval(list(ci), r), dtype=float) for ci in polyder_vec(c, 2, exact=True)]).T\n", |
132 | 128 | "zt3 = np.array([np.asarray(mpmath.polyval(list(ci), r), dtype=float) for ci in polyder_vec(c, 3, exact=True)]).T\n", |
133 | 129 | "# CPU version\n", |
134 | | - "zr0 = zernike_radial_cpu(r, basis.modes[:, 0], basis.modes[:, 1], 0)\n", |
135 | | - "zr1 = zernike_radial_cpu(r, basis.modes[:, 0], basis.modes[:, 1], 1)\n", |
136 | | - "zr2 = zernike_radial_cpu(r, basis.modes[:, 0], basis.modes[:, 1], 2)\n", |
137 | 130 | "zr3 = zernike_radial_cpu(r, basis.modes[:, 0], basis.modes[:, 1], 3)\n", |
138 | 131 | "# GPU version\n", |
139 | | - "zd0 = zernike_radial_gpu(\n", |
140 | | - " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], 0\n", |
141 | | - ")\n", |
142 | | - "zd1 = zernike_radial_gpu(\n", |
143 | | - " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], 1\n", |
144 | | - ")\n", |
145 | | - "zd2 = zernike_radial_gpu(\n", |
146 | | - " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], 2\n", |
147 | | - ")\n", |
148 | 132 | "zd3 = zernike_radial_gpu(\n", |
149 | 133 | " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], 3\n", |
150 | 134 | ")\n", |
151 | 135 | "\n", |
152 | 136 | "mpmath.mp.dps = 10\n", |
153 | 137 | "# Polynomial computation\n", |
154 | | - "zp0 = zernike_radial_poly(\n", |
155 | | - " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], dr=0, exact=False\n", |
156 | | - ")\n", |
157 | | - "zp1 = zernike_radial_poly(\n", |
158 | | - " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], dr=1, exact=False\n", |
159 | | - ")\n", |
160 | | - "zp2 = zernike_radial_poly(\n", |
161 | | - " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], dr=2, exact=False\n", |
162 | | - ")\n", |
163 | 138 | "zp3 = zernike_radial_poly(\n", |
164 | 139 | " r[:, np.newaxis], basis.modes[:, 0], basis.modes[:, 1], dr=3, exact=False\n", |
165 | 140 | ")" |
|
187 | 162 | }, |
188 | 163 | { |
189 | 164 | "cell_type": "code", |
190 | | - "execution_count": 8, |
| 165 | + "execution_count": 10, |
191 | 166 | "metadata": {}, |
192 | 167 | "outputs": [ |
193 | 168 | { |
|
196 | 171 | "text": [ |
197 | 172 | "zernike_radial, derivative order: 0\n", |
198 | 173 | "# With no duplicate modes (might have lacking modes)\n", |
199 | | - "929 μs ± 327 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n", |
200 | | - "# With all the checks necessary but no reverse mode AutoDiff capable\n", |
201 | | - "11.3 ms ± 480 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
| 174 | + "1.24 ms ± 308 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n", |
| 175 | + "# With all the checks necessary\n", |
| 176 | + "12.9 ms ± 274 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
202 | 177 | "# With all the checks necessary but less efficient on CPU\n", |
203 | | - "41.1 ms ± 1.19 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" |
| 178 | + "44.6 ms ± 418 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" |
204 | 179 | ] |
205 | 180 | } |
206 | 181 | ], |
|
211 | 186 | "print(\"# With no duplicate modes (might have lacking modes)\")\n", |
212 | 187 | "%timeit _ = zernike_radial_unique(r, basis.modes[:,0], basis.modes[:,1], dr).block_until_ready()\n", |
213 | 188 | "\n", |
214 | | - "print(\"# With all the checks necessary but no reverse mode AutoDiff capable\")\n", |
| 189 | + "print(\"# With all the checks necessary\")\n", |
215 | 190 | "%timeit _ = zernike_radial_cpu(r, basis.modes[:,0], basis.modes[:,1], dr).block_until_ready()\n", |
216 | 191 | "\n", |
217 | 192 | "print(\"# With all the checks necessary but less efficient on CPU\")\n", |
|
220 | 195 | }, |
221 | 196 | { |
222 | 197 | "cell_type": "code", |
223 | | - "execution_count": 9, |
| 198 | + "execution_count": 11, |
224 | 199 | "metadata": {}, |
225 | 200 | "outputs": [ |
226 | 201 | { |
|
229 | 204 | "text": [ |
230 | 205 | "zernike_radial, derivative order: 1\n", |
231 | 206 | "# With no duplicate modes (might have lacking modes)\n", |
232 | | - "1.42 ms ± 303 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n", |
233 | | - "# With all the checks necessary but no reverse mode AutoDiff capable\n", |
234 | | - "11.1 ms ± 303 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
| 207 | + "1.93 ms ± 6.67 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n", |
| 208 | + "# With all the checks necessary\n", |
| 209 | + "13.2 ms ± 303 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n", |
235 | 210 | "# With all the checks necessary but less efficient on CPU\n", |
236 | | - "68.9 ms ± 460 μs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" |
| 211 | + "75.4 ms ± 1.11 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" |
237 | 212 | ] |
238 | 213 | } |
239 | 214 | ], |
|
244 | 219 | "print(\"# With no duplicate modes (might have lacking modes)\")\n", |
245 | 220 | "%timeit _ = zernike_radial_unique(r, basis.modes[:,0], basis.modes[:,1], dr).block_until_ready()\n", |
246 | 221 | "\n", |
247 | | - "print(\"# With all the checks necessary but no reverse mode AutoDiff capable\")\n", |
| 222 | + "print(\"# With all the checks necessary\")\n", |
248 | 223 | "%timeit _ = zernike_radial_cpu(r, basis.modes[:,0], basis.modes[:,1], dr).block_until_ready()\n", |
249 | 224 | "\n", |
250 | 225 | "print(\"# With all the checks necessary but less efficient on CPU\")\n", |
|
0 commit comments