|
327 | 327 |
|
328 | 328 | # --------------------------------------------------------------------------------------- |
329 | 329 | if cupy_enabled: |
| 330 | + import cupy as cp |
| 331 | + |
330 | 332 | if "PARALLELPROJ_CUDA_KERNEL_FILE" in os.environ: |
331 | 333 | cuda_kernel_file = Path(os.environ["PARALLELPROJ_CUDA_KERNEL_FILE"]) |
332 | 334 | else: |
@@ -536,7 +538,9 @@ def joseph3d_fwd( |
536 | 538 | np.asarray(img.shape, dtype=np.int32), |
537 | 539 | ) |
538 | 540 |
|
539 | | - return xp.asarray(img_fwd, device=array_api_compat.device(img)) |
| 541 | + return array_api_compat.to_device( |
| 542 | + xp.from_dlpack(img_fwd), array_api_compat.device(img) |
| 543 | + ) |
540 | 544 |
|
541 | 545 |
|
542 | 546 | def joseph3d_back( |
@@ -651,7 +655,9 @@ def joseph3d_back( |
651 | 655 | np.asarray(back_img.shape, dtype=np.int32), |
652 | 656 | ) |
653 | 657 |
|
654 | | - return xp.asarray(back_img, device=array_api_compat.device(img_fwd)) |
| 658 | + return array_api_compat.to_device( |
| 659 | + xp.from_dlpack(back_img), array_api_compat.device(img_fwd) |
| 660 | + ) |
655 | 661 |
|
656 | 662 |
|
657 | 663 | def joseph3d_fwd_tof_sino( |
@@ -816,7 +822,9 @@ def joseph3d_fwd_tof_sino( |
816 | 822 | lor_dependent_tofcenter_offset, |
817 | 823 | ) |
818 | 824 |
|
819 | | - return xp.asarray(img_fwd, device=array_api_compat.device(img)) |
| 825 | + return array_api_compat.to_device( |
| 826 | + xp.from_dlpack(img_fwd), array_api_compat.device(img) |
| 827 | + ) |
820 | 828 |
|
821 | 829 |
|
822 | 830 | def joseph3d_back_tof_sino( |
@@ -995,7 +1003,9 @@ def joseph3d_back_tof_sino( |
995 | 1003 | lor_dependent_tofcenter_offset, |
996 | 1004 | ) |
997 | 1005 |
|
998 | | - return xp.asarray(back_img, device=array_api_compat.device(img_fwd)) |
| 1006 | + return array_api_compat.to_device( |
| 1007 | + xp.from_dlpack(back_img), array_api_compat.device(img_fwd) |
| 1008 | + ) |
999 | 1009 |
|
1000 | 1010 |
|
1001 | 1011 | def joseph3d_fwd_tof_lm( |
@@ -1163,7 +1173,9 @@ def joseph3d_fwd_tof_lm( |
1163 | 1173 | lor_dependent_tofcenter_offset, |
1164 | 1174 | ) |
1165 | 1175 |
|
1166 | | - return xp.asarray(img_fwd, device=array_api_compat.device(img)) |
| 1176 | + return array_api_compat.to_device( |
| 1177 | + xp.from_dlpack(img_fwd), array_api_compat.device(img) |
| 1178 | + ) |
1167 | 1179 |
|
1168 | 1180 |
|
1169 | 1181 | def joseph3d_back_tof_lm( |
@@ -1343,7 +1355,9 @@ def joseph3d_back_tof_lm( |
1343 | 1355 | lor_dependent_tofcenter_offset, |
1344 | 1356 | ) |
1345 | 1357 |
|
1346 | | - return xp.asarray(back_img, device=array_api_compat.device(img_fwd)) |
| 1358 | + return array_api_compat.to_device( |
| 1359 | + xp.from_dlpack(back_img), array_api_compat.device(img_fwd) |
| 1360 | + ) |
1347 | 1361 |
|
1348 | 1362 |
|
1349 | 1363 | if cupy_enabled: |
@@ -1439,7 +1453,7 @@ def count_event_multiplicity(events: Array) -> Array: |
1439 | 1453 | else: |
1440 | 1454 | tmp = np.unique(events, axis=0, return_counts=True, return_inverse=True) |
1441 | 1455 |
|
1442 | | - mu = xp.asarray(tmp[2][tmp[1]], device=dev) |
| 1456 | + mu = array_api_compat.to_device(xp.from_dlpack(tmp[2][tmp[1]]), dev) |
1443 | 1457 | mu = xp.reshape(mu, (array_api_compat.size(mu),)) |
1444 | 1458 |
|
1445 | 1459 | return mu |
|
0 commit comments