diffct-mlx 1.0.1__py3-none-any.whl

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.
@@ -0,0 +1,502 @@
1
+ """Metal kernels for 2D fan beam projections.
2
+
3
+ This module contains Metal kernel source strings implementing the Siddon
4
+ ray-tracing method for 2D fan beam forward projection and backprojection,
5
+ optimized for Apple Silicon GPUs.
6
+ """
7
+
8
+ import mlx.core as mx
9
+
10
+ # ---------------------------------------------------------------------------
11
+ # Constants for Metal kernels
12
+ # ---------------------------------------------------------------------------
13
+ _EPSILON_STR = "1e-6f"
14
+ _INF_STR = "1e30f"
15
+
16
+ # ============================================================================
17
+ # 2D Fan Beam Forward Projection Metal Kernel
18
+ # ============================================================================
19
+
20
+ _FAN_2D_FORWARD_SOURCE = """
21
+ // Thread position: (iang, idet)
22
+ uint iang = thread_position_in_grid.x;
23
+ uint idet = thread_position_in_grid.y;
24
+
25
+ // Read scalar parameters
26
+ int n_ang = params[0];
27
+ int n_det = params[1];
28
+ int Nx = params[2];
29
+ int Ny = params[3];
30
+
31
+ float det_spacing = fparams[0];
32
+ float cx = fparams[1];
33
+ float cy = fparams[2];
34
+ float voxel_spacing = fparams[3];
35
+
36
+ if ((int)iang >= n_ang || (int)idet >= n_det) return;
37
+
38
+ float eps = """ + _EPSILON_STR + """;
39
+
40
+ // === 2D FAN BEAM GEOMETRY SETUP ===
41
+ float src_x = src_pos[iang * 2 + 0] / voxel_spacing;
42
+ float src_y = src_pos[iang * 2 + 1] / voxel_spacing;
43
+
44
+ float det_cx = det_center[iang * 2 + 0] / voxel_spacing;
45
+ float det_cy = det_center[iang * 2 + 1] / voxel_spacing;
46
+
47
+ float u_vec_x = det_u_vec[iang * 2 + 0];
48
+ float u_vec_y = det_u_vec[iang * 2 + 1];
49
+
50
+ float u_offset = ((float)idet - (float)n_det * 0.5f) * det_spacing / voxel_spacing;
51
+
52
+ float det_x = det_cx + u_offset * u_vec_x;
53
+ float det_y = det_cy + u_offset * u_vec_y;
54
+
55
+ // === RAY DIRECTION ===
56
+ float dir_x = det_x - src_x;
57
+ float dir_y = det_y - src_y;
58
+ float length = metal::sqrt(dir_x * dir_x + dir_y * dir_y);
59
+ if (length < eps) {
60
+ sino[iang * n_det + idet] = 0.0f;
61
+ return;
62
+ }
63
+ float inv_len = 1.0f / length;
64
+ dir_x *= inv_len;
65
+ dir_y *= inv_len;
66
+
67
+ // === RAY-VOLUME INTERSECTION ===
68
+ float t_min = -""" + _INF_STR + """;
69
+ float t_max = """ + _INF_STR + """;
70
+
71
+ if (metal::abs(dir_x) > eps) {
72
+ float tx1 = (-cx - src_x) / dir_x;
73
+ float tx2 = ( cx - src_x) / dir_x;
74
+ t_min = metal::max(t_min, metal::min(tx1, tx2));
75
+ t_max = metal::min(t_max, metal::max(tx1, tx2));
76
+ } else if (src_x < -cx || src_x > cx) {
77
+ sino[iang * n_det + idet] = 0.0f;
78
+ return;
79
+ }
80
+
81
+ if (metal::abs(dir_y) > eps) {
82
+ float ty1 = (-cy - src_y) / dir_y;
83
+ float ty2 = ( cy - src_y) / dir_y;
84
+ t_min = metal::max(t_min, metal::min(ty1, ty2));
85
+ t_max = metal::min(t_max, metal::max(ty1, ty2));
86
+ } else if (src_y < -cy || src_y > cy) {
87
+ sino[iang * n_det + idet] = 0.0f;
88
+ return;
89
+ }
90
+
91
+ if (t_min >= t_max) {
92
+ sino[iang * n_det + idet] = 0.0f;
93
+ return;
94
+ }
95
+
96
+ // === SIDDON TRAVERSAL ===
97
+ float accum = 0.0f;
98
+ float t = t_min;
99
+
100
+ int ix = (int)metal::floor(src_x + t * dir_x + cx);
101
+ int iy = (int)metal::floor(src_y + t * dir_y + cy);
102
+
103
+ int step_x = (dir_x >= 0.0f) ? 1 : -1;
104
+ int step_y = (dir_y >= 0.0f) ? 1 : -1;
105
+
106
+ float inv_dir_x = (metal::abs(dir_x) > eps) ? (1.0f / dir_x) : 0.0f;
107
+ float inv_dir_y = (metal::abs(dir_y) > eps) ? (1.0f / dir_y) : 0.0f;
108
+ float dt_x = (metal::abs(dir_x) > eps) ? metal::abs(inv_dir_x) : """ + _INF_STR + """;
109
+ float dt_y = (metal::abs(dir_y) > eps) ? metal::abs(inv_dir_y) : """ + _INF_STR + """;
110
+
111
+ float tx = (metal::abs(dir_x) > eps) ? ((float)(ix + (step_x > 0 ? 1 : 0)) - cx - src_x) * inv_dir_x : """ + _INF_STR + """;
112
+ float ty = (metal::abs(dir_y) > eps) ? ((float)(iy + (step_y > 0 ? 1 : 0)) - cy - src_y) * inv_dir_y : """ + _INF_STR + """;
113
+
114
+ while (t < t_max) {
115
+ if (ix >= 0 && ix < Nx && iy >= 0 && iy < Ny) {
116
+ float t_next = metal::min(metal::min(tx, ty), t_max);
117
+ float seg_len = t_next - t;
118
+
119
+ if (seg_len > eps) {
120
+ float t_mid = t + seg_len * 0.5f;
121
+ float mid_x = src_x + t_mid * dir_x + cx;
122
+ float mid_y = src_y + t_mid * dir_y + cy;
123
+
124
+ int ix0 = (int)metal::floor(mid_x);
125
+ int iy0 = (int)metal::floor(mid_y);
126
+ float dx = mid_x - (float)ix0;
127
+ float dy = mid_y - (float)iy0;
128
+
129
+ ix0 = metal::max(0, metal::min(ix0, Nx - 2));
130
+ iy0 = metal::max(0, metal::min(iy0, Ny - 2));
131
+
132
+ float omdx = 1.0f - dx;
133
+ float omdy = 1.0f - dy;
134
+
135
+ float v00 = image[iy0 * Nx + ix0];
136
+ float v10 = image[iy0 * Nx + ix0 + 1];
137
+ float v01 = image[(iy0 + 1) * Nx + ix0];
138
+ float v11 = image[(iy0 + 1) * Nx + ix0 + 1];
139
+
140
+ float val = (v00 * omdx + v10 * dx) * omdy +
141
+ (v01 * omdx + v11 * dx) * dy;
142
+ accum += val * seg_len;
143
+ }
144
+ }
145
+
146
+ if (tx <= ty) {
147
+ t = tx;
148
+ ix += step_x;
149
+ tx += dt_x;
150
+ } else {
151
+ t = ty;
152
+ iy += step_y;
153
+ ty += dt_y;
154
+ }
155
+ }
156
+
157
+ sino[iang * n_det + idet] = accum;
158
+ """
159
+
160
+ fan_2d_forward_kernel = mx.fast.metal_kernel(
161
+ name="fan_2d_forward",
162
+ input_names=["image", "src_pos", "det_center", "det_u_vec", "params", "fparams"],
163
+ output_names=["sino"],
164
+ source=_FAN_2D_FORWARD_SOURCE,
165
+ )
166
+
167
+ # ============================================================================
168
+ # 2D Fan Beam Backprojection Metal Kernel
169
+ # ============================================================================
170
+
171
+ _FAN_2D_BACKWARD_SOURCE = """
172
+ // Thread position: (iang, idet)
173
+ uint iang = thread_position_in_grid.x;
174
+ uint idet = thread_position_in_grid.y;
175
+
176
+ // Read scalar parameters
177
+ int n_ang = params[0];
178
+ int n_det = params[1];
179
+ int Nx = params[2];
180
+ int Ny = params[3];
181
+
182
+ float det_spacing = fparams[0];
183
+ float cx = fparams[1];
184
+ float cy = fparams[2];
185
+ float voxel_spacing = fparams[3];
186
+
187
+ if ((int)iang >= n_ang || (int)idet >= n_det) return;
188
+
189
+ float eps = """ + _EPSILON_STR + """;
190
+
191
+ float val = sino[iang * n_det + idet];
192
+
193
+ // === 2D FAN BEAM GEOMETRY SETUP ===
194
+ float src_x = src_pos[iang * 2 + 0] / voxel_spacing;
195
+ float src_y = src_pos[iang * 2 + 1] / voxel_spacing;
196
+
197
+ float det_cx = det_center_arr[iang * 2 + 0] / voxel_spacing;
198
+ float det_cy = det_center_arr[iang * 2 + 1] / voxel_spacing;
199
+
200
+ float u_vec_x = det_u_vec[iang * 2 + 0];
201
+ float u_vec_y = det_u_vec[iang * 2 + 1];
202
+
203
+ float u_offset = ((float)idet - (float)n_det * 0.5f) * det_spacing / voxel_spacing;
204
+
205
+ float det_x = det_cx + u_offset * u_vec_x;
206
+ float det_y = det_cy + u_offset * u_vec_y;
207
+
208
+ // === RAY DIRECTION ===
209
+ float dir_x = det_x - src_x;
210
+ float dir_y = det_y - src_y;
211
+ float length = metal::sqrt(dir_x * dir_x + dir_y * dir_y);
212
+ if (length < eps) return;
213
+ float inv_len = 1.0f / length;
214
+ dir_x *= inv_len;
215
+ dir_y *= inv_len;
216
+
217
+ // === RAY-VOLUME INTERSECTION ===
218
+ float t_min = -""" + _INF_STR + """;
219
+ float t_max = """ + _INF_STR + """;
220
+
221
+ if (metal::abs(dir_x) > eps) {
222
+ float tx1 = (-cx - src_x) / dir_x;
223
+ float tx2 = ( cx - src_x) / dir_x;
224
+ t_min = metal::max(t_min, metal::min(tx1, tx2));
225
+ t_max = metal::min(t_max, metal::max(tx1, tx2));
226
+ } else if (src_x < -cx || src_x > cx) { return; }
227
+
228
+ if (metal::abs(dir_y) > eps) {
229
+ float ty1 = (-cy - src_y) / dir_y;
230
+ float ty2 = ( cy - src_y) / dir_y;
231
+ t_min = metal::max(t_min, metal::min(ty1, ty2));
232
+ t_max = metal::min(t_max, metal::max(ty1, ty2));
233
+ } else if (src_y < -cy || src_y > cy) { return; }
234
+
235
+ if (t_min >= t_max) return;
236
+
237
+ // === SIDDON TRAVERSAL ===
238
+ float t = t_min;
239
+ int ix = (int)metal::floor(src_x + t * dir_x + cx);
240
+ int iy = (int)metal::floor(src_y + t * dir_y + cy);
241
+
242
+ int step_x = (dir_x >= 0.0f) ? 1 : -1;
243
+ int step_y = (dir_y >= 0.0f) ? 1 : -1;
244
+
245
+ float inv_dir_x = (metal::abs(dir_x) > eps) ? (1.0f / dir_x) : 0.0f;
246
+ float inv_dir_y = (metal::abs(dir_y) > eps) ? (1.0f / dir_y) : 0.0f;
247
+ float dt_x = (metal::abs(dir_x) > eps) ? metal::abs(inv_dir_x) : """ + _INF_STR + """;
248
+ float dt_y = (metal::abs(dir_y) > eps) ? metal::abs(inv_dir_y) : """ + _INF_STR + """;
249
+
250
+ float tx = (metal::abs(dir_x) > eps) ? ((float)(ix + (step_x > 0 ? 1 : 0)) - cx - src_x) * inv_dir_x : """ + _INF_STR + """;
251
+ float ty = (metal::abs(dir_y) > eps) ? ((float)(iy + (step_y > 0 ? 1 : 0)) - cy - src_y) * inv_dir_y : """ + _INF_STR + """;
252
+
253
+ while (t < t_max) {
254
+ if (ix >= 0 && ix < Nx && iy >= 0 && iy < Ny) {
255
+ float t_next = metal::min(metal::min(tx, ty), t_max);
256
+ float seg_len = t_next - t;
257
+
258
+ if (seg_len > eps) {
259
+ float t_mid = t + seg_len * 0.5f;
260
+ float mid_x = src_x + t_mid * dir_x + cx;
261
+ float mid_y = src_y + t_mid * dir_y + cy;
262
+
263
+ int ix0 = (int)metal::floor(mid_x);
264
+ int iy0 = (int)metal::floor(mid_y);
265
+ float dx = mid_x - (float)ix0;
266
+ float dy = mid_y - (float)iy0;
267
+
268
+ ix0 = metal::max(0, metal::min(ix0, Nx - 2));
269
+ iy0 = metal::max(0, metal::min(iy0, Ny - 2));
270
+
271
+ float omdx = 1.0f - dx;
272
+ float omdy = 1.0f - dy;
273
+ float cval = val * seg_len;
274
+
275
+ atomic_fetch_add_explicit(&grad_image[iy0 * Nx + ix0], cval * omdx * omdy, memory_order_relaxed);
276
+ atomic_fetch_add_explicit(&grad_image[iy0 * Nx + ix0 + 1], cval * dx * omdy, memory_order_relaxed);
277
+ atomic_fetch_add_explicit(&grad_image[(iy0 + 1) * Nx + ix0], cval * omdx * dy, memory_order_relaxed);
278
+ atomic_fetch_add_explicit(&grad_image[(iy0 + 1) * Nx + ix0 + 1], cval * dx * dy, memory_order_relaxed);
279
+ }
280
+ }
281
+
282
+ if (tx <= ty) {
283
+ t = tx;
284
+ ix += step_x;
285
+ tx += dt_x;
286
+ } else {
287
+ t = ty;
288
+ iy += step_y;
289
+ ty += dt_y;
290
+ }
291
+ }
292
+ """
293
+
294
+ fan_2d_backward_kernel = mx.fast.metal_kernel(
295
+ name="fan_2d_backward",
296
+ input_names=["sino", "src_pos", "det_center_arr", "det_u_vec", "params", "fparams"],
297
+ output_names=["grad_image"],
298
+ source=_FAN_2D_BACKWARD_SOURCE,
299
+ atomic_outputs=True,
300
+ )
301
+
302
+ # ============================================================================
303
+ # 2D Fan Beam Footprint-Matched Projector Pair
304
+ # ============================================================================
305
+
306
+ _FAN_2D_FOOTPRINT_FORWARD_SOURCE = """
307
+ // Thread position: (iang, iy)
308
+ uint iang = thread_position_in_grid.x;
309
+ uint iy = thread_position_in_grid.y;
310
+
311
+ int n_ang = params[0];
312
+ int n_det = params[1];
313
+ int Nx = params[2];
314
+ int Ny = params[3];
315
+
316
+ float det_spacing = fparams[0];
317
+ float cx = fparams[1];
318
+ float cy = fparams[2];
319
+ float voxel_spacing = fparams[3];
320
+
321
+ if ((int)iang >= n_ang || (int)iy >= Ny) return;
322
+
323
+ float eps = """ + _EPSILON_STR + """;
324
+ float det_spacing_vox = det_spacing / voxel_spacing;
325
+ float center_u = (float)n_det * 0.5f;
326
+
327
+ float src_x = src_pos[iang * 2 + 0] / voxel_spacing;
328
+ float src_y = src_pos[iang * 2 + 1] / voxel_spacing;
329
+ float det_cx = det_center[iang * 2 + 0] / voxel_spacing;
330
+ float det_cy = det_center[iang * 2 + 1] / voxel_spacing;
331
+ float u_vec_x = det_u_vec[iang * 2 + 0];
332
+ float u_vec_y = det_u_vec[iang * 2 + 1];
333
+ float n_x = -u_vec_y;
334
+ float n_y = u_vec_x;
335
+
336
+ float plane_dx = det_cx - src_x;
337
+ float plane_dy = det_cy - src_y;
338
+ float plane_dist = plane_dx * n_x + plane_dy * n_y;
339
+ if (metal::abs(plane_dist) <= eps) return;
340
+
341
+ float py = ((float)iy + 0.5f) - cy;
342
+
343
+ for (int ix = 0; ix < Nx; ++ix) {
344
+ float val = image[(int)iy * Nx + ix];
345
+ if (metal::abs(val) <= eps) continue;
346
+
347
+ float px = ((float)ix + 0.5f) - cx;
348
+ float rx = px - src_x;
349
+ float ry = py - src_y;
350
+ float denom = rx * n_x + ry * n_y;
351
+ if (metal::abs(denom) <= eps) continue;
352
+
353
+ float t = plane_dist / denom;
354
+ if (t <= 0.0f) continue;
355
+
356
+ float qx = src_x + t * rx;
357
+ float qy = src_y + t * ry;
358
+ float rel_x = qx - det_cx;
359
+ float rel_y = qy - det_cy;
360
+ float u0 = rel_x * u_vec_x + rel_y * u_vec_y;
361
+
362
+ float ru = rx * u_vec_x + ry * u_vec_y;
363
+ float inv_denom = 1.0f / denom;
364
+ float grad_ux = t * u_vec_x - t * ru * inv_denom * n_x;
365
+ float grad_uy = t * u_vec_y - t * ru * inv_denom * n_y;
366
+ float half_u = 0.5f * (metal::abs(grad_ux) + metal::abs(grad_uy));
367
+ half_u = metal::max(half_u, 0.5f * det_spacing_vox);
368
+ float width_u = metal::max(2.0f * half_u, det_spacing_vox);
369
+ float support_u = half_u + 0.5f * det_spacing_vox;
370
+
371
+ float ray_len = metal::sqrt(rx * rx + ry * ry);
372
+ if (ray_len <= eps) continue;
373
+ float dir_x = rx / ray_len;
374
+ float dir_y = ry / ray_len;
375
+ float l_phi = 1.0f / metal::max(metal::max(metal::abs(dir_x), metal::abs(dir_y)), eps);
376
+
377
+ int idet_min = (int)metal::floor(u0 / det_spacing_vox + center_u - support_u / det_spacing_vox);
378
+ int idet_max = (int)metal::ceil(u0 / det_spacing_vox + center_u + support_u / det_spacing_vox);
379
+ idet_min = metal::max(0, idet_min);
380
+ idet_max = metal::min(n_det - 1, idet_max);
381
+
382
+ float fp_lo = u0 - half_u;
383
+ float fp_hi = u0 + half_u;
384
+ float scaled_val = val * l_phi;
385
+
386
+ for (int idet = idet_min; idet <= idet_max; ++idet) {
387
+ float pixel_u = ((float)idet - center_u) * det_spacing_vox;
388
+ float pixel_lo = pixel_u - 0.5f * det_spacing_vox;
389
+ float pixel_hi = pixel_u + 0.5f * det_spacing_vox;
390
+ float overlap = metal::min(pixel_hi, fp_hi) - metal::max(pixel_lo, fp_lo);
391
+ if (overlap <= eps) continue;
392
+ float weight = overlap / width_u;
393
+ atomic_fetch_add_explicit(&sino[iang * n_det + idet], scaled_val * weight, memory_order_relaxed);
394
+ }
395
+ }
396
+ """
397
+
398
+ fan_2d_footprint_forward_kernel = mx.fast.metal_kernel(
399
+ name="fan_2d_footprint_forward",
400
+ input_names=["image", "src_pos", "det_center", "det_u_vec", "params", "fparams"],
401
+ output_names=["sino"],
402
+ source=_FAN_2D_FOOTPRINT_FORWARD_SOURCE,
403
+ atomic_outputs=True,
404
+ )
405
+
406
+ _FAN_2D_FOOTPRINT_BACKWARD_SOURCE = """
407
+ // Thread position: (ix, iy)
408
+ uint ix = thread_position_in_grid.x;
409
+ uint iy = thread_position_in_grid.y;
410
+
411
+ int n_ang = params[0];
412
+ int n_det = params[1];
413
+ int Nx = params[2];
414
+ int Ny = params[3];
415
+
416
+ float det_spacing = fparams[0];
417
+ float cx = fparams[1];
418
+ float cy = fparams[2];
419
+ float voxel_spacing = fparams[3];
420
+
421
+ if ((int)ix >= Nx || (int)iy >= Ny) return;
422
+
423
+ float eps = """ + _EPSILON_STR + """;
424
+ float det_spacing_vox = det_spacing / voxel_spacing;
425
+ float center_u = (float)n_det * 0.5f;
426
+ float px = ((float)ix + 0.5f) - cx;
427
+ float py = ((float)iy + 0.5f) - cy;
428
+
429
+ float accum = 0.0f;
430
+
431
+ for (int iang = 0; iang < n_ang; ++iang) {
432
+ float src_x = src_pos[iang * 2 + 0] / voxel_spacing;
433
+ float src_y = src_pos[iang * 2 + 1] / voxel_spacing;
434
+ float det_cx = det_center_arr[iang * 2 + 0] / voxel_spacing;
435
+ float det_cy = det_center_arr[iang * 2 + 1] / voxel_spacing;
436
+ float u_vec_x = det_u_vec[iang * 2 + 0];
437
+ float u_vec_y = det_u_vec[iang * 2 + 1];
438
+ float n_x = -u_vec_y;
439
+ float n_y = u_vec_x;
440
+
441
+ float plane_dx = det_cx - src_x;
442
+ float plane_dy = det_cy - src_y;
443
+ float plane_dist = plane_dx * n_x + plane_dy * n_y;
444
+ if (metal::abs(plane_dist) <= eps) continue;
445
+
446
+ float rx = px - src_x;
447
+ float ry = py - src_y;
448
+ float denom = rx * n_x + ry * n_y;
449
+ if (metal::abs(denom) <= eps) continue;
450
+
451
+ float t = plane_dist / denom;
452
+ if (t <= 0.0f) continue;
453
+
454
+ float qx = src_x + t * rx;
455
+ float qy = src_y + t * ry;
456
+ float rel_x = qx - det_cx;
457
+ float rel_y = qy - det_cy;
458
+ float u0 = rel_x * u_vec_x + rel_y * u_vec_y;
459
+
460
+ float ru = rx * u_vec_x + ry * u_vec_y;
461
+ float inv_denom = 1.0f / denom;
462
+ float grad_ux = t * u_vec_x - t * ru * inv_denom * n_x;
463
+ float grad_uy = t * u_vec_y - t * ru * inv_denom * n_y;
464
+ float half_u = 0.5f * (metal::abs(grad_ux) + metal::abs(grad_uy));
465
+ half_u = metal::max(half_u, 0.5f * det_spacing_vox);
466
+ float width_u = metal::max(2.0f * half_u, det_spacing_vox);
467
+ float support_u = half_u + 0.5f * det_spacing_vox;
468
+
469
+ float ray_len = metal::sqrt(rx * rx + ry * ry);
470
+ if (ray_len <= eps) continue;
471
+ float dir_x = rx / ray_len;
472
+ float dir_y = ry / ray_len;
473
+ float l_phi = 1.0f / metal::max(metal::max(metal::abs(dir_x), metal::abs(dir_y)), eps);
474
+
475
+ int idet_min = (int)metal::floor(u0 / det_spacing_vox + center_u - support_u / det_spacing_vox);
476
+ int idet_max = (int)metal::ceil(u0 / det_spacing_vox + center_u + support_u / det_spacing_vox);
477
+ idet_min = metal::max(0, idet_min);
478
+ idet_max = metal::min(n_det - 1, idet_max);
479
+
480
+ float fp_lo = u0 - half_u;
481
+ float fp_hi = u0 + half_u;
482
+
483
+ for (int idet = idet_min; idet <= idet_max; ++idet) {
484
+ float pixel_u = ((float)idet - center_u) * det_spacing_vox;
485
+ float pixel_lo = pixel_u - 0.5f * det_spacing_vox;
486
+ float pixel_hi = pixel_u + 0.5f * det_spacing_vox;
487
+ float overlap = metal::min(pixel_hi, fp_hi) - metal::max(pixel_lo, fp_lo);
488
+ if (overlap <= eps) continue;
489
+ float weight = overlap / width_u;
490
+ accum += sino[iang * n_det + idet] * weight * l_phi;
491
+ }
492
+ }
493
+
494
+ grad_image[(int)iy * Nx + (int)ix] = accum;
495
+ """
496
+
497
+ fan_2d_footprint_backward_kernel = mx.fast.metal_kernel(
498
+ name="fan_2d_footprint_backward",
499
+ input_names=["sino", "src_pos", "det_center_arr", "det_u_vec", "params", "fparams"],
500
+ output_names=["grad_image"],
501
+ source=_FAN_2D_FOOTPRINT_BACKWARD_SOURCE,
502
+ )